Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Apr 20, 2022
0 parents commit af3642d
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifacts/
stage/
mnt/
Binary file added Images/installing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Kouji Matsui

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Setup latest Debian mipsel on qemu malta

Reference:
https://gist.github.com/extremecoders-re/3ddddce9416fc8b293198cd13891b68c

----

## How to use it

Perhaps the script needs to be modified slightly to match the latest image. I used [Latest Debian 11 (bullseye) from "debian-11.3.0-mipsel-netinst.iso"](http://cdimage.debian.org/cdimage/release/current/mipsel/iso-cd/debian-11.3.0-mipsel-netinst.iso) as a base.

1. Run `build.sh`, it will download cd image from debian server, build qcow virtual hard disk image and run debian installer.

![installing](Images/installing.png)

2. Rebooted in finally installation step, choose `Execute shell` from menu and do `poweroff` command, then will exit qemu.

3. Ready to use. Run `run.sh` then raise up debian 11 mipsel on qemu!

![run](Images/run.png)

### Enabled ssh forwarding on port 2222

```bash
ssh localhost -p 2222
```

Have fun!

----

## Background

It's completely off-topic, and probably a strange nerd story :)

I am developing [a .NET library for video capture](https://github.com/kekyo/FlashCap).
I thought this library should be tested in a variety of environments in order to be truly multi-platform.
So, I was looking for a somewhat minor environment in which .NET (actually mono) would work,
and ["Imagination Creator Ci20" was found.](https://uk.rs-online.com/web/p/single-board-computers/1253305)

The Ci20 is a MIPS 32-bit architecture that is still barely available and can operate as a USB host.
It seemed feasible to perform video capture via V4L2, supporting USB Video Class.
So, we quickly obtained this board and found that only supports Debian 8 (jessie) and
Moreover, it seemed to have been removed from the supported list as a beta release.

After [some information and trial and error](https://gist.github.com/kekyo/1d851907bf5b59ddb204448de3b18383),
I succeeded in applying the latest binary packages for Debian 8.
Apparently there is still an eMMC access bug in the kernel, which causes the system to stop
with UBIFS-derived panic when I/O is under high load.
Also, I need a relatively new version of Clang, but Debian 8 only has an older version,
and If I try to build it on my own, I get the above panic and am out of luck.

I wish I could fix this kernel fundamentally, but unfortunately, I do not have that much knowledge.
So I have decided to take other steps.

I realized that building the code on a modern Debian 11 using qemu's mipsel emulation would work fine,
so I created this script by trial and error from my sources.

----

## License

MIT
79 changes: 79 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# https://gist.github.com/extremecoders-re/3ddddce9416fc8b293198cd13891b68c

#--------------------------------------------
# Require these packages.
echo "sudo apt install qemu qemu-system-mips qemu-utils"
sudo apt install qemu qemu-system-mips qemu-utils

#--------------------------------------------
# Enable qcow mounter.
sudo modprobe nbd max_part=8

#--------------------------------------------
# Create staging directories.
if [ ! -d artifacts ]; then
mkdir artifacts
fi
if [ ! -d stage ]; then
mkdir stage
fi
if [ ! -d mnt ]; then
mkdir mnt
fi

#--------------------------------------------
# Download debian image.
cd artifacts

# Choose mirror server and latest image file.
if [ ! -f debian-*.iso ]; then
wget http://cdimage.debian.org/cdimage/release/current/mipsel/iso-cd/debian-11.3.0-mipsel-netinst.iso
fi

cd ..

#--------------------------------------------
# Extract installer kernel image and root filesystem image.

sudo mount -r -t iso9660 artifacts/debian-*.iso mnt/
cp mnt/install/malta/netboot/vmlinuz* artifacts/vmlinuz-netinst
cp mnt/install/malta/netboot/initrd* artifacts/initrd-netinst.gz
sudo umount mnt/

#--------------------------------------------
# Create hard disk image.

cd stage
qemu-img create -f qcow2 hda.qcow 16G

#--------------------------------------------
# Install debian.

qemu-system-mipsel \
-M malta \
-m 1024 \
-cdrom ../artifacts/debian-*.iso \
-hda hda.qcow \
-kernel ../artifacts/vmlinuz-netinst \
-initrd ../artifacts/initrd-netinst.gz \
-boot d \
-nographic \
-append "root=/dev/sda1 nokaslr"

cd ..

#--------------------------------------------
# Extract bootable kernel image and root filesystem image.

sudo qemu-nbd --connect=/dev/nbd0 `pwd`/stage/hda.qcow
sudo mount -r /dev/nbd0p1 `pwd`/mnt
cp mnt/boot/vmlinuz* stage/vmlinuz
cp mnt/boot/initrd* stage/initrd.img
sudo umount /dev/nbd0p1
sudo qemu-nbd --disconnect /dev/nbd0

#--------------------------------------------

echo "Done."
19 changes: 19 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

#--------------------------------------------
# Run debian on qemu.

cd stage

qemu-system-mipsel \
-M malta \
-m 2048 \
-hda hda.qcow \
-kernel vmlinuz \
-initrd initrd.img \
-append "root=/dev/sda1 console=ttyS0 nokaslr" \
-nographic \
-net user,hostfwd=tcp:127.0.0.1:2222-:22 \
-net nic,model=e1000-82545em

cd ..

0 comments on commit af3642d

Please sign in to comment.