Skip to contentSkip to conversation

FDT on second address of android image

U-Boot Superseded Michael Trimarchi 2 participants 6 messages Jun 12, 2016 – Jun 16, 2016

lore
Share & tools
lore
#0 lore raw

This is not a patch, but just an idea of what I would like to have. I don't know what is the best option to change the image-fit file. So I have just tried because the boot_get_fdt start to be a very long function and would make sense to split in some way.
There are two point where make sense to insert this code in my opinion. As you can see here or complicated this condition

  } else if (images->legacy_hdr_valid &&
                        image_check_type(&images->legacy_hdr_os_copy,
                                         IH_TYPE_MULTI)) {

I don't test it so far. Anyway, I have seen that some android image (aka fsl) use this address.

common/image-android.c +20 -0
index ee03b96..9701acd 100644
@@ -146,6 +146,27 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 	return 0;
 }
 
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+			  ulong *dts_data, ulong *dts_len)
+{
+	if (!hdr->second_size) {
+		*dts_data = *dts_len = 0;
+		return -1;
+	}
+
+	printf("Dts load addr 0x%08x size %u KiB\n",
+	       hdr->second_addr, DIV_ROUND_UP(hdr->second_size, 1024));
+
+	*dts_data = (unsigned long)hdr;
+	*dts_data += hdr->page_size;
+	*dts_data += ALIGN(hdr->kernel_size, hdr->page_size);
+	*dts_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
+
+	*dts_len = hdr->second_size;
+	return 0;
+}
+
 #if !defined(CONFIG_SPL_BUILD)
 /**
  * android_print_contents - prints out the contents of the Android format image
common/image-fdt.c +24 -0
index 6cac7db..cdcdfd3 100644
@@ -345,6 +345,30 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 			fdt_addr = load;
 			break;
 #endif
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+			case IMAGE_FORMAT_ANDROID: {
+				ulong fdt_data, fdt_len;
+				android_image_get_dts(buf, &fdt_data, &fdt_len);
+				if (fdt_len) {
+					fdt_blob = (char *)fdt_data;
+					printf("   Booting using the fdt at 0x%p\n", fdt_blob);
+
+					if (fdt_check_header(fdt_blob) != 0) {
+						fdt_error("image is not a fdt");
+						goto error;
+					}
+
+					if (fdt_totalsize(fdt_blob) != fdt_len) {
+						fdt_error("fdt size != image size");
+						goto error;
+					}
+				} else {
+					debug("## No Flattened Device Tree\n");
+					goto no_fdt;
+				}
+			}
+			break;
+#endif
 		case IMAGE_FORMAT_FIT:
 			/*
 			 * This case will catch both: new uImage format
include/image.h +2 -0
index 61b5d3b..f475481 100644
@@ -1147,6 +1147,8 @@ struct andr_img_hdr;
 int android_image_check_header(const struct andr_img_hdr *hdr);
 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
 			     ulong *os_data, ulong *os_len);
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+			  ulong *dts_data, ulong *dts_len);
 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 			      ulong *rd_data, ulong *rd_len);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
#1 lore raw

RFC PATCH 1/1 common: image-fdt: support dts from the second address of android image

We can support dts load from the second address of android image. This let us to boot board (aka freescale)

---
 common/image-fdt.c | 26 ++++++++++++++++++++++++++
 include/image.h    |  2 ++
 2 files changed, 28 insertions(+)
common/image-fdt.c +26 -0
index 6cac7db..782c489 100644
@@ -345,6 +345,31 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 			fdt_addr = load;
 			break;
 #endif
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+			case IMAGE_FORMAT_ANDROID: {
+				ulong fdt_data, fdt_len;
+				android_image_get_dts(buf, &fdt_data, &fdt_len);
+				if (fdt_len) {
+					fdt_blob = (char *)fdt_data;
+					printf("   Booting using the fdt at 0x%p\n", fdt_blob);
+
+					if (fdt_check_header(fdt_blob) != 0) {
+						fdt_error("image is not a fdt");
+						goto error;
+					}
+
+					if (fdt_totalsize(fdt_blob) != fdt_len) {
+						fdt_error("fdt size != image size");
+						goto error;
+					}
+					goto boot_fdt;
+				} else {
+					debug("## No Flattened Device Tree\n");
+					goto no_fdt;
+				}
+			}
+			break;
+#endif
 		case IMAGE_FORMAT_FIT:
 			/*
 			 * This case will catch both: new uImage format
@@ -422,6 +447,7 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 		goto no_fdt;
 	}
 
+boot_fdt:
 	*of_flat_tree = fdt_blob;
 	*of_size = fdt_totalsize(fdt_blob);
 	debug("   of_flat_tree at 0x%08lx size 0x%08lx\n",
include/image.h +2 -0
index 61b5d3b..f475481 100644
@@ -1147,6 +1147,8 @@ struct andr_img_hdr;
 int android_image_check_header(const struct andr_img_hdr *hdr);
 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
 			     ulong *os_data, ulong *os_len);
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+			  ulong *dts_data, ulong *dts_len);
 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 			      ulong *rd_data, ulong *rd_len);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
Signature · 7 lines
2.8.4

-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#2 lore raw

RFC PATCH v2 1/1 common: image-fdt: support dts from the second address of android image

We can support dts load from the second address of android image. This let us to boot board (aka freescale)

---
 common/image-android.c | 21 +++++++++++++++++++++
 common/image-fdt.c     | 12 ++++++++++++
 include/image.h        |  2 ++
 3 files changed, 35 insertions(+)
common/image-android.c +21 -0
index ee03b96..9701acd 100644
@@ -146,6 +146,27 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 	return 0;
 }
 
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+			  ulong *dts_data, ulong *dts_len)
+{
+	if (!hdr->second_size) {
+		*dts_data = *dts_len = 0;
+		return -1;
+	}
+
+	printf("Dts load addr 0x%08x size %u KiB\n",
+	       hdr->second_addr, DIV_ROUND_UP(hdr->second_size, 1024));
+
+	*dts_data = (unsigned long)hdr;
+	*dts_data += hdr->page_size;
+	*dts_data += ALIGN(hdr->kernel_size, hdr->page_size);
+	*dts_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
+
+	*dts_len = hdr->second_size;
+	return 0;
+}
+
+
 #if !defined(CONFIG_SPL_BUILD)
 /**
  * android_print_contents - prints out the contents of the Android format image
common/image-fdt.c +12 -0
index 6cac7db..732a1a3 100644
@@ -345,6 +345,14 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 			fdt_addr = load;
 			break;
 #endif
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+			case IMAGE_FORMAT_ANDROID: {
+				ulong fdt_data, fdt_len;
+				android_image_get_dts(buf, &fdt_data, &fdt_len);
+				goto boot_fdt;
+			}
+			break;
+#endif
 		case IMAGE_FORMAT_FIT:
 			/*
 			 * This case will catch both: new uImage format
@@ -400,6 +408,10 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 
 		image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
 				   &fdt_len);
+
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+boot_fdt:
+#endif
 		if (fdt_len) {
 			fdt_blob = (char *)fdt_data;
 			printf("   Booting using the fdt at 0x%p\n", fdt_blob);
include/image.h +2 -0
index 61b5d3b..f475481 100644
@@ -1147,6 +1147,8 @@ struct andr_img_hdr;
 int android_image_check_header(const struct andr_img_hdr *hdr);
 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
 			     ulong *os_data, ulong *os_len);
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+			  ulong *dts_data, ulong *dts_len);
 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 			      ulong *rd_data, ulong *rd_len);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
Signature · 7 lines
2.8.4

-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#3 lore raw

RFC PATCH v3 1/1 common: image-fdt: support dts from the second address of android image

We can support dts load from the second address of android image. This let us to boot board (aka freescale)

---
Changes:

	v2 -> v3: Move variable fdt_data and fdt_len in main body
	v1 -> v2: reduce code and cleanup
---
 common/image-android.c | 21 +++++++++++++++++++++
 common/image-fdt.c     | 13 +++++++++++--
 include/image.h        |  2 ++
 3 files changed, 34 insertions(+), 2 deletions(-)
common/image-android.c +21 -0
index ee03b96..9701acd 100644
@@ -146,6 +146,27 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 	return 0;
 }
 
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+			  ulong *dts_data, ulong *dts_len)
+{
+	if (!hdr->second_size) {
+		*dts_data = *dts_len = 0;
+		return -1;
+	}
+
+	printf("Dts load addr 0x%08x size %u KiB\n",
+	       hdr->second_addr, DIV_ROUND_UP(hdr->second_size, 1024));
+
+	*dts_data = (unsigned long)hdr;
+	*dts_data += hdr->page_size;
+	*dts_data += ALIGN(hdr->kernel_size, hdr->page_size);
+	*dts_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
+
+	*dts_len = hdr->second_size;
+	return 0;
+}
+
+
 #if !defined(CONFIG_SPL_BUILD)
 /**
  * android_print_contents - prints out the contents of the Android format image
common/image-fdt.c +11 -2
index 6cac7db..fb4cceb 100644
@@ -237,6 +237,7 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 	ulong		default_addr;
 	int		fdt_noffset;
 #endif
+	ulong fdt_data, fdt_len;
 	const char *select = NULL;
 	int		ok_no_fdt = 0;
 
@@ -345,6 +346,12 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 			fdt_addr = load;
 			break;
 #endif
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+		case IMAGE_FORMAT_ANDROID:
+			android_image_get_dts(buf, &fdt_data, &fdt_len);
+			goto boot_fdt;
+			break;
+#endif
 		case IMAGE_FORMAT_FIT:
 			/*
 			 * This case will catch both: new uImage format
@@ -389,8 +396,6 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 	} else if (images->legacy_hdr_valid &&
 			image_check_type(&images->legacy_hdr_os_copy,
 					 IH_TYPE_MULTI)) {
-		ulong fdt_data, fdt_len;
-
 		/*
 		 * Now check if we have a legacy multi-component image,
 		 * get second entry data start address and len.
@@ -400,6 +405,10 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 
 		image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
 				   &fdt_len);
+
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+boot_fdt:
+#endif
 		if (fdt_len) {
 			fdt_blob = (char *)fdt_data;
 			printf("   Booting using the fdt at 0x%p\n", fdt_blob);
include/image.h +2 -0
index 61b5d3b..f475481 100644
@@ -1147,6 +1147,8 @@ struct andr_img_hdr;
 int android_image_check_header(const struct andr_img_hdr *hdr);
 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
 			     ulong *os_data, ulong *os_len);
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+			  ulong *dts_data, ulong *dts_len);
 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 			      ulong *rd_data, ulong *rd_len);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
Signature · 1 line
2.8.4
#4 lore raw

RFC PATCH v3 1/1 common: image-fdt: support dts from the second address of android image

Hi Michael,

Quoted 7 lines · Michael Trimarchi

We can support dts load from the second address of android image. This let us to boot board (aka freescale)

---
Changes:

Quoted 7 lines
        v2 -> v3: Move variable fdt_data and fdt_len in main body
        v1 -> v2: reduce code and cleanup
---
 common/image-android.c | 21 +++++++++++++++++++++
 common/image-fdt.c     | 13 +++++++++++--
 include/image.h        |  2 ++
 3 files changed, 34 insertions(+), 2 deletions(-)

But please see below.

Quoted 38 lines
common/image-android.c +21 -0
index ee03b96..9701acd 100644
@@ -146,6 +146,27 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
        return 0;
 }
 
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+                         ulong *dts_data, ulong *dts_len)
+{
+       if (!hdr->second_size) {
+               *dts_data = *dts_len = 0;
+               return -1;
+       }
+
+       printf("Dts load addr 0x%08x size %u KiB\n",
+              hdr->second_addr, DIV_ROUND_UP(hdr->second_size, 1024));
+
+       *dts_data = (unsigned long)hdr;
+       *dts_data += hdr->page_size;
+       *dts_data += ALIGN(hdr->kernel_size, hdr->page_size);
+       *dts_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
+
+       *dts_len = hdr->second_size;
+       return 0;
+}
+
+
 #if !defined(CONFIG_SPL_BUILD)
 /**
  * android_print_contents - prints out the contents of the Android format image
common/image-fdt.c +0 -0
index 6cac7db..fb4cceb 100644

common/image-fdt.c int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch, · line 240

Quoted 4 lines
common/image-fdt.c +1 -0
@@ -237,6 +237,7 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
        ulong           default_addr;
        int             fdt_noffset;
 #endif
+       ulong fdt_data, fdt_len;

Won't this give an unused variable warning if
CONFIG_ANDROID_BOOT_IMAGE is not defined?

Quoted 50 lines
common/image-fdt.c +10 -2
        const char *select = NULL;
        int             ok_no_fdt = 0;
 
@@ -345,6 +346,12 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
                        fdt_addr = load;
                        break;
 #endif
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+               case IMAGE_FORMAT_ANDROID:
+                       android_image_get_dts(buf, &fdt_data, &fdt_len);
+                       goto boot_fdt;
+                       break;
+#endif
                case IMAGE_FORMAT_FIT:
                        /*
                         * This case will catch both: new uImage format
@@ -389,8 +396,6 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
        } else if (images->legacy_hdr_valid &&
                        image_check_type(&images->legacy_hdr_os_copy,
                                         IH_TYPE_MULTI)) {
-               ulong fdt_data, fdt_len;
-
                /*
                 * Now check if we have a legacy multi-component image,
                 * get second entry data start address and len.
@@ -400,6 +405,10 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 
                image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
                                   &fdt_len);
+
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+boot_fdt:
+#endif
                if (fdt_len) {
                        fdt_blob = (char *)fdt_data;
                        printf("   Booting using the fdt at 0x%p\n", fdt_blob);
include/image.h +2 -1
index 61b5d3b..f475481 100644
@@ -1147,6 +1147,8 @@ struct andr_img_hdr;
 int android_image_check_header(const struct andr_img_hdr *hdr);
 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
                             ulong *os_data, ulong *os_len);
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+                         ulong *dts_data, ulong *dts_len);
 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
                              ulong *rd_data, ulong *rd_len);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
--
Quoted 2 lines

2.8.4

Regards,
Simon

#5 lore raw

RFC PATCH v3 1/1 common: image-fdt: support dts from the second address of android image

Hi

Quoted 60 lines · Simon Glass

Hi Michael,

Quoted 7 lines · Michael Trimarchi

We can support dts load from the second address of android image. This let us to boot board (aka freescale)

---
Changes:

Quoted 7 lines
        v2 -> v3: Move variable fdt_data and fdt_len in main body
        v1 -> v2: reduce code and cleanup
---
 common/image-android.c | 21 +++++++++++++++++++++
 common/image-fdt.c     | 13 +++++++++++--
 include/image.h        |  2 ++
 3 files changed, 34 insertions(+), 2 deletions(-)

But please see below.

Quoted 37 lines
common/image-android.c +21 -0
index ee03b96..9701acd 100644
@@ -146,6 +146,27 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
        return 0;
 }
 
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+                         ulong *dts_data, ulong *dts_len)
+{
+       if (!hdr->second_size) {
+               *dts_data = *dts_len = 0;
+               return -1;
+       }
+
+       printf("Dts load addr 0x%08x size %u KiB\n",
+              hdr->second_addr, DIV_ROUND_UP(hdr->second_size, 1024));
+
+       *dts_data = (unsigned long)hdr;
+       *dts_data += hdr->page_size;
+       *dts_data += ALIGN(hdr->kernel_size, hdr->page_size);
+       *dts_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
+
+       *dts_len = hdr->second_size;
+       return 0;
+}
+
+
 #if !defined(CONFIG_SPL_BUILD)
 /**
  * android_print_contents - prints out the contents of the Android format image
common/image-fdt.c +0 -0
index 6cac7db..fb4cceb 100644
Quoted 9 lines

common/image-fdt.c int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch, · line 240

Quoted 5 lines
common/image-fdt.c +1 -0
@@ -237,6 +237,7 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
        ulong           default_addr;
        int             fdt_noffset;
 #endif
+       ulong fdt_data, fdt_len;

Won't this give an unused variable warning if
CONFIG_ANDROID_BOOT_IMAGE is not defined?

I had the same feeling but if I remember correctly the other path is always compiled. I will check and in case I will add may_unsed or somenthing similar

Michael

Quoted 55 lines
Quoted 50 lines
common/image-fdt.c +10 -2
        const char *select = NULL;
        int             ok_no_fdt = 0;
 
@@ -345,6 +346,12 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
                        fdt_addr = load;
                        break;
 #endif
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+               case IMAGE_FORMAT_ANDROID:
+                       android_image_get_dts(buf, &fdt_data, &fdt_len);
+                       goto boot_fdt;
+                       break;
+#endif
                case IMAGE_FORMAT_FIT:
                        /*
                         * This case will catch both: new uImage format
@@ -389,8 +396,6 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
        } else if (images->legacy_hdr_valid &&
                        image_check_type(&images->legacy_hdr_os_copy,
                                         IH_TYPE_MULTI)) {
-               ulong fdt_data, fdt_len;
-
                /*
                 * Now check if we have a legacy multi-component image,
                 * get second entry data start address and len.
@@ -400,6 +405,10 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 
                image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
                                   &fdt_len);
+
+#if defined(CONFIG_ANDROID_BOOT_IMAGE)
+boot_fdt:
+#endif
                if (fdt_len) {
                        fdt_blob = (char *)fdt_data;
                        printf("   Booting using the fdt at 0x%p\n", fdt_blob);
include/image.h +2 -1
index 61b5d3b..f475481 100644
@@ -1147,6 +1147,8 @@ struct andr_img_hdr;
 int android_image_check_header(const struct andr_img_hdr *hdr);
 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
                             ulong *os_data, ulong *os_len);
+int android_image_get_dts(const struct andr_img_hdr *hdr,
+                         ulong *dts_data, ulong *dts_len);
 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
                              ulong *rd_data, ulong *rd_len);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
--
Quoted 2 lines

2.8.4

Regards,
Simon

Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |