Skip to contentSkip to conversation

Load splash from FIT image (internal, external, offset)

PATCH New Mark Jonas 2 participants 6 messages Feb 1, 2019 – Feb 4, 2019

lore
Share & tools
lore

Mark Jonas

author
#0 lore raw

cover Load splash from FIT image (internal, external, offset)

We store a splash screen in SPI-NOR. We chose to use a FIT image as a container because we want to
- store more than just the splash screen in SPI-NOR,
- do not create a bunch of MTD partitions,
- do not waste storage space, and
- avoid the overhead of a real file system.

In general U-Boot already supports this. But there were some ripples we had to smooth out. The following patches resolve these.

Leo Ruan (2):
splash: Use splashfile instead of location->name
splash: load internal and external data from FIT

 common/splash_source.c   | 66 +++++++++++++++++++++++++++++++-----------------
 doc/README.splashprepare |  6 ++---
 2 files changed, 46 insertions(+), 26 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/2 splash: Use splashfile instead of location->name

From: Leo Ruan <[email protected]>

The splash image could be loaded from different sources (e.g. sf, mmc) with different formats (e.g. raw, file-system). These sources are structured by a board dependent object 'splash_location'. To decide where is the splash image loaded, following environment variables are used to select the splash source and file:
- 'splashsource' is used to select the splash source by setting its value to specified name of splash location.
- 'splashfile' specify the name of splash image file

But, when loads the splash image from FIT, the name of splash image within FIT is specified by splash location name. Due to the splash location name is already used for the splash source, its name may conflicts with the name of splash image.

To solve the conflict, the environment variable 'splashfile' is used to specify the splash image in FIT, and keeps the splash location name for the splash source.

---
 common/splash_source.c   | 10 ++++++++--
 doc/README.splashprepare |  6 +++---
 2 files changed, 11 insertions(+), 5 deletions(-)
common/splash_source.c +8 -2
index 62763b9..e1e73db 100644
@@ -303,6 +303,7 @@ static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)
 {
 	int res;
 	int node_offset;
+	const char *splash_file;
 	int splash_offset;
 	int splash_size;
 	struct image_header *img_header;
@@ -335,10 +336,15 @@ static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)
 		return -EINVAL;
 	}
 
-	node_offset = fit_image_get_node(fit_header, location->name);
+	/* Get the splash image node */
+	splash_file = env_get("splashfile");
+	if (!splash_file)
+		splash_file = SPLASH_SOURCE_DEFAULT_FILE_NAME;
+
+	node_offset = fit_image_get_node(fit_header, splash_file);
 	if (node_offset < 0) {
 		debug("Could not find splash image '%s' in FIT\n",
-		      location->name);
+		      splash_file);
 		return -ENOENT;
 	}
 
doc/README.splashprepare +3 -3
index f1418de..c7f7493 100644
@@ -26,6 +26,6 @@ screen data is loaded as a file. The name of the splash screen file can be
 controlled with the environment variable "splashfile".
 
 To enable loading the splash image from a FIT image, CONFIG_FIT must be
-enabled. Struct splash_location field 'name' should match the splash image
-name within the FIT and the FIT should start at the 'offset' field address in
-the specified storage.
+enabled. The FIT image has to start at the 'offset' field address in the
+selected splash location. The name of splash image within the FIT shall be
+specified by the environment variable "splashfile".
Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/2 splash: Use splashfile instead of location->name

Hi Mark,

Quoted 21 lines · Mark Jonas

From: Leo Ruan <[email protected]>

The splash image could be loaded from different sources (e.g. sf, mmc) with different formats (e.g. raw, file-system). These sources are structured by a board dependent object 'splash_location'. To decide where is the splash image loaded, following environment variables are used to select the splash source and file:
- 'splashsource' is used to select the splash source by setting its value to specified name of splash location.
- 'splashfile' specify the name of splash image file

But, when loads the splash image from FIT, the name of splash image within FIT is specified by splash location name. Due to the splash location name is already used for the splash source, its name may conflicts with the name of splash image.

To solve the conflict, the environment variable 'splashfile' is used to specify the splash image in FIT, and keeps the splash location name for the splash source.

Quoted 7 lines
---
 common/splash_source.c   | 10 ++++++++--
 doc/README.splashprepare |  6 +++---
 2 files changed, 11 insertions(+), 5 deletions(-)

