Skip to contentSkip to conversation

Fix do_bootm_linux() so that multi-file images with FDT blob boot.

PATCH New Bartlomiej Sieka 3 participants 7 messages Aug 31, 2007 – Sep 6, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix do_bootm_linux() so that multi-file images with FDT blob boot.

Fix the following issues in do_bootm_linux() that prevent booting the kernel from a mulit-file image (kernel + initrd + blob):
- incorrect initrd address and length calculation
- incorrect blob address calculation

Also, make minor updates to the U-Boot's output and to the coding style.

---
Tested on two MPC5200B-based boards, one using CONFIG_OF_FLAT_TREE (still), the other using CONFIG_OF_LIBFDT. On each board the mulit-file image was booted from an address in RAM, as well as in Flash.

common/cmd_bootm.c +21 -13
index bcb927f..4aca783 100644
@@ -724,9 +724,8 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 		if (tail) {
 			data += 4 - tail;
 		}
-
-		len   = ntohl(len_ptr[1]);
-
+		len = ntohl (((image_header_t *)data)->ih_size);
+		data = data + sizeof(image_header_t);
 	} else {
 		/*
 		 * no initrd image
@@ -817,27 +816,32 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 		int i;
 
 		/* skip kernel length, initrd length, and terminator */
-		of_data = (ulong)(&len_ptr[3]);
+		of_flat_tree = (char *)(&len_ptr[3]);
 		/* skip any additional image length fields */
 		for (i=2; len_ptr[i]; ++i)
-			of_data += 4;
+			of_flat_tree += 4;
 		/* add kernel length, and align */
-		of_data += ntohl(len_ptr[0]);
+		of_flat_tree += ntohl(len_ptr[0]);
 		if (tail) {
-			of_data += 4 - tail;
+			of_flat_tree += 4 - tail;
 		}
 
 		/* add initrd length, and align */
 		tail = ntohl(len_ptr[1]) % 4;
-		of_data += ntohl(len_ptr[1]);
+		of_flat_tree += ntohl(len_ptr[1]);
 		if (tail) {
-			of_data += 4 - tail;
+			of_flat_tree += 4 - tail;
 		}
 
+		/* move the blob if it is in flash (set of_data to !null) */
+		if (addr2info ((ulong)of_flat_tree) != NULL)
+			of_data = (ulong)of_flat_tree;
+
+
 #if defined(CONFIG_OF_FLAT_TREE)
-		if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) {
+		if (*((ulong *)(of_flat_tree)) != OF_DT_HEADER) {
 #else
-		if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) != 0) {
+		if (fdt_check_header (of_flat_tree) != 0) {
 #endif
 			puts ("ERROR: image is not a fdt - "
 				"must RESET the board to recover.\n");
@@ -845,9 +849,11 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 		}
 
 #if defined(CONFIG_OF_FLAT_TREE)
-		if (((struct boot_param_header *)of_data)->totalsize != ntohl(len_ptr[2])) {
+		if (((struct boot_param_header *)of_flat_tree)->totalsize !=
+			ntohl (len_ptr[2])) {
 #else
-		if (be32_to_cpu(fdt_totalsize(of_data)) !=  ntohl(len_ptr[2])) {
+		if (be32_to_cpu (fdt_totalsize (of_flat_tree)) !=
+			ntohl(len_ptr[2])) {
 #endif
 			puts ("ERROR: fdt size != image size - "
 				"must RESET the board to recover.\n");
@@ -957,6 +963,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 				"must RESET the board to recover.\n");
 			do_reset (cmdtp, flag, argc, argv);
 		}
+		puts ("OK\n");
 	}
 	/*
 	 * Add the chosen node if it doesn't exist, add the env and bd_t
@@ -1011,6 +1018,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 		printf ("   Loading Device Tree to %08lx, end %08lx ... ",
 			of_start, of_start + of_len - 1);
 		memmove ((void *)of_start, (void *)of_data, of_len);
+		puts ("OK\n");
 	}
 	/*
 	 * Create the /chosen node and modify the blob with board specific
#1 lore raw

PATCH 1/1 Fix do_bootm_linux() so that multi-file images with FDT blob boot.

Quoted 3 lines · Bartlomiej Sieka

Fix the following issues in do_bootm_linux() that prevent booting the kernel from a mulit-file image (kernel + initrd + blob):
- incorrect initrd address and length calculation

I thought this bug has already been fixed. Are the initrd address and length calculations broken again?

Signature · 2 lines
Timur Tabi
Linux Kernel Developer @ Freescale
#2 lore raw

PATCH 1/1 Fix do_bootm_linux() so that multi-file images with FDT blob boot.

Quoted 8 lines · Timur Tabi
Quoted 4 lines · Bartlomiej Sieka

Fix the following issues in do_bootm_linux() that prevent booting the kernel
from a mulit-file image (kernel + initrd + blob):
- incorrect initrd address and length calculation

I thought this bug has already been fixed. Are the initrd address and length calculations broken again?

I don't know - I have tested today's U-Boot (60174746) and multi-file image booting didn't work:

## Booting image at ff180000 ...

    Image Name:   Kernel + initial ram disk + FDT
    Created:      2007-08-31  12:24:07 UTC
    Image Type:   PowerPC Linux Multi-File Image (gzip compressed)
    Data Size:    2894640 Bytes =  2.8 MB
    Load Address: 00000000
    Entry Point:  00000000
    Contents:
    Image 0:  1351205 Bytes =  1.3 MB
    Image 1:  1531127 Bytes =  1.5 MB
    Image 2:    12288 Bytes = 12 kB
    Verifying Checksum ... OK
    Uncompressing Multi-File Image ... OK

ERROR: image is not a fdt - must RESET the board to recover.

I might have missed a patch, though - could you provide a pointer to the fix that you have in mind?

Regards,
Bartlomiej

#4 lore raw

PATCH 1/1 Fix do_bootm_linux() so that multi-file images with FDT blob boot.

Quoted 6 lines · Timur Tabi
Quoted 2 lines · Bartlomiej Sieka

I might have missed a patch, though - could you provide a pointer to the fix that you have in mind?

http://www.denx.de/cgi-bin/gitweb.cgi?p=u-boot.git;a=commit;h=9877d7dcd1eebe61aa5d8b8ffe9c048ea426e6f6

Timur,

As I said - I have tested today's ToT U-Boot - which contains the above patch - and observed the problem. And more importantly, the patch is not related to booting mulit-image files, which is the scenario I am dealing with.

Regards,
Bartlomiej

#5 lore raw

PATCH v2 1/1 Fix do_bootm_linux() so that multi-file images with FDT blob boot.

In reply to Bartlomiej Sieka

Fix incorrect blob address calculation in do_bootm_linux() that prevents booting the kernel from a multi-file image (kernel + initrd + blob).

Also, make minor updates to the U-Boot's output and to the coding style.

---
My previous patch was wrong in "fixing" the initrd length. do_bootm_linux() expects the initial ramdisk embedded in a multi-file image to be a raw compressed initrd (like ramdisk_image.gz), and not an U-Boot image (like uRamdisk).

Tested on two MPC5200B-based boards, one using CONFIG_OF_FLAT_TREE (still), the other using CONFIG_OF_LIBFDT. On each board the multi-file image was booted from an address in RAM, as well as in Flash.

common/cmd_bootm.c +19 -10
index bcb927f..9d99262 100644
@@ -817,27 +817,32 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 		int i;
 
 		/* skip kernel length, initrd length, and terminator */
-		of_data = (ulong)(&len_ptr[3]);
+		of_flat_tree = (char *)(&len_ptr[3]);
 		/* skip any additional image length fields */
 		for (i=2; len_ptr[i]; ++i)
-			of_data += 4;
+			of_flat_tree += 4;
 		/* add kernel length, and align */
-		of_data += ntohl(len_ptr[0]);
+		of_flat_tree += ntohl(len_ptr[0]);
 		if (tail) {
-			of_data += 4 - tail;
+			of_flat_tree += 4 - tail;
 		}
 
 		/* add initrd length, and align */
 		tail = ntohl(len_ptr[1]) % 4;
-		of_data += ntohl(len_ptr[1]);
+		of_flat_tree += ntohl(len_ptr[1]);
 		if (tail) {
-			of_data += 4 - tail;
+			of_flat_tree += 4 - tail;
 		}
 
+		/* move the blob if it is in flash (set of_data to !null) */
+		if (addr2info ((ulong)of_flat_tree) != NULL)
+			of_data = (ulong)of_flat_tree;
+
+
 #if defined(CONFIG_OF_FLAT_TREE)
-		if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) {
+		if (*((ulong *)(of_flat_tree)) != OF_DT_HEADER) {
 #else
-		if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) != 0) {
+		if (fdt_check_header (of_flat_tree) != 0) {
 #endif
 			puts ("ERROR: image is not a fdt - "
 				"must RESET the board to recover.\n");
@@ -845,9 +850,11 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 		}
 
 #if defined(CONFIG_OF_FLAT_TREE)
-		if (((struct boot_param_header *)of_data)->totalsize != ntohl(len_ptr[2])) {
+		if (((struct boot_param_header *)of_flat_tree)->totalsize !=
+			ntohl (len_ptr[2])) {
 #else
-		if (be32_to_cpu(fdt_totalsize(of_data)) !=  ntohl(len_ptr[2])) {
+		if (be32_to_cpu (fdt_totalsize (of_flat_tree)) !=
+			ntohl(len_ptr[2])) {
 #endif
 			puts ("ERROR: fdt size != image size - "
 				"must RESET the board to recover.\n");
@@ -957,6 +964,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 				"must RESET the board to recover.\n");
 			do_reset (cmdtp, flag, argc, argv);
 		}
+		puts ("OK\n");
 	}
 	/*
 	 * Add the chosen node if it doesn't exist, add the env and bd_t
@@ -1011,6 +1019,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 		printf ("   Loading Device Tree to %08lx, end %08lx ... ",
 			of_start, of_start + of_len - 1);
 		memmove ((void *)of_start, (void *)of_data, of_len);
+		puts ("OK\n");
 	}
 	/*
 	 * Create the /chosen node and modify the blob with board specific
#6 lore raw

PATCH v2 1/1 Fix do_bootm_linux() so that multi-file images with FDT blob boot.

Quoted 4 lines · In message <[email protected]> you wrote:

Fix incorrect blob address calculation in do_bootm_linux() that prevents booting the kernel from a multi-file image (kernel + initrd + blob).

Also, make minor updates to the U-Boot's output and to the coding style.

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"A complex system that works is invariably found to have evolved from
a simple system that worked."             - John Gall, _Systemantics_