Skip to contentSkip to conversation

spl: Jump to image at end of board_init_r

PATCH In review Jonas Karlman 5 participants 11 messages Sep 28, 2023 – Oct 10, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spl: Jump to image at end of board_init_r

spl_board_prepare_for_boot() is not called before jumping/invoking atf, optee, opensbi or linux images.

Jump to image at the end of board_init_r() to fix this.

---
This patch have dependencies on the following patches:

spl: add __noreturn attribute to spl_invoke_opensbi function
https://patchwork.ozlabs.org/patch/1827057/

spl: add __noreturn attribute to spl_invoke_atf function
https://patchwork.ozlabs.org/patch/1831366/

spl: Drop the switch() statement for OS selection from the "spl: Preparation for Universal Payload" series
https://patchwork.ozlabs.org/patch/1839731/

---
 common/spl/spl.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
common/spl/spl.c +7 -5
index f7608f14e365..79c39820262a 100644
@@ -647,6 +647,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 		BOOT_DEVICE_NONE,
 		BOOT_DEVICE_NONE,
 	};
+	typedef void __noreturn (*jump_to_image_t)(struct spl_image_info *);
+	jump_to_image_t jump_to_image = &jump_to_image_no_args;
 	struct spl_image_info spl_image;
 	int ret, os;
 
@@ -735,20 +737,20 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	} else if (CONFIG_IS_ENABLED(ATF) && os == IH_OS_ARM_TRUSTED_FIRMWARE) {
 		debug("Jumping to U-Boot via ARM Trusted Firmware\n");
 		spl_fixup_fdt(spl_image_fdt_addr(&spl_image));
-		spl_invoke_atf(&spl_image);
+		jump_to_image = &spl_invoke_atf;
 	} else if (CONFIG_IS_ENABLED(OPTEE_IMAGE) && os == IH_OS_TEE) {
 		debug("Jumping to U-Boot via OP-TEE\n");
 		spl_board_prepare_for_optee(spl_image_fdt_addr(&spl_image));
-		jump_to_image_optee(&spl_image);
+		jump_to_image = &jump_to_image_optee;
 	} else if (CONFIG_IS_ENABLED(OPENSBI) && os == IH_OS_OPENSBI) {
 		debug("Jumping to U-Boot via RISC-V OpenSBI\n");
-		spl_invoke_opensbi(&spl_image);
+		jump_to_image = &spl_invoke_opensbi;
 	} else if (CONFIG_IS_ENABLED(OS_BOOT) && os == IH_OS_LINUX) {
 		debug("Jumping to Linux\n");
 		if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
 			spl_fixup_fdt((void *)SPL_PAYLOAD_ARGS_ADDR);
 		spl_board_prepare_for_linux();
-		jump_to_image_linux(&spl_image);
+		jump_to_image = &jump_to_image_linux;
 	} else {
 		debug("Unsupported OS image.. Jumping nevertheless..\n");
 	}
@@ -788,7 +790,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	}
 
 	spl_board_prepare_for_boot();
