Alpine Linux on the Duo?

I’ve been messing around with Alpine on the Raspberry Pi Zero as of late for a personal project. Has anyone here tried getting Alpine running on the Duo? I imagine it would run a bit slower than the Buildroot, but could be more capable.

I build the image, loop mount, and then replace rootfs with alpine. (need to copy many files and lib from the original image to alpine) The result is quite perfect.

Do you think you can upload the image to GitHub or somewhere else? Thanks.

Let me refine some parts of it, then I will upload my final image.

@boba here the image and instruction. Release Proof of Concept 1 · cwt/duo-buildroot-sdk · GitHub

2 Likes

Thanks! I’ll be sure to check it out when I get the chance…

1 Like

I tried it :slight_smile: - thanks!

My feedback:

I tried Ubuntu (as posted in Ubuntu on the milk-v duo) but apt is really slow, so for now ArchLinux and AlpineLinux are the best choices with a decent package manager.

may be you ran it before the RTC was set? I will take some time after boot to be able to get time from the NTP server.

I didn’t use rndis much, but I use ethernet on the IO board. I added this file:

milkv-duo:~# cat /etc/network/if-pre-up.d/set_eth0_mac 

#!/bin/sh

if test -d /sys/class/net/eth0; then
	ifconfig eth0 down
	ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX  # <-- there should be some algorithm to ensure that this MAC is unique and without overlapping any some well-known manufacturers?
	ifconfig eth0 up
fi

Just apk update && apk upgrade today, there is something wrong with clang-17:

milkv-duo:~# clang
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang
1.	Compilation construction
Illegal instruction

while dmesg show this:

[  300.985245] clang[1570]: unhandled signal 4 code 0x1 at 0x0000003fe2314a46 in libLLVM-17.so[3fe1696000+7a8d000]
[  301.000945] CPU: 0 PID: 1570 Comm: clang Tainted: GF          O      5.10.4-tag- #4
[  301.008917] epc: 0000003fe2314a46 ra : 0000003fe2314a46 sp : 0000003fffdd8110
[  301.016318]  gp : 0000002ae3503800 tp : 0000003fed535e68 t0 : 0000000000000039
[  301.023872]  t1 : 0000003fed5339b0 t2 : 0000000000000036 s0 : 0000003fe1181410
[  301.031405]  s1 : 0000003fe1167400 a0 : 000000000213c800 a1 : 0000000000000015
[  301.038938]  a2 : 0000000000000000 a3 : 0000000000200000 a4 : 000000000233c800
[  301.046437]  a5 : 000000000213c800 a6 : 000000007fffffff a7 : 0000002ae3507cb4
[  301.053928]  s2 : ffffffffffffffff s3 : 0000003fffdd8330 s4 : ffffffffffffffff
[  301.061418]  s5 : 0000003fe11673b0 s6 : 0000003fffdd82e8 s7 : 0000003fe1181410
[  301.068907]  s8 : 0000003fffdd8680 s9 : 0000000000000001 s10: 0000003febbd3d22
[  301.076397]  s11: 0000003fffdd8340 t3 : 0000003fed4c0b72 t4 : 0000000000000006
[  301.083884]  t5 : 0000000000000008 t6 : 000000000000002d
[  301.089402] status: 8000000201804020 badaddr: 000000008330000f cause: 0000000000000002

I guess that the instruction code in libLLVM-17.so contains something that cannot be executed on Duo.

1 Like

Would you mind listing the kernel config changes needed?

Do you mean this?

Just a big “Thank you!” to CWT (and to SpritDude) for the Alpine image. I’ve had a lot of fun playing around with this over the past couple of weeks.

A couple of tips which might help others:-

If you’re using Linux for the server-side of the USB-RNDIS connection, it helps if you use the network manager utility (on the Linux machine) to create a static IPV4 address for usb0, so that it automatically assigns 192.168.42.2 (netmask=24, leave the gateway blank).
This will create a stable connection as soon as the Duo kicks off RNDIS.

Once you’ve logged into the Duo (and set a default route with 192.168.42.2 as the gateway), you can use the command “chronyc makestep” to immediately sync the RTC with NTP. This will fix the “apk” failures and allow you to load new packages.

Thanks again folks!

4 Likes

For Milk-V Duo 256M: milkv-duo-256m-alpinelinux-cwt-2023-10-28.zip - Google Drive

2 Likes

I’ve been playing with this build quite happily.

There’s one - rather wild - issue when trying to compile wiringX for use with the mailbox_test utility:

