Skip to contentSkip to conversation

sunxi: binman fixes and SCP firmware support

PATCH Superseded Samuel Holland 3 participants 13 messages Sep 12, 2020 – Oct 22, 2020

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Samuel Holland

author maintainer
#0 lore raw

v4 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.

This patch series is based on u-boot-dm/next.

- The first two patches apply to binman FIT support generally.
- The third patch is unchanged from previous versions.
- Patches 4-6 fix small issues in the new sunxi binman description.
- Patches 7-9 implement the same functionality as previous versions of this series, but using binman instead of a shell script.

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
spl: fit: Minimally parse OS properties with FIT_IMAGE_TINY
sunxi: binman: Fix spacing between nodes
sunxi: binman: Provide a default BL31 filename
sunxi: binman: Use a macro for the BL31 load address
sunxi: binman: Update FIT component descriptions
binman: Add support for SCP firmware
sunxi: binman: Add support for including SCP firmware

 Makefile                       |  4 +++-
 arch/arm/dts/sunxi-u-boot.dtsi | 42 +++++++++++++++++++++++++--------
 board/sunxi/README.sunxi64     | 43 ++++++++++++++++++++++++++++------
 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/test/172_scp.dts  | 16 +++++++++++++
 10 files changed, 138 insertions(+), 30 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 v4 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 65024c74089..d5aa8605c0a 100644
@@ -1438,11 +1438,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 v4 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. 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 c291eb26bad..01fa51367e6 100644
@@ -179,10 +179,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 v4 3/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 af8255a8d6a..041b47244bd 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 365104fe028..a31ab6c5992 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
#4 lore raw

PATCH v4 4/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 1d1c3691099..82b97a9503f 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 {
 					};
 				};
@@ -60,6 +64,7 @@
 
 			configurations {
 				default = "config-1";
+
 				@config-SEQ {
 					description = "NAME";
 					firmware = "uboot";
Signature · 1 line
2.26.2
author maintainer
#5 lore raw

PATCH v4 5/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 82b97a9503f..6ab0c783ba5 100644
@@ -52,6 +52,7 @@
 #endif
 
 					atf-bl31 {
+						filename = "bl31.bin";
 					};
 				};
 
Signature · 1 line
2.26.2
#6 lore raw

PATCH v4 5/9 sunxi: binman: Provide a default BL31 filename

Hi Samuel,

Quoted 19 lines · 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 +0 -0
index 82b97a9503f..6ab0c783ba5 100644

arch/arm/dts/sunxi-u-boot.dtsi line 55

Quoted 4 lines
arch/arm/dts/sunxi-u-boot.dtsi +1 -0
@@ -52,6 +52,7 @@
 #endif
 
                                        atf-bl31 {
+                                               filename = "bl31.bin";

I have dropped missing-msg = "atf-bl31-sunxi"; and used filename
section as above.

Build showing below messages.

MKIMAGE u-boot.img
MKIMAGE u-boot-dtb.img
BINMAN all
Image 'main-section' is missing external blobs and is non-functional: scp

Some images are invalid

Cannot we make scp as optional for the build?

Jagan.

author maintainer
#7 lore raw

PATCH v4 5/9 sunxi: binman: Provide a default BL31 filename

Quoted 32 lines · Jagan Teki

Hi Samuel,

Quoted 19 lines · 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 +0 -0
index 82b97a9503f..6ab0c783ba5 100644

arch/arm/dts/sunxi-u-boot.dtsi line 55

Quoted 4 lines
arch/arm/dts/sunxi-u-boot.dtsi +1 -0
@@ -52,6 +52,7 @@
 #endif
 
                                        atf-bl31 {
+                                               filename = "bl31.bin";

I have dropped missing-msg = "atf-bl31-sunxi"; and used filename
section as above.

Build showing below messages.

Quoted 8 lines

MKIMAGE u-boot.img
MKIMAGE u-boot-dtb.img
BINMAN all
Image 'main-section' is missing external blobs and is non-functional: scp

Some images are invalid

Cannot we make scp as optional for the build?

It already is optional. Even with that warning message, u-boot-sunxi-with-spl.bin is still created and will still boot.

Now that the missing-msg is merged to mainline, I will add one for SCP firmware saying it is optional. However, I cannot control the existing binman warning. I will also explain in the documentation how to silence the warning (with an empty file).

Quoted 1 line

Jagan.

Cheers,
Samuel

author maintainer
#8 lore raw

PATCH v4 6/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 6ab0c783ba5..4d599720382 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
#9 lore raw

PATCH v4 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 4d599720382..ff3fff599f4 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>;
@@ -68,8 +70,8 @@
 
 				@config-SEQ {
 					description = "NAME";
-					firmware = "uboot";
-					loadables = "atf";
+					firmware = "atf";
+					loadables = "uboot";
 					fdt = "fdt-SEQ";
 				};
 			};
tools/binman/README.entries +2 -2
index d2628dffd5d..c45aed0a681 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 01fa51367e6..73793ecda31 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
#10 lore raw

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

In reply to Samuel Holland

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

---
 Makefile                      |  2 +-
 tools/binman/etype/scp.py     | 19 +++++++++++++++++++
 tools/binman/ftest.py         |  7 +++++++
 tools/binman/test/172_scp.dts | 16 ++++++++++++++++
 4 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/etype/scp.py
 create mode 100644 tools/binman/test/172_scp.dts
Makefile +1 -1
index d5aa8605c0a..5a6681f129e 100644
@@ -1328,7 +1328,7 @@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
 		build -u -d u-boot.dtb -O . -m --allow-missing \
 		-I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
 		-I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
-		-a atf-bl31-path=${BL31} \
+		-a atf-bl31-path=${BL31} -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 78d0e9c2b93..72e738913eb 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'
 
@@ -174,6 +175,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,
@@ -3575,6 +3577,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
#11 lore raw

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

Quoted 5 lines · Samuel Holland

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

Quoted 8 lines
---
 Makefile                      |  2 +-
 tools/binman/etype/scp.py     | 19 +++++++++++++++++++
 tools/binman/ftest.py         |  7 +++++++
 tools/binman/test/172_scp.dts | 16 ++++++++++++++++
 4 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/etype/scp.py
 create mode 100644 tools/binman/test/172_scp.dts
author maintainer
#12 lore raw

PATCH v4 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 | 16 ++++++++++++-
 board/sunxi/README.sunxi64     | 43 ++++++++++++++++++++++++++++------
 2 files changed, 51 insertions(+), 8 deletions(-)
arch/arm/dts/sunxi-u-boot.dtsi +15 -1
index ff3fff599f4..5ab7c6c23b7 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
 
 / {
@@ -58,6 +60,18 @@
 					};
 				};
 
+				scp {
+					description = "SCP firmware";
+					type = "firmware";
+					arch = "or1k";
+					compression = "none";
+					load = <SCP_ADDR>;
+
+					scp {
+						filename = "scp.bin";
+					};
+				};
+
 				@fdt-SEQ {
 					description = "NAME";
 					type = "flat_dt";
@@ -71,7 +85,7 @@
 				@config-SEQ {
 					description = "NAME";
 					firmware = "atf";
-					loadables = "uboot";
+					loadables = "scp", "uboot";
 					fdt = "fdt-SEQ";
 				};
 			};
board/sunxi/README.sunxi64 +36 -7

63 lines not on this page · raw message

Signature · 1 line
2.26.2