Skip to contentSkip to conversation

sunxi: binman fixes and SCP firmware support

PATCH New Samuel Holland 2 participants 11 messages Oct 22, 2020

Subsystems (3)
lore
Share & tools
lore

Samuel Holland

author maintainer
#0 lore raw

v5 cover sunxi: binman fixes and SCP firmware support

This is a rework of my previous patch series adding SCP firmware support for system suspend, on top of the binman rewrite of mksunxi_fit_atf.sh. Now that the generic binman updates have all been merged, this patchset is based on u-boot/master.

- Patches 1-2 apply to binman FIT support generally.
- Patches 3-5 fix small issues in the new sunxi binman description.
- Patch 6 is unchanged (improvements to FIT_IMAGE_TINY).
- Patches 7-9 implement the SCP firmware support as in previous versions of this series, but using binman instead of a shell script.

Changes v4->v5:
- Move patch 6 later in the series to emphasize that the binman fixes do not depend on it.
- Rebase on top of u-boot/master.
- Add a missing-msg for scp-sunxi.
- Explain in documentation how to silence the binman messages.

Changes v3->v4:
- Added a test for the SCP firmware entry type.

Samuel Holland (9):
Makefile: Only define u-boot.itb rule when applicable
binman: Only write FDT once per node
sunxi: binman: Fix spacing between nodes
sunxi: binman: Provide a default BL31 filename
sunxi: binman: Use a macro for the BL31 load address
spl: fit: Minimally parse OS properties with FIT_IMAGE_TINY
sunxi: binman: Update FIT component descriptions
binman: Add support for SCP firmware
sunxi: binman: Add support for including SCP firmware

 Makefile                       |  3 +++
 arch/arm/dts/sunxi-u-boot.dtsi | 43 +++++++++++++++++++++++--------
 board/sunxi/README.sunxi64     | 47 +++++++++++++++++++++++++++++-----
 common/spl/Kconfig             |  4 +--
 common/spl/spl_fit.c           | 17 +++++++++++-
 tools/binman/README.entries    |  4 +--
 tools/binman/etype/fit.py      | 12 ++++-----
 tools/binman/etype/scp.py      | 19 ++++++++++++++
 tools/binman/ftest.py          |  7 +++++
 tools/binman/missing-blob-help |  4 +++
 tools/binman/test/172_scp.dts  | 16 ++++++++++++
 11 files changed, 147 insertions(+), 29 deletions(-)
 create mode 100644 tools/binman/etype/scp.py
 create mode 100644 tools/binman/test/172_scp.dts
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH v5 1/9 Makefile: Only define u-boot.itb rule when applicable

If neither CONFIG_SPL_FIT_SOURCE nor CONFIG_USE_SPL_FIT_GENERATOR is enabled, U_BOOT_ITS will be undefined, and attempting to make u-boot.itb will pass invalid arguments to mkimage, causing it to print its help message.

Remove the rule in that case, so it is more obvious that u-boot.itb is not something that can be made. This will reduce confusion as platforms move away from CONFIG_USE_SPL_FIT_GENERATOR, as u-boot.itb was previously a valid goal for those platforms.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -0
index 6c3a953fdbd..9e0985f14a5 100644
@@ -1441,11 +1441,13 @@ else
 MKIMAGEFLAGS_u-boot.itb = -E
 endif
 
+ifdef U_BOOT_ITS
 u-boot.itb: u-boot-nodtb.bin \
 		$(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_OF_HOSTFILE),dts/dt.dtb) \
 		$(U_BOOT_ITS) FORCE
 	$(call if_changed,mkfitimage)
 	$(BOARD_SIZE_CHECK)
+endif
 
 u-boot-spl.kwb: u-boot.img spl/u-boot-spl.bin FORCE
 	$(call if_changed,mkimage)
Signature · 1 line
2.26.2
author maintainer
#2 lore raw

PATCH v5 2/9 binman: Only write FDT once per node

In reply to Samuel Holland

Due to an extra level of indentation, the "data" property containing the FDT was being written repeatedly after every other property in the node. This caused the generated FIT image to be invalid.

Move the block up one level, so the property is added exactly once.

---
 tools/binman/etype/fit.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/binman/etype/fit.py +4 -4
index de4745c5521..8a24f12aa59 100644
@@ -205,10 +205,10 @@ class Entry_fit(Entry):
                                         b'SEQ', tools.ToBytes(str(seq + 1)))
                                     fsw.property(pname, val)
 
-                                    # Add data for 'fdt' nodes (but not 'config')
-                                    if depth == 1 and in_images:
-                                        fsw.property('data',
-                                                     tools.ReadFile(fname))
+                                # Add data for 'fdt' nodes (but not 'config')
+                                if depth == 1 and in_images:
+                                    fsw.property('data',
+                                                 tools.ReadFile(fname))
                     else:
                         if self._fdts is None:
                             if self._fit_list_prop:
Signature · 1 line
2.26.2
author maintainer
#3 lore raw

PATCH v5 3/9 sunxi: binman: Fix spacing between nodes

In reply to Samuel Holland

Nodes should have a blank line separating them from sibling nodes and properties. Add the necessary lines.

---
 arch/arm/dts/sunxi-u-boot.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/dts/sunxi-u-boot.dtsi +5 -0
index c97943b3c19..92a64472318 100644
@@ -14,9 +14,11 @@
 	u-boot-sunxi-with-spl {
 		filename = "u-boot-sunxi-with-spl.bin";
 		pad-byte = <0xff>;
+
 		blob {
 			filename = "spl/sunxi-spl.bin";
 		};
+
 #ifdef CONFIG_ARM64
 		fit {
 			description = "Configuration to load ATF before U-Boot";
@@ -34,6 +36,7 @@
 					u-boot-nodtb {
 					};
 				};
+
 				atf {
 					description = "ARM Trusted Firmware";
 					type = "firmware";
@@ -47,6 +50,7 @@
 					load = <0x44000>;
 					entry = <0x44000>;
 #endif
+
 					atf-bl31 {
 						missing-msg = "atf-bl31-sunxi";
 					};
@@ -61,6 +65,7 @@
 
 			configurations {
 				default = "config-1";
+
 				@config-SEQ {
 					description = "NAME";
 					firmware = "uboot";
Signature · 1 line
2.26.2
author maintainer
#4 lore raw

PATCH v5 4/9 sunxi: binman: Provide a default BL31 filename

In reply to Samuel Holland

Prior to commit 7f7f8aca8257 ("sunxi: Convert 64-bit boards to use binman"), if the BL31 environment variable was not defined, the firmware would be loaded from a file "bl31.bin" in the current directory. Restore that behavior by providing that as the default filename in case no entry arg is provided, which will be the case if the environment variable is unset.

---
 arch/arm/dts/sunxi-u-boot.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm/dts/sunxi-u-boot.dtsi +1 -0
index 92a64472318..b7195c56710 100644
@@ -52,6 +52,7 @@
 #endif
 
 					atf-bl31 {
+						filename = "bl31.bin";
 						missing-msg = "atf-bl31-sunxi";
 					};
 				};
Signature · 1 line
2.26.2
author maintainer
#5 lore raw

PATCH v5 5/9 sunxi: binman: Use a macro for the BL31 load address

In reply to Samuel Holland

This consolidates the SoC-specific part at the top of the file to avoid cluttering it up with preprocessor conditions.

---
 arch/arm/dts/sunxi-u-boot.dtsi | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
arch/arm/dts/sunxi-u-boot.dtsi +8 -8
index b7195c56710..b8a0d4b6b08 100644
@@ -1,5 +1,11 @@
 #include <config.h>
 
+#ifdef CONFIG_MACH_SUN50I_H6
+#define BL31_ADDR 0x104000
+#else
+#define BL31_ADDR  0x44000
+#endif
+
 / {
 	aliases {
 		mmc1 = &mmc2;
@@ -42,14 +48,8 @@
 					type = "firmware";
 					arch = "arm64";
 					compression = "none";
-/* TODO: Do this with an overwrite in this board's dtb? */
-#ifdef CONFIG_MACH_SUN50I_H6
-					load = <0x104000>;
-					entry = <0x104000>;
-#else
-					load = <0x44000>;
-					entry = <0x44000>;
-#endif
+					load = <BL31_ADDR>;
+					entry = <BL31_ADDR>;
 
 					atf-bl31 {
 						filename = "bl31.bin";
Signature · 1 line
2.26.2
author maintainer
#6 lore raw

PATCH v5 6/9 spl: fit: Minimally parse OS properties with FIT_IMAGE_TINY

In reply to Samuel Holland

Some boards, specifically 64-bit Allwinner boards (sun50i), are extremely limited on SPL size. One strategy that was used to make space was to remove the FIT "os" property parsing code, because it uses a rather large lookup table.

However, this forces the legacy FIT parsing code path, which requires the "firmware" entry in the FIT to reference the U-Boot binary, even if U-Boot is not the next binary in the boot sequence (for example, on sun50i boards, ATF is run first).

This prevents the same FIT image from being used with a SPL with CONFIG_SPL_FIT_IMAGE_TINY=n and CONFIG_SPL_ATF=y, because the boot method selection code looks at spl_image.os, which is only set from the "firmware" entry's "os" property.

To be able to use CONFIG_SPL_ATF=y, the "firmware" entry in the FIT must be ATF, and U-Boot must be a loadable. For this to work, we need to parse the "os" property just enough to tell U-Boot from other images, so we can find it in the loadables list to append the FDT, and so we don't try to append the FDT to ATF (which could clobber adjacent firmware).

So add the minimal code necessary to distinguish U-Boot/non-U-Boot loadables with CONFIG_SPL_FIT_IMAGE_TINY=y. This adds about 300 bytes, much less than the 7400 bytes added by CONFIG_SPL_FIT_IMAGE_TINY=n.

---
 common/spl/Kconfig   |  4 +---
 common/spl/spl_fit.c | 17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 4 deletions(-)
common/spl/Kconfig +1 -3
index 620ea1e8b43..8d8126d08eb 100644
@@ -465,9 +465,7 @@ config SPL_FIT_IMAGE_TINY
 	  Enable this to reduce the size of the FIT image loading code
 	  in SPL, if space for the SPL binary is very tight.
 
-	  This removes the detection of image types (which forces the
-	  first image to be treated as having a U-Boot style calling
-	  convention) and skips the recording of each loaded payload
+	  This skips the recording of each loaded payload
 	  (i.e. loadable) into the FDT (modifying the loaded FDT to
 	  ensure this information is available to the next image
 	  invoked).
common/spl/spl_fit.c +16 -1
index a90d821c82e..fd6086a65c3 100644
@@ -466,7 +466,22 @@ static int spl_fit_record_loadable(const void *fit, int images, int index,
 static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
 {
 #if CONFIG_IS_ENABLED(FIT_IMAGE_TINY) && !defined(CONFIG_SPL_OS_BOOT)
-	return -ENOTSUPP;
+	const char *name = fdt_getprop(fit, noffset, FIT_OS_PROP, NULL);
+
+	if (!name)
+		return -ENOENT;
+
+	/*
+	 * We don't care what the type of the image actually is,
+	 * only whether or not it is U-Boot. This saves some
+	 * space by omitting the large table of OS types.
+	 */
+	if (!strcmp(name, "u-boot"))
+		*os = IH_OS_U_BOOT;
+	else
+		*os = IH_OS_INVALID;
+
+	return 0;
 #else
 	return fit_image_get_os(fit, noffset, os);
 #endif
Signature · 1 line
2.26.2
author maintainer
#7 lore raw

PATCH v5 7/9 sunxi: binman: Update FIT component descriptions

In reply to Samuel Holland

Since commit d879616e9e64 ("spl: fit: simplify logic for FDT loading for non-OS boots"), the SPL looks at the "os" properties of FIT images to determine where to append the FDT.

The "os" property of the "firmware" image also determines how to execute the next stage of the boot process, as in 1d3790905d9c ("spl: atf:
introduce spl_invoke_atf and make bl31_entry private"). For this reason, the next stage must be specified in "firmware", not in "loadables".

To support this additional functionality, and to properly model the boot process, where ATF runs before U-Boot, add the "os" properties and swap the firmware/loadable images in the FIT image.

Since this description was copied as an example in commit 70248d6a2916 ("binman: Support generating FITs with multiple dtbs"), update those examples as well for correctness and consistency.

---
 arch/arm/dts/sunxi-u-boot.dtsi | 6 ++++--
 tools/binman/README.entries    | 4 ++--
 tools/binman/etype/fit.py      | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)
arch/arm/dts/sunxi-u-boot.dtsi +4 -2
index b8a0d4b6b08..9f5b103cbb8 100644
@@ -35,6 +35,7 @@
 				uboot {
 					description = "U-Boot (64-bit)";
 					type = "standalone";
+					os = "u-boot";
 					arch = "arm64";
 					compression = "none";
 					load = <0x4a000000>;
@@ -46,6 +47,7 @@
 				atf {
 					description = "ARM Trusted Firmware";
 					type = "firmware";
+					os = "arm-trusted-firmware";
 					arch = "arm64";
 					compression = "none";
 					load = <BL31_ADDR>;
@@ -69,8 +71,8 @@
 
 				@config-SEQ {
 					description = "NAME";
-					firmware = "uboot";
-					loadables = "atf";
+					firmware = "atf";
+					loadables = "uboot";
 					fdt = "fdt-SEQ";
 				};
 			};
tools/binman/README.entries +2 -2
index c1d436563e8..bdb4fd6ee51 100644
@@ -385,8 +385,8 @@ You can create config nodes in a similar way:
         default = "@config-DEFAULT-SEQ";
         @config-SEQ {
             description = "NAME";
-            firmware = "uboot";
-            loadables = "atf";
+            firmware = "atf";
+            loadables = "uboot";
             fdt = "fdt-SEQ";
         };
     };
tools/binman/etype/fit.py +2 -2
index 8a24f12aa59..1a7cbd7cec7 100644
@@ -73,8 +73,8 @@ class Entry_fit(Entry):
             default = "@config-DEFAULT-SEQ";
             @config-SEQ {
                 description = "NAME";
-                firmware = "uboot";
-                loadables = "atf";
+                firmware = "atf";
+                loadables = "uboot";
                 fdt = "fdt-SEQ";
             };
         };
Signature · 1 line
2.26.2
author maintainer
#8 lore raw

PATCH v5 8/9 binman: Add support for SCP firmware

In reply to Samuel Holland

Add an entry type for a firmware blob for a System Control Processor, given by an entry arg. This firmware is a raw binary blob.

---
 Makefile                      |  1 +
 tools/binman/etype/scp.py     | 19 +++++++++++++++++++
 tools/binman/ftest.py         |  7 +++++++
 tools/binman/test/172_scp.dts | 16 ++++++++++++++++
 4 files changed, 43 insertions(+)
 create mode 100644 tools/binman/etype/scp.py
 create mode 100644 tools/binman/test/172_scp.dts
Makefile +1 -0
index 9e0985f14a5..81d575dd3b5 100644
@@ -1332,6 +1332,7 @@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
 		-I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
 		-a atf-bl31-path=${BL31} \
 		-a default-dt=$(default_dt) \
+		-a scp-path=$(SCP) \
 		$(BINMAN_$(@F))
 
 OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
tools/binman/etype/scp.py new file +19 -0
new file mode 100644
index 00000000000..93f8787d2d7
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2020 Samuel Holland <[email protected]>
+#
+# Entry-type module for System Control Processor (SCP) firmware blob
+#
+
+from binman.etype.blob_named_by_arg import Entry_blob_named_by_arg
+
+class Entry_scp(Entry_blob_named_by_arg):
+    """Entry containing a System Control Processor (SCP) firmware blob
+
+    Properties / Entry arguments:
+        - scp-path: Filename of file to read into the entry, typically scp.bin
+
+    This entry holds firmware for an external platform-specific coprocessor.
+    """
+    def __init__(self, section, etype, node):
+        super().__init__(section, etype, node, 'scp')
+        self.external = True
tools/binman/ftest.py +7 -0
index b771b9d5df7..75f6ca3a895 100644
@@ -75,6 +75,7 @@ FSP_M_DATA            = b'fsp_m'
 FSP_S_DATA            = b'fsp_s'
 FSP_T_DATA            = b'fsp_t'
 ATF_BL31_DATA         = b'bl31'
+SCP_DATA              = b'scp'
 TEST_FDT1_DATA        = b'fdt1'
 TEST_FDT2_DATA        = b'test-fdt2'
 ENV_DATA              = b'var1=1\nvar2="2"'
@@ -175,6 +176,7 @@ class TestFunctional(unittest.TestCase):
 
         TestFunctional._MakeInputFile('compress', COMPRESS_DATA)
         TestFunctional._MakeInputFile('bl31.bin', ATF_BL31_DATA)
+        TestFunctional._MakeInputFile('scp.bin', SCP_DATA)
 
         # Add a few .dtb files for testing
         TestFunctional._MakeInputFile('%s/test-fdt1.dtb' % TEST_FDT_SUBDIR,
@@ -3578,6 +3580,11 @@ class TestFunctional(unittest.TestCase):
         data = self._DoReadFile('169_atf_bl31.dts')
         self.assertEqual(ATF_BL31_DATA, data[:len(ATF_BL31_DATA)])
 
+    def testPackScp(self):
+        """Test that an image with an SCP binary can be created"""
+        data = self._DoReadFile('172_scp.dts')
+        self.assertEqual(SCP_DATA, data[:len(SCP_DATA)])
+
     def testFitFdt(self):
         """Test an image with an FIT with multiple FDT images"""
         def _CheckFdt(seq, expected_data):
tools/binman/test/172_scp.dts new file +16 -0
new file mode 100644
index 00000000000..354e4ef17df
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		size = <16>;
+
+		scp {
+			filename = "scp.bin";
+		};
+	};
+};
Signature · 1 line
2.26.2
author maintainer
#9 lore raw

PATCH v5 9/9 sunxi: binman: Add support for including SCP firmware

In reply to Samuel Holland

Allwinner sun50i SoCs contain an OpenRISC 1000 CPU that functions as a System Control Processor, or SCP. ARM Trusted Firmware (ATF) communicates with the SCP over SCPI to implement the PSCI system suspend, shutdown and reset functionality. Currently, SCP firmware is optional; the system will boot and run without it, but system suspend will be unavailable.

Since all communication with the SCP is mediated by ATF, the only thing U-Boot needs to do is load the firmware into SRAM. The SCP firmware occupies the last 16KiB of SRAM A2, immediately following ATF.

---
 arch/arm/dts/sunxi-u-boot.dtsi | 17 +++++++++++-
 board/sunxi/README.sunxi64     | 47 +++++++++++++++++++++++++++++-----
 tools/binman/missing-blob-help |  4 +++
 3 files changed, 60 insertions(+), 8 deletions(-)
arch/arm/dts/sunxi-u-boot.dtsi +16 -1
index 9f5b103cbb8..c77cf7cacf0 100644
@@ -2,8 +2,10 @@
 
 #ifdef CONFIG_MACH_SUN50I_H6
 #define BL31_ADDR 0x104000
+#define  SCP_ADDR 0x114000
 #else
 #define BL31_ADDR  0x44000
+#define  SCP_ADDR  0x50000
 #endif
 
 / {
@@ -59,6 +61,19 @@
 					};
 				};
 
+				scp {
+					description = "SCP firmware";
+					type = "firmware";
+					arch = "or1k";
+					compression = "none";
+					load = <SCP_ADDR>;
+
+					scp {
+						filename = "scp.bin";
+						missing-msg = "scp-sunxi";
+					};
+				};
+
 				@fdt-SEQ {
 					description = "NAME";
 					type = "flat_dt";
@@ -72,7 +87,7 @@
 				@config-SEQ {
 					description = "NAME";
 					firmware = "atf";
-					loadables = "uboot";
+					loadables = "scp", "uboot";
 					fdt = "fdt-SEQ";
 				};
 			};
board/sunxi/README.sunxi64 +40 -7

67 lines not on this page · raw message

tools/binman/missing-blob-help +4 -0
index 7cf1c346101..f7bc80ea830 100644
@@ -13,3 +13,7 @@ Firmware and build with BL31=/path/to/bl31.bin
 atf-bl31-sunxi:
 Please read the section on ARM Trusted Firmware (ATF) in
 board/sunxi/README.sunxi64
+
+scp-sunxi:
+SCP firmware is required for system suspend, but is otherwise optional.
+Please read the section on SCP firmware in board/sunxi/README.sunxi64
Signature · 1 line
2.26.2
#10 lore raw

v5 cover sunxi: binman fixes and SCP firmware support

In reply to Samuel Holland
Quoted 11 lines · Samuel Holland

This is a rework of my previous patch series adding SCP firmware support for system suspend, on top of the binman rewrite of mksunxi_fit_atf.sh. Now that the generic binman updates have all been merged, this patchset is based on u-boot/master.

- Patches 1-2 apply to binman FIT support generally.
- Patches 3-5 fix small issues in the new sunxi binman description.
- Patch 6 is unchanged (improvements to FIT_IMAGE_TINY).
- Patches 7-9 implement the SCP firmware support as in previous versions of this series, but using binman instead of a shell script.

Thanks!
Maxime
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201022/f7464daf/attachment.sig>