milkv-duo:/install/wiringx/src/wiringX-a6bb3092d262f9801a685a4591eff937fbd4a403/src$ cmake ..
Illegal instruction
ilkv-duo:/install/wiringx# dmesg| tail -14
[13724.270094] cmake[1617]: unhandled signal 4 code 0x1 at 0x0000002ad0e9df8c in cmake[2ad0adc000+940000]
[13724.279860] CPU: 0 PID: 1617 Comm: cmake Tainted: GF          O      5.10.4-tag- #1
[13724.287819] epc: 0000002ad0e9df8c ra : 0000002ad0e9dfca sp : 0000003fffcb6620
[13724.295253]  gp : 0000002ad143a7f0 tp : 0000003fcf160d98 t0 : 0000000000000055
[13724.302769]  t1 : 0000002ad0b3f45c t2 : 0000003fcf15e558 s0 : 0000003fce7a3138
[13724.310276]  s1 : 0000003fffcb66b8 a0 : 0000003fce795870 a1 : 0000003fce79afa0
[13724.317782]  a2 : 0000000000000000 a3 : 0000003fce7958a0 a4 : 0000003fce7958b8
[13724.325288]  a5 : 0000003fce795870 a6 : f1f64841f8711880 a7 : 0000003fce78f5e0
[13724.332794]  s2 : 0000003fffcb6698 s3 : 0000000000000010 s4 : 0000003fcf15e558
[13724.340300]  s5 : 0000003fce79b540 s6 : 0000003fffcb66a8 s7 : 0000000000000000
[13724.347806]  s8 : 0000003fcf15e558 s9 : 0000000000000000 s10: 0000003fffcb68f8
[13724.360282]  s11: 0000000000000001 t3 : 0000003fcf116c16 t4 : 0000000000000045
[13724.376294]  t5 : 0000000000000043 t6 : 0000000000000052
[13724.388289] status: 8000000201804020 badaddr: 000000008330000f cause: 0000000000000002

i looked at the Risc-V ISA but i’m too stupid to decode 000000008330000f.
I found some chinese posts in the forum here where one set GNUTLS_CPUID_OVERRIDE=3 (or 0x3?) but basically not even 0x1 has done anything for me.

Any idea what to do here?

  • clang-16 also runs into an illegal instruction.

What would you do?

edit: just noticed that you ran into that before…

I found a post yesterday saying that they got donated two Pioneer builders, so it would be possible that it’s some difference between the CPU on the Milk-V and the Pioneer!

One more finding, after googling explicitely for the above code.

https://support.primatelabs.com/discussions/geekbench/81697-risc-v-geekbench-54-preview-fails-with-illegal-instruction-on-some-chips

Quotes:

  1. “It could be related to fact that some risc-v doesn’t handle unaligned memory access well”
  2. “[…] FENCE.TSO instruction should not crash on boards that support the FENCE instruction but not the FENCE.TSO instruction.”

So, this apparently some instruction that concerns memory regions is failing here on the duo. Amazingly working with SBCs really gets you closer to the hardware :wink:
I don’t know if there could be a microcode update that changes the behaviour.

I think the tl;dr is we need to keep the bootstrap’d clang and cmake if we want something working. The upstream builder’s code will not match with the Duo CPU and the CPU seems to not correctly handle this case.
We could probably successfully apk build the affected packages on a Duo S for peformance.
I did also report this on the alpine-devel list, but no feedback so far.

The newer compiler used to make the debian/arch images emits a FENCE.TSO instruction which is not supported on the C906 implemented in the CV200x (and I suspect the CV180x as well although I don’t own one to test)

You need these patches for opensbi that will emulate the FENCE.TSO instructions:

1 Like

Kudos to you for helping out here!
edit: it works, I manually applied the patches, and cmake no longer crashes with Illegal instruction. Trying to build wiringx now :slight_smile:

Everything works.

  • manually apply patch
  • Rebuild from buildroot
  • change build config to free memory, rebuild again

I set it to be only 1M multimedia memory for FreeRTOS from the original 27MB. This way there’s enough RAM for the OS to run well. At 32MB it was unbearable.

Get the files from /boot in image.

root@sdk-duo:/scratch/duo-buildroot-sdk# mount /dev/mapper/loop7p1 /mnt/milk
root@sdk-duo:/scratch/duo-buildroot-sdk# ls /mnt/milk
boot.sd  fip.bin
root@sdk-duo:/scratch/duo-buildroot-sdk# ls -l /mnt/milk
total 3142
-rwxr-xr-x 1 root root 2896068 Apr 12 01:29 boot.sd
-rwxr-xr-x 1 root root  317952 Apr 12 01:29 fip.bin
root@sdk-duo:/scratch/duo-buildroot-sdk# ls -lh /mnt/milk
total 3.1M
-rwxr-xr-x 1 root root 2.8M Apr 12 01:29 boot.sd
-rwxr-xr-x 1 root root 311K Apr 12 01:29 fip.bin

You need to drop them on the SD card (scp into live system or put the SD card in another computer)

  • abuild build wiringX package (make clean! ensure the fix_time_t.patch patch is applied) gives me ./packages/install/riscv64/wiringx-0_git20240319-r2.apk. The patch to build for riscv is also upstreamed.
  • test the compiled library via mailbox_test

I think it works!!?

milkv-duo:/opt/milkv# ./mailbox_test 
C906B: cmd.param_ptr = 0x4
C906B: cmd.param_ptr = 0x3

(it’s been so many intermediate steps to get here I don’t even remember where the documentation was)