diff --git a/.clang-format b/.clang-format index 001deef8..3715edfd 100644 --- a/.clang-format +++ b/.clang-format @@ -3,3 +3,4 @@ IndentWidth: 4 UseTab: Never ColumnLimit: 100 AllowShortFunctionsOnASingleLine: Inline +SortIncludes: false diff --git a/.gitignore b/.gitignore index 5d5742ef..0840359c 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ videos/** .piolibdeps lib/ .vscode/ +bin diff --git a/brick/Makefile b/brick/Makefile new file mode 100644 index 00000000..857f8dbd --- /dev/null +++ b/brick/Makefile @@ -0,0 +1,12 @@ +all: mod uf2 + +mod: + $(MAKE) -C .. MOD=d_usbdev M=`pwd`/kernel ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- + @mkdir -p bin + cp kernel/*.ko bin/ + +uf2: + $(MAKE) -C uf2daemon + @mkdir -p bin + cp uf2daemon/server bin/uf2daemon + diff --git a/brick/README.md b/brick/README.md new file mode 100644 index 00000000..aab6706b --- /dev/null +++ b/brick/README.md @@ -0,0 +1,34 @@ +# Support code to run on EV3 brick + +## Kernel module + +Kernel module is based on LEGO's `d_usbdev` module, with the addition of slightly modified `g_mass_storage` +module from the Linux kernel. The module and supporting sources are licensed under GPLv2 (since +they are derived from GPLv2 code). + +### Modifications + +* the `d_usbdev` uses the composite framework to register an additional mass storage function in addtion + to the pre-existing custom USB HID function +* the `g_mass_storage` module has the following changes: + * a bug fixed, where page-misaligned writes would hang + * additional `/sys/.../lun0/active` entry is added, which allows for signaling drive eject to the host + +### Kernel modifications + +The kernel itself has modified FIFO queue sizes. The LEGO kernel uses `1024` for `ep1in` and `ep1out`, +and then `64` for `ep2` and `ep3`. Note that this is non-standard modification done with a kernel patch, +that I didn't manage to find. The MSD requires `512` for `ep2` and `ep3`. I have binary edited the kernel +to do so. + +Note that there's 4k of FIFO memory in the hardware. If you set the queue sizes with a sum of more than +4k, the kernel will hang, and you will not know why. + +## UF2 Daemon + +The [UF2](https://github.com/Microsoft/uf2) daemon is based on +[UF2 ATSAMD21](https://github.com/Microsoft/uf2-samd21) bootloader code. It exposes a virtual +FAT16 file system over Linux Network Block Device interface (`/dev/nbd0` to be precise). +This device is then exposed via the `g_mass_storage` module to the host computer. + +The Daemon is licensed under MIT. diff --git a/brick/ins b/brick/ins new file mode 100755 index 00000000..c1c3c35d --- /dev/null +++ b/brick/ins @@ -0,0 +1,22 @@ +#!/bin/sh +set -ex +cd /mnt/ramdisk/prjs/ko +insmod ./nbd.ko +sleep 1 +./nbd-serv & +sleep 1 +insmod ./d_usbdev.ko file=/dev/nbd0 HostStr=EV3 SerialStr=0016535543af +L=/sys/devices/platform/musb_hdrc/gadget/lun0 +echo $L +echo -n "ent: " +read LINE +#echo > $L/file +echo 3 > $L/reset +killall nbd-serv +sleep 1 +./nbd-serv & +sleep 1 +#echo /dev/nbd0 > $L/file +#sleep 1 +echo 4 > $L/reset + diff --git a/brick/mk b/brick/mk new file mode 100755 index 00000000..ac3922a3 --- /dev/null +++ b/brick/mk @@ -0,0 +1,7 @@ +#!/bin/sh +set -xe +scp -qr * vm:linux/pxt/ +ssh vm "cd linux/pxt; make $1" +mkdir -p bin +scp vm:linux/pxt/bin/* bin/ + diff --git a/brick/send b/brick/send new file mode 100755 index 00000000..ff9e6704 --- /dev/null +++ b/brick/send @@ -0,0 +1,8 @@ +#!/bin/sh + +./mk +ev3duder up bin/d_usbdev.ko ../prjs/ko/d_usbdev.ko +ev3duder up bin/nbd.ko ../prjs/ko/nbd.ko +ev3duder up bin/nbd-serv ../prjs/ko/nbd-serv +ev3duder up ins ../prjs/ko/ins +