Skip to content

Commit

Permalink
bananapi: switch to skiff-init-squashfs and fix u-boot
Browse files Browse the repository at this point in the history
 - update u-boot scripts
 - use skiff-init-squashfs instead of ramdisk
 - increase partition sizes
 - add buildimage
 - disable smartd

BREAKING CHANGE: partition layout change for bananapi

Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Apr 13, 2023
1 parent 06247e5 commit f802fbe
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 123 deletions.
14 changes: 14 additions & 0 deletions configs/bananapi/common/buildroot/target
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# use skiff-init-squashfs
BR2_PACKAGE_SKIFF_INIT_SQUASHFS=y
BR2_PACKAGE_SKIFF_INIT_SQUASHFS_MUTABLE_OVERLAY_SIZE="25%"
BR2_PACKAGE_SKIFF_INIT_SQUASHFS_PATH="/rootfs.squashfs"
BR2_PACKAGE_SKIFF_INIT_SQUASHFS_RESIZE2FS_BIN_PATH="/skiff-init/resize2fs"
BR2_PACKAGE_SKIFF_INIT_SQUASHFS_RESIZE2FS_CONF_PATH="/skiff-init/resize2fs.conf"
BR2_PACKAGE_SKIFF_INIT_SQUASHFS_RESIZE2FS=y
BR2_PACKAGE_SKIFF_INIT_SQUASHFS_ROOT_AS_BOOT=y
# BR2_PACKAGE_SKIFF_INIT_SQUASHFS_ROOT_AS_PERSIST is not set
BR2_PACKAGE_SKIFF_INIT_RESIZE2FS=y

# BR2_TARGET_ROOTFS_CPIO is not set
BR2_TARGET_ROOTFS_SQUASHFS=y
BR2_TARGET_ROOTFS_SQUASHFS4_LZ4=y
6 changes: 6 additions & 0 deletions configs/bananapi/common/hooks/post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -eo pipefail

IMAGES_DIR=${SKIFF_BUILDROOT_DIR}/images
mkdir -p ${IMAGES_DIR}/skiff-init
cp ${SKIFF_CURRENT_CONF_DIR}/resources/resize2fs.conf ${IMAGES_DIR}/skiff-init/resize2fs.conf
1 change: 1 addition & 0 deletions configs/bananapi/common/metadata/commands
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
format Format a SD card and install bootloader.
install Installs to a formatted SD card.
buildimage Builds an image using a loopback device.
1 change: 1 addition & 0 deletions configs/bananapi/common/resources/resize2fs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dev/mmcblk0p2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export PERSIST_DEVICE="/dev/mmcblk0p2"
export ROOTFS_DEVICE="/mnt/persist/rootfs"
export ROOTFS_MNT_FLAGS="--rbind"
export ROOTFS_DEVICE_MKDIR="true"
43 changes: 43 additions & 0 deletions configs/bananapi/common/scripts/build_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

if [ $EUID != 0 ]; then
echo "This script requires sudo, so it might not work."
fi

set -e

if [ -z "$PI_IMAGE" ]; then
echo "Please set PI_IMAGE to the path to the output image."
exit 1
fi

if [[ "$PI_IMAGE" != /* ]]; then
# the "make" command is run from the skiff root,
# it's most intuitive to take that as the base path
PI_IMAGE=$SKIFF_ROOT_DIR/$PI_IMAGE
fi

echo "Allocating sparse image..."
fallocate -l 1.5G $PI_IMAGE

echo "Setting up loopback device..."
export PI_SD=$(losetup --show -fP $PI_IMAGE)
function cleanup {
echo "Removing loopback device..." || true
sync || true
losetup -d $PI_SD || true
}
trap cleanup EXIT

if [ -z "${PI_SD}" ] || [ ! -b ${PI_SD} ]; then
echo "Failed to setup loop device."
exit 1
fi

# Setup no interactive since we know its a brand new file.
export SKIFF_NO_INTERACTIVE=1
export DISABLE_CREATE_SWAPFILE=1

echo "Using loopback device at ${PI_SD}"
$SKIFF_CURRENT_CONF_DIR/scripts/format_sd.sh
$SKIFF_CURRENT_CONF_DIR/scripts/install_sd.sh
24 changes: 9 additions & 15 deletions configs/bananapi/common/scripts/format_sd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,20 @@ set -x
set -e

echo "Zeroing out partition table..."
dd if=/dev/zero of=${PI_SD} conv=fsync bs=1024 count=4900
sudo dd if=/dev/zero of=${PI_SD} conv=fsync bs=1024 count=4900

echo "Formatting device..."
parted $PI_SD mklabel msdos
sudo parted $PI_SD mklabel msdos

echo "Making boot partition..."
parted -a optimal $PI_SD mkpart primary fat32 100MiB 410MiB

echo "Making rootfs partition..."
parted -a optimal $PI_SD mkpart primary ext4 410MiB 600MiB
sudo parted -a optimal $PI_SD -- mkpart primary fat16 0% 1G

echo "Making persist partition..."
parted -a optimal $PI_SD -- mkpart primary ext4 600MiB "-1s"
sudo parted -a optimal $PI_SD -- mkpart primary ext4 1G "-1s"

echo "Waiting for partprobe..."
sync && sync
partprobe $PI_SD || true
sudo partprobe $PI_SD || true
sleep 2

PI_SD_SFX=$PI_SD
Expand All @@ -80,16 +77,13 @@ if [ -b ${PI_SD}p1 ]; then
fi

echo "Building fat filesystem for boot..."
mkfs.vfat -F 32 ${PI_SD_SFX}1
fatlabel ${PI_SD_SFX}1 boot

echo "Building ext4 filesystem for rootfs..."
$MKEXT4 -L "rootfs" ${PI_SD_SFX}2
sudo mkfs.vfat -F 32 ${PI_SD_SFX}1
sudo fatlabel ${PI_SD_SFX}1 boot

echo "Building ext4 filesystem for persist..."
$MKEXT4 -L "persist" ${PI_SD_SFX}3
sudo $MKEXT4 -L "persist" ${PI_SD_SFX}2

echo "Flashing u-boot..."
dd if=$ubootimg of=${PI_SD} conv=fsync bs=1024 seek=8
sudo dd if=$ubootimg of=${PI_SD} conv=fsync bs=1024 seek=8

echo "Done!"
104 changes: 56 additions & 48 deletions configs/bananapi/common/scripts/install_sd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,41 @@ if [ ! -b "$PI_SD" ]; then
exit 1
fi

resources_path="${SKIFF_CURRENT_CONF_DIR}/resources"
PI_SD_SFX=$PI_SD
if [ -b ${PI_SD}p1 ]; then
PI_SD_SFX=${PI_SD}p
fi

outp_path="${BUILDROOT_DIR}/output"
images_path="${outp_path}/images"
uimg_path="${images_path}/zImage"
squashfs_path="${images_path}/rootfs.squashfs"
skiff_init_path="${images_path}/skiff-init/"
firm_path="${images_path}/rpi-firmware"

img_path="${images_path}/Image"
zimg_path="${images_path}/zImage"
uinit_path="${images_path}/rootfs.cpio.uboot"
dtb_path=$(find ${images_path}/ -name '*.dtb' -print -quit)

source ${SKIFF_CURRENT_CONF_DIR}/scripts/determine_config.sh

if [ ! -f $dtb_path ]; then
echo "dtb not found, make sure Buildroot is done compiling."
exit 1
fi

if [ ! -f "$img_path" ]; then
img_path=$zimg_path
if [ ! -f "$uimg_path" ]; then
uimg_path="${images_path}/Image"
fi

if [ ! -f "$img_path" ]; then
if [ ! -f "$uimg_path" ]; then
echo "zImage or Image not found, make sure Buildroot is done compiling."
exit 1
fi

source ${SKIFF_CURRENT_CONF_DIR}/scripts/determine_config.sh

mounts=()
MOUNTS_DIR=${outp_path}/mounts
mkdir -p ${MOUNTS_DIR}
WORK_DIR=`mktemp -d -p "${MOUNTS_DIR}"`
RS="rsync -rav --no-perms --no-owner --no-group --progress --inplace"

# deletes the temp directory
function cleanup {
sync || true
for mount in "${mounts[@]}"; do
echo "Unmounting ${mount}..."
sudo umount $mount || true
umount $mount || true
done
mounts=()
if [ -d "$WORK_DIR" ]; then
Expand All @@ -60,48 +59,60 @@ fi
trap cleanup EXIT

boot_dir="${WORK_DIR}/boot"
rootfs_dir="${WORK_DIR}/rootfs"
persist_dir="${WORK_DIR}/persist"

PI_SD_SFX=$PI_SD
if [ -b ${PI_SD}p1 ]; then
PI_SD_SFX=${PI_SD}p
fi
rootfs_dir="${persist_dir}/rootfs"

mkdir -p $boot_dir
echo "Mounting ${PI_SD_SFX}1 to $boot_dir..."
mounts+=("$boot_dir")
sudo mount ${PI_SD_SFX}1 $boot_dir
mount ${PI_SD_SFX}1 $boot_dir

echo "Mounting ${PI_SD_SFX}2 to $rootfs_dir..."
mkdir -p $rootfs_dir
mounts+=("$rootfs_dir")
sudo mount ${PI_SD_SFX}2 $rootfs_dir

echo "Mounting ${PI_SD_SFX}3 to $persist_dir..."
echo "Mounting ${PI_SD_SFX}2 to $persist_dir..."
mkdir -p $persist_dir
mounts+=("$persist_dir")
sudo mount ${PI_SD_SFX}3 $persist_dir
mount ${PI_SD_SFX}2 $persist_dir

echo "Copying kernel image..."
sync
rsync -rav --no-perms --no-owner --no-group $img_path $boot_dir/
echo "Copying kernel..."
${RS} $uimg_path $boot_dir/
sync

echo "Copying uInitrd..."
rsync -rav --no-perms --no-owner --no-group $uinit_path $boot_dir/rootfs.cpio.uboot
sync
if [ -d "$outp_path/images/boot_part" ]; then
echo "Copying boot_part..."
${RS} $outp_path/images/boot_part/ $boot_dir/
sync
fi

if [ -d "$outp_path/images/rootfs_part" ]; then
echo "Copying rootfs_part..."
rsync -rav --no-perms --no-owner --no-group $outp_path/images/rootfs_part/ $rootfs_dir/
sync
echo "Copying rootfs_part..."
mkdir -p ${rootfs_dir}
${RS} $outp_path/images/rootfs_part/ $rootfs_dir/
sync
fi

if [ -d "$outp_path/images/persist_part" ]; then
echo "Copying persist_part..."
rsync -rav --no-perms --no-owner --no-group $outp_path/images/persist_part/ $persist_dir/
sync
echo "Copying persist_part..."
${RS} $outp_path/images/persist_part/ $persist_dir/
sync
fi

if [ -f $squashfs_path ]; then
echo "Copying rootfs.squashfs..."
${RS} $squashfs_path $boot_dir/rootfs.squashfs
sync
fi

if [ -d $skiff_init_path ]; then
echo "Copying skiff-init..."
${RS} $skiff_init_path $boot_dir/skiff-init/
sync
fi

if [ -z "$DISABLE_CREATE_SWAPFILE" ]; then
PERSIST_SWAP=${persist_dir}/primary.swap
if [ ! -f ${PERSIST_SWAP} ]; then
echo "Pre-allocating 2GB swapfile with zeros (ignoring errors)..."
dd if=/dev/zero of=${PERSIST_SWAP} bs=1M count=2000 || true
fi
fi

enable_silent() {
Expand All @@ -121,10 +132,7 @@ else
cp $boot_conf $boot_dir/boot.ini
enable_silent $boot_dir/boot.ini
fi
sync

echo "Copying device tree..."
rsync -rav --no-perms --no-owner --no-group ${images_path}/*.dtb $boot_dir/
echo "Copying device tree(s)..."
${RS} ${images_path}/*.dtb $boot_dir/
sync

cleanup
41 changes: 31 additions & 10 deletions configs/bananapi/m1/resources/boot-scripts/boot.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
setenv condev "console=ttyS0,115200"
setenv bootargs "root=/dev/initrd rootwait ro ramdisk_size=100000 ${condev} earlyprintk no_console_suspend net.ifnames=0"
setenv dtb_name "sun7i-a20-bananapi.dtb"
setenv condev "console=tty1 console=ttyS0,115200n8"
setenv verify 0
setenv bootlogo "false"

setenv dtb_addr_r "0x42000000"
setenv kernel_addr_r "0x40008000"
setenv initramfs_addr_r "0x44000000"
setenv devtype mmc
setenv devnum 0
setenv bootpart 1

mmc dev 0
fatload mmc 0 ${initramfs_addr_r} rootfs.cpio.uboot
fatload mmc 0 ${kernel_addr_r} zImage
fatload mmc 0 ${dtb_addr_r} sun7i-a20-bananapi.dtb
setenv fdt_addr_r "0x43000000"
setenv kernel_addr_r "0x42000000"
setenv ramdisk_addr_r "0x43400000"

bootz ${kernel_addr_r} ${initramfs_addr_r} ${dtb_addr_r}
# determine uuid of the boot partition
part uuid ${devtype} ${devnum}:${bootpart} uuid

# use /init script to deferred mount /
setenv bootmem "root=PARTUUID=${uuid} rw rootwait init=/skiff-init/skiff-init-squashfs"

# boot args
setenv bootargs "${bootmem} ${condev} no_console_suspend fsck.repair=yes net.ifnames=0"

# boot from sd card
setenv devnum 0
mmc dev ${devnum}

echo "Loading zImage to ${kernel_addr_r}"
load mmc ${devnum}:${bootpart} ${kernel_addr_r} zImage

echo "Loading dtb to ${fdt_addr_r}"
load mmc ${devnum}:${bootpart} ${fdt_addr_r} ${dtb_name}

echo "Booting with bootargs: ${bootargs}"
bootz ${kernel_addr_r} - ${fdt_addr_r}
41 changes: 31 additions & 10 deletions configs/bananapi/m1plus/resources/boot-scripts/boot.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
setenv condev "console=ttyS0,115200"
setenv bootargs "root=/dev/initrd rootwait ro ramdisk_size=100000 ${condev} earlyprintk no_console_suspend net.ifnames=0"
setenv dtb_name "sun7i-a20-bananapi-m1-plus.dtb"
setenv condev "console=tty1 console=ttyS0,115200n8"
setenv verify 0
setenv bootlogo "false"

setenv dtb_addr_r "0x42000000"
setenv kernel_addr_r "0x40008000"
setenv initramfs_addr_r "0x44000000"
setenv devtype mmc
setenv devnum 0
setenv bootpart 1

mmc dev 0
fatload mmc 0 ${initramfs_addr_r} rootfs.cpio.uboot
fatload mmc 0 ${kernel_addr_r} zImage
fatload mmc 0 ${dtb_addr_r} sun7i-a20-bananapi-m1-plus.dtb
setenv fdt_addr_r "0x43000000"
setenv kernel_addr_r "0x42000000"
setenv ramdisk_addr_r "0x43400000"

bootz ${kernel_addr_r} ${initramfs_addr_r} ${dtb_addr_r}
# determine uuid of the boot partition
part uuid ${devtype} ${devnum}:${bootpart} uuid

# use /init script to deferred mount /
setenv bootmem "root=PARTUUID=${uuid} rw rootwait init=/skiff-init/skiff-init-squashfs"

# boot args
setenv bootargs "${bootmem} ${condev} no_console_suspend fsck.repair=yes net.ifnames=0"

# boot from sd card
setenv devnum 0
mmc dev ${devnum}

echo "Loading zImage to ${kernel_addr_r}"
load mmc ${devnum}:${bootpart} ${kernel_addr_r} zImage

echo "Loading dtb to ${fdt_addr_r}"
load mmc ${devnum}:${bootpart} ${fdt_addr_r} ${dtb_name}

echo "Booting with bootargs: ${bootargs}"
bootz ${kernel_addr_r} - ${fdt_addr_r}
Loading

0 comments on commit f802fbe

Please sign in to comment.