On 2019-05-08 07:34 UTC, Domenico Andreoli wrote:
> Salsa MR #6 adds support for GPT partition tables with up to 4 entries
> to u-boot-install-sunxi64.
Hi Domenico and Vagrant,
I was interested in this idea so I found the patch on salsa:
--- a/debian/bin/u-boot-install-sunxi64
+++ b/debian/bin/u-boot-install-sunxi64
@@ -69,11 +69,22 @@ if [ -z "$FORCE" ]; then
exit 1
fi
- # But, on sunxi64, spl will trample upon GPT.
+ # But, on sunxi64, spl will trample upon GPT (except when the number of
entries is <= 4)
printf "EFI PART" >gpt-sign
if cmp -s -i 0:512 -n 8 gpt-sign "$DEV"; then
- echo >&2 "$0: device/image ($DEV) uses GPT partition table, unusable on
sunxi64"
- exit 1
+ GPT_OK=false
+ for GPT_ENTRIES in `seq 4`; do
+ # Need printf from coreutils so to correctly handle zero bytes
+ /usr/bin/printf '%b' "\0$GPT_ENTRIES\0\0\0" >gpt-entries
+ if cmp -s -i 0:592 -n 4 gpt-entries "$DEV"; then
+ GPT_OK=true
+ break
+ fi
+ done
+ if ! $GPT_OK; then
+ echo >&2 "$0: device/image ($DEV) uses GPT partition table with
more than 4 entries, unusable on sunxi64"
+ exit 1
+ fi
fi
fi
I think that as long as the partition entry size is the standard 128 bytes
it's OK to have up to 56 entries, because the total size of MBR + GPT header +
GPT entries still doesn't exceed 8K. u-boot-install-sunxi does already work
with such a GPT if the user specifies the -f option.
But it would be good if the script could support a standard-sized GPT, and a
possible way is suggested by this note in doc/board/allwinner/sunxi.rst:
The traditional SD card location the Allwinner BootROM loads from is 8KB
(sector 16). This works fine with the old MBR partitioning scheme, which most
SD cards come formatted with. However this is in the middle of a potential
GPT partition table, which will become invalid in this step. Newer SoCs
(starting with the H3 from late 2014) also support booting from 128KB, which
is beyond even a GPT and thus a safer location.
So perhaps there could be a new command-line option that made dd write to 128K
instead of 8K, and the error message upon detecting a GPT could suggest using
that option. I've suggested a simple patch below. (It assumes that the GPT
doesn't extend beyond 128K.)
Best wishes,
Harold.
--- a/debian/bin/u-boot-install-sunxi
+++ b/debian/bin/u-boot-install-sunxi
@@ -53,14 +53,22 @@ if [ -z "$TARGET" ] && [ -f "${dtmodel}" ]; then
esac
fi
+wroff="8K"
+while [ -n "$1" ]; do
case "$1" in
+ -a|--alt-offset)
+ wroff="128K"
+ shift;;
-f|--force)
FORCE=y
shift;;
-*)
echo >&2 "$0: unknown option '$1'"
exit 1;;
+ *)
+ break;;
esac
+done
DEV="$1"
if [ -z "$DEV" ] || ! shift || [ -n "$*" ]; then
@@ -87,9 +95,10 @@ 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"
+ # But writing at offset 8K will trample upon GPT.
+ if [ "$wroff" = "8K" ] && printf 'EFI PART' | cmp -s -i 0:512 -n 8 -
"$DEV"; then
+ echo >&2 "$0: device/image ($DEV) uses GUID partition table"
+ echo >&2 "$0: Use -a to install at alternative offset"
exit 1
fi
fi
@@ -100,5 +109,5 @@ 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
+echo "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..350d280530 100644
--- a/debian/manpages/u-boot-install-sunxi.8
+++ b/debian/manpages/u-boot-install-sunxi.8
@@ -31,10 +31,13 @@ deduced from the current running system, but if the
environment variable is set, its contents are used instead.
.SH OPTIONS
.TP
+-a | --alt-offset
+Install at offset 128K on the device rather than the default 8K. This
+is useful if the device has a standard-sized GUID partition table (GPT)
+and your board supports booting from this alternative offset.
-f | --force
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 default U-Boot location of 8K, but this option lets
you trample upon them anyway.