mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM64/RISC-V: booti: support global.bootm.image.loadaddr
@ 2022-06-03  7:26 Ahmad Fatoum
  2022-06-07  7:09 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-06-03  7:26 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

So far $global.bootm.image.loadaddr was ignored. Fix this, so user code
may explicitly decide placement if needed. barebox will still sanity
check the address and align it if necessary, but won't go below it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/booti.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/common/booti.c b/common/booti.c
index a2d63d8c3188..fbf0d8008443 100644
--- a/common/booti.c
+++ b/common/booti.c
@@ -6,11 +6,30 @@
 #include <bootm.h>
 #include <linux/sizes.h>
 
+static unsigned long get_kernel_address(unsigned long os_address,
+					unsigned long text_offset)
+{
+	resource_size_t start, end;
+	int ret;
+
+	if (os_address == UIMAGE_SOME_ADDRESS) {
+		ret = memory_bank_first_find_space(&start, &end);
+		if (ret)
+			return UIMAGE_INVALID_ADDRESS;
+
+		return ALIGN(start, SZ_2M) + text_offset;
+	}
+
+	if (os_address >= text_offset && IS_ALIGNED(os_address - text_offset, SZ_2M))
+		return os_address;
+
+	return ALIGN(os_address, SZ_2M) + text_offset;
+}
+
 void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
 {
 	const void *kernel_header =
 			data->os_fit ? data->fit_kernel : data->os_header;
-	resource_size_t start, end;
 	unsigned long text_offset, image_size, devicetree, kernel;
 	unsigned long image_end;
 	int ret;
@@ -19,11 +38,9 @@ void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
 	text_offset = le64_to_cpup(kernel_header + 8);
 	image_size = le64_to_cpup(kernel_header + 16);
 
-	ret = memory_bank_first_find_space(&start, &end);
-	if (ret)
-		return ERR_PTR(ret);
-
-	kernel = ALIGN(start, SZ_2M) + text_offset;
+	kernel = get_kernel_address(data->os_address, text_offset);
+	if (kernel == UIMAGE_INVALID_ADDRESS)
+		return ERR_PTR(-ENOENT);
 
 	ret = bootm_load_os(data, kernel);
 	if (ret)
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ARM64/RISC-V: booti: support global.bootm.image.loadaddr
  2022-06-03  7:26 [PATCH] ARM64/RISC-V: booti: support global.bootm.image.loadaddr Ahmad Fatoum
@ 2022-06-07  7:09 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-06-07  7:09 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Fri, Jun 03, 2022 at 09:26:12AM +0200, Ahmad Fatoum wrote:
> So far $global.bootm.image.loadaddr was ignored. Fix this, so user code
> may explicitly decide placement if needed. barebox will still sanity
> check the address and align it if necessary, but won't go below it.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  common/booti.c | 29 +++++++++++++++++++++++------
>  1 file changed, 23 insertions(+), 6 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/booti.c b/common/booti.c
> index a2d63d8c3188..fbf0d8008443 100644
> --- a/common/booti.c
> +++ b/common/booti.c
> @@ -6,11 +6,30 @@
>  #include <bootm.h>
>  #include <linux/sizes.h>
>  
> +static unsigned long get_kernel_address(unsigned long os_address,
> +					unsigned long text_offset)
> +{
> +	resource_size_t start, end;
> +	int ret;
> +
> +	if (os_address == UIMAGE_SOME_ADDRESS) {
> +		ret = memory_bank_first_find_space(&start, &end);
> +		if (ret)
> +			return UIMAGE_INVALID_ADDRESS;
> +
> +		return ALIGN(start, SZ_2M) + text_offset;
> +	}
> +
> +	if (os_address >= text_offset && IS_ALIGNED(os_address - text_offset, SZ_2M))
> +		return os_address;
> +
> +	return ALIGN(os_address, SZ_2M) + text_offset;
> +}
> +
>  void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
>  {
>  	const void *kernel_header =
>  			data->os_fit ? data->fit_kernel : data->os_header;
> -	resource_size_t start, end;
>  	unsigned long text_offset, image_size, devicetree, kernel;
>  	unsigned long image_end;
>  	int ret;
> @@ -19,11 +38,9 @@ void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
>  	text_offset = le64_to_cpup(kernel_header + 8);
>  	image_size = le64_to_cpup(kernel_header + 16);
>  
> -	ret = memory_bank_first_find_space(&start, &end);
> -	if (ret)
> -		return ERR_PTR(ret);
> -
> -	kernel = ALIGN(start, SZ_2M) + text_offset;
> +	kernel = get_kernel_address(data->os_address, text_offset);
> +	if (kernel == UIMAGE_INVALID_ADDRESS)
> +		return ERR_PTR(-ENOENT);
>  
>  	ret = bootm_load_os(data, kernel);
>  	if (ret)
> -- 
> 2.30.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-07  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-03  7:26 [PATCH] ARM64/RISC-V: booti: support global.bootm.image.loadaddr Ahmad Fatoum
2022-06-07  7:09 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox