diff mbox series

[U-Boot,RFC,v1,6/9] spl: fit: Allow calling spl_load_fit_image() to only get the image size

Message ID 20190322143956.14767-7-jjhiblot@ti.com
State RFC
Delegated to: Tom Rini
Headers show
Series Add support for applications of overlays in SPL | expand

Commit Message

Jean-Jacques Hiblot March 22, 2019, 2:39 p.m. UTC
To allow for dynamic allocation of the area where the image will be loaded,
adapt spl_load_fit_image() to be able to get the size of the image without
doing to the actual load.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---

 common/spl/spl_fit.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

Comments

Michal Simek March 25, 2019, 8:12 a.m. UTC | #1
On 22. 03. 19 15:39, Jean-Jacques Hiblot wrote:
> To allow for dynamic allocation of the area where the image will be loaded,
> adapt spl_load_fit_image() to be able to get the size of the image without
> doing to the actual load.
> 
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
> 
>  common/spl/spl_fit.c | 26 +++++++++++++++++++++-----
>  1 file changed, 21 insertions(+), 5 deletions(-)
> 
> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
> index db436268cb..90bf458ee8 100644
> --- a/common/spl/spl_fit.c
> +++ b/common/spl/spl_fit.c
> @@ -164,12 +164,15 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
>   *		If the FIT node does not contain a "load" (address) property,
>   *		the image gets loaded to the address pointed to by the
>   *		load_addr member in this struct.
> + * @no_load:	If true, the data is not loaded from the medium. Used to get
> + *		the size of the data in the case of a dynamic allocation of
> + *		the memory.
>   *
>   * Return:	0 on success or a negative error number.
>   */
>  static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>  			      void *fit, ulong base_offset, int node,
> -			      struct spl_image_info *image_info)
> +			      struct spl_image_info *image_info, bool no_load)
>  {
>  	int offset;
>  	size_t length;
> @@ -216,7 +219,20 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
>  
>  		load_ptr = (load_addr + align_len) & ~align_len;
>  		length = len;
> +	} else {
> +		/* Embedded data */
> +		if (fit_image_get_data(fit, node, &data, &length)) {
> +			puts("Cannot get image data/size\n");
> +			return -ENOENT;
> +		}
> +	}
>  
> +	if (no_load && image_info) {
> +		image_info->size = length;
> +		return 0;
> +	}

This is return you size of image in FIT but not size of image after
uncompression. There is SPL_GZIP support and that's the size you should
work with.

M
diff mbox series

Patch

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index db436268cb..90bf458ee8 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -164,12 +164,15 @@  static int get_aligned_image_size(struct spl_load_info *info, int data_size,
  *		If the FIT node does not contain a "load" (address) property,
  *		the image gets loaded to the address pointed to by the
  *		load_addr member in this struct.
+ * @no_load:	If true, the data is not loaded from the medium. Used to get
+ *		the size of the data in the case of a dynamic allocation of
+ *		the memory.
  *
  * Return:	0 on success or a negative error number.
  */
 static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 			      void *fit, ulong base_offset, int node,
-			      struct spl_image_info *image_info)
+			      struct spl_image_info *image_info, bool no_load)
 {
 	int offset;
 	size_t length;
@@ -216,7 +219,20 @@  static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 
 		load_ptr = (load_addr + align_len) & ~align_len;
 		length = len;
+	} else {
+		/* Embedded data */
+		if (fit_image_get_data(fit, node, &data, &length)) {
+			puts("Cannot get image data/size\n");
+			return -ENOENT;
+		}
+	}
 
+	if (no_load && image_info) {
+		image_info->size = length;
+		return 0;
+	}
+
+	if (external_data) {
 		overhead = get_aligned_image_overhead(info, offset);
 		nr_sectors = get_aligned_image_size(info, length, offset);
 
@@ -293,7 +309,7 @@  static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 	 */
 	image_info.load_addr = spl_image->load_addr + spl_image->size;
 	ret = spl_load_fit_image(info, sector, fit, base_offset, node,
-				 &image_info);
+				 &image_info, false);
 
 	if (ret < 0)
 		return ret;
@@ -401,7 +417,7 @@  int spl_load_simple_fit(struct spl_image_info *spl_image,
 	if (node >= 0) {
 		/* Load the image and set up the spl_image structure */
 		ret = spl_load_fit_image(info, sector, fit, base_offset, node,
-					 spl_image);
+					 spl_image, false);
 		if (ret) {
 			printf("%s: Cannot load the FPGA: %i\n", __func__, ret);
 			return ret;
@@ -453,7 +469,7 @@  int spl_load_simple_fit(struct spl_image_info *spl_image,
 
 	/* Load the image and set up the spl_image structure */
 	ret = spl_load_fit_image(info, sector, fit, base_offset, node,
-				 spl_image);
+				 spl_image, false);
 	if (ret)
 		return ret;
 
@@ -485,7 +501,7 @@  int spl_load_simple_fit(struct spl_image_info *spl_image,
 			break;
 
 		ret = spl_load_fit_image(info, sector, fit, base_offset, node,
-					 &image_info);
+					 &image_info, false);
 		if (ret < 0)
 			continue;