Skip to contentSkip to conversation

mkimage: allow zynqmpbif to use a register initialization file

PATCH Superseded Erich E. Hoover 2 participants 4 messages Jun 5 – Jun 12 Arm/Zynq architecture

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mkimage: allow zynqmpbif to use a register initialization file

The ZynqMP Boot Image Format allows specifying the register initialization file with the "[init]" attribute. Since this feature is already supported by the "zynqmpimage" backend, this commit leverages that existing capability to add support for the "[init]" attribute in the zynqmpbif backend:
https://docs.amd.com/r/en-US/ug1283-bootgen-user-guide/init

We are using this feature, in combination with other zynqmpbif options, like so:
===

image : {
     [init] fsbl.int
     [bootloader] fsbl.elf
     [pmufw_image] pmufw.elf
     [destination_cpu=none] fsbl.tcl
     [destination_cpu=a53-0, exception_level=el-3] bl31.elf
     [destination_cpu=a53-0, exception_level=el-2, load=0x08000000,

startup=0x08000000] u-boot.bin
}
===

---
 tools/zynqmpbif.c   | 16 ++++++++++++++--
 tools/zynqmpimage.c |  4 ++--
 tools/zynqmpimage.h |  2 ++
 3 files changed, 18 insertions(+), 4 deletions(-)
tools/zynqmpbif.c +14 -2
index 82ce0ac1a52..546b9e4fd9d 100644
@@ -191,6 +191,7 @@ static char *parse_partition_owner(char *line, struct bif_entry *bf)
 }
 
 static const struct bif_flags bif_flags[] = {
+	{ "init", BIF_FLAG_INIT },
 	{ "fsbl_config", BIF_FLAG_FSBL_CONFIG },
 	{ "trustzone", BIF_FLAG_TZ },
 	{ "pmufw_image", BIF_FLAG_PMUFW_IMAGE },
@@ -279,7 +280,7 @@ static int bif_add_blob(const void *data, size_t len, size_t *offset)
 	return 0;
 }
 
-static int bif_init(void)
+static int bif_initialize(void)
 {
 	struct zynqmp_header header = { { 0 } };
 	int r;
@@ -316,6 +317,15 @@ static int bif_add_pmufw(struct bif_entry *bf, const char *data, size_t len)
 	return 0;
 }
 
+static int bif_init(struct bif_entry *init)
+{
+	/* User can pass in text file with init list */
+	if (strlen(init->filename))
+		zynqmpimage_parse_initparams(bif_output.header, init->filename);
+
+	return 0;
+}
+
 static int bif_add_part(struct bif_entry *bf, const char *data, size_t len)
 {
 	size_t parthdr_offset = 0;
@@ -340,6 +350,8 @@ static int bif_add_part(struct bif_entry *bf, const char *data, size_t len)
 
 	if (bf->flags & (1ULL << BIF_FLAG_PMUFW_IMAGE))
 		return bif_add_pmufw(bf, data, len);
+	else if (bf->flags & (1ULL << BIF_FLAG_INIT))
+		return bif_init(bf);
 
 	r = bif_add_blob(data, len, &bf->offset);
 	if (r)
@@ -837,7 +849,7 @@ int zynqmpbif_copy_image(int outfd, struct image_tool_params *mparams)
 	uint32_t csum;
 	int bldr = -1;
 
-	bif_init();
+	bif_initialize();
 
 	/* Read .bif input file */
 	bif = read_full_file(mparams->datafile, NULL);
tools/zynqmpimage.c +2 -2
index 4db9877127e..eb79c0696cc 100644
@@ -400,8 +400,8 @@ static void zynqmpimage_pmufw(struct zynqmp_header *zynqhdr,
 	fclose(fpmu);
 }
 
-static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
-	const char *filename)
+void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
+				  const char *filename)
 {
 	FILE *fp;
 	struct zynqmp_reginit reginit;
tools/zynqmpimage.h +2 -0
index 7c47dc0763b..867fc5294a3 100644
@@ -142,6 +142,8 @@ struct zynqmp_header {
 
 void zynqmpimage_default_header(struct zynqmp_header *ptr);
 void zynqmpimage_print_header(const void *ptr, struct image_tool_params *params);
+void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr,
+				  const char *filename);
 
 static inline struct image_header_table *
 zynqmp_get_iht(const struct zynqmp_header *zynqhdr)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 8 lines · Erich E. Hoover

The ZynqMP Boot Image Format allows specifying the register initialization file with the "[init]" attribute. Since this feature is already supported by the "zynqmpimage" backend, this commit leverages that existing capability to add support for the "[init]" attribute in the zynqmpbif backend:
https://docs.amd.com/r/en-US/ug1283-bootgen-user-guide/init

We are using this feature, in combination with other zynqmpbif

imperative mood.

Quoted 4 lines

options, like so:
===
image : {
[init] fsbl.int

please use different name then fsbl because fsbl is not doing this programming. That's done by bootrom itself.

Topic board is defining it like this. board/topic/zynq/zynq-topic-miamiplus/ps7_regs.txt

but that's for zynq

Actually I think would be good to recap format because origin format is different compare to what it is used by bootgen right now.

https://docs.amd.com/r/en-US/ug1283-bootgen-user-guide/Initialization-Pairs-and-INT-File-Attribute

Quoted 29 lines
      [bootloader] fsbl.elf
      [pmufw_image] pmufw.elf
      [destination_cpu=none] fsbl.tcl
      [destination_cpu=a53-0, exception_level=el-3] bl31.elf
      [destination_cpu=a53-0, exception_level=el-2, load=0x08000000,

startup=0x08000000] u-boot.bin
}
===

---
  tools/zynqmpbif.c   | 16 ++++++++++++++--
  tools/zynqmpimage.c |  4 ++--
  tools/zynqmpimage.h |  2 ++
  3 files changed, 18 insertions(+), 4 deletions(-)
tools/zynqmpbif.c +1 -0
index 82ce0ac1a52..546b9e4fd9d 100644
@@ -191,6 +191,7 @@ static char *parse_partition_owner(char *line, struct bif_entry *bf)
  }
 
  static const struct bif_flags bif_flags[] = {
+	{ "init", BIF_FLAG_INIT },
  	{ "fsbl_config", BIF_FLAG_FSBL_CONFIG },
  	{ "trustzone", BIF_FLAG_TZ },
  	{ "pmufw_image", BIF_FLAG_PMUFW_IMAGE },

tools/zynqmpbif.c static int bif_add_blob(const void *data, size_t len, size_t *offset) · line 283

Quoted 5 lines
tools/zynqmpbif.c +1 -1
@@ -279,7 +280,7 @@ static int bif_add_blob(const void *data, size_t len, size_t *offset)
  	return 0;
  }
 
-static int bif_init(void)
+static int bif_initialize(void)

What's the reason for this rename? I don't think you should rename it because it is just distracting.

Anyway I have tested this patch and output looks reasonable. I would obviously prefer to add more features there (like ignoring comments) or unify the format but that's out of the purpose of this patch.

Thanks,
Michal

#2 lore raw
Quoted 7 lines · Michal Simek
Quoted 5 lines · Erich E. Hoover