-	jump_to_image_no_args(&spl_image);
+	jump_to_image(&spl_image);
 }
 
 /*
Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Jonas Karlman

spl_board_prepare_for_boot() is not called before jumping/invoking atf, optee, opensbi or linux images.

Jump to image at the end of board_init_r() to fix this.

---
This patch have dependencies on the following patches:

spl: add __noreturn attribute to spl_invoke_opensbi function
https://patchwork.ozlabs.org/patch/1827057/

spl: add __noreturn attribute to spl_invoke_atf function
https://patchwork.ozlabs.org/patch/1831366/

Quoted 7 lines

spl: Drop the switch() statement for OS selection from the "spl: Preparation for Universal Payload" series
https://patchwork.ozlabs.org/patch/1839731/

---
 common/spl/spl.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Very nice to see this!

#2 lore raw
Quoted 25 lines · Simon Glass
Quoted 16 lines · Jonas Karlman

spl_board_prepare_for_boot() is not called before jumping/invoking atf, optee, opensbi or linux images.

Jump to image at the end of board_init_r() to fix this.

---
This patch have dependencies on the following patches:

spl: add __noreturn attribute to spl_invoke_opensbi function
https://patchwork.ozlabs.org/patch/1827057/

spl: add __noreturn attribute to spl_invoke_atf function
https://patchwork.ozlabs.org/patch/1831366/

Quoted 7 lines

spl: Drop the switch() statement for OS selection from the "spl: Preparation for Universal Payload" series
https://patchwork.ozlabs.org/patch/1839731/

---
 common/spl/spl.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Quoted 3 lines

Very nice to see this!

Nice indeed!

#3 lore raw
In reply to Jonas Karlman
Quoted 61 lines · Jonas Karlman

spl_board_prepare_for_boot() is not called before jumping/invoking atf, optee, opensbi or linux images.

Jump to image at the end of board_init_r() to fix this.

---
This patch have dependencies on the following patches:

spl: add __noreturn attribute to spl_invoke_opensbi function
https://patchwork.ozlabs.org/patch/1827057/

spl: add __noreturn attribute to spl_invoke_atf function
https://patchwork.ozlabs.org/patch/1831366/

spl: Drop the switch() statement for OS selection from the "spl: Preparation for Universal Payload" series
https://patchwork.ozlabs.org/patch/1839731/

---
  common/spl/spl.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
common/spl/spl.c +6 -4
index f7608f14e365..79c39820262a 100644
@@ -647,6 +647,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  		BOOT_DEVICE_NONE,
  		BOOT_DEVICE_NONE,
  	};
+	typedef void __noreturn (*jump_to_image_t)(struct spl_image_info *);
+	jump_to_image_t jump_to_image = &jump_to_image_no_args;
  	struct spl_image_info spl_image;
  	int ret, os;
 
@@ -735,20 +737,20 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  	} else if (CONFIG_IS_ENABLED(ATF) && os == IH_OS_ARM_TRUSTED_FIRMWARE) {
  		debug("Jumping to U-Boot via ARM Trusted Firmware\n");
  		spl_fixup_fdt(spl_image_fdt_addr(&spl_image));
-		spl_invoke_atf(&spl_image);
+		jump_to_image = &spl_invoke_atf;
  	} else if (CONFIG_IS_ENABLED(OPTEE_IMAGE) && os == IH_OS_TEE) {
  		debug("Jumping to U-Boot via OP-TEE\n");
  		spl_board_prepare_for_optee(spl_image_fdt_addr(&spl_image));
-		jump_to_image_optee(&spl_image);
+		jump_to_image = &jump_to_image_optee;
  	} else if (CONFIG_IS_ENABLED(OPENSBI) && os == IH_OS_OPENSBI) {
  		debug("Jumping to U-Boot via RISC-V OpenSBI\n");
-		spl_invoke_opensbi(&spl_image);
+		jump_to_image = &spl_invoke_opensbi;
  	} else if (CONFIG_IS_ENABLED(OS_BOOT) && os == IH_OS_LINUX) {
  		debug("Jumping to Linux\n");
  		if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
  			spl_fixup_fdt((void *)SPL_PAYLOAD_ARGS_ADDR);
  		spl_board_prepare_for_linux();
-		jump_to_image_linux(&spl_image);
+		jump_to_image = &jump_to_image_linux;
  	} else {
  		debug("Unsupported OS image.. Jumping nevertheless..\n");
  	}

common/spl/spl.c void board_init_r(gd_t *dummy1, ulong dummy2) · line 796

Quoted 8 lines
common/spl/spl.c +1 -1
@@ -788,7 +790,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  	}
 
  	spl_board_prepare_for_boot();
-	jump_to_image_no_args(&spl_image);
+	jump_to_image(&spl_image);
  }
 
  /*

In SPL we are fighting for every byte of binary size.

What is the impact of this change on the code size?

I would expect that your increasing it; especially if only one of the CONFIG_OPTIONS is enabled.

If so, NAK to this patch despite all elegance.

Best regards

Heinrich

#4 lore raw

Hi Heinrich,

Quoted 8 lines · Heinrich Schuchardt

In SPL we are fighting for every byte of binary size.

What is the impact of this change on the code size?

I would expect that your increasing it; especially if only one of the CONFIG_OPTIONS is enabled.

If so, NAK to this patch despite all elegance.

Would you prefer removing spl_board_prepare_for_boot() instead? A handful of boards make use for it so I'd say this is a bug if it never gets ran on those.

Or would it be better if it was enabled with a CONFIG_ option?

Cheers.

Quoted 4 lines

Best regards

Heinrich

#5 lore raw
Quoted 10 lines · Ferass El Hafidi

Hi Heinrich,

Quoted 7 lines · Heinrich Schuchardt

In SPL we are fighting for every byte of binary size.

What is the impact of this change on the code size?

I would expect that your increasing it; especially if only one of the CONFIG_OPTIONS is enabled.

Quoted 7 lines
Quoted 1 line

If so, NAK to this patch despite all elegance.

Would you prefer removing spl_board_prepare_for_boot() instead? A handful of boards make use for it so I'd say this is a bug if it never gets ran on those.

Or would it be better if it was enabled with a CONFIG_ option?

We should understand the implications of your patch on the code size. If it leads to binary code growth, we should evaluate alternatives.

Best regards

Heinrich

#6 lore raw
Quoted 2 lines

We should understand the implications of your patch on the code size. If it leads to binary code growth, we should evaluate alternatives.

This is not my patch, but Jonas'. But sure.

Cheers.

#7 lore raw
In reply to Heinrich Schuchardt
Quoted 73 lines · Heinrich Schuchardt
Quoted 61 lines · Jonas Karlman

spl_board_prepare_for_boot() is not called before jumping/invoking atf, optee, opensbi or linux images.

Jump to image at the end of board_init_r() to fix this.

---
This patch have dependencies on the following patches:

spl: add __noreturn attribute to spl_invoke_opensbi function
https://patchwork.ozlabs.org/patch/1827057/

spl: add __noreturn attribute to spl_invoke_atf function
https://patchwork.ozlabs.org/patch/1831366/

spl: Drop the switch() statement for OS selection from the "spl: Preparation for Universal Payload" series
https://patchwork.ozlabs.org/patch/1839731/

---
  common/spl/spl.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
common/spl/spl.c +6 -4
index f7608f14e365..79c39820262a 100644
@@ -647,6 +647,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  		BOOT_DEVICE_NONE,
  		BOOT_DEVICE_NONE,
  	};
+	typedef void __noreturn (*jump_to_image_t)(struct spl_image_info *);
+	jump_to_image_t jump_to_image = &jump_to_image_no_args;
  	struct spl_image_info spl_image;
  	int ret, os;
 
@@ -735,20 +737,20 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  	} else if (CONFIG_IS_ENABLED(ATF) && os == IH_OS_ARM_TRUSTED_FIRMWARE) {
  		debug("Jumping to U-Boot via ARM Trusted Firmware\n");
  		spl_fixup_fdt(spl_image_fdt_addr(&spl_image));
-		spl_invoke_atf(&spl_image);
+		jump_to_image = &spl_invoke_atf;
  	} else if (CONFIG_IS_ENABLED(OPTEE_IMAGE) && os == IH_OS_TEE) {
  		debug("Jumping to U-Boot via OP-TEE\n");
  		spl_board_prepare_for_optee(spl_image_fdt_addr(&spl_image));
-		jump_to_image_optee(&spl_image);
+		jump_to_image = &jump_to_image_optee;
  	} else if (CONFIG_IS_ENABLED(OPENSBI) && os == IH_OS_OPENSBI) {
  		debug("Jumping to U-Boot via RISC-V OpenSBI\n");
-		spl_invoke_opensbi(&spl_image);
+		jump_to_image = &spl_invoke_opensbi;
  	} else if (CONFIG_IS_ENABLED(OS_BOOT) && os == IH_OS_LINUX) {
  		debug("Jumping to Linux\n");
  		if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
  			spl_fixup_fdt((void *)SPL_PAYLOAD_ARGS_ADDR);
  		spl_board_prepare_for_linux();
-		jump_to_image_linux(&spl_image);
+		jump_to_image = &jump_to_image_linux;
  	} else {
  		debug("Unsupported OS image.. Jumping nevertheless..\n");
  	}

common/spl/spl.c void board_init_r(gd_t *dummy1, ulong dummy2) · line 796

Quoted 8 lines
common/spl/spl.c +1 -1
@@ -788,7 +790,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  	}
 
  	spl_board_prepare_for_boot();
-	jump_to_image_no_args(&spl_image);
+	jump_to_image(&spl_image);
  }
 
  /*

In SPL we are fighting for every byte of binary size.

Quoted 6 lines

What is the impact of this change on the code size?

I would expect that your increasing it; especially if only one of the CONFIG_OPTIONS is enabled.

If so, NAK to this patch despite all elegance.

We aren't _that_ strict, no. And a very quick peek shows that this seems fine overall. Since you raised the question I'll do a quick world build but socfpga_agilex_vab (as a config I had size change results for in front of me for something else) shrank by 4 bytes with just the prerequsites and this patch applied.

Signature · 1 line
Tom
#8 lore raw
Quoted 79 lines · Tom Rini
Quoted 78 lines · Heinrich Schuchardt
Quoted 61 lines · Jonas Karlman

spl_board_prepare_for_boot() is not called before jumping/invoking atf, optee, opensbi or linux images.

Jump to image at the end of board_init_r() to fix this.

---
This patch have dependencies on the following patches:

spl: add __noreturn attribute to spl_invoke_opensbi function
https://patchwork.ozlabs.org/patch/1827057/

spl: add __noreturn attribute to spl_invoke_atf function
https://patchwork.ozlabs.org/patch/1831366/

spl: Drop the switch() statement for OS selection from the "spl: Preparation for Universal Payload" series
https://patchwork.ozlabs.org/patch/1839731/

---
   common/spl/spl.c | 12 +++++++-----
   1 file changed, 7 insertions(+), 5 deletions(-)
common/spl/spl.c +6 -4
index f7608f14e365..79c39820262a 100644
@@ -647,6 +647,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
   		BOOT_DEVICE_NONE,
   		BOOT_DEVICE_NONE,
   	};
+	typedef void __noreturn (*jump_to_image_t)(struct spl_image_info *);
+	jump_to_image_t jump_to_image = &jump_to_image_no_args;
   	struct spl_image_info spl_image;
   	int ret, os;
 
@@ -735,20 +737,20 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
   	} else if (CONFIG_IS_ENABLED(ATF) && os == IH_OS_ARM_TRUSTED_FIRMWARE) {
   		debug("Jumping to U-Boot via ARM Trusted Firmware\n");
   		spl_fixup_fdt(spl_image_fdt_addr(&spl_image));
-		spl_invoke_atf(&spl_image);
+		jump_to_image = &spl_invoke_atf;
   	} else if (CONFIG_IS_ENABLED(OPTEE_IMAGE) && os == IH_OS_TEE) {
   		debug("Jumping to U-Boot via OP-TEE\n");
   		spl_board_prepare_for_optee(spl_image_fdt_addr(&spl_image));
-		jump_to_image_optee(&spl_image);
+		jump_to_image = &jump_to_image_optee;
   	} else if (CONFIG_IS_ENABLED(OPENSBI) && os == IH_OS_OPENSBI) {
   		debug("Jumping to U-Boot via RISC-V OpenSBI\n");
-		spl_invoke_opensbi(&spl_image);
+		jump_to_image = &spl_invoke_opensbi;
   	} else if (CONFIG_IS_ENABLED(OS_BOOT) && os == IH_OS_LINUX) {
   		debug("Jumping to Linux\n");
   		if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
   			spl_fixup_fdt((void *)SPL_PAYLOAD_ARGS_ADDR);
   		spl_board_prepare_for_linux();
-		jump_to_image_linux(&spl_image);
+		jump_to_image = &jump_to_image_linux;
   	} else {
   		debug("Unsupported OS image.. Jumping nevertheless..\n");
   	}

common/spl/spl.c void board_init_r(gd_t *dummy1, ulong dummy2) · line 796

Quoted 8 lines
common/spl/spl.c +1 -1
@@ -788,7 +790,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
   	}
 
   	spl_board_prepare_for_boot();
-	jump_to_image_no_args(&spl_image);
+	jump_to_image(&spl_image);
   }
 
   /*

In SPL we are fighting for every byte of binary size.

What is the impact of this change on the code size?

I would expect that your increasing it; especially if only one of the CONFIG_OPTIONS is enabled.

Quoted 8 lines
Quoted 1 line

If so, NAK to this patch despite all elegance.

We aren't _that_ strict, no. And a very quick peek shows that this seems fine overall. Since you raised the question I'll do a quick world build but socfpga_agilex_vab (as a config I had size change results for in front of me for something else) shrank by 4 bytes with just the prerequsites and this patch applied.

Shrinking the size sounds great. Thanks for measuring.

Best regards

Heinrich

#9 lore raw
In reply to Tom Rini
Quoted 79 lines · Tom Rini
Quoted 78 lines · Heinrich Schuchardt
Quoted 61 lines · Jonas Karlman

spl_board_prepare_for_boot() is not called before jumping/invoking atf, optee, opensbi or linux images.

Jump to image at the end of board_init_r() to fix this.

---
This patch have dependencies on the following patches:

spl: add __noreturn attribute to spl_invoke_opensbi function
https://patchwork.ozlabs.org/patch/1827057/

spl: add __noreturn attribute to spl_invoke_atf function
https://patchwork.ozlabs.org/patch/1831366/

spl: Drop the switch() statement for OS selection from the "spl: Preparation for Universal Payload" series
https://patchwork.ozlabs.org/patch/1839731/

---
  common/spl/spl.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
common/spl/spl.c +6 -4
index f7608f14e365..79c39820262a 100644
@@ -647,6 +647,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  		BOOT_DEVICE_NONE,
  		BOOT_DEVICE_NONE,
  	};
+	typedef void __noreturn (*jump_to_image_t)(struct spl_image_info *);
+	jump_to_image_t jump_to_image = &jump_to_image_no_args;
  	struct spl_image_info spl_image;
  	int ret, os;
 
@@ -735,20 +737,20 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  	} else if (CONFIG_IS_ENABLED(ATF) && os == IH_OS_ARM_TRUSTED_FIRMWARE) {
  		debug("Jumping to U-Boot via ARM Trusted Firmware\n");
  		spl_fixup_fdt(spl_image_fdt_addr(&spl_image));
-		spl_invoke_atf(&spl_image);
+		jump_to_image = &spl_invoke_atf;
  	} else if (CONFIG_IS_ENABLED(OPTEE_IMAGE) && os == IH_OS_TEE) {
  		debug("Jumping to U-Boot via OP-TEE\n");
  		spl_board_prepare_for_optee(spl_image_fdt_addr(&spl_image));
-		jump_to_image_optee(&spl_image);
+		jump_to_image = &jump_to_image_optee;
  	} else if (CONFIG_IS_ENABLED(OPENSBI) && os == IH_OS_OPENSBI) {
  		debug("Jumping to U-Boot via RISC-V OpenSBI\n");
-		spl_invoke_opensbi(&spl_image);
+		jump_to_image = &spl_invoke_opensbi;
  	} else if (CONFIG_IS_ENABLED(OS_BOOT) && os == IH_OS_LINUX) {
  		debug("Jumping to Linux\n");
  		if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
  			spl_fixup_fdt((void *)SPL_PAYLOAD_ARGS_ADDR);
  		spl_board_prepare_for_linux();
-		jump_to_image_linux(&spl_image);
+		jump_to_image = &jump_to_image_linux;
  	} else {
  		debug("Unsupported OS image.. Jumping nevertheless..\n");
  	}

common/spl/spl.c void board_init_r(gd_t *dummy1, ulong dummy2) · line 796

Quoted 8 lines
common/spl/spl.c +1 -1
@@ -788,7 +790,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
  	}
 
  	spl_board_prepare_for_boot();
-	jump_to_image_no_args(&spl_image);
+	jump_to_image(&spl_image);
  }
 
  /*

In SPL we are fighting for every byte of binary size.

What is the impact of this change on the code size?

I would expect that your increasing it; especially if only one of the CONFIG_OPTIONS is enabled.

Quoted 7 lines
Quoted 1 line

If so, NAK to this patch despite all elegance.

We aren't _that_ strict, no. And a very quick peek shows that this seems fine overall. Since you raised the question I'll do a quick world build but socfpga_agilex_vab (as a config I had size change results for in front of me for something else) shrank by 4 bytes with just the prerequsites and this patch applied.

Yes, this generally is a small shrink or a small growth and fine.

Signature · 1 line
Tom