#!/bin/sh # Build SD card image BOARD_ID="${1}" # For example "bananapi" CHIP_ID="${2}" # For example "allwinner-a10" DEFCONFIG="${3}" # For example "Bananapi_defconfig" TUPLE="${4}" # For example "arm-linux-gnueabihf" set -ex build-u_boot "${DEFCONFIG}" "${TUPLE}" # Write Raspberry Pi boot config cat << EOF > config.txt kernel=u-boot.bin boot_delay=0 boot_delay_ms=100 gpu_mem=16 enable_uart=1 EOF if [ "${TUPLE}" = "aarch64-linux-gnu" ] then echo "arm_64bit=1" >> config.txt fi # Download Raspberry Pi boot files FIRMWARE="https://github.com/raspberrypi/firmware/raw/stable" if [ "${CHIP_ID}" = "bcm2711" ]; then wget --tries 3 \ --retry-on-http-error 500,502,503,504 \ --no-verbose \ "${FIRMWARE}/boot/fixup4.dat" \ "${FIRMWARE}/boot/fixup4x.dat" \ "${FIRMWARE}/boot/fixup4cd.dat" \ "${FIRMWARE}/boot/fixup4db.dat" \ "${FIRMWARE}/boot/start4.elf" \ "${FIRMWARE}/boot/start4x.elf" \ "${FIRMWARE}/boot/start4cd.elf" \ "${FIRMWARE}/boot/start4db.elf" \ "${FIRMWARE}/boot/bootcode.bin" else wget --tries 3 \ --retry-on-http-error 500,502,503,504 \ --no-verbose \ "${FIRMWARE}/boot/fixup.dat" \ "${FIRMWARE}/boot/fixup_x.dat" \ "${FIRMWARE}/boot/fixup_cd.dat" \ "${FIRMWARE}/boot/fixup_db.dat" \ "${FIRMWARE}/boot/start.elf" \ "${FIRMWARE}/boot/start_x.elf" \ "${FIRMWARE}/boot/start_cd.elf" \ "${FIRMWARE}/boot/start_db.elf" \ "${FIRMWARE}/boot/bootcode.bin" fi # Magic thing to get debug output sed -i -e "s/BOOT_UART=0/BOOT_UART=1/" bootcode.bin # Create empty FAT partition rm -f vfat.img fallocate -l 28MiB vfat.img mkfs.vfat vfat.img # Copy boot files to FAT partition mcopy -v -i vfat.img u-boot/u-boot.bin config.txt fixup*.dat start*.elf bootcode.bin :: # Copy FAT partition to image dd if=vfat.img of=tmp.img bs=1K seek=4K conv=notrunc