Skip to content

Commit 6f87814

Browse files
committed
labsi: add configs + scripts for SI labs
1 parent 284530a commit 6f87814

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# Builds a U-Boot only RaspberryPI image (with partitions)
3+
4+
set -eo pipefail
5+
SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../" && pwd)"
6+
source "$SRC_DIR/lib/common.sh"
7+
8+
# image builder options
9+
DIST_DIR="$SRC_DIR/dist"
10+
TMP_DOWNLOAD_DIR="$BUILD_DEST/tmp"
11+
UBOOT_IMAGE_DEST=${UBOOT_IMAGE_DEST:-"$BUILD_DEST/u-boot-image.bin"}
12+
MOUNT_TMP="${MOUNT_TMP:-/tmp/rpi.mount}"
13+
IMAGE_SIZE_MB=150
14+
15+
_lo_umount() {
16+
if [[ "$0" != "--force" && "$DEBUG" -gt 2 ]]; then return 0; fi
17+
log_info "Unmounting loopback device..."
18+
mountpoint -q "$MOUNT_TMP$RPI_FIRMWARE_DIR" && $SUDO umount "$MOUNT_TMP$RPI_FIRMWARE_DIR" || true
19+
mountpoint -q "$MOUNT_TMP" && $SUDO umount "$MOUNT_TMP" || true
20+
if [[ -n "$LO_DEV" ]]; then
21+
$SUDO losetup -d "$LO_DEV"
22+
else $SUDO losetup -D; fi
23+
}
24+
if [[ "$1" =~ ^(-u|--un?mount)$ ]]; then _lo_umount --force; exit 0; fi
25+
26+
# reseve the image file
27+
dd if=/dev/zero of="$UBOOT_IMAGE_DEST" bs=1M count="$IMAGE_SIZE_MB"
28+
29+
_PARTED_BOOT_START=1
30+
_PARTED_BOOT_END=$(( "$IMAGE_BOOT_PART_MB" + "$_PARTED_BOOT_START" ))
31+
32+
log_info "Creating partitions..."
33+
log_debug \
34+
'1:' "${_PARTED_BOOT_START}MiB" "${_PARTED_BOOT_END}MiB" $'\n' \
35+
'2:' "${_PARTED_BOOT_END}MiB" "100%"
36+
37+
parted --script "$UBOOT_IMAGE_DEST" \
38+
mklabel msdos \
39+
mkpart primary "${_PARTED_BOOT_START}MiB" "${_PARTED_BOOT_END}MiB" \
40+
type 1 0x0B set 1 boot on
41+
42+
LO_DEV=$($SUDO losetup -f)
43+
$SUDO losetup -P "$LO_DEV" "$UBOOT_IMAGE_DEST"
44+
log_info "Loopback device $LO_DEV mapped to '$UBOOT_IMAGE_DEST'"
45+
trap _lo_umount EXIT
46+
47+
if [[ ! -b "${LO_DEV}p1" ]]; then
48+
log_fatal "Image partition scanning failed!"
49+
fi
50+
51+
log_info "Formatting boot partition..."
52+
$SUDO mkfs.vfat -n "$IMAGE_BOOT_PART_NAME" "${LO_DEV}p1"
53+
54+
# use the /boot/firmware convention to split partitions
55+
$SUDO mkdir -p "$MOUNT_TMP"
56+
log_debug "mount ${LO_DEV}p1 $MOUNT_TMP"
57+
$SUDO mount "${LO_DEV}p1" "$MOUNT_TMP"
58+
59+
mkdir -p "$TMP_DOWNLOAD_DIR"
60+
for file in "${RPI_FIRMWARE_FILES[@]}"; do
61+
# download the latest rpi firmware files (debian repo is outdated)
62+
wget "https://github.com/raspberrypi/firmware/raw/master/boot/$file" \
63+
-O "$TMP_DOWNLOAD_DIR/$file"
64+
$SUDO cp -f "$TMP_DOWNLOAD_DIR/$file" "$MOUNT_TMP/$file"
65+
done
66+
67+
$SUDO cp -f "$DIST_DIR/labsi-rpi4/u-boot.bin" "$MOUNT_TMP/u-boot.bin"
68+
$SUDO cp -f "$DIST_DIR/labsi-rpi4/"*".dtb" "$MOUNT_TMP/"
69+
$SUDO cp -f "$CUSTOM_CONFIG_DIR/files/boot/config.txt" "$MOUNT_TMP/config.txt"
70+
71+
log_debug $'Firmware files list: \n' "$(ls -lh "$MOUNT_TMP")"
72+
$SUDO du -hs "$MOUNT_TMP"
73+
74+
echo "Successfully generated U-Boot image!"
75+
ls -l "$UBOOT_IMAGE_DEST"
76+

configs/labsi-rpi4/config.inc.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Embedded Systems Debian rootfs configuration for labs
2+
3+
KERNEL_VERSION=${KERNEL_VERSION:-6.1}
4+
KERNEL_BRANCH="rpi-$KERNEL_VERSION.y"
5+
KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:-"bcm2711_defconfig"}
6+
7+
UBOOT_DEFCONFIG=${UBOOT_DEFCONFIG:-"rpi_4_defconfig"}
8+
9+
EXTRA_PACKAGES=(raspi-firmware linux-image-generic linux-headers-generic linux-libc-dev)
10+
11+
SKIP_BOOT_FILES=y
12+
RPI_SKIP_IMAGE_GEN=1
13+
14+
function rootfs_install_hook() {
15+
# copy custom install scripts to exec. dir
16+
cp -ar "$CUSTOM_CONFIG_DIR/install-scripts/"* "$INSTALL_SRC/scripts/"
17+
cp -ar "$CUSTOM_CONFIG_DIR/files/"* "$INSTALL_SRC/files/"
18+
}
19+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# RPI BL2 `config.txt` file to run U-Boot
2+
3+
# VPU boot settings
4+
boot_delay=1
5+
disable_overscan=1
6+
disable_splash=1
7+
8+
# Use DesignWare Core 2 (SoC's USB 2.0 controller) for Linux OTG support
9+
dtoverlay=dwc2
10+
11+
# Next stage config (run U-Boot)
12+
arm_64bit=1
13+
kernel=u-boot.bin
14+
enable_uart=1
15+
uart_2ndstage=1
16+
17+
# include extra config, if any
18+
include extraconfig.txt
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# need to configure raspi-firmware to use a specific ROOTPART
3+
4+
CUSTOM_ROOTPART="/dev/mmcblk1p2"
5+
6+
sed -i -E 's|^(#\s*)?ROOTPART=.*$|ROOTPART='"$CUSTOM_ROOTPART"'|' /etc/default/raspi-firmware
7+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# post-bootloader install hook
3+
4+
# re-generate initramfs
5+
update-initramfs -u -k all
6+

rootfs-install/files/initramfs/rpi-post-update-hook

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ function download_firmware_files() {
4545

4646
if [[ -n "$RPI_SKIP_IMAGE_GEN" ]]; then
4747
# save config.txt to /boot
48-
interpolate_vars "$RPI_CONFIG" "${INTERPOLATE_VARS[@]}" > "/boot/config.txt"
48+
mkdir -p /boot/firmware
49+
download_firmware_files "/boot/firmware"
50+
interpolate_vars "$RPI_CONFIG" "${INTERPOLATE_VARS[@]}" > "/boot/firmware/config.txt"
4951
exit 0
5052
fi
5153

0 commit comments

Comments
 (0)