Hi Pascal, thanks for your quick reply.

On 01/09/2025 at 20:57 UTC, Pascal Hambourg wrote:
> Note that debian-installer uses u-boot-install-sunxi to build SD card 
> images only for arm64 platforms, not armhf ones.

OK. So we might want some adjustments to build/boot/arm/u-boot-image-config 
in debian-installer as well.


> Looks good to me. Can you open a merge request in salsa ? [...]

I'd like to know Vagrant's opinion on this idea, but if he's happy with the 
proposed patch then yes certainly I can make a merge request.


> Is warning enough ? If a boot loader is present at offset 8KiB, its part 
> beyond offset 128KiB will be overwritten and boot will probably fail. 
> Shouldn't the magic number be deleted too ? [...]

You're absolutely right. The user expects the newly-installed boot program 
to become the active one. So yes the script should disable any boot program 
at 8K when installing elsewhere. Thanks very much for questioning that.

Please see the revised patch below.

Best wishes,
Harold.

diff --git a/debian/bin/u-boot-install-sunxi b/debian/bin/u-boot-install-sunxi
index fca4ddc436..32748ee646 100755
--- a/debian/bin/u-boot-install-sunxi
+++ b/debian/bin/u-boot-install-sunxi
@@ -79,6 +79,32 @@ if [ ! -w "$DEV" ] && [ -z "$FORCE" ]; then
     exit 1
 fi
 
+board=$(basename "$TARGET")
+echo >&2 "Selected board: ${board}"
+
+# Select write offset based on board
+case "$board" in
+       # H2+ or H3 SoC
+       "nanopi_neo" | "nanopi_neo_air" | "orangepi_pc_plus" | "orangepi_plus" 
| "orangepi_zero" )
+               wroff="128K" ;;
+       # A64, H5 or H6 SoC
+       "a64-olinuxino" | "a64-olinuxino-emmc" | "nanopi_neo2" | 
"nanopi_neo_plus2" |\
+       "orangepi_one_plus" | "orangepi_zero_plus2" | "pine64-lts" | 
"pine64_plus" |\
+       "pinebook" | "pinephone" | "pinetab" | "sopine_baseboard" | "teres_i" )
+               wroff="128K" ;;
+       # Older SoC
+       *)
+               wroff="8K" ;;
+esac
+echo >&2 "Selected offset: ${wroff}"
+
+# Check for any other boot program that would take precedence
+disable8k="n"
+if [ "$wroff" != "8K" ] && printf 'eGON.BT0' | cmp -s -i 0:8196 -n 8 - "$DEV"; 
then
+       echo >&2 "Found boot program in ${DEV} at offset 8K, needs disabling"
+       disable8k="y"
+fi
+
 if [ -z "$FORCE" ]; then
     # A very simple sanity check.  GPT mandates a "protective MBR" so this 
works
     # even with GPT partitioning.
@@ -87,10 +113,12 @@ if [ -z "$FORCE" ]; then
        exit 1
     fi
 
-    # But, on sunxi64, spl will trample upon GPT.
-    if printf 'EFI PART' | cmp -s -i 0:512 -n 8 - "$DEV"; then
-       echo >&2 "$0: device/image ($DEV) uses GPT partition table, unusable on 
sunxi64"
-       exit 1
+    # But writing at offset 8K will trample upon GPT.
+    if [ "$wroff" = "8K" ] || [ "$disable8k" = "y" ]; then
+        if printf 'EFI PART' | cmp -s -i 0:512 -n 8 - "$DEV"; then
+            echo >&2 "$0: device/image ($DEV) uses GUID partition table, would 
overwrite it"
+            exit 1
+        fi
     fi
 fi
 
@@ -100,5 +128,10 @@ if [ ! -f "$imfile" ]; then
     exit 1
 fi
 
-echo "Writing U-Boot image ${imfile} to ${DEV}"
-dd conv=fsync,notrunc if="$imfile" of="$DEV" bs=8K seek=1
+if [ "$disable8k" = "y" ]; then
+       echo >&2 "Disabling boot program in ${DEV} at offset 8K"
+       printf 'DISUSED!' | dd conv=fsync,notrunc of="$DEV" bs=8196 seek=1
+fi
+
+echo >&2 "Writing U-Boot image ${imfile} to ${DEV} at offset ${wroff}"
+dd conv=fsync,notrunc if="$imfile" of="$DEV" bs="$wroff" seek=1
diff --git a/debian/manpages/u-boot-install-sunxi.8 
b/debian/manpages/u-boot-install-sunxi.8
index 744679ec78..a5dda95fa7 100644
--- a/debian/manpages/u-boot-install-sunxi.8
+++ b/debian/manpages/u-boot-install-sunxi.8
@@ -35,6 +35,5 @@ environment variable is set, its contents are used instead.
 Skip partition table sanity checks.  Usually, a MBR partition table is
 required (so u-boot has something to work with), but in rare setups you
 may put the data on another disk.  Likewise, GPT partition tables are
-incompatible with the layout used on sunxi devices (spl is written at
-offset 16384 while GPT occupies bytes [512..33280) ) but this option lets
+incompatible with the boot program location of 8K, but this option lets
 you trample upon them anyway.

Reply via email to