Skip to contentSkip to conversation

tools: mkimage: Add Allwinner TOC1 support

RFC PATCH New Samuel Holland 1 participant 2 messages Oct 15, 2021 Arm/Allwinner sunXi SoC support

lore
Share & tools
lore

Samuel Holland

author maintainer
#0 lore raw

cover tools: mkimage: Add Allwinner TOC1 support

The SPL port for the Allwinner D1 RISC-V SoC will probably take a while longer than porting U-Boot proper, as none of the relevant drivers are set up for DM in SPL. In the meantime, we are using[1][2] a fork[3] of Allwinner's boot0 loader, which they also call "spl" in their BSP. boot0 uses this TOC1 image format.

The vendor tools for generating TOC1 images require a binary config file generated by their FEX compiler. Instead of trying to support that, I made up a simple human-readable config file format. I didn't see any existing platform-agnostic parser for multi-image containers in mkimage.

I am sending this as RFC because it is only of temporary/limited use. It only works with one specific fork of boot0 which was modified to "behave" (the the original vendor version monkey-patches a custom header inside the U-Boot image during boot). So it will be obsolete once U-Boot SPL is ported. And it is Yet Another Image Format. On the other hand, it does work, and it is currently being used.

[1]: https://linux-sunxi.org/Allwinner_Nezha#U-Boot
[2]: https://fedoraproject.org/wiki/Architectures/RISC-V/Allwinner
[3]: https://github.com/smaeul/sun20i_d1_spl

Samuel Holland (1):
tools: mkimage: Add Allwinner TOC1 support

 common/image.c        |   1 +
 include/image.h       |   1 +
 include/sunxi_image.h |  26 ++++
 tools/Makefile        |   1 +
 tools/sunxi_toc1.c    | 318 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 347 insertions(+)
 create mode 100644 tools/sunxi_toc1.c
Signature · 1 line
2.32.0
author maintainer
#1 lore raw

RFC PATCH 1/1 tools: mkimage: Add Allwinner TOC1 support

TOC1 is an container format used by Allwinner's boot0 that can hold multiple images. It supports encryption and signatures, but that functionality is not implemented, only the basic "non-secure" subset.

A config file is used to provide the list of data files to include. Its path is passed as the argument to "-d". It contains sections of the following form:

[name]
file = /path/to/file
addr = 0x12345678

Specific well-known names, such as "dtb", "opensbi", and "u-boot", are used by the bootloader to distinguish the items inside the image.

---

 common/image.c        |   1 +
 include/image.h       |   1 +
 include/sunxi_image.h |  26 ++++
 tools/Makefile        |   1 +
 tools/sunxi_toc1.c    | 318 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 347 insertions(+)
 create mode 100644 tools/sunxi_toc1.c
common/image.c +1 -0
index d15b47ebbe..a2b925c0c5 100644
@@ -186,6 +186,7 @@ static const table_entry_t uimage_type[] = {
 	{	IH_TYPE_COPRO, "copro", "Coprocessor Image"},
 	{	IH_TYPE_SUNXI_EGON, "sunxi_egon",  "Allwinner eGON Boot Image" },
 	{	IH_TYPE_SUNXI_TOC0, "sunxi_toc0",  "Allwinner TOC0 Boot Image" },
+	{	IH_TYPE_SUNXI_TOC1, "sunxi_toc1",  "Allwinner TOC1 Boot Image" },
 	{	-1,		    "",		  "",			},
 };
 
include/image.h +1 -0
index 1547246ec8..eb165f34da 100644
@@ -228,6 +228,7 @@ enum {
 	IH_TYPE_COPRO,			/* Coprocessor Image for remoteproc*/
 	IH_TYPE_SUNXI_EGON,		/* Allwinner eGON Boot Image */
 	IH_TYPE_SUNXI_TOC0,		/* Allwinner TOC0 Boot Image */
+	IH_TYPE_SUNXI_TOC1,		/* Allwinner TOC1 Boot Image */
 
 	IH_TYPE_COUNT,			/* Number of image types */
 };
include/sunxi_image.h +26 -0
index 379ca9196e..98f381bbe6 100644
@@ -116,4 +116,30 @@ struct __packed toc0_item_info {
 #define TOC0_ITEM_INFO_NAME_KEY		0x00010303
 #define TOC0_ITEM_INFO_END		"IIE;"
 
+struct __packed toc1_main_info {
+	uint8_t name[16];
+	__le32  magic;
+	__le32  checksum;
+	__le32  serial;
+	__le32  status;
+	__le32  num_items;
+	__le32  length;
+	__le32	major_version;
+	__le32	minor_version;
+	__le32	reserved[3];
+	uint8_t end[4];
+};
+
+struct __packed toc1_item_info {
+	uint8_t name[64];
+	__le32  offset;
+	__le32  length;
+	__le32  encryption;
+	__le32  type;
+	__le32  load_addr;
+	__le32  index;
+	__le32	reserved[69];
+	uint8_t end[4];
+};
+
 #endif
tools/Makefile +1 -0
index e2aeb097aa..8b42f3ff6f 100644
@@ -132,6 +132,7 @@ dumpimage-mkimage-objs := aisimage.o \
 			$(ROCKCHIP_OBS) \
 			socfpgaimage.o \
 			sunxi_egon.o \
+			sunxi_toc1.o \
 			lib/crc16.o \
 			lib/hash-checksum.o \
 			lib/sha1.o \
tools/sunxi_toc1.c new file +318 -0

318 lines not on this page · raw message

Signature · 1 line
2.32.0