Skip to content

Instantly share code, notes, and snippets.

@axcxl
Last active May 17, 2020 15:43
Show Gist options
  • Save axcxl/c9ed143333f10115f09296217bb72976 to your computer and use it in GitHub Desktop.
Save axcxl/c9ed143333f10115f09296217bb72976 to your computer and use it in GitHub Desktop.
Manually installing Debian Buster on old BananaPi board in 2019

Toolchain for u-boot

Used: arm-linux-gnueabihf-gcc (Linaro GCC 6.4-2017.08) 6.4.1 20170707

U-Boot

I used mainline u-boot for this - tested with 2019.10-rc3:

git clone https://gitlab.denx.de/u-boot/u-boot.git
cd u-boot
make Bananapi_defconfig
make -j$(nproc) CROSS_COMPILE=arm-linux-gnueabihf-

NOTE: latest u-boot requires swig! (apt-get install swig)

You need two files: u-boot-sunxi-with-spl.bin and the device tree u-boot.dtb (still investigating if this is the correct DT).

Rootfs and kernel - Debian

Card preparation

Manually formatted card with two partitions using Gparted. Used MBR partition table and created:

  • boot partition - 16MB - FAT16 partition starting from 1M offset
  • rootfs partition - the reset of the space - EXT4 partition

Install u-boot to card

Do this after the formatting:

dd if=u-boot-sunxi-with-spl.bin of=${card} bs=1024 seek=8

WARNING: DO NOT USE THE PARITION, write directly to the card (ex: /dev/sdh, not /dev/sdh1!) NOTE: the file does not appear in the partition! Not sure if there is a better way.

At this stage the SD card can be tested in the board: plug it in, plug in a 3.3V serial in UART0(TX <--> RX; RX <--> TX), open a terminal with 115200 baud and see u-boot starting.

Install rootfs and kernel to card

I used debootstrap to install these to the card. Plug in the card and make sure the rootfs partition is mounted somewhere. First install these on the host PC:

apt-get install debootstrap  qemu-user-static

Then run bootstrap first stage:

debootstrap --arch=armhf --foreign buster <rootfs mount point>

If you get an error about noexec or nodev, use sudo mount -o remount,exec,dev <rootfs mount point> Chroot to the initial image:

cp /usr/bin/qemu-arm-static /<rootfs mount point>/usr/bin/
chroot <rootfs mount point> /usr/bin/qemu-arm-static /bin/sh -i

Start the second stage

/debootstrap/debootstrap --second-stage

Then deviated a little from the sunxi guide and used the Debian one:

apt-get install makedev
mount none /proc -t proc
cd /dev
MAKEDEV


editor /etc/adjtime

Here is a sample:
0.0 0 0.0
0
UTC

dpkg-reconfigure tzdata

systemctl enable serial-getty@ttyS0.service
systemctl set-default multi-user.target

apt-get install locales
dpkg-reconfigure locales

Now the system should be up, and it only needs a kernel:

apt search linux-image

Then install the kernel package of your choice using its package name.
# apt install linux-image-arch-etc

Booting the image

Manually - this is good for the proof-of-concept

  • Stop u-boot autoboot
  • Set the following env variables
setenv bootargs console=ttyS0,115200n8 root=/dev/mmcblk0p2 rootwait panic=10
ext4load mmc 0:2 ${fdt_addr_r} boot/u-boot.dtb
ext4load mmc 0:2 ${kernel_addr_r} boot/vmlinuz-4.19.0-5-armmp <replace with correct version>
ext4load mmc 0:2 ${ramdisk_addr_r} boot/initrd.img-4.19.0-5-armmp <replace with correct version>
  • Boot the image - NOTE: initrd last for filesize to work!
bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}

WARNING: if you get a kernel panic about not finding init adjust the root=/dev/<device>

Automate the start after the manual part works

Run these commands. The saveenv part makes it permanent.

setenv bootargs console=ttyS0,115200n8 root=/dev/mmcblk0p2 rootwait panic=10
setenv bootcmd_mine 'ext4load mmc 0:2 \${fdt_addr_r} boot/u-boot.dtb; ext4load mmc 0:2 \${kernel_addr_r} vmlinuz; ext4load mmc 0:2 \${ramdisk_addr_r} initrd.img; bootz \${kernel_addr_r} \${ramdisk_addr_r}:\${filesize} \${fdt_addr_r};'
setenv bootcmd "run bootcmd_mine"
saveenv

References

NOTES

  • Make sure that the following line is in /etc/fstab:
/dev/mmcblk0p2 /        ext4    defaults                        0       1

Otherwise the rootfs will be mounted RO all the time.

  • The normal kernel seems to hang from time to time, might the SD card speed. Trying the RT version now.
  • To solve the "IR event FIFO is full!" in dmesg, only option for now - blacklist the modules
cat /etc/modprobe.d/blacklist.conf
blacklist ir_lirc_codec
blacklist lirc_dev
blacklist sunxi-cir
  • In case you notice long startup times for ssh server (or any other software calling getrandom(), see debian bug #912087) on your device, it can be alleviated by installing haveged package:
apt-get install haveged

https://linux-sunxi.org/Debootstrap

Optimizations

Disable logging to save the card

Disabled everything in /etc/rsyslog.conf.

https://linux-sunxi.org/Optimizing_system_performance#Reducing_system_logging_activity

Optimize cache

Added this script to /etc/profile.d/xdg_cache_home.sh:

 #!/bin/bash
export XDG_CACHE_HOME="/run/shm/.cache

https://linux-sunxi.org/Optimizing_system_performance#Optimizing_cache_directories

Save SD card writes

Add noatime to /etc/fstab -> /dev/mmcblk0p2, after defaults

Turn off some memory usage in the video part (I am using this as a headless server)

setenv bootargs console=ttyS0,115200n8 root=/dev/mmcblk0p2 rootwait panic=10 sunxi_ve_mem_reserve=0 cma=96M sunxi_g2d_mem_reserve=0 sunxi_fb_mem_reserve=16
saveenv

Initially, had 616.7M free, now have 916.8M free (according to top)

(source https://linux-sunxi.org/Kernel_arguments )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment