Skip to contentSkip to conversation

tools: zynqmpbif: Add support for load=after

PATCH New Alexander Graf 2 participants 4 messages Apr 26, 2018 – Apr 27, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: zynqmpbif: Add support for load=after

Some times it's handy to have a partition loaded immediately after the end of the previous blob. The most obvious example for this is a U-Boot binary (coming from .elf) and a device tree file.

This patch adds that logic. With this, the following bif snippet does what you would expect:

[destination_cpu=a5x-0, exception_level=el-2] u-boot.elf [load=after] u-boot.dtb

converts to

FSBL payload on CPU a5x-0 (PS):

    Offset     : 0x00590500
    Size       : 577768 (0x8d0e8) bytes
    Load       : 0x08000000
    Attributes : EL2
    Checksum   : 0xefca2cad
  FSBL payload on CPU none (PS):
    Offset     : 0x0061d640
    Size       : 129760 (0x1fae0) bytes
    Load       : 0x0808d0e8 (entry=0x00000000)

Attributes : EL3
Checksum : 0xf7dd3d49

---
 tools/zynqmpbif.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/zynqmpbif.c +15 -0
index 6c8f66055d..47c233c15f 100644
@@ -42,6 +42,7 @@ enum bif_flag {
 	BIF_FLAG_PUF_FILE,
 	BIF_FLAG_AARCH32,
 	BIF_FLAG_PART_OWNER_UBOOT,
+	BIF_FLAG_LOAD_AFTER,
 
 	/* Internal flags */
 	BIF_FLAG_BIT_FILE,
@@ -151,6 +152,11 @@ static char *parse_load(char *line, struct bif_entry *bf)
 {
 	char *endptr;
 
+	if (!strncmp(line, "after", strlen("after"))) {
+		bf->flags |= (1ULL << BIF_FLAG_LOAD_AFTER);
+		return line + strlen("after");
+	}
+
 	bf->load = strtoll(line, &endptr, 0);
 
 	return endptr;
@@ -336,6 +342,15 @@ static int bif_add_part(struct bif_entry *bf, const char *data, size_t len)
 	if (r)
 		return r;
 
+	if (bf->flags & (1ULL << BIF_FLAG_LOAD_AFTER) &&
+	    bif_output.last_part) {
+		struct partition_header *p = bif_output.last_part;
+		uint64_t load = le64_to_cpu(p->load_address);
+
+		load += le32_to_cpu(p->len) * 4;
+		parthdr.load_address = cpu_to_le64(load);
+	}
+
 	parthdr.offset = cpu_to_le32(bf->offset / 4);
 
 	if (bf->flags & (1ULL << BIF_FLAG_BOOTLOADER)) {
Signature · 1 line
2.12.3
#1 lore raw

PATCH 1/1 tools: zynqmpbif: Add support for load=after

Quoted 61 lines · Alexander Graf

Some times it's handy to have a partition loaded immediately after the end of the previous blob. The most obvious example for this is a U-Boot binary (coming from .elf) and a device tree file.

This patch adds that logic. With this, the following bif snippet does what you would expect:

[destination_cpu=a5x-0, exception_level=el-2] u-boot.elf [load=after] u-boot.dtb

converts to

FSBL payload on CPU a5x-0 (PS):

    Offset     : 0x00590500
    Size       : 577768 (0x8d0e8) bytes
    Load       : 0x08000000
    Attributes : EL2
    Checksum   : 0xefca2cad
  FSBL payload on CPU none (PS):
    Offset     : 0x0061d640
    Size       : 129760 (0x1fae0) bytes
    Load       : 0x0808d0e8 (entry=0x00000000)

Attributes : EL3
Checksum : 0xf7dd3d49

---
 tools/zynqmpbif.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/zynqmpbif.c +8 -0
index 6c8f66055d..47c233c15f 100644
@@ -42,6 +42,7 @@ enum bif_flag {
 	BIF_FLAG_PUF_FILE,
 	BIF_FLAG_AARCH32,
 	BIF_FLAG_PART_OWNER_UBOOT,
+	BIF_FLAG_LOAD_AFTER,
 
 	/* Internal flags */
 	BIF_FLAG_BIT_FILE,
@@ -151,6 +152,11 @@ static char *parse_load(char *line, struct bif_entry *bf)
 {
 	char *endptr;
 
+	if (!strncmp(line, "after", strlen("after"))) {
+		bf->flags |= (1ULL << BIF_FLAG_LOAD_AFTER);
+		return line + strlen("after");
+	}
+
 	bf->load = strtoll(line, &endptr, 0);
 
 	return endptr;
@@ -336,6 +342,15 @@ static int bif_add_part(struct bif_entry *bf, const char *data, size_t len)
 	if (r)
 		return r;
 
+	if (bf->flags & (1ULL << BIF_FLAG_LOAD_AFTER) &&
+	    bif_output.last_part) {

tools/zynqmpbif.c static int bif_add_part(struct bif_entry *bf, const char *data, size_t len) · line 356

Quoted 10 lines
tools/zynqmpbif.c +7 -0
+		struct partition_header *p = bif_output.last_part;
+		uint64_t load = le64_to_cpu(p->load_address);
+
+		load += le32_to_cpu(p->len) * 4;
+		parthdr.load_address = cpu_to_le64(load);
+	}
+
 	parthdr.offset = cpu_to_le32(bf->offset / 4);
 
 	if (bf->flags & (1ULL << BIF_FLAG_BOOTLOADER)) {

As we have discussed over IRC this is out of current bif supported options and load option with OF_SEPARATE/OF_BOARD should be used instead. Some platforms are using CONFIG_SYS_FDT_BASE for that. Generic solution for that would be good because right now is fdt_blob is at &_end.

At least like this.

lib/fdtdec.c +4 -0
index 320ee1dc56b3..4262ac0677d3 100644
@@ -1292,8 +1292,12 @@ __weak void *board_fdt_blob_setup(void)
        else
                fdt_blob = (ulong *)&__bss_end;
 #else
+#ifndef CONFIG_SYS_FDT_BASE
        /* FDT is at end of image */
        fdt_blob = (ulong *)&_end;
+#else
+       fdt_blob = CONFIG_SYS_FDT_BASE;
+#endif
 #endif
        return fdt_blob;
 }

Thanks,
Michal

#2 lore raw

PATCH 1/1 tools: zynqmpbif: Add support for load=after

Quoted 70 lines · Michal Simek
Quoted 69 lines · Alexander Graf

Some times it's handy to have a partition loaded immediately after the end of the previous blob. The most obvious example for this is a U-Boot binary (coming from .elf) and a device tree file.

This patch adds that logic. With this, the following bif snippet does what you would expect:

[destination_cpu=a5x-0, exception_level=el-2] u-boot.elf [load=after] u-boot.dtb

converts to

   FSBL payload on CPU a5x-0 (PS):
     Offset     : 0x00590500
     Size       : 577768 (0x8d0e8) bytes
     Load       : 0x08000000
     Attributes : EL2
     Checksum   : 0xefca2cad
   FSBL payload on CPU none (PS):
     Offset     : 0x0061d640
     Size       : 129760 (0x1fae0) bytes
     Load       : 0x0808d0e8 (entry=0x00000000)
     Attributes : EL3
     Checksum   : 0xf7dd3d49
---
  tools/zynqmpbif.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
tools/zynqmpbif.c +15 -0
index 6c8f66055d..47c233c15f 100644
@@ -42,6 +42,7 @@ enum bif_flag {
  	BIF_FLAG_PUF_FILE,
  	BIF_FLAG_AARCH32,
  	BIF_FLAG_PART_OWNER_UBOOT,
+	BIF_FLAG_LOAD_AFTER,
 
  	/* Internal flags */
  	BIF_FLAG_BIT_FILE,
@@ -151,6 +152,11 @@ static char *parse_load(char *line, struct bif_entry *bf)
  {
  	char *endptr;
 
+	if (!strncmp(line, "after", strlen("after"))) {
+		bf->flags |= (1ULL << BIF_FLAG_LOAD_AFTER);
+		return line + strlen("after");
+	}
+
  	bf->load = strtoll(line, &endptr, 0);
 
  	return endptr;
@@ -336,6 +342,15 @@ static int bif_add_part(struct bif_entry *bf, const char *data, size_t len)
  	if (r)
  		return r;
 
+	if (bf->flags & (1ULL << BIF_FLAG_LOAD_AFTER) &&
+	    bif_output.last_part) {
+		struct partition_header *p = bif_output.last_part;
+		uint64_t load = le64_to_cpu(p->load_address);
+
+		load += le32_to_cpu(p->len) * 4;
+		parthdr.load_address = cpu_to_le64(load);
+	}
+
  	parthdr.offset = cpu_to_le32(bf->offset / 4);
 
Quoted 7 lines

tools/zynqmpbif.c static int bif_add_part(struct bif_entry *bf, const char *data, size_t len) · line 356

Quoted 2 lines
tools/zynqmpbif.c +0 -0
  	if (bf->flags & (1ULL << BIF_FLAG_BOOTLOADER)) {

As we have discussed over IRC this is out of current bif supported options and load option with OF_SEPARATE/OF_BOARD should be used instead. Some platforms are using CONFIG_SYS_FDT_BASE for that. Generic solution for that would be good because right now is fdt_blob is at &_end.

Yes, the &_end is what this patch enables to map in bif.

Quoted 7 lines

At least like this.

lib/fdtdec.c +0 -0
index 320ee1dc56b3..4262ac0677d3 100644

lib/fdtdec.c __weak void *board_fdt_blob_setup(void) · line 1300

Quoted 9 lines
lib/fdtdec.c +4 -0
@@ -1292,8 +1292,12 @@ __weak void *board_fdt_blob_setup(void)
         else
                 fdt_blob = (ulong *)&__bss_end;
  #else
+#ifndef CONFIG_SYS_FDT_BASE
         /* FDT is at end of image */
         fdt_blob = (ulong *)&_end;
+#else
+       fdt_blob = CONFIG_SYS_FDT_BASE;
+#endif

I agree that this is an alternative approach to this, but I like it much less :). It just feels wrong to hard code random addresses to load things from when everything is easy enough to pull out dynamically.

I'd much rather prefer to extend the official bif syntax with this. If we can't have that, I guess the next "best" option is to just create a combined .bin file and manually set the load/entry address from the elf header in my boot.bin generation script.

Alex

#3 lore raw

PATCH 1/1 tools: zynqmpbif: Add support for load=after

Quoted 99 lines · Alexander Graf
Quoted 66 lines · Michal Simek
Quoted 65 lines · Alexander Graf

Some times it's handy to have a partition loaded immediately after the end of the previous blob. The most obvious example for this is a U-Boot binary (coming from .elf) and a device tree file.

This patch adds that logic. With this, the following bif snippet does what you would expect:

   [destination_cpu=a5x-0, exception_level=el-2] u-boot.elf [load=after] u-boot.dtb

converts to

   FSBL payload on CPU a5x-0 (PS):
     Offset     : 0x00590500
     Size       : 577768 (0x8d0e8) bytes
     Load       : 0x08000000
     Attributes : EL2
     Checksum   : 0xefca2cad
   FSBL payload on CPU none (PS):
     Offset     : 0x0061d640
     Size       : 129760 (0x1fae0) bytes
     Load       : 0x0808d0e8 (entry=0x00000000)
     Attributes : EL3
     Checksum   : 0xf7dd3d49

---
  tools/zynqmpbif.c | 15 +++++++++++++++

  1 file changed, 15 insertions(+)
tools/zynqmpbif.c +5 -0
index 6c8f66055d..47c233c15f 100644
@@ -42,6 +42,7 @@ enum bif_flag {
       BIF_FLAG_PUF_FILE,
       BIF_FLAG_AARCH32,
       BIF_FLAG_PART_OWNER_UBOOT,
+    BIF_FLAG_LOAD_AFTER,
         /* Internal flags */
       BIF_FLAG_BIT_FILE,
@@ -151,6 +152,11 @@ static char *parse_load(char *line, struct
 bif_entry *bf)
   {
       char *endptr;
   +    if (!strncmp(line, "after", strlen("after"))) {
+        bf->flags |= (1ULL << BIF_FLAG_LOAD_AFTER);
+        return line + strlen("after");
+    }
+
       bf->load = strtoll(line, &endptr, 0);
         return endptr;
@@ -336,6 +342,15 @@ static int bif_add_part(struct bif_entry *bf,
 const char *data, size_t len)
       if (r)
           return r;

  +    if (bf->flags & (1ULL << BIF_FLAG_LOAD_AFTER) && +        bif_output.last_part) {
+        struct partition_header *p = bif_output.last_part; +        uint64_t load = le64_to_cpu(p->load_address);

tools/zynqmpbif.c +5 -0
+
+        load += le32_to_cpu(p->len) * 4;
+        parthdr.load_address = cpu_to_le64(load);
+    }
+
Quoted 8 lines
Quoted 3 lines

      parthdr.offset = cpu_to_le32(bf->offset / 4); if (bf->flags & (1ULL << BIF_FLAG_BOOTLOADER)) {

As we have discussed over IRC this is out of current bif supported options and load option with OF_SEPARATE/OF_BOARD should be used instead. Some platforms are using CONFIG_SYS_FDT_BASE for that. Generic solution for that would be good because right now is fdt_blob is at &_end.

Yes, the &_end is what this patch enables to map in bif.

Quoted 13 lines

At least like this.

lib/fdtdec.c +0 -0
index 320ee1dc56b3..4262ac0677d3 100644
@@ -1292,8 +1292,12 @@ __weak void *board_fdt_blob_setup(void)

         else
                 fdt_blob = (ulong *)&__bss_end;
  #else
+#ifndef CONFIG_SYS_FDT_BASE
         /* FDT is at end of image */
         fdt_blob = (ulong *)&_end;

lib/fdtdec.c __weak void *board_fdt_blob_setup(void) · line 1300

Quoted 3 lines
lib/fdtdec.c +3 -0
+#else
+       fdt_blob = CONFIG_SYS_FDT_BASE;
+#endif

I agree that this is an alternative approach to this, but I like it much less :). It just feels wrong to hard code random addresses to load things from when everything is easy enough to pull out dynamically.

Quoted 4 lines

I'd much rather prefer to extend the official bif syntax with this. If we can't have that, I guess the next "best" option is to just create a combined .bin file and manually set the load/entry address from the elf header in my boot.bin generation script.

I don't think this is going to happen for zynqmp and will see what can be done for next gen. But my guess is that chance is quite low.

That's how it is done for OF_SEPARATE today
cat u-boot-nodtb.bin dts/dt.dtb > u-boot-dtb.bin cp u-boot-dtb.bin u-boot.bin

It means the same will be in your script.

Thanks,
Michal

Quoted 4 lines

Alex