View Issue Details

IDProjectCategoryView StatusLast Update
0000614fileGeneralpublic2025-01-14 19:17
Reporterzhaofeng Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status newResolutionopen 
Summary0000614: Allwinner boot images
DescriptionHi,

The attached patch adds detection of 3 boot image formats used by Allwinner SoCs (aka "sunxi"): eGON, TOC0, TOC1.

Sample output and testing instructions:

# Use https://github.com/smaeul/u-boot (branch "allwinner"):
# make tools-only_defconfig
# make cross_tools HOST_TOOLS_ALL=y NO_SDL=1
# export PATH="$PWD/tools:$PATH"

# mkimage -T sunxi_egon -A riscv -d any-file.bin test.egon
test.egon: Allwinner eGON.BT0 Boot Image (RISC-V), size 8192

# openssl genrsa -out root_key.pem
# mkimage -A arm64 -T sunxi_toc0 -d any-file.bin test.toc0
test.toc0: Allwinner TOC0 Boot Image with 3 items: key (offset 0x90, size 0x538), certificate (offset 0x5c8, size 0x25b), firmware (offset 0x840, size 0x1c66)

# echo -e "[first]\nfile = any-file.bin\naddr = 0x1000\n\n[second]\nfile = any-file.bin\naddr = 0x2000" >test-toc1.cfg
# mkimage -T sunxi_toc1 -d test-toc1.cfg test.toc1
test.toc1: Allwinner TOC1 Boot Image with 2 items: first (offset 0x400, size 0x1c66), second (offset 0x2200, size 0x1c66)
TagsNo tags attached.

Activities

zhaofeng

2025-01-14 19:17

reporter  

0001-Add-Allwinner-boot-image-formats-eGON-TOC0-TOC1.patch (2,271 bytes)   
From 9e35ecac5ae077c1b0b7314ede8657ad8bdcdec0 Mon Sep 17 00:00:00 2001
From: Zhaofeng Li <hello@zhaofeng.li>
Date: Tue, 14 Jan 2025 09:13:29 +0000
Subject: [PATCH] Add Allwinner boot image formats (eGON, TOC0, TOC1)

---
 magic/Magdir/firmware | 75 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/magic/Magdir/firmware b/magic/Magdir/firmware
index 21ba1ed5..f30ab6a4 100644
--- a/magic/Magdir/firmware
+++ b/magic/Magdir/firmware
@@ -275,3 +275,78 @@
 >-10	string		\x1A\x01UFD
 >>-12	uleshort	x		\b, for device %04X:
 >>-14	uleshort	x		\b%04X
+
+# Allwinner eGON Boot Image
+# Reference: https://linux-sunxi.org/EGON
+
+0	name	egon-details
+# ARM b instruction
+>0	ulelong&0xff000000	0xea000000	(ARM)
+# RISC-V jal instruction
+>0	ulelong&0x00000fff	0x0000006f	(RISC-V)
+>16	ulelong	x	\b, size %u
+
+4	string	eGON.BT0	Allwinner eGON.BT0 Boot Image
+>0	use	egon-details
+
+4	string	eGON.BT1	Allwinner eGON.BT1 Boot Image
+>0	use	egon-details
+
+# Allwinner TOC0 Boot Image
+# Reference: https://linux-sunxi.org/TOC0
+0	name	toc0-item
+>0	ulelong	0x010101	certificate
+>0	ulelong	0x010202	firmware
+>0	ulelong	0x010303	key
+>4	ulelong	x	(offset 0x%x
+>8	ulelong	x	\b, size 0x%x)
+
+8	ulelong	0x89119800	Allwinner TOC0 Boot Image
+>24	ulelong	x	with %u items
+# each item is 32 bytes
+# item 0
+>24	ulelong	>0	\b:
+>>48	use	toc0-item
+# item 1
+>24	ulelong	>1	\b,
+>>80	use	toc0-item
+# item 2
+>24	ulelong	>2	\b,
+>>112	use	toc0-item
+# item 3
+>24	ulelong	>3	\b,
+>>144	use	toc0-item
+# item 4
+>24	ulelong	>4	\b,
+>>176	use	toc0-item
+# item 5+
+>24	ulelong	>5	\b, ...
+
+# Allwinner TOC1 Boot Image
+# Reference: https://lore.kernel.org/all/20211015040811.56856-2-samuel@sholland.org/T/
+0	name	toc1-item
+>0	string/64/T	x	%s
+>64	ulelong	x	(offset 0x%x
+>68	ulelong	x	\b, size 0x%x)
+
+16	ulelong	0x89119800	Allwinner TOC1 Boot Image
+>0	string/16/T	>\0	(name "%s")
+>32	ulelong	x	with %u items
+# each item is 368 bytes
+# item 0
+>32	ulelong	>0	\b:
+>>64	use	toc1-item
+# item 1
+>32	ulelong	>1	\b,
+>>432	use	toc1-item
+# item 2
+>32	ulelong	>2	\b,
+>>800	use	toc1-item
+# item 3
+>32	ulelong	>3	\b,
+>>1168	use	toc1-item
+# item 4
+>32	ulelong	>4	\b,
+>>1536	use	toc1-item
+# item 5+
+>32	ulelong	>5	\b, ...
-- 
2.47.0

Issue History

Date Modified Username Field Change
2025-01-14 19:17 zhaofeng New Issue
2025-01-14 19:17 zhaofeng File Added: 0001-Add-Allwinner-boot-image-formats-eGON-TOC0-TOC1.patch