Skip to content
Snippets Groups Projects
Commit 784f84d5 authored by Brian Ruley's avatar Brian Ruley Committed by Fabio Estevam
Browse files

binman: cosmetic: refactor `nxp_imx8mcst' etype code


Simplify code and conform to the style guide used in the project by
making the following changes:
* Capitalize global constants
* Use single quotes for multiline strings (except docstrings)
* Fix line width to 79 cols
* Use f-string instead of formatting a regular string or using a
  complicated concatenation
* Move common suffix used in keys to a global variable "KEY_NAME"
  to reduce the likelihood of typos and making future changes
  easier

Signed-off-by: default avatarBrian Ruley <brian.ruley@gehealthcare.com>
Cc: Marek Vasut <marex@denx.de>
parent e612d5c2
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,9 @@ from u_boot_pylib import tools ...@@ -23,7 +23,9 @@ from u_boot_pylib import tools
MAGIC_NXP_IMX_IVT = 0x412000d1 MAGIC_NXP_IMX_IVT = 0x412000d1
MAGIC_FITIMAGE = 0xedfe0dd0 MAGIC_FITIMAGE = 0xedfe0dd0
csf_config_template = """ KEY_NAME = 'sha256_4096_65537_v3_usr_crt'
CSF_CONFIG_TEMPLATE = f'''
[Header] [Header]
Version = 4.3 Version = 4.3
Hash Algorithm = sha256 Hash Algorithm = sha256
...@@ -37,7 +39,7 @@ csf_config_template = """ ...@@ -37,7 +39,7 @@ csf_config_template = """
Source index = 0 Source index = 0
[Install CSFK] [Install CSFK]
File = "CSF1_1_sha256_4096_65537_v3_usr_crt.pem" File = "CSF1_1_{KEY_NAME}.pem"
[Authenticate CSF] [Authenticate CSF]
...@@ -48,12 +50,12 @@ csf_config_template = """ ...@@ -48,12 +50,12 @@ csf_config_template = """
[Install Key] [Install Key]
Verification index = 0 Verification index = 0
Target Index = 2 Target Index = 2
File = "IMG1_1_sha256_4096_65537_v3_usr_crt.pem" File = "IMG1_1_{KEY_NAME}.pem"
[Authenticate Data] [Authenticate Data]
Verification index = 2 Verification index = 2
Blocks = 0x1234 0x78 0xabcd "data.bin" Blocks = 0x1234 0x78 0xabcd "data.bin"
""" '''
class Entry_nxp_imx8mcst(Entry_mkimage): class Entry_nxp_imx8mcst(Entry_mkimage):
"""NXP i.MX8M CST .cfg file generator and cst invoker """NXP i.MX8M CST .cfg file generator and cst invoker
...@@ -69,9 +71,15 @@ class Entry_nxp_imx8mcst(Entry_mkimage): ...@@ -69,9 +71,15 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
def ReadNode(self): def ReadNode(self):
super().ReadNode() super().ReadNode()
self.loader_address = fdt_util.GetInt(self._node, 'nxp,loader-address') self.loader_address = fdt_util.GetInt(self._node, 'nxp,loader-address')
self.srk_table = os.getenv('SRK_TABLE', fdt_util.GetString(self._node, 'nxp,srk-table', 'SRK_1_2_3_4_table.bin')) self.srk_table = os.getenv(
self.csf_crt = os.getenv('CSF_KEY', fdt_util.GetString(self._node, 'nxp,csf-crt', 'CSF1_1_sha256_4096_65537_v3_usr_crt.pem')) 'SRK_TABLE', fdt_util.GetString(self._node, 'nxp,srk-table',
self.img_crt = os.getenv('IMG_KEY', fdt_util.GetString(self._node, 'nxp,img-crt', 'IMG1_1_sha256_4096_65537_v3_usr_crt.pem')) 'SRK_1_2_3_4_table.bin'))
self.csf_crt = os.getenv(
'CSF_KEY', fdt_util.GetString(self._node, 'nxp,csf-crt',
f'CSF1_1_{KEY_NAME}.pem'))
self.img_crt = os.getenv(
'IMG_KEY', fdt_util.GetString(self._node, 'nxp,img-crt',
f'IMG1_1_{KEY_NAME}.pem'))
self.unlock = fdt_util.GetBool(self._node, 'nxp,unlock') self.unlock = fdt_util.GetBool(self._node, 'nxp,unlock')
self.ReadEntries() self.ReadEntries()
...@@ -118,16 +126,18 @@ class Entry_nxp_imx8mcst(Entry_mkimage): ...@@ -118,16 +126,18 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
tools.write_file(output_dname, data) tools.write_file(output_dname, data)
# Generate CST configuration file used to sign payload # Generate CST configuration file used to sign payload
cfg_fname = tools.get_output_filename('nxp.csf-config-txt.%s' % uniq) cfg_fname = tools.get_output_filename(f'nxp.csf-config-txt.{uniq}')
config = configparser.ConfigParser() config = configparser.ConfigParser()
# Do not make key names lowercase # Do not make key names lowercase
config.optionxform = str config.optionxform = str
# Load configuration template and modify keys of interest # Load configuration template and modify keys of interest
config.read_string(csf_config_template) config.read_string(CSF_CONFIG_TEMPLATE)
config['Install SRK']['File'] = '"' + self.srk_table + '"' config['Install SRK']['File'] = f'"{self.srk_table}"'
config['Install CSFK']['File'] = '"' + self.csf_crt + '"' config['Install CSFK']['File'] = f'"{self.csf_crt}"'
config['Install Key']['File'] = '"' + self.img_crt + '"' config['Install Key']['File'] = f'"{self.img_crt}"'
config['Authenticate Data']['Blocks'] = hex(signbase) + ' 0 ' + hex(len(data)) + ' "' + str(output_dname) + '"' config['Authenticate Data']['Blocks'] = \
f'{signbase:#x} 0 {len(data):#x} "{output_dname}"'
if not self.unlock: if not self.unlock:
config.remove_section('Unlock') config.remove_section('Unlock')
with open(cfg_fname, 'w') as cfgf: with open(cfg_fname, 'w') as cfgf:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment