#! @bash@/bin/sh -e shopt -s nullglob export PATH=/empty for i in @path@; do PATH=$PATH:$i/bin; done usage() { echo "usage: $0 -t -c [-d ] [-g ] [-n ]" >&2 exit 1 } timeout= # Timeout in centiseconds default= # Default configuration target=/boot # Target directory numGenerations=0 # Number of other generations to include in the menu while getopts "t:c:d:g:n:" opt; do case "$opt" in t) # U-Boot interprets '0' as infinite and negative as instant boot if [ "$OPTARG" -lt 0 ]; then timeout=0 elif [ "$OPTARG" = 0 ]; then timeout=-10 else timeout=$((OPTARG * 10)) fi ;; c) default="$OPTARG" ;; d) target="$OPTARG" ;; g) numGenerations="$OPTARG" ;; n) dtbName="$OPTARG" ;; \?) usage ;; esac done [ "$timeout" = "" -o "$default" = "" ] && usage mkdir -p $target/nixos # Convert a path to a file in the Nix store such as # /nix/store/-/file to --. cleanName() { local path="$1" echo "$path" | sed 's|^/nix/store/||' | sed 's|/|-|g' } # Copy a file from the Nix store to $target/nixos. declare -A filesCopied copyToKernelsDir() { local src=$(readlink -f "$1") local dst="$target/nixos/$(cleanName $src)" # Don't copy the file if $dst already exists. This means that we # have to create $dst atomically to prevent partially copied # kernels or initrd if this script is ever interrupted. if ! test -e $dst; then local dstTmp=$dst.tmp.$$ cp -r $src $dstTmp mv $dstTmp $dst fi filesCopied[$dst]=1 result=$dst } copyInitrd() { local src=$(readlink -f "$1") local dst="$target/nixos/$(cleanName $src)" if ! test -e $dst; then local initrd=$dst.initrd.tmp.$$ local dstTmp=$dst.tmp.$$ # Unzip and convert ramdisk to uInitrd format (u-boot initrd) gzip -d <"$path/initrd" >$initrd mkimage -A arm64 -O linux -T ramdisk -C none -d "$initrd" "$dstTmp" >/dev/null rm $initrd mv $dstTmp $dst fi filesCopied[$dst]=1 result=$dst } # Copy its kernel, initrd and dtbs to $target/nixos, and echo out boot.ini entry addEntry() { local path=$(readlink -f "$1") local tag="$2" # Generation number or 'default' if ! test -e $path/kernel -a -e $path/initrd; then return fi copyToKernelsDir "$path/kernel" kernel=$result copyInitrd "$path/initrd" initrd=$result dtbDir=$(readlink -m "$path/dtbs") if [ -e "$dtbDir" ]; then copyToKernelsDir "$dtbDir" dtbs=$result fi echo "load mmc \${devno}:1 \${k_addr} nixos/$(basename $kernel)" echo "load mmc \${devno}:1 \${dtb_loadaddr} nixos/$(basename $dtbs)/amlogic/meson64_odroid\${variant}.dtb" echo "fdt addr \${dtb_loadaddr}" echo "load mmc \${devno}:1 \${initrd_loadaddr} nixos/$(basename $initrd)" echo "setenv bootargs \"\${bootargs} \"" echo "# Boot Args" echo "setenv bootargs \"root=root=/dev/mmcblk\${devno}p2 rootwait rw \${condev} \${amlogic} no_console_suspend fsck.repair=yes net.ifnames=0 elevator=noop hdmimode=\${hdmimode} cvbsmode=576cvbs max_freq_a55=\${max_freq_a55} maxcpus=\${maxcpus} voutmode=\${voutmode} \${cmode} disablehpd=\${disablehpd} cvbscable=\${cvbscable} overscan=\${overscan} \${hid_quirks} monitor_onoff=\${monitor_onoff} logo=osd0,loaded \${cec_enable} sdrmode=\${sdrmode} enable_wol=\${enable_wol} systemConfig=$path init=$path/init\"" } tmpFile="$target/boot.ini.tmp.$$" # This configuration was adapted from the Ubuntu 20.04 image provided # on the Hardkernel Wiki. cat >$tmpFile <>$tmpFile cat >>$tmpFile <