From c15f320ff697b3ec7b072e5a07bfd5f923c91982 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 13 Oct 2017 14:26:38 +0100 Subject: [PATCH] tools: Add mkimage-rpi3 to build images for raspberry Pi 3 The package contains u-boot and the RPi firmware blobs. It expects a tar ball of the root filesystem (including kernel and dtbs) on stdin and produces a compressed tar ball on stdout with the files to copy to a FAT32 formatted SD card. Signed-off-by: Rolf Neugebauer --- tools/mkimage-rpi3/Dockerfile | 56 +++++++++++++++++++++++++++++++++ tools/mkimage-rpi3/boot.script | 9 ++++++ tools/mkimage-rpi3/build.yml | 4 +++ tools/mkimage-rpi3/config.txt | 5 +++ tools/mkimage-rpi3/make-rpi3 | 29 +++++++++++++++++ tools/mkimage-rpi3/u-boot.patch | 11 +++++++ 6 files changed, 114 insertions(+) create mode 100644 tools/mkimage-rpi3/Dockerfile create mode 100644 tools/mkimage-rpi3/boot.script create mode 100644 tools/mkimage-rpi3/build.yml create mode 100644 tools/mkimage-rpi3/config.txt create mode 100755 tools/mkimage-rpi3/make-rpi3 create mode 100644 tools/mkimage-rpi3/u-boot.patch diff --git a/tools/mkimage-rpi3/Dockerfile b/tools/mkimage-rpi3/Dockerfile new file mode 100644 index 000000000..6bc3fbbc8 --- /dev/null +++ b/tools/mkimage-rpi3/Dockerfile @@ -0,0 +1,56 @@ +FROM linuxkit/alpine:b3f8da6c6f02440ee9c4c72bbf4dabdf500b1d8c as build +RUN apk add \ + bc \ + dtc \ + curl \ + make \ + gcc \ + git \ + musl-dev \ + patch + +# Create small rootfs +RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/ +RUN apk add --no-cache --initdb -p /out \ + alpine-baselayout \ + busybox \ + libarchive-tools \ + musl \ + tar +RUN rm -rf /out/etc/apk /out/lib/apk /out/var/cache + +# u-boot compile. The patch is needed to handle larger kernels +ENV UBOOT_COMMIT=v2017.09 +COPY u-boot.patch . +RUN git clone https://github.com/u-boot/u-boot.git && \ + cd /u-boot && \ + git checkout $UBOOT_COMMIT +WORKDIR /u-boot +RUN patch -p 1 < /u-boot.patch && \ + make rpi_3_defconfig all && \ + mkdir -p /out/boot && \ + cp u-boot.bin /out/boot && \ + mkdir -p /out/bin && \ + cp tools/mkimage /out/bin + +# fetch the Raspberry Pi 3 firmware (latest master) +ENV RPI_COMMIT=478d637c476e838ffcfa8535232ff0b86daf5918 +RUN mkdir -p /out/boot && \ + cd /out/boot && \ + curl -fsSLO https://github.com/raspberrypi/firmware/raw/$RPI_COMMIT/boot/bootcode.bin && \ + curl -fsSLO https://github.com/raspberrypi/firmware/raw/$RPI_COMMIT/boot/bootcode.bin && \ + curl -fsSLO https://github.com/raspberrypi/firmware/raw/$RPI_COMMIT/boot/fixup_cd.dat && \ + curl -fsSLO https://github.com/raspberrypi/firmware/raw/$RPI_COMMIT/boot/fixup.dat && \ + curl -fsSLO https://github.com/raspberrypi/firmware/raw/$RPI_COMMIT/boot/fixup_x.dat && \ + curl -fsSLO https://github.com/raspberrypi/firmware/raw/$RPI_COMMIT/boot/start_cd.elf && \ + curl -fsSLO https://github.com/raspberrypi/firmware/raw/$RPI_COMMIT/boot/start.elf && \ + curl -fsSLO https://github.com/raspberrypi/firmware/raw/$RPI_COMMIT/boot/start_x.elf + +FROM scratch +ENTRYPOINT [] +CMD [] +WORKDIR / +COPY --from=build /out/ / +COPY config.txt boot.script /boot/ +COPY make-rpi3 / +ENTRYPOINT [ "/make-rpi3" ] diff --git a/tools/mkimage-rpi3/boot.script b/tools/mkimage-rpi3/boot.script new file mode 100644 index 000000000..c717ccb8a --- /dev/null +++ b/tools/mkimage-rpi3/boot.script @@ -0,0 +1,9 @@ +setenv bootargs "dwc_otg.lpm_enable=0 earlyprintk console=tty1 console=ttyS0,115200 root=/dev/ram0 rw" +setenv dtbfile bcm2837-rpi-3-b.dtb +setenv machid 0x00000c42 +saveenv + +fatload mmc 0:1 ${kernel_addr_r} kernel.uimg +fatload mmc 0:1 ${fdt_addr_r} ${dtbfile} +fatload mmc 0:1 ${ramdisk_addr_r} initrd.uimg +bootm ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} diff --git a/tools/mkimage-rpi3/build.yml b/tools/mkimage-rpi3/build.yml new file mode 100644 index 000000000..b38e9c82b --- /dev/null +++ b/tools/mkimage-rpi3/build.yml @@ -0,0 +1,4 @@ +image: mkimage-rpi3 +network: true +arches: + - arm64 diff --git a/tools/mkimage-rpi3/config.txt b/tools/mkimage-rpi3/config.txt new file mode 100644 index 000000000..95400f34a --- /dev/null +++ b/tools/mkimage-rpi3/config.txt @@ -0,0 +1,5 @@ +avoid_warnings=2 +# 64bit mode, serial and kernel +arm_control=0x200 +enable_uart=1 +kernel=u-boot.bin diff --git a/tools/mkimage-rpi3/make-rpi3 b/tools/mkimage-rpi3/make-rpi3 new file mode 100755 index 000000000..d41818d9a --- /dev/null +++ b/tools/mkimage-rpi3/make-rpi3 @@ -0,0 +1,29 @@ +#!/bin/sh + +set -e + +# input is a tarball on stdin with kernel, dtbs and cmdline in /boot +# output is an tar to be extracted onto a SD card + +mkdir -p /files +cd /files + +# extract. BSD tar auto recognises compression +[ -t 0 ] || bsdtar xzf - + +cd / + +# copy/convert files +cp /files/boot/dtb/broadcom/bcm2837-rpi-3-b.dtb /boot +/bin/mkimage -A arm64 -O linux -T kernel -C gzip -a 0x80000 -e 0x80000 \ + -d /files/boot/kernel /boot/kernel.uimg >> /boot/uboot.log +/bin/mkimage -A arm64 -O linux -T script -C none -a 0x00000000 -e 0x00000000 -n RPi3 \ + -d /boot/boot.script /boot/boot.scr >> /boot/uboot.log + +# build an initrd and convert it +rm -rf /files/boot +cd /files && find . | cpio -o -H newc | gzip > /initrd.img +/bin/mkimage -A arm64 -O linux -T ramdisk -d /initrd.img /boot/initrd.uimg >> /boot/uboot.log + +# now everything is setup in /boot just need to tar it +cd /boot && tar cf - . diff --git a/tools/mkimage-rpi3/u-boot.patch b/tools/mkimage-rpi3/u-boot.patch new file mode 100644 index 000000000..709b0f8f6 --- /dev/null +++ b/tools/mkimage-rpi3/u-boot.patch @@ -0,0 +1,11 @@ +diff --git a/include/configs/rpi.h b/include/configs/rpi.h +index c499b45..1faae3c 100644 +--- a/include/configs/rpi.h ++++ b/include/configs/rpi.h +@@ -161,4 +161,6 @@ + BOOTENV + + ++#define CONFIG_SYS_BOOTM_LEN (64 * 1024 * 1024) ++ + #endif