Moving legacy image builder to genimage with custom u-boot

I’m trying to revive our image builder scripts. They rely on the omap image builder and a script setup_sdcard. I’m looking to move to genimage, but unsure how to setup up the genimage configuration.

Our current layout is a single partition with bootloader in raw memory. I’ve been following this article up until now, but this will yield a completely different partition table. If it helps, I’ve attached the output from fdisk for an sd card running the old image.

Device Boot Start End Sectors Size Id Type /dev/sda1 * 8192 121634782 121626591 58G 83 Linux

This is our old config for setup_sdcard.sh

#!/bin/bash
#        --dtb oresat-bootloader (BeagleBone & BeagleBone Black:supported)

#Bootloader:

#Bootloader Partition:
bootloader_location="dd_spl_uboot_boot"

spl_uboot_name="MLO"
dd_spl_uboot_count="2"
dd_spl_uboot_seek="1"
dd_spl_uboot_conf=""
dd_spl_uboot_bs="128k"
spl_name="MLO"

uboot_name="u-boot.img"
dd_uboot_count="4"
dd_uboot_seek="1"
dd_uboot_conf=""
dd_uboot_bs="384k"
boot_name="u-boot.img"

#extlinux
extlinux_console="ttyS0,115200n8"
extlinux="enable"
extlinux_fdtdir="enable"
extlinux_append="console=$extlinux_console root=/dev/mmcblk0p1 ro rootfstype=ext4 rootwait quiet"

#Kernel:
loops_per_jiffy="lpj=1990656"

The MLO and u-boot image part make sense to me, but I’m unsure how to attach the rootfs in the same partition. I worry that if the partition table changes, I’ll end up breaking something else in our setup.

I have a long term goal to convert it to genimage… As you see I’ve started updating a few of my forum pages…

But lately been more focused on hardware fixes.

1 Like

Well, just want to throw debos as an option too. I did get bootable images built in the past using the recipe here.

2 Likes

Ended up powering through with genimage, attaching the script that I used.

#!/bin/bash -e

if [ "$(id -u)" != "0" ]; then
  echo "Log: (post-build) need to be root"
  exit 1
fi

target_dir="fs"
root_fs="fs/fs-rootfs"
boot_fs="fs/fs-bootfs"
dtbs_path=""
fdt=""

# these are supplied by the project config file
rfs_username=""
rfs_password=""
rfs_hostname=""
config_path="./image-builder.project"

# load build configuration
# exit if not present
if [ ! -f image-builder.project ]; then
  echo "ERROR: (post-build) missing .project configuration"
  exit 1
fi

# shellcheck disable=SC1090
. "${config_path}"

mkdir -p "${target_dir}"

if [ ! -f "MLO" ]; then
  echo "ERROR: (post-build) MLO missing"
  exit 1
fi

cp -v MLO "${target_dir}"

if [ ! -f "u-boot-dtb.img" ]; then
  echo "ERROR: (post-build) u-boot-dtb.img missing"
  exit 1
fi

cp -v u-boot-dtb.img "${target_dir}"

echo "Log: (post-build) building root fs"
mkdir -p "${root_fs}"
tar xf armhf-rootfs-debian-*.tar -C "${root_fs}"

dir_check="${root_fs}/boot"
kernel_select() {
  echo "debug: kernel_select: picking the first available kernel..."
  unset check
  check=$(ls "${dir_check}" | grep vmlinuz- | head -n 1)
  if [ "${check}" != "" ]; then
    kernel_version=$(ls "${dir_check}" | grep vmlinuz- | head -n 1 | awk -F'vmlinuz-' '{print $2}')
    echo "debug: kernel_select: found: [${kernel_version}]"
  else
    echo "ERROR: no installed kernel"
    exit
  fi
}

# get the first available kernel
kernel_select

# set up uenv
echo "Log: (post-build) building boot fs"
echo "uname_r=${kernel_version}" >>"${root_fs}/boot/uEnv.txt"
echo "cmdline=fsck.repair=yes earlycon net.ifnames=0" >>"${root_fs}/boot/uEnv.txt"

mkdir -p "${boot_fs}"
cat <<__EOF__ >"${boot_fs}/sysconf.txt"
user_name="${rfs_username}"
user_password="${rfs_password}"
hostname="${rfs_hostname}"
__EOF__

cp -v "${root_fs}/boot/vmlinuz-${kernel_version}" "${boot_fs}"
cp -v "${root_fs}/boot/initrd.img-${kernel_version}" "${boot_fs}"

echo "Log: (post-build) copying fdt"
mkdir -p "${boot_fs}/dtbs/${kernel_version}"

shopt -s nullglob
if [ "${rfs_hostname}" != "oresat-dev" ]; then
  dtbs_path=("${root_fs}/boot/dtbs/${kernel_version}/${rfs_hostname}"-*.dtb)
  fdt="${dtbs_path[0]##*/}"
else
  fdt="am335x-boneblack.dtb"
fi

echo "Log: (post-build) configuring extlinux"
cp -v "${root_fs}/boot/dtbs/${kernel_version}/${fdt}" "${boot_fs}/dtbs/${kernel_version}"

mkdir -p "${boot_fs}/extlinux"
cat <<__EOF__ >"${boot_fs}/extlinux/extlinux.conf"
TIMEOUT 1
DEFAULT linux

LABEL linux
KERNEL /vmlinuz-${kernel_version}
INITRD /initrd.img-${kernel_version}
FDT /dtbs/${kernel_version}/${fdt}
APPEND console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait
__EOF__

if [ ! -f ./genimage.cfg ]; then
  echo "ERROR: (post-build) genimage configuration missing"
  exit 1
fi

genimage --rootpath "${target_dir}" --inputpath "${target_dir}" --config genimage.cfg