common/splash_source.c static int splash_load_fit(struct splash_location

Quoted 5 lines
common/splash_source.c +0 -0
index 62763b9..e1e73db 100644
@@ -303,6 +303,7 @@ static int splash_load_fit(struct splash_location

*location, u32 bmp_load_addr)

common/splash_source.c static int splash_load_fit(struct splash_location

Quoted 8 lines
common/splash_source.c +1 -0
 {
        int res;
        int node_offset;
+       const char *splash_file;
        int splash_offset;
        int splash_size;
        struct image_header *img_header;
@@ -335,10 +336,15 @@ static int splash_load_fit(struct splash_location

*location, u32 bmp_load_addr)

doc/README.splashprepare screen data is loaded as a file. The name of the splash

Quoted 22 lines
common/splash_source.c +7 -2
                return -EINVAL;
        }
 
-       node_offset = fit_image_get_node(fit_header, location->name);
+       /* Get the splash image node */
+       splash_file = env_get("splashfile");
+       if (!splash_file)
+               splash_file = SPLASH_SOURCE_DEFAULT_FILE_NAME;
+
+       node_offset = fit_image_get_node(fit_header, splash_file);
        if (node_offset < 0) {
                debug("Could not find splash image '%s' in FIT\n",
-                     location->name);
+                     splash_file);
                return -ENOENT;
        }
 
doc/README.splashprepare +0 -0
index f1418de..c7f7493 100644
@@ -26,6 +26,6 @@ screen data is loaded as a file. The name of the splash

screen file can be

doc/README.splashprepare screen data is loaded as a file. The name of the splash screen file can be

Quoted 4 lines
doc/README.splashprepare +0 -1
 controlled with the environment variable "splashfile".
 
 To enable loading the splash image from a FIT image, CONFIG_FIT must be
-enabled. Struct splash_location field 'name' should match the splash

image

doc/README.splashprepare screen data is loaded as a file. The name of the splash · line 30

Quoted 1 line
doc/README.splashprepare +0 -1
-name within the FIT and the FIT should start at the 'offset' field

address in

doc/README.splashprepare screen data is loaded as a file. The name of the splash screen file can be

Quoted 3 lines
doc/README.splashprepare +2 -1
-the specified storage.
+enabled. The FIT image has to start at the 'offset' field address in the
+selected splash location. The name of splash image within the FIT shall

be

doc/README.splashprepare screen data is loaded as a file. The name of the splash screen file can be · line 31

Quoted 1 line
doc/README.splashprepare +1 -0
+specified by the environment variable "splashfile".

Can you also mention the default name?

Regards,
Simon

author
#3 lore raw

PATCH 2/2 splash: Load internal and external data from FIT

In reply to Mark Jonas

From: Leo Ruan <[email protected]>

The FIT image could contain the splash data in 3 different structure:
- The splash data is embedded in FIT image (internal)
In this case, the property 'data' presents in FIT image header. And internal information 'start' and 'end' represent the location and size of splash data inside of FIT image.
- The splash data is external with absolute position in FIT image This case is made by 'mkimage -p [pos]'. The splash data is stored at the absolute position. Instead the property 'data', the properties 'data-position' and 'data-size' are used to specify the location and size of the splash data.
- the splash data is external with relative offset in FIT image This case is made by 'mkimage -E'. The splash data is placed after the FIT image header with 4 byte alignment. Instead the property 'data', the properties 'data-offset' and 'data-size' are used to specify the location and size of the splash data.

Currently, the splash only support to load external data with relative offset from FIT image. This commit make it possible to load the splash data embedded in FIT image or the external data with absolute position

This inspiration comes from Simon Glass <[email protected]>, see common/spl_fit.c

---
 common/splash_source.c | 56 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 21 deletions(-)
common/splash_source.c +35 -21
index e1e73db..88fba7d 100644
@@ -304,8 +304,11 @@ static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)
 	int res;
 	int node_offset;
 	const char *splash_file;
-	int splash_offset;
-	int splash_size;
+	const void *internal_splash_data;
+	size_t internal_splash_size;
+	int external_splash_addr;
+	int external_splash_size;
+	bool is_splash_external = false;
 	struct image_header *img_header;
 	const u32 *fit_header;
 	u32 fit_size;
@@ -348,29 +351,40 @@ static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)
 		return -ENOENT;
 	}
 
-	res = fit_image_get_data_offset(fit_header, node_offset,
-					&splash_offset);
-	if (res < 0) {
-		printf("Failed to load splash image (err=%d)\n", res);
-		return res;
+	/* Extract the splash data from FIT */
+	/* 1. Test if splash is in FIT internal data. */
+	if (!fit_image_get_data(fit_header, node_offset, &internal_splash_data, &internal_splash_size))
+		memmove((void *)bmp_load_addr, internal_splash_data, internal_splash_size);
+	/* 2. Test if splash is in FIT external data with fixed position. */
+	else if (!fit_image_get_data_position(fit_header, node_offset, &external_splash_addr))
+		is_splash_external = true;
+	/* 3. Test if splash is in FIT external data with offset. */
+	else if (!fit_image_get_data_offset(fit_header, node_offset, &external_splash_addr)) {
+		/* Align data offset to 4-byte boundrary */
+		fit_size = fdt_totalsize(fit_header);
+		fit_size = (fit_size + 3) & ~3;
+		/* External splash offset means the offset by end of FIT header */
+		external_splash_addr += location->offset + fit_size;
+		is_splash_external = true;
+	} else {
+		printf("Failed to get splash image from FIT\n");
+		return -ENODATA;
 	}
 
-	res = fit_image_get_data_size(fit_header, node_offset, &splash_size);
-	if (res < 0) {
-		printf("Failed to load splash image (err=%d)\n", res);
-		return res;
+	if (is_splash_external) {
+		res = fit_image_get_data_size(fit_header, node_offset, &external_splash_size);
+		if (res < 0) {
+			printf("Failed to get size of splash image (err=%d)\n", res);
+			return res;
+		}
+
+		/* Read in the splash data */
+		location->offset = external_splash_addr;
+		res = splash_storage_read_raw(location, bmp_load_addr, external_splash_size);
+		if (res < 0)
+			return res;
 	}
 
-	/* Align data offset to 4-byte boundrary */
-	fit_size = fdt_totalsize(fit_header);
-	fit_size = (fit_size + 3) & ~3;
-
-	/* Read in the splash data */
-	location->offset = (location->offset + fit_size + splash_offset);
-	res = splash_storage_read_raw(location, bmp_load_addr , splash_size);
-	if (res < 0)
-		return res;
-
 	return 0;
 }
 #endif /* CONFIG_FIT */
Signature · 1 line
2.7.4
#4 lore raw

PATCH 2/2 splash: Load internal and external data from FIT

Hi Mark,

Quoted 23 lines · Mark Jonas

From: Leo Ruan <[email protected]>

The FIT image could contain the splash data in 3 different structure:
- The splash data is embedded in FIT image (internal)
In this case, the property 'data' presents in FIT image header. And internal information 'start' and 'end' represent the location and size of splash data inside of FIT image.
- The splash data is external with absolute position in FIT image This case is made by 'mkimage -p [pos]'. The splash data is stored at the absolute position. Instead the property 'data', the properties 'data-position' and 'data-size' are used to specify the location and size of the splash data.
- the splash data is external with relative offset in FIT image This case is made by 'mkimage -E'. The splash data is placed after the FIT image header with 4 byte alignment. Instead the property 'data', the properties 'data-offset' and 'data-size' are used to specify the location and size of the splash data.

Currently, the splash only support to load external data with relative offset from FIT image. This commit make it possible to load the splash data embedded in FIT image or the external data with absolute position

Quoted 7 lines

This inspiration comes from Simon Glass <[email protected]>, see common/spl_fit.c

---
 common/splash_source.c | 56

+++++++++++++++++++++++++++++++-------------------

Quoted 1 line
 1 file changed, 35 insertions(+), 21 deletions(-)

nits below

common/splash_source.c static int splash_load_fit(struct splash_location

Quoted 6 lines
common/splash_source.c +0 -0
index e1e73db..88fba7d 100644
@@ -304,8 +304,11 @@ static int splash_load_fit(struct splash_location

*location, u32 bmp_load_addr)

common/splash_source.c static int splash_load_fit(struct splash_location

Quoted 14 lines
common/splash_source.c +5 -2
        int res;
        int node_offset;
        const char *splash_file;
-       int splash_offset;
-       int splash_size;
+       const void *internal_splash_data;
+       size_t internal_splash_size;
+       int external_splash_addr;
+       int external_splash_size;
+       bool is_splash_external = false;
        struct image_header *img_header;
        const u32 *fit_header;
        u32 fit_size;
@@ -348,29 +351,40 @@ static int splash_load_fit(struct splash_location

*location, u32 bmp_load_addr)

common/splash_source.c static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)

Quoted 11 lines
common/splash_source.c +3 -5
                return -ENOENT;
        }
 
-       res = fit_image_get_data_offset(fit_header, node_offset,
-                                       &splash_offset);
-       if (res < 0) {
-               printf("Failed to load splash image (err=%d)\n", res);
-               return res;
+       /* Extract the splash data from FIT */
+       /* 1. Test if splash is in FIT internal data. */
+       if (!fit_image_get_data(fit_header, node_offset,

&internal_splash_data, &internal_splash_size))

common/splash_source.c static int splash_load_fit(struct splash_location · line 357

Quoted 1 line
common/splash_source.c +1 -0
+               memmove((void *)bmp_load_addr, internal_splash_data,

internal_splash_size);

common/splash_source.c static int splash_load_fit(struct splash_location · line 358

Quoted 1 line
common/splash_source.c +1 -0
+       /* 2. Test if splash is in FIT external data with fixed position.

*/

common/splash_source.c static int splash_load_fit(struct splash_location · line 359

Quoted 1 line
common/splash_source.c +1 -0
+       else if (!fit_image_get_data_position(fit_header, node_offset,

&external_splash_addr))

common/splash_source.c static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)

Quoted 3 lines
common/splash_source.c +3 -0
+               is_splash_external = true;
+       /* 3. Test if splash is in FIT external data with offset. */
+       else if (!fit_image_get_data_offset(fit_header, node_offset,

&external_splash_addr)) {

common/splash_source.c static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr) · line 365

Quoted 3 lines
common/splash_source.c +3 -0
+               /* Align data offset to 4-byte boundrary */
+               fit_size = fdt_totalsize(fit_header);
+               fit_size = (fit_size + 3) & ~3;

Can you use ALIGN()?

common/splash_source.c static int splash_load_fit(struct splash_location · line 366

Quoted 1 line
common/splash_source.c +1 -0
+               /* External splash offset means the offset by end of FIT

header */

common/splash_source.c static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)

Quoted 8 lines
common/splash_source.c +5 -1
+               external_splash_addr += location->offset + fit_size;
+               is_splash_external = true;
+       } else {
+               printf("Failed to get splash image from FIT\n");
+               return -ENODATA;
        }
 
-       res = fit_image_get_data_size(fit_header, node_offset,

&splash_size);

common/splash_source.c static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)

Quoted 5 lines
common/splash_source.c +2 -3
-       if (res < 0) {
-               printf("Failed to load splash image (err=%d)\n", res);
-               return res;
+       if (is_splash_external) {
+               res = fit_image_get_data_size(fit_header, node_offset,

&external_splash_size);

common/splash_source.c static int splash_load_fit(struct splash_location · line 377

Quoted 2 lines
common/splash_source.c +2 -0
+               if (res < 0) {
+                       printf("Failed to get size of splash image

(err=%d)\n", res);

common/splash_source.c static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)

Quoted 6 lines
common/splash_source.c +6 -0
+                       return res;
+               }
+
+               /* Read in the splash data */
+               location->offset = external_splash_addr;
+               res = splash_storage_read_raw(location, bmp_load_addr,

external_splash_size);

common/splash_source.c static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr)

Quoted 11 lines
common/splash_source.c +2 -7
+               if (res < 0)
+                       return res;
        }
 
-       /* Align data offset to 4-byte boundrary */
-       fit_size = fdt_totalsize(fit_header);
-       fit_size = (fit_size + 3) & ~3;
-
-       /* Read in the splash data */
-       location->offset = (location->offset + fit_size + splash_offset);
-       res = splash_storage_read_raw(location, bmp_load_addr ,

splash_size);

Quoted 9 lines
common/splash_source.c +0 -4
-       if (res < 0)
-               return res;
-
        return 0;
 }
 #endif /* CONFIG_FIT */
--

2.7.4

Regards,
Simon

#5 lore raw

PATCH 2/2 splash: Load internal and external data from FIT

Hi Simon,

Quoted 5 lines
Quoted 3 lines

+               /* Align data offset to 4-byte boundrary */ +               fit_size = fdt_totalsize(fit_header); +               fit_size = (fit_size + 3) & ~3;

Can you use ALIGN()?

I think so. I'll send an updated version.

Greetings,
Mark

Building Technologies, Panel Software Fire (BT-FIR/ENG1)
Bosch Sicherheitssysteme GmbH | Postfach 11 11 | 85626 Grasbrunn | GERMANY | http://www.boschsecurity.com

Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart HRB 23118
Aufsichtsratsvorsitzender: Christian Fischer; Geschäftsführung: Tanja Rückert, Andreas Bartz, Thomas Quante, Bernhard Schuster