Skip to contentSkip to conversation

binman: nxp_imx8mcst: Handle FCFB header during SPI NOR boot

PATCH In review Marek Vasut 2 participants 3 messages Jul 15 – Jul 28 1 message not in the archive Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 binman: nxp_imx8mcst: Handle FCFB header during SPI NOR boot

In case the image that is wrapped in the nxp_imx8mcst already contains an FCFB header which is mandatory for SPI NOR boot, then the IVT is at offset 0x1000 instead of offset 0x0, but the whole image including the FCFB header must be signed to prevent attacker from tampering with any of the headers. Add the FCFB handling.

---
Cc: "NXP i.MX U-Boot Team" <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefano Babic <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]

---
 tools/binman/etype/nxp_imx8mcst.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/binman/etype/nxp_imx8mcst.py +10 -2
index a10f61aa01f..b45d7298037 100644
@@ -20,8 +20,9 @@ from binman import elf
 from dtoc import fdt_util
 from u_boot_pylib import tools
 
-MAGIC_NXP_IMX_IVT = 0x412000d1
-MAGIC_FITIMAGE    = 0xedfe0dd0
+MAGIC_NXP_IMX_IVT  = 0x412000d1
+MAGIC_NXP_IMX_FCFB = 0x42464346
+MAGIC_FITIMAGE     = 0xedfe0dd0
 
 KEY_NAME = 'sha256_4096_65537_v3_usr_crt'
 
@@ -125,6 +126,13 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
             signsize = struct.unpack('<I', data[24:28])[0] - signbase
             # Remove mkimage generated padding from the end of data
             data = data[:signsize]
+        elif signtype == MAGIC_NXP_IMX_FCFB: # SPL/imx8mimage with FCFB
+            # Sign the payload including FCFB and imx8mimage headers
+            # (extra 0x1000 and 0x40 bytes before the payload)
+            signbase -= 0x1040
+            signsize = struct.unpack('<I', data[4120:4124])[0] - signbase
+            # Remove mkimage generated padding from the end of data
+            data = data[:signsize]
         elif signtype == MAGIC_FITIMAGE: # fitImage
             # Align fitImage to 4k
             signsize = tools.align(len(data), 0x1000)
Signature · 1 line
2.53.0
#1 lore raw

Hi Marek,

Quoted 15 lines · Marek Vasut

binman: nxp_imx8mcst: Handle FCFB header during SPI NOR boot

In case the image that is wrapped in the nxp_imx8mcst already contains an FCFB header which is mandatory for SPI NOR boot, then the IVT is at offset 0x1000 instead of offset 0x0, but the whole image including the FCFB header must be signed to prevent attacker from tampering with any of the headers. Add the FCFB handling.

tools/binman/etype/nxp_imx8mcst.py | 12 ++++++++++--

 1 file changed, 10 insertions(+), 2 deletions(-)

tools/binman/etype/nxp_imx8mcst.py class Entry_nxp_imx8mcst(Entry_mkimage): · line 119

Quoted 5 lines
tools/binman/etype/nxp_imx8mcst.py +5 -0
@@ -114,6 +115,13 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
+        elif signtype == MAGIC_NXP_IMX_FCFB: # SPL/imx8mimage with FCFB
+            # Sign the payload including FCFB and imx8mimage headers
+            # (extra 0x1000 and 0x40 bytes before the payload)
+            signbase -= 0x1040
+            signsize = struct.unpack('<I', data[4120:4124])[0] - signbase

Please see below for test ideas.

Also, 4120 is quite obscure as a decimal literal. Since this branch is the IVT one shifted by 0x1000, perhaps the two could be merged, e.g.:

    if signtype in (MAGIC_NXP_IMX_IVT, MAGIC_NXP_IMX_FCFB):
        off = 0x1000 if signtype == MAGIC_NXP_IMX_FCFB else 0
        signbase -= off + 0x40
        signsize = struct.unpack(
            '<I', data[off + 24:off + 28])[0] - signbase
        data = data[:signsize]

That makes it clear the value being read is the csf pointer at IVT offset 24, same as the existing case. What do you think?

tools/binman/etype/nxp_imx8mcst.py class Entry_nxp_imx8mcst(Entry_mkimage): · line 115

Quoted 3 lines
tools/binman/etype/nxp_imx8mcst.py +1 -0
@@ -114,6 +115,13 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
+        elif signtype == MAGIC_NXP_IMX_FCFB: # SPL/imx8mimage with FCFB

Please can you also update the block comment above this code ("Parse the input data and figure out what it is that is being signed") to mention the FCFB case?

Here is my attempt at a test (it doesn't actually check the output though):

def testNxpImx8mCSTFcfb(self):

    """Test CST signing with an FCFB header (SPI NOR boot)

    When the payload is wrapped for SPI NOR boot it starts with an FCFB
    header, so the imx8mimage IVT sits at offset 0x1000 and the size word it
    carries is at offset 0x1018 (4120). Build a fake blob with the FCFB magic
    and that size word so the FCFB branch is exercised.
    """
    fcfb_data = struct.pack('<I', 0x42464346)
    fcfb_data += b'\x00' * (4120 - 4)
    fcfb_data += struct.pack('<I', 0)
    self._MakeInputFile('imx8m-ivt.bin', fcfb_data)
    with terminal.capture() as (_, stderr):
        self._DoTestFile('vendor/nxp_imx8_csf.dts',

force_missing_bintools='cst')
err = stderr.getvalue()
self.assertRegex(err, "Image 'image'.*missing bintools.*: cst")

Regards,
Simon

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Hi Marek,

Quoted 39 lines · Marek Vasut

On 7/17/26 4:05 PM, Simon Glass wrote:

Hello Simon,

Quoted 20 lines

tools/binman/etype/nxp_imx8mcst.py class Entry_nxp_imx8mcst(Entry_mkimage): · line 119

Quoted 7 lines
tools/binman/etype/nxp_imx8mcst.py +5 -0
@@ -114,6 +115,13 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
+        elif signtype == MAGIC_NXP_IMX_FCFB: # SPL/imx8mimage with FCFB
+            # Sign the payload including FCFB and imx8mimage headers
+            # (extra 0x1000 and 0x40 bytes before the payload)
+            signbase -= 0x1040
+            signsize = struct.unpack('<I', data[4120:4124])[0] - signbase

Please see below for test ideas.

Also, 4120 is quite obscure as a decimal literal. Since this branch is the IVT one shifted by 0x1000, perhaps the two could be merged, e.g.:

     if signtype in (MAGIC_NXP_IMX_IVT, MAGIC_NXP_IMX_FCFB):
         off = 0x1000 if signtype == MAGIC_NXP_IMX_FCFB else 0
         signbase -= off + 0x40
         signsize = struct.unpack(
             '<I', data[off + 24:off + 28])[0] - signbase
         data = data[:signsize]
Quoted 2 lines

That makes it clear the value being read is the csf pointer at IVT offset 24, same as the existing case. What do you think?

Yuck, no, I would very much prefer the current readable form than this conflated horribleness. The image assembly is convoluted enough as it is.

Quoted 7 lines

tools/binman/etype/nxp_imx8mcst.py class Entry_nxp_imx8mcst(Entry_mkimage): · line 115

Quoted 3 lines
tools/binman/etype/nxp_imx8mcst.py +1 -0
@@ -114,6 +115,13 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
+        elif signtype == MAGIC_NXP_IMX_FCFB: # SPL/imx8mimage with FCFB

Please can you also update the block comment above this code ("Parse the input data and figure out what it is that is being signed") to mention the FCFB case?

Quoted 5 lines

Done in V2.

Quoted 1 line

Here is my attempt at a test (it doesn't actually check the output though):

If you would like to write a proper test, I can help with providing expected outputs.

Checking outputs is nice but (perhaps oddly!) not essential. Binman just requires that tests exercise the code. So the test I sent previously should be enough to get 'binman test -T' to pass.

Regards,
Simon