binman: add CST backend selection for i.MX8M signing
PATCH v3 1/1 binman: add CST backend selection for i.MX8M signing
Add support for setting the CST backend, both via DT property and CST_BACKEND environment variable. The CST currently supports two backends, 'ssl' and 'pkcs11', with 'ssl' being the default when CST tool is invoked without any -b parameter. Keep 'ssl' backend as the default, but explicitly pass it via the '-b' parameter, unless the user selects 'pkcs11' via either method.
---
Cc: Alper Nebi Yasak <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Fill in documentation for all used DT properties
V3: Fill third copy of documentation into nxp_imx8mcst.py
--- doc/imx/habv4/guides/mx8m_spl_secure_boot.txt | 30 ++++++++++++------- tools/binman/entries.rst | 7 +++++ tools/binman/etype/nxp_imx8mcst.py | 19 +++++++++++- 3 files changed, 44 insertions(+), 12 deletions(-)
doc/imx/habv4/guides/mx8m_spl_secure_boot.txt +19 -11
@@ -167,17 +167,25 @@ The nxp-imx8mcst etype is configurable using either DT properties or environment variables. The following DT properties and environment variables are supported. Note that environment variables override DT properties. -+--------------------+-----------+------------------------------------------------------------------+ -| DT property | Variable | Description | -+====================+===========+==================================================================+ -| nxp,loader-address | | SPL base address | -+--------------------+-----------+------------------------------------------------------------------+ -| nxp,srk-table | SRK_TABLE | full path to SRK_1_2_3_4_table.bin | -+--------------------+-----------+------------------------------------------------------------------+ -| nxp,csf-crt | CSF_KEY | full path to the CSF Key CSF1_1_sha256_4096_65537_v3_usr_crt.pem | -+--------------------+-----------+------------------------------------------------------------------+ -| nxp,img-crt | IMG_KEY | full path to the IMG Key IMG1_1_sha256_4096_65537_v3_usr_crt.pem | -+--------------------+-----------+------------------------------------------------------------------+ ++--------------------+-------------+------------------------------------------------------------------+ +| DT property | Variable | Description | ++====================+=============+==================================================================+ +| nxp,loader-address | | SPL base address | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,srk-table | SRK_TABLE | full path to SRK_1_2_3_4_table.bin | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,csf-crt | CSF_KEY | full path to the CSF Key CSF1_1_sha256_4096_65537_v3_usr_crt.pem | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,img-crt | IMG_KEY | full path to the IMG Key IMG1_1_sha256_4096_65537_v3_usr_crt.pem | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,fast-auth | | enable fast authentication method | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,srk-crt | SRK_KEY | full path to the SRK Key SRK1_sha256_4096_65537_v3_ca_crt.pem | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,unlock | | unlock CAAM in SPL | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,cst-backend | CST_BACKEND | CST tool backend, default is 'ssl', or selectable 'pkcs11' | ++--------------------+-------------+------------------------------------------------------------------+ Environment variables can be set as follows to point the build process to external key material:
tools/binman/entries.rst +7 -0
@@ -1664,6 +1664,13 @@ Entry: nxp-imx8mcst: NXP i.MX8M CST .cfg file generator and cst invoker Properties / Entry arguments: - nxp,loader-address - loader address (SPL text base) + - nxp,srk-table - full path to SRK_1_2_3_4_table.bin + - nxp,csf-crt - full path to the CSF Key CSF1_1_sha256_4096_65537_v3_usr_crt.pem + - nxp,img-crt - full path to the IMG Key IMG1_1_sha256_4096_65537_v3_usr_crt.pem + - nxp,fast-auth - enable fast authentication method + - nxp,srk-crt - full path to the SRK Key SRK1_sha256_4096_65537_v3_ca_crt.pem + - nxp,unlock - unlock CAAM in SPL + - nxp,cst-backend - CST tool backend, default is 'ssl', or selectable 'pkcs11'
tools/binman/etype/nxp_imx8mcst.py +18 -1
@@ -65,6 +65,13 @@ class Entry_nxp_imx8mcst(Entry_mkimage): Properties / Entry arguments: - nxp,loader-address - loader address (SPL text base) + - nxp,srk-table - full path to SRK_1_2_3_4_table.bin + - nxp,csf-crt - full path to the CSF Key CSF1_1_sha256_4096_65537_v3_usr_crt.pem + - nxp,img-crt - full path to the IMG Key IMG1_1_sha256_4096_65537_v3_usr_crt.pem + - nxp,fast-auth - enable fast authentication method + - nxp,srk-crt - full path to the SRK Key SRK1_sha256_4096_65537_v3_ca_crt.pem + - nxp,unlock - unlock CAAM in SPL + - nxp,cst-backend - CST tool backend, default is 'ssl', or selectable 'pkcs11' """ def __init__(self, section, etype, node):
@@ -90,6 +97,10 @@ class Entry_nxp_imx8mcst(Entry_mkimage): 'SRK_KEY', fdt_util.GetString(self._node, 'nxp,srk-crt', f'SRK1_{KEY_NAME}.pem')) + self.backend = os.getenv( + 'CST_BACKEND', fdt_util.GetString(self._node, 'nxp,cst-backend', + 'ssl')) + self.unlock = fdt_util.GetBool(self._node, 'nxp,unlock') self.ReadEntries()
@@ -161,8 +172,14 @@ class Entry_nxp_imx8mcst(Entry_mkimage): with open(cfg_fname, 'w') as cfgf: config.write(cfgf) + # SSL is the default backend, PKCS11 backend is optional + if self.backend == "pkcs11": + cst_backend = "pkcs11" + else: + cst_backend = "ssl" + output_fname = tools.get_output_filename(f'nxp.csf-output-blob.{uniq}') - args = ['-i', cfg_fname, '-o', output_fname] + args = ['-i', cfg_fname, '-o', output_fname, '-b', cst_backend] if self.cst.run_cmd(*args) is not None: outdata = tools.read_file(output_fname) # fixme: 0x2000 should be CONFIG_CSF_SIZE
Signature · 1 line
2.53.0
Hi Marek,
Quoted 17 lines · Marek Vasut
Add support for setting the CST backend, both via DT property and
CST_BACKENDenvironment variable. The CST currently supports two backends, 'ssl' and 'pkcs11', with 'ssl' being the default when CST tool is invoked without any -b parameter. Keep 'ssl' backend as the default, but explicitly pass it via the '-b' parameter, unless the user selects 'pkcs11' via either method.Signed-off-by Marek Vasut <[email protected]>---
Cc: Alper Nebi Yasak <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Fill in documentation for all used DT properties
V3: Fill third copy of documentation intonxp_imx8mcst.py
Quoted 6 lines
--- doc/imx/habv4/guides/mx8m_spl_secure_boot.txt | 30 ++++++++++++------- tools/binman/entries.rst | 7 +++++ tools/binman/etype/nxp_imx8mcst.py | 19 +++++++++++- 3 files changed, 44 insertions(+), 12 deletions(-)
This is missing coverage for line 177 of nxp_imx8mcst.py:
cst_backend = "pkcs11"
Please can you use (or mock) this feature in a test.
Quoted 105 lines
doc/imx/habv4/guides/mx8m_spl_secure_boot.txt +19
-11@@ -167,17 +167,25 @@ The nxp-imx8mcst etype is configurable using either DT properties or environment variables. The following DT properties and environment variables are supported. Note that environment variables override DT properties. -+--------------------+-----------+------------------------------------------------------------------+ -| DT property | Variable | Description | -+====================+===========+==================================================================+ -| nxp,loader-address | | SPL base address | -+--------------------+-----------+------------------------------------------------------------------+ -| nxp,srk-table | SRK_TABLE | full path to SRK_1_2_3_4_table.bin | -+--------------------+-----------+------------------------------------------------------------------+ -| nxp,csf-crt | CSF_KEY | full path to the CSF Key CSF1_1_sha256_4096_65537_v3_usr_crt.pem | -+--------------------+-----------+------------------------------------------------------------------+ -| nxp,img-crt | IMG_KEY | full path to the IMG Key IMG1_1_sha256_4096_65537_v3_usr_crt.pem | -+--------------------+-----------+------------------------------------------------------------------+ ++--------------------+-------------+------------------------------------------------------------------+ +| DT property | Variable | Description | ++====================+=============+==================================================================+ +| nxp,loader-address | | SPL base address | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,srk-table | SRK_TABLE | full path to SRK_1_2_3_4_table.bin | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,csf-crt | CSF_KEY | full path to the CSF Key CSF1_1_sha256_4096_65537_v3_usr_crt.pem | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,img-crt | IMG_KEY | full path to the IMG Key IMG1_1_sha256_4096_65537_v3_usr_crt.pem | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,fast-auth | | enable fast authentication method | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,srk-crt | SRK_KEY | full path to the SRK Key SRK1_sha256_4096_65537_v3_ca_crt.pem | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,unlock | | unlock CAAM in SPL | ++--------------------+-------------+------------------------------------------------------------------+ +| nxp,cst-backend | CST_BACKEND | CST tool backend, default is 'ssl', or selectable 'pkcs11' | ++--------------------+-------------+------------------------------------------------------------------+ Environment variables can be set as follows to point the build process to external key material:tools/binman/entries.rst +7
-0@@ -1664,6 +1664,13 @@ Entry: nxp-imx8mcst: NXP i.MX8M CST .cfg file generator and cst invoker Properties / Entry arguments: - nxp,loader-address - loader address (SPL text base) + - nxp,srk-table - full path to SRK_1_2_3_4_table.bin + - nxp,csf-crt - full path to the CSF Key CSF1_1_sha256_4096_65537_v3_usr_crt.pem + - nxp,img-crt - full path to the IMG Key IMG1_1_sha256_4096_65537_v3_usr_crt.pem + - nxp,fast-auth - enable fast authentication method + - nxp,srk-crt - full path to the SRK Key SRK1_sha256_4096_65537_v3_ca_crt.pem + - nxp,unlock - unlock CAAM in SPL + - nxp,cst-backend - CST tool backend, default is 'ssl', or selectable 'pkcs11'tools/binman/etype/nxp_imx8mcst.py +18
-2@@ -65,6 +65,13 @@ class Entry_nxp_imx8mcst(Entry_mkimage): Properties / Entry arguments: - nxp,loader-address - loader address (SPL text base) + - nxp,srk-table - full path to SRK_1_2_3_4_table.bin + - nxp,csf-crt - full path to the CSF Key CSF1_1_sha256_4096_65537_v3_usr_crt.pem + - nxp,img-crt - full path to the IMG Key IMG1_1_sha256_4096_65537_v3_usr_crt.pem + - nxp,fast-auth - enable fast authentication method + - nxp,srk-crt - full path to the SRK Key SRK1_sha256_4096_65537_v3_ca_crt.pem + - nxp,unlock - unlock CAAM in SPL + - nxp,cst-backend - CST tool backend, default is 'ssl', or selectable 'pkcs11' """ def __init__(self, section, etype, node):@@ -90,6 +97,10 @@ class Entry_nxp_imx8mcst(Entry_mkimage): 'SRK_KEY', fdt_util.GetString(self._node, 'nxp,srk-crt', f'SRK1_{KEY_NAME}.pem')) + self.backend = os.getenv( + 'CST_BACKEND', fdt_util.GetString(self._node, 'nxp,cst-backend', + 'ssl')) + self.unlock = fdt_util.GetBool(self._node, 'nxp,unlock') self.ReadEntries()@@ -161,8 +172,14 @@ class Entry_nxp_imx8mcst(Entry_mkimage): with open(cfg_fname, 'w') as cfgf: config.write(cfgf) + # SSL is the default backend, PKCS11 backend is optional + if self.backend == "pkcs11": + cst_backend = "pkcs11" + else: + cst_backend = "ssl" + output_fname = tools.get_output_filename(f'nxp.csf-output-blob.{uniq}') - args = ['-i', cfg_fname, '-o', output_fname] + args = ['-i', cfg_fname, '-o', output_fname, '-b', cst_backend] if self.cst.run_cmd(*args) is not None: outdata = tools.read_file(output_fname) # fixme: 0x2000 should be CONFIG_CSF_SIZE --
Quoted 2 lines
2.53.0
Regards,
SImon
Quoted 27 lines · Simon Glass
Hi Marek,
Quoted 17 lines · Marek Vasut
Add support for setting the CST backend, both via DT property and
CST_BACKENDenvironment variable. The CST currently supports two backends, 'ssl' and 'pkcs11', with 'ssl' being the default when CST tool is invoked without any -b parameter. Keep 'ssl' backend as the default, but explicitly pass it via the '-b' parameter, unless the user selects 'pkcs11' via either method.Signed-off-by Marek Vasut <[email protected]>---
Cc: Alper Nebi Yasak <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Fill in documentation for all used DT properties
V3: Fill third copy of documentation intonxp_imx8mcst.pyQuoted 6 lines
--- doc/imx/habv4/guides/mx8m_spl_secure_boot.txt | 30 ++++++++++++------- tools/binman/entries.rst | 7 +++++ tools/binman/etype/nxp_imx8mcst.py | 19 +++++++++++- 3 files changed, 44 insertions(+), 12 deletions(-)
Quoted 5 lines
This is missing coverage for line 177 of
nxp_imx8mcst.py:cst_backend = "pkcs11"Please can you use (or mock) this feature in a test.
I already invested a lot of effort into binman tests before in [PATCH] binman: Fill in most of the imx8mimage and imx8mcst tests and it went nowhere.
Can you provide (an example of) such a test ?
Hi Marek,
Quoted 13 lines · Marek Vasut
Quoted 11 lines · Simon Glass
Hi Marek,
Quoted 8 lines · Marek Vasut
Add support for setting the CST backend, both via DT property and
CST_BACKENDenvironment variable. The CST currently supports two backends, 'ssl' and 'pkcs11', with 'ssl' being the default when CST tool is invoked without any -b parameter. Keep 'ssl' backend as the default, but explicitly pass it via the '-b' parameter, unless the user selects 'pkcs11' via either method.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Signed-off-by Marek Vasut <[email protected]>---
Cc: Alper Nebi Yasak <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: Fill in documentation for all used DT properties
V3: Fill third copy of documentation intonxp_imx8mcst.py--- doc/imx/habv4/guides/mx8m_spl_secure_boot.txt | 30
++++++++++++-------
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
tools/binman/entries.rst | 7 +++++ tools/binman/etype/nxp_imx8mcst.py | 19 +++++++++++- 3 files changed, 44 insertions(+), 12 deletions(-)This is missing coverage for line 177 of
nxp_imx8mcst.py:
Quoted 8 lines
Quoted 3 lines
cst_backend = "pkcs11"Please can you use (or mock) this feature in a test.
I already invested a lot of effort into binman tests before in [PATCH]
binman: Fill in most of the imx8mimage and imx8mcst tests and it went nowhere.Can you provide (an example of) such a test ?
Yes you created quite a few tests. Then I invested a lot of time to finish it off[1] so that we are finnaly back up to 100%
Since you are adding a new feature your may need a test file with a 'nxp,cst-backend' set to 'pkcs11'
Regards,
Simon
[1] https://patchwork.ozlabs.org/project/uboot/list/?series=494765&state=*