projects github about
Raspberry Pi 3 Alpine Linux arm64
*** 18-09-20: Will update soon...
*** 17-07-06: To fix brcmfmac loading error: directly place brcm folder inside our custom initramfs-rpi3 file.
*** 17-07-06: b43 is optional…

As i was been busy studying and learning about Docker and how nice it is to use Alpine linux as the docker image for .NetCore because of it being small in size… unlike using ubuntu as a docker image file…This time… i decided to try Alpine linux on Raspberry Pi 3.

Alpine 3.7 Generic arm64file_download

Make sure SquashFS is enabled
1
2
3
4
5
// Kernel config

File systems
    |-  Miscellaneous filesystems
        |-  [*] SquashFS 4.0
For our custom kernel and U-boot… just follow Raspberry Pi 3 64-bit kernel.

The files that we need from alpine to modify is initramfs-vanilla, and a copy of apk folder (alpine.apkovl.tar.gz is optional). so go ahead and extract them.

initramfs-vanilla is a compressed cpio archive. To extract it we do this:

1
2
3
mkdir $HOME/temp
cd $HOME/temp
sudo gunzip -c /boot/initramfs-vanilla | cpio -i

Then we need to install our latest modules into it…assuming you already compiled a kernel following this Raspberry Pi 3 64-bit kernel.

1
2
3
4
5
6
7
8
9
sudo ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -C rpi-4.14/ modules_install INSTALL_MOD_PATH=$HOME/temp/
        
        # When it is done go back to /temp/ folder where we extract the initramfs and into the modules folder.

cd $HOME/temp/lib/modules/
        
        # And remove the previous version and the build, source folder symlink in $HOME/temp/lib/modules/4.1x~/ folder

sudo rm -rf 4.9~/

Now we have our custom initramfs and then recreate the compressed cpio archive again. Inside the folder run:

1
2
3
sudo find . | cpio -H newc -o | gzip -9 > [file destination]/initramfs-rpi3-cpio
cd ..
sudo mkimage -A arm64 -O linux -T ramdisk -d initramfs-rpi3-cpio initramfs-rpi3 // For U-boot

modloop-vanilla is a squashfs file. We can make from scratch or unsquash it using this command:

1
sudo unsquashfs -f -d [file destination] [file location]/file.squashfs

To create our own modloop file let start by making a folder

1
2
sudo mkdir modules 
        # Then inside this module, let's install again our rpi-4.11y modules from above

After you’ve installed our modules from above on the modules folder that we’ve just created.. you’ll have a folder structure like so:

1
2
3
4
5
6
7
8
/modules
        |- /lib
                |- /firmware
                        # firmware_install INSTALL_FW_PATH=[in this location or just use from the moodlop-vanilla]
                        # Use firmware_install if using kernel <- 4.13

                |- /modules
                        # again remove build and source symlink folder here

Rearrange above modules folder to:

1
2
/modules/modules/firmware
/modules/modules/4.1x~

Squash it using this command:

1
sudo mksquashfs [folder to be squash] [filename] -comp [compression method: I use 'xz' -Xdict-size 100%

And now we have our own initramfs-rpi3 and modloop-rpi3. Our µsd card should now look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
/apk
/boot/Image
/boot/u-boot.bin
/boot/boot.scr
/boot/initramfs-rpi3
/boot/modloop-rpi3
bcm2710-rpi-3-b.dtb
bootcode.bin
start.elf 
fixup.dat 
config.txt
cmdline.txt
alpine.apkovl.tar.gz // optional will be created once we setup our alpine linux

We’ll modify the cmdline.txt and boot.scr for alpine linux. alerts/code.html type=”cmdline.txt:” code=”

1
2
3
modules=loop,squashfs,sd-mod,usb-storage quiet net.ifnames=0 dwc_otg.lpm_enable=0 console=ttyS0,115200 fsck.repair=yes rootwait

# the quiet command can be remove: it just hide the message buffer of kernel. `ttyS0` can be replace by `ttyAMA0`
1
2
3
4
5
6
7
8
9
fdt addr 0x100
fdt get value bootargs /chosen bootargs
setenv kernel_addr_r 0x01000000
setenv ramdisk_addr_r 0x02100000
fatload mmc 0:1 ${kernel_addr_r} boot/Image
fatload mmc 0:1 ${ramdisk_addr_r} boot/initramfs-rpi3
setenv initrdsize $filesize
fatload mmc 0:1 ${fdt_addr_r} bcm2710-rpi-3-b.dtb
booti ${kernel_addr_r} ${ramdisk_addr_r}:${initrdsize} ${fdt_addr_r}

Go ahead noew and try to boot it up. You should have an output like this:

As you can see… there’s a hwclock error since our raspberry pi 3 don’t have any. So after you run setup-alpine and use lbu commit to save changes…run this:

1
2
rc-update add swclock boot    // enable the software clock
rc-update del hwclock boot    // disable the hardware clock

In my case i use Busybox NTP as it might be the most lightweight solution. Save the changes and reboot.

1
2
3
lbu commit
apk add wireless-tools wpa_supplicant  // will be installed even when not connected to the net
reboot


Wifi: (*Optional)

I didn’t include the brcm above because i encouter a brcmf_sdio_htclk error but can be resolve by reloading the module: brcmfmac The good thing about alpine linux is if you make a firmware folder on the root directory of our µsd card, it’ll be recognized by alpine and load it once alpine boot up. Don’t worry if the rest of the folder inside the OS fimrware folder is gone(it’s just hidden in plain site). So i place my brcm folder there for now.

According to alpine linux… Connecting to a wireless access point Broadcom Wi-Fi Chipset Users: we need b43-firmware so go ahead and follow that or we can compile it somewhere else like what i did.

On ubuntu 16.04 i install b43-fwcutter then get b43-firmware and follow the instruction here

1
2
tar -xjf broadcom-wl-4.150.10.5.tar.bz2       // make sure bzip is installed
b43-fwcutter -w [$FIRMWARE_INSTALL_DIR/b43] broadcom-wl-4.150.10.5/driver/wl_apsta_mimo.o

Then copy that b43 folder to firmware folder on the root of our µsd card.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/apk
/boot/Image
/boot/kernel8.img
/boot/boot.scr
/boot/initramfs-rpi3
/boot/modloop-rpi3
/firmware/b43
/firmware/brcm
bcm2710-rpi-3-b.dtb
bootcode.bin
start.elf 
fixup.dat 
config.txt
cmdline.txt
alpine.apkovl.tar.gz # optional will be created once we setup our alpine linux

Load the b43 kernel and enable it at boot up:

1
2
3
modprobe b43
echo b43 >> /etc/modules
lbu commit    // To save changes

If you run dmesg command and display a brcmfmac error just reload brcmfmac module:

1
2
modprobe -r brcmfmac  // For now
modprobe brcmfmac


Reference :

http://backreference.org/2010/07/04/modifying-initrdinitramfs-files/
https://askubuntu.com/questions/437880/extract-a-squashfs-to-an-existing-directory
https://wiki.alpinelinux.org/wiki/DIY_Fully_working_Alpine_Linux_for_Allwinner_and_Other_ARM_SOCs
https://wiki.alpinelinux.org/wiki/Raspberry_Pi