Skip to contentSkip to conversation

SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

PATCH Superseded Michal Simek 4 participants 10 messages May 17, 2016 – May 20, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Changes in v2:
- Fix empty line
- Fix addr name and remove SPL_LOAD_FIT macro

 common/spl/spl.c | 45 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 9 deletions(-)
common/spl/spl.c +36 -9
index 0fc5b058be31..3faa751e4b43 100644
@@ -136,20 +136,47 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 	image_entry();
 }
 
+#ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
+# define CONFIG_SPL_LOAD_FIT_ADDRESS	0
+#endif
+
 #ifdef CONFIG_SPL_RAM_DEVICE
+static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
+			       ulong count, void *buf)
+{
+	debug("%s: sector %lx, count %lx, buf %lx\n",
+	      __func__, sector, count, (ulong)buf);
+	memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count);
+	return count;
+}
+
 static int spl_ram_load_image(void)
 {
-	const struct image_header *header;
+	struct image_header *header;
 
-	/*
-	 * Get the header.  It will point to an address defined by handoff
-	 * which will tell where the image located inside the flash. For
-	 * now, it will temporary fixed to address pointed by U-Boot.
-	 */
-	header = (struct image_header *)
-		(CONFIG_SYS_TEXT_BASE -	sizeof(struct image_header));
+	header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS;
 
-	spl_parse_image_header(header);
+	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+	    image_get_magic(header) == FDT_MAGIC) {
+		struct spl_load_info load;
+
+		debug("Found FIT\n");
+		load.bl_len = 1;
+		load.read = spl_ram_load_read;
+		spl_load_simple_fit(&load, 0, header);
+	} else {
+		debug("Legacy image\n");
+		/*
+		 * Get the header.  It will point to an address defined by
+		 * handoff which will tell where the image located inside
+		 * the flash. For now, it will temporary fixed to address
+		 * pointed by U-Boot.
+		 */
+		header = (struct image_header *)
+			(CONFIG_SYS_TEXT_BASE -	sizeof(struct image_header));
+
+		spl_parse_image_header(header);
+	}
 
 	return 0;
 }
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Quoted 20 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Changes in v2:
- Fix empty line
- Fix addr name and remove SPL_LOAD_FIT macro

  common/spl/spl.c | 45 ++++++++++++++++++++++++++++++++++++---------
  1 file changed, 36 insertions(+), 9 deletions(-)
common/spl/spl.c +0 -0
index 0fc5b058be31..3faa751e4b43 100644

common/spl/spl.c __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) · line 142

Quoted 7 lines
common/spl/spl.c +4 -0
@@ -136,20 +136,47 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  	image_entry();
  }
 
+#ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
+# define CONFIG_SPL_LOAD_FIT_ADDRESS	0
+#endif
+

May be a good idea to default this to CONFIG_SYS_TEXT_BASE instead of 0?

Other than that patch looks good to me.

Thanks and regards,
Lokesh

Quoted 50 lines
common/spl/spl.c +32 -9
  #ifdef CONFIG_SPL_RAM_DEVICE
+static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
+			       ulong count, void *buf)
+{
+	debug("%s: sector %lx, count %lx, buf %lx\n",
+	      __func__, sector, count, (ulong)buf);
+	memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count);
+	return count;
+}
+
  static int spl_ram_load_image(void)
  {
-	const struct image_header *header;
+	struct image_header *header;
 
-	/*
-	 * Get the header.  It will point to an address defined by handoff
-	 * which will tell where the image located inside the flash. For
-	 * now, it will temporary fixed to address pointed by U-Boot.
-	 */
-	header = (struct image_header *)
-		(CONFIG_SYS_TEXT_BASE -	sizeof(struct image_header));
+	header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS;
 
-	spl_parse_image_header(header);
+	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+	    image_get_magic(header) == FDT_MAGIC) {
+		struct spl_load_info load;
+
+		debug("Found FIT\n");
+		load.bl_len = 1;
+		load.read = spl_ram_load_read;
+		spl_load_simple_fit(&load, 0, header);
+	} else {
+		debug("Legacy image\n");
+		/*
+		 * Get the header.  It will point to an address defined by
+		 * handoff which will tell where the image located inside
+		 * the flash. For now, it will temporary fixed to address
+		 * pointed by U-Boot.
+		 */
+		header = (struct image_header *)
+			(CONFIG_SYS_TEXT_BASE -	sizeof(struct image_header));
+
+		spl_parse_image_header(header);
+	}
 
  	return 0;
  }
#2 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Quoted 27 lines · Lokesh Vutla
Quoted 24 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Changes in v2:
- Fix empty line
- Fix addr name and remove SPL_LOAD_FIT macro

  common/spl/spl.c | 45 ++++++++++++++++++++++++++++++++++++---------
  1 file changed, 36 insertions(+), 9 deletions(-)
common/spl/spl.c +0 -0
index 0fc5b058be31..3faa751e4b43 100644
@@ -136,20 +136,47 @@ __weak void __noreturn
 jump_to_image_no_args(struct spl_image_info *spl_image)
      image_entry();
  }
 
Quoted 6 lines

common/spl/spl.c __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) · line 142

Quoted 4 lines
common/spl/spl.c +4 -0
+#ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
+# define CONFIG_SPL_LOAD_FIT_ADDRESS    0
+#endif
+

May be a good idea to default this to CONFIG_SYS_TEXT_BASE instead of 0?

The problem is that if u-boot is in FIT that it will be loaded to TEXT_BASE address.
Maybe easier to just don't define any value which end up in compilation error.

Thanks,
Michal

#3 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Quoted 35 lines · Michal Simek
Quoted 27 lines · Lokesh Vutla
Quoted 24 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Changes in v2:
- Fix empty line
- Fix addr name and remove SPL_LOAD_FIT macro

   common/spl/spl.c | 45 ++++++++++++++++++++++++++++++++++++---------
   1 file changed, 36 insertions(+), 9 deletions(-)
common/spl/spl.c +0 -0
index 0fc5b058be31..3faa751e4b43 100644
@@ -136,20 +136,47 @@ __weak void __noreturn
 jump_to_image_no_args(struct spl_image_info *spl_image)
       image_entry();
   }
 
Quoted 6 lines

common/spl/spl.c __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) · line 142

Quoted 4 lines
common/spl/spl.c +4 -0
+#ifndef CONFIG_SPL_LOAD_FIT_ADDRESS
+# define CONFIG_SPL_LOAD_FIT_ADDRESS    0
+#endif
+

May be a good idea to default this to CONFIG_SYS_TEXT_BASE instead of 0?

Quoted 4 lines

The problem is that if u-boot is in FIT that it will be loaded to TEXT_BASE address.
Maybe easier to just don't define any value which end up in compilation error.

Yeah, you were right. Initially I was thinking there won't be a problem overriding the data. You can leave it as is.

Thanks and regards,
Lokesh

Quoted 4 lines

Thanks,
Michal

#4 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

In reply to Michal Simek
Quoted 7 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

That's a very useful addition to the SPL FIT toolbox! I have a use case where I may need to decrypt/authenticate an SPL FIT image in its entirety before processing it so this can be used for this as well.

--
Andreas Dannenberg
Texas Instruments Inc

#5 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Quoted 9 lines · Andreas Dannenberg
Quoted 7 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Quoted 6 lines

That's a very useful addition to the SPL FIT toolbox! I have a use case where I may need to decrypt/authenticate an SPL FIT image in its entirety before processing it so this can be used for this as well.

Do you have also use case where you need to load more files from FIT? There is loadable entry in FIT config entry.

Thanks,
Michal

#6 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Hi Michal,

Quoted 13 lines · Michal Simek
Quoted 12 lines · Andreas Dannenberg
Quoted 7 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Quoted 6 lines
Quoted 3 lines

That's a very useful addition to the SPL FIT toolbox! I have a use case where I may need to decrypt/authenticate an SPL FIT image in its entirety before processing it so this can be used for this as well.

Do you have also use case where you need to load more files from FIT? There is loadable entry in FIT config entry.

Not yet but I may get there. I'm experimenting with using U-Boot to load and install a secure monitor mode application (specifically, OP-TEE OS), so that will need to come from somewhere eventually and FIT would be a natural place for that binary to reside since we can easily authenticate it.

Thanks and Regards,
Andreas

#7 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Hi Andreas,

2016-05-19 20:16 GMT+02:00 Andreas Dannenberg <[email protected]>:

Quoted 21 lines

Hi Michal,

Quoted 10 lines · Michal Simek
Quoted 9 lines · Andreas Dannenberg
Quoted 7 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Quoted 5 lines
Quoted 5 lines

That's a very useful addition to the SPL FIT toolbox! I have a use case where I may need to decrypt/authenticate an SPL FIT image in its

entirety

Quoted 2 lines
Quoted 1 line

before processing it so this can be used for this as well.

Quoted 8 lines
Quoted 2 lines

Do you have also use case where you need to load more files from FIT? There is loadable entry in FIT config entry.

Not yet but I may get there. I'm experimenting with using U-Boot to load and install a secure monitor mode application (specifically, OP-TEE OS), so that will need to come from somewhere eventually and FIT would be a natural place for that binary to reside since we can easily authenticate it.

ok what arch?
What's the flow which you want to support?
SPL to load OPTEE and ATF and full u-boot and jump to ATF which runs OPTEE and run to U-Boot?

Thanks,
Michal

#8 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Hi Michael,

Quoted 35 lines · Michal Simek

Hi Andreas,

2016-05-19 20:16 GMT+02:00 Andreas Dannenberg <[email protected]>:

Quoted 21 lines

Hi Michal,

Quoted 10 lines · Michal Simek
Quoted 9 lines · Andreas Dannenberg
Quoted 7 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Quoted 5 lines
Quoted 5 lines

That's a very useful addition to the SPL FIT toolbox! I have a use case where I may need to decrypt/authenticate an SPL FIT image in its

entirety

Quoted 2 lines
Quoted 1 line

before processing it so this can be used for this as well.

Quoted 8 lines
Quoted 2 lines

Do you have also use case where you need to load more files from FIT? There is loadable entry in FIT config entry.

Not yet but I may get there. I'm experimenting with using U-Boot to load and install a secure monitor mode application (specifically, OP-TEE OS), so that will need to come from somewhere eventually and FIT would be a natural place for that binary to reside since we can easily authenticate it.

Quoted 4 lines

ok what arch?
What's the flow which you want to support?
SPL to load OPTEE and ATF and full u-boot and jump to ATF which runs OPTEE and run to U-Boot?

I working with TI's current SoCs and those are ARMv7-A and there is no ATF but instead a proprietary solution comprising ROM code and some low-level code that gets loaded/authenticated/executed by said ROM in a secure fashion before the regular boot flow starts (SPL, U-Boot, and so on). There is flexibility to load/install a new secure monitor code during SPL, U-Boot, or in fact at any other time (even after let's say Linux is booted up) but from an overall system architecture POV we need that new secure monitor (OP-TEE OS in this case) to be up before the Kernel is loaded.

Anyways the goal is not only to get it working but also to have a solution that plays nice with everything else and can be contributed upstream.

Thanks and Regards,
Andreas

#9 lore raw

PATCH v2 1/1 SPL: FIT: Enable SPL_FIT_LOAD in RAM based boot mode

Quoted 53 lines · Andreas Dannenberg

Hi Michael,

Quoted 35 lines · Michal Simek

Hi Andreas,

2016-05-19 20:16 GMT+02:00 Andreas Dannenberg <[email protected]>:

Quoted 21 lines

Hi Michal,

Quoted 10 lines · Michal Simek
Quoted 9 lines · Andreas Dannenberg
Quoted 7 lines · Michal Simek

Support loading FIT in SPL for RAM bootmode. CONFIG_SPL_LOAD_FIT_ADRESS points to address where FIT image is stored in memory.

---

Quoted 5 lines
Quoted 5 lines

That's a very useful addition to the SPL FIT toolbox! I have a use case where I may need to decrypt/authenticate an SPL FIT image in its

entirety

Quoted 2 lines
Quoted 1 line

before processing it so this can be used for this as well.

Quoted 8 lines
Quoted 2 lines

Do you have also use case where you need to load more files from FIT? There is loadable entry in FIT config entry.

Not yet but I may get there. I'm experimenting with using U-Boot to load and install a secure monitor mode application (specifically, OP-TEE OS), so that will need to come from somewhere eventually and FIT would be a natural place for that binary to reside since we can easily authenticate it.

Quoted 4 lines

ok what arch?
What's the flow which you want to support?
SPL to load OPTEE and ATF and full u-boot and jump to ATF which runs OPTEE and run to U-Boot?

I working with TI's current SoCs and those are ARMv7-A and there is no ATF but instead a proprietary solution comprising ROM code and some low-level code that gets loaded/authenticated/executed by said ROM in a secure fashion before the regular boot flow starts (SPL, U-Boot, and so on). There is flexibility to load/install a new secure monitor code during SPL, U-Boot, or in fact at any other time (even after let's say Linux is booted up) but from an overall system architecture POV we need that new secure monitor (OP-TEE OS in this case) to be up before the Kernel is loaded.

Quoted 3 lines

Anyways the goal is not only to get it working but also to have a solution that plays nice with everything else and can be contributed upstream.

Ok. I see. I will definitely keep my eyes on this one. Because I have sent SPL for ZynqMP and if you look closely to setting I use without FIT falcon bootmode to be able to load ATF and full u-boot to the memory. For FIT I have sent patches to extend format with fpga part which bootm supports. I have also additional patches (not in mainline) to load bitstream from SPL.
But the goal should be that SPL will be able to load FPGA and several images. Just to make long story short support fpga and loadables sections in FIT format.

Thanks,
Michal

Signature · 14 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160520/8d49cf89/attachment.sig>