...
options, like so:
===
image : {
[init] fsbl.int

Quoted 6 lines

please use different name then fsbl because fsbl is not doing this programming. That's done by bootrom itself.

Topic board is defining it like this. board/topic/zynq/zynq-topic-miamiplus/ps7_regs.txt but that's for zynq

My apologies, maybe "reginit.int" like the example for the Versal in UG1283? I'll remove this line as well, since that's more specific to what we're doing:
[destination_cpu=none] fsbl.tcl

Quoted 5 lines

Actually I think would be good to recap format because origin format is different compare to what it is used by bootgen right now.

https://docs.amd.com/r/en-US/ug1283-bootgen-user-guide/Initialization-Pairs-and-INT-File-Attribute
...

Are you suggesting adding an additional comment to the commit akin to "This currently uses the same register initialization file format as zynqmpimage (ASCII text hex values with each line composed of a pair of register address and value) and is not yet compatible with the format used by bootgen."?

Quoted 9 lines
Quoted 9 lines
  static const struct bif_flags bif_flags[] = {
tools/zynqmpbif.c +1 -0
+     { "init", BIF_FLAG_INIT },
      { "fsbl_config", BIF_FLAG_FSBL_CONFIG },
      { "trustzone", BIF_FLAG_TZ },
      { "pmufw_image", BIF_FLAG_PMUFW_IMAGE },
@@ -279,7 +280,7 @@ static int bif_add_blob(const void *data, size_t len, size_t *offset)
      return 0;
  }
 
Quoted 5 lines

tools/zynqmpbif.c static int bif_add_blob(const void *data, size_t len, size_t *offset) · line 283

Quoted 2 lines
tools/zynqmpbif.c +1 -1
-static int bif_init(void)
+static int bif_initialize(void)

What's the reason for this rename? I don't think you should rename it because it is just distracting.

I was trying to match nearby behavior with other flags ("bif_fsbl_config" as an example). How about I change the new function to "bif_add_reginit" (similar to bif_add_pmufw instead)?

Quoted 3 lines

Anyway I have tested this patch and output looks reasonable. I would obviously prefer to add more features there (like ignoring comments) or unify the format but that's out of the purpose of this patch.

I would be happy to add some more features to this, would you like patches for this added as part of a series or submitted separately?

Best,
Erich

maintainer
#3 lore raw
Quoted 11 lines · Erich E. Hoover
Quoted 10 lines · Michal Simek
Quoted 5 lines · Erich E. Hoover

...
options, like so:
===
image : {
[init] fsbl.int

please use different name then fsbl because fsbl is not doing this programming. That's done by bootrom itself.

Quoted 8 lines
Quoted 3 lines

Topic board is defining it like this. board/topic/zynq/zynq-topic-miamiplus/ps7_regs.txt but that's for zynq

My apologies, maybe "reginit.int" like the example for the Versal in UG1283? I'll remove this line as well, since that's more specific to what we're doing:
[destination_cpu=none] fsbl.tcl

definitely not fsbl.
reginit.int name is fine.

Quoted 4 lines
Quoted 4 lines

Actually I think would be good to recap format because origin format is different compare to what it is used by bootgen right now.

Quoted 8 lines
Quoted 2 lines

https://docs.amd.com/r/en-US/ug1283-bootgen-user-guide/Initialization-Pairs-and-INT-File-Attribute
...

Are you suggesting adding an additional comment to the commit akin to "This currently uses the same register initialization file format as zynqmpimage (ASCII text hex values with each line composed of a pair of register address and value) and is not yet compatible with the format used by bootgen."?

Description is fine I would put it as example like this.

0xff003248 0x12345678

Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
   static const struct bif_flags bif_flags[] = {
tools/zynqmpbif.c +1 -0
+     { "init", BIF_FLAG_INIT },
       { "fsbl_config", BIF_FLAG_FSBL_CONFIG },
       { "trustzone", BIF_FLAG_TZ },
       { "pmufw_image", BIF_FLAG_PMUFW_IMAGE },
@@ -279,7 +280,7 @@ static int bif_add_blob(const void *data, size_t len, size_t *offset)
       return 0;
   }
 
Quoted 5 lines

tools/zynqmpbif.c static int bif_add_blob(const void *data, size_t len, size_t *offset) · line 283

Quoted 2 lines
tools/zynqmpbif.c +1 -1
-static int bif_init(void)
+static int bif_initialize(void)

What's the reason for this rename? I don't think you should rename it because it is just distracting.

Quoted 3 lines

I was trying to match nearby behavior with other flags ("bif_fsbl_config" as an example). How about I change the new function to "bif_add_reginit" (similar to bif_add_pmufw instead)?

If you want to change names to be aligned, do it in separate patch with own description. And no issue with it.

Quoted 7 lines
Quoted 4 lines

Anyway I have tested this patch and output looks reasonable. I would obviously prefer to add more features there (like ignoring comments) or unify the format but that's out of the purpose of this patch.

I would be happy to add some more features to this, would you like patches for this added as part of a series or submitted separately?

It can be done separately and I think it would be better for you too.

Thanks,
Michal