Skip to contentSkip to conversation

bootm refactoring

PATCH New Kumar Gala 3 participants 18 messages Aug 12, 2008 – Aug 13, 2008

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

cover bootm refactoring

This patch set is a refactoring of the bootm functionality to get it ready for the sub-command functionality. Its a WIP but I wanted to get some early feedback to see if this is the right direction.

We do see some reduction of the arch specific code which is pretty nice.

- k

author
#1 lore raw

PATCH 1/11 Update linux bootm to support ePAPR client interface

the ePAPR spec has some subtle differences from the current device tree based boot interface to the powerpc linux kernel. The powerpc linux kernel currently ignores the differences that ePAPR specifies.

---
 lib_ppc/bootm.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)
lib_ppc/bootm.c +23 -10
index cbe5592..e83c860 100644
@@ -80,7 +80,8 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	ulong	cmd_start, cmd_end, bootmap_base;
 	bd_t	*kbd;
 	ulong	ep = 0;
-	void	(*kernel)(bd_t *, ulong, ulong, ulong, ulong);
+	void	(*kernel)(bd_t *, ulong r4, ulong r5, ulong r6,
+			  ulong r7, ulong r8, ulong r9);
 	int	ret;
 	ulong	of_size = 0;
 	struct lmb *lmb = images->lmb;
@@ -166,8 +167,8 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		puts ("Could not find kernel entry point!\n");
 		goto error;
 	}
-	kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
-
+	kernel = (void (*)(bd_t *, ulong, ulong, ulong,
+			   ulong, ulong, ulong))ep;
 	/* find ramdisk */
 	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_PPC,
 			&rd_data_start, &rd_data_end);
@@ -282,14 +283,23 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	if (of_flat_tree) {	/* device tree; boot new style */
 		/*
 		 * Linux Kernel Parameters (passing device tree):
-		 *   r3: pointer to the fdt, followed by the board info data
-		 *   r4: physical pointer to the kernel itself
-		 *   r5: NULL
-		 *   r6: NULL
-		 *   r7: NULL
+		 *   r3: pointer to the fdt
+		 *   r4: 0
+		 *   r5: 0
+		 *   r6: epapr magic
+		 *   r7: size of IMA in bytes
+		 *   r8: 0
+		 *   r9: 0
 		 */
+#if defined(CONFIG_85xx) || defined(CONFIG_440)
+ #define EPAPR_MAGIC	(0x45504150)
+#else
+ #define EPAPR_MAGIC	(0x65504150)
+#endif
+
 		debug ("   Booting using OF flat tree...\n");
-		(*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
+		(*kernel) ((bd_t *)of_flat_tree, 0, 0, EPAPR_MAGIC,
+			   CFG_BOOTMAPSZ, 0, 0);
 		/* does not return */
 	} else
 #endif
@@ -301,9 +311,12 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		 *   r5: initrd_end - unused if r4 is 0
 		 *   r6: Start of command line string
 		 *   r7: End   of command line string
+		 *   r8: 0
+		 *   r9: 0
 		 */
 		debug ("   Booting using board info...\n");
-		(*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
+		(*kernel) (kbd, initrd_start, initrd_end,
+			   cmd_start, cmd_end, 0, 0);
 		/* does not return */
 	}
 	return ;
Signature · 1 line
1.5.5.1
author
#2 lore raw

PATCH 2/11 add ability to disable ft_board_setup as part of bootm

if the environment variable 'no_ft_board_setup' is set we skip doing the ft_board_setup().

---
 lib_ppc/bootm.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
lib_ppc/bootm.c +2 -1
index e83c860..3cb17bf 100644
@@ -193,7 +193,8 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		}
 #ifdef CONFIG_OF_BOARD_SETUP
 		/* Call the board-specific fixup routine */
-		ft_board_setup(of_flat_tree, gd->bd);
+		if (!getenv("no_ft_board_setup"))
+			ft_board_setup(of_flat_tree, gd->bd);
 #endif
 	}
 
Signature · 1 line
1.5.5.1
author
#3 lore raw

PATCH 3/11 Clean up usage of icache_disable/dcache_disable

There is no point in disabling the icache on 7xx/74xx/86xx parts and not also flushing the icache. All callers of invalidate_l1_instruction_cache() call icache_disable() right after. Make it so icache_disable() calls invalidate_l1_instruction_cache() for us.

Also, dcache_disable() already calls dcache_flush() so there is no point in the explicit calls of dcache_flush().

---
 board/Marvell/db64360/db64360.c           |    5 -----
 board/Marvell/db64460/db64460.c           |    5 -----
 board/esd/cpci750/cpci750.c               |    4 ----
 board/freescale/mpc7448hpc2/mpc7448hpc2.c |    2 --
 board/prodrive/p3mx/p3mx.c                |    2 --
 common/cmd_bootm.c                        |    2 --
 cpu/74xx_7xx/cache.S                      |    4 ++++
 cpu/mpc86xx/cache.S                       |    4 ++++
 8 files changed, 8 insertions(+), 20 deletions(-)
board/Marvell/db64360/db64360.c +0 -5
index a2ab2d7..2a810a6 100644
@@ -51,9 +51,6 @@
 #define DP(x)
 #endif
 
-extern void flush_data_cache (void);
-extern void invalidate_l1_instruction_cache (void);
-
 /* ------------------------------------------------------------------------- */
 
 /* this is the current GT register space location */
@@ -930,7 +927,5 @@ void board_prebootm_init ()
 	my_remap_gt_regs_bootm (CFG_GT_REGS, BRIDGE_REG_BASE_BOOTM);
 
 	icache_disable ();
-	invalidate_l1_instruction_cache ();
-	flush_data_cache ();
 	dcache_disable ();
 }
board/Marvell/db64460/db64460.c +0 -5
index a4abf8d..1ae898d 100644
@@ -51,9 +51,6 @@
 #define DP(x)
 #endif
 
-extern void flush_data_cache (void);
-extern void invalidate_l1_instruction_cache (void);
-
 /* ------------------------------------------------------------------------- */
 
 /* this is the current GT register space location */
@@ -930,7 +927,5 @@ void board_prebootm_init ()
 	my_remap_gt_regs_bootm (CFG_GT_REGS, BRIDGE_REG_BASE_BOOTM);
 
 	icache_disable ();
-	invalidate_l1_instruction_cache ();
-	flush_data_cache ();
 	dcache_disable ();
 }
board/esd/cpci750/cpci750.c +0 -4
index 298aa6a..5ab76c6 100644
@@ -120,8 +120,6 @@ static char show_config_tab[][15] = {{"PCI0DLL_2     "},  /* 31 */
 				     {"DRAMPLL_NDiv_1"},  /* 01 */
 				     {"DRAMPLL_NDiv_0"}}; /* 00 */
 
-extern void flush_data_cache (void);
-extern void invalidate_l1_instruction_cache (void);
 extern flash_info_t flash_info[];
 
 /* ------------------------------------------------------------------------- */
@@ -961,8 +959,6 @@ void board_prebootm_init ()
 	my_remap_gt_regs_bootm (CFG_GT_REGS, CFG_DFL_GT_REGS);
 
 	icache_disable ();
-	invalidate_l1_instruction_cache ();
-	flush_data_cache ();
 	dcache_disable ();
 }
 
board/freescale/mpc7448hpc2/mpc7448hpc2.c +0 -2
index b3d83cc..6f74c31 100644
@@ -37,8 +37,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-extern void flush_data_cache (void);
-extern void invalidate_l1_instruction_cache (void);
 extern void tsi108_init_f (void);
 
 int display_mem_map (void);
board/prodrive/p3mx/p3mx.c +0 -2
index d54ddaf..69d7c9b 100644
@@ -62,8 +62,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #define DP(x)
 #endif
 
-extern void flush_data_cache (void);
-extern void invalidate_l1_instruction_cache (void);
 extern flash_info_t flash_info[];
 
 /* ------------------------------------------------------------------------- */
common/cmd_bootm.c +0 -2
index 5295969..0b14b06 100644
@@ -236,8 +236,6 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	 * bios emulation, so turn them off again
 	 */
 	icache_disable();
-	invalidate_l1_instruction_cache();
-	flush_data_cache();
 	dcache_disable();
 #endif
 
cpu/74xx_7xx/cache.S +4 -0
index 3a745cb..eac4544 100644
@@ -245,6 +245,10 @@ _GLOBAL(icache_enable)
  * Disable L1 Instruction cache
  */
 _GLOBAL(icache_disable)
+	mflr	r4
+	bl	invalidate_l1_instruction_cache		/* uses r3 */
+	sync
+	mtlr	r4
 	mfspr	r3, HID0
 	li	r5, 0
 	ori	r5, r5, HID0_ICE
cpu/mpc86xx/cache.S +4 -0
index 2e4ea02..80ff688 100644
@@ -232,6 +232,10 @@ _GLOBAL(icache_enable)
  * Disable L1 Instruction cache
  */
 _GLOBAL(icache_disable)
+	mflr	r4
+	bl	invalidate_l1_instruction_cache		/* uses r3 */
+	sync
+	mtlr	r4
 	mfspr	r3, HID0
 	li	r5, 0
 	ori	r5, r5, HID0_ICE
Signature · 1 line
1.5.5.1
author
#4 lore raw

PATCH 4/11 bootm: refactor entry point code

Move entry point code out of each arch and into common code. Keep the entry point in the bootm_headers_t images struct.

---
 common/cmd_bootm.c     |   31 ++++++++++++++++++++++---------
 include/image.h        |    2 ++
 lib_arm/bootm.c        |   19 +------------------
 lib_avr32/bootm.c      |   19 +------------------
 lib_blackfin/bootm.c   |   19 +------------------
 lib_m68k/bootm.c       |   19 +------------------
 lib_microblaze/bootm.c |   19 +------------------
 lib_mips/bootm.c       |   18 +-----------------
 lib_nios2/bootm.c      |   20 +-------------------
 lib_ppc/bootm.c        |   22 +++-------------------
 lib_sh/bootm.c         |   19 +------------------
 lib_sparc/bootm.c      |   12 ++----------
 12 files changed, 37 insertions(+), 182 deletions(-)
common/cmd_bootm.c +22 -9
index 0b14b06..3f63b84 100644
@@ -205,6 +205,23 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		return 1;
 	}
 
+	/* find kernel entry point */
+	if (images.legacy_hdr_valid) {
+		images.ep = image_get_ep (&images.legacy_hdr_os_copy);
+#if defined(CONFIG_FIT)
+	} else if (images.fit_uname_os) {
+		ret = fit_image_get_entry (images.fit_hdr_os,
+				images.fit_noffset_os, &images.ep);
+		if (ret) {
+			puts ("Can't get entry point property!\n");
+			return 1;
+		}
+#endif
+	} else {
+		puts ("Could not find kernel entry point!\n");
+		return 1;
+	}
+
 	image_start = (ulong)os_hdr;
 	load_end = 0;
 	type_name = genimg_get_type_name (type);
@@ -942,7 +959,7 @@ static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
 		cmdline = "";
 	}
 
-	loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
+	loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
 
 	printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
 		(ulong)loader);
@@ -981,7 +998,6 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
 			   int argc, char *argv[],
 			   bootm_headers_t *images)
 {
-	image_header_t *hdr = &images->legacy_hdr_os_copy;
 	void (*entry_point)(bd_t *);
 
 #if defined(CONFIG_FIT)
@@ -991,7 +1007,7 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
 	}
 #endif
 
-	entry_point = (void (*)(bd_t *))image_get_ep (hdr);
+	entry_point = (void (*)(bd_t *))images->ep;
 
 	printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
 		(ulong)entry_point);
@@ -1011,7 +1027,6 @@ static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
 			     bootm_headers_t *images)
 {
 	char str[80];
-	image_header_t *hdr = &images->legacy_hdr_os_copy;
 
 #if defined(CONFIG_FIT)
 	if (!images->legacy_hdr_valid) {
@@ -1020,7 +1035,7 @@ static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
 	}
 #endif
 
-	sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
+	sprintf(str, "%lx", images->ep); /* write entry-point into string */
 	setenv("loadaddr", str);
 	do_bootvx(cmdtp, 0, 0, NULL);
 }
@@ -1031,7 +1046,6 @@ static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
 {
 	char *local_args[2];
 	char str[16];
-	image_header_t *hdr = &images->legacy_hdr_os_copy;
 
 #if defined(CONFIG_FIT)
 	if (!images->legacy_hdr_valid) {
@@ -1040,7 +1054,7 @@ static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
 	}
 #endif
 
-	sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
+	sprintf(str, "%lx", images->ep); /* write entry-point into string */
 	local_args[0] = argv[0];
 	local_args[1] = str;	/* and provide it via the arguments */
 	do_bootelf(cmdtp, 0, 2, local_args);
@@ -1058,7 +1072,6 @@ static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
 	int i, j, nxt, len, envno, envsz;
 	bd_t *kbd;
 	void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
-	image_header_t *hdr = &images->legacy_hdr_os_copy;
 
 #if defined(CONFIG_FIT)
 	if (!images->legacy_hdr_valid) {
@@ -1133,7 +1146,7 @@ static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
 	}
 	*ss++ = NULL;	/* terminate */
 
-	entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
+	entry = (void (*)(bd_t *, char *, char **, ulong))images->ep;
 	(*entry) (kbd, cmdline, fwenv, top);
 }
 #endif
include/image.h +2 -0
index 4b9c582..e16c253 100644
@@ -219,6 +219,8 @@ typedef struct bootm_headers {
 #endif
 #endif
 
+	ulong		ep;		/* entry point of OS */
+
 	int		verify;		/* getenv("verify")[0] != 'n' */
 	struct lmb	*lmb;		/* for memory mgmt */
 } bootm_headers_t;
lib_arm/bootm.c +1 -18
index 955a1ae..5660a50 100644
@@ -62,7 +62,6 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		     bootm_headers_t *images)
 {
 	ulong	initrd_start, initrd_end;
-	ulong	ep = 0;
 	bd_t	*bd = gd->bd;
 	char	*s;
 	int	machid = bd->bi_arch_number;
@@ -73,23 +72,7 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	char *commandline = getenv ("bootargs");
 #endif
 
-	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		ret = fit_image_get_entry (images->fit_hdr_os,
-					images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	theKernel = (void (*)(int, int, uint))ep;
+	theKernel = (void (*)(int, int, uint))images->ep;
 
 	s = getenv ("machid");
 	if (s) {
lib_avr32/bootm.c +1 -18
index 60e6b36..7beab99 100644
@@ -177,29 +177,12 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		    bootm_headers_t *images)
 {
 	ulong	initrd_start, initrd_end;
-	ulong	ep = 0;
 	void	(*theKernel)(int magic, void *tagtable);
 	struct	tag *params, *params_start;
 	char	*commandline = getenv("bootargs");
 	int	ret;
 
-	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		ret = fit_image_get_entry (images->fit_hdr_os,
-				images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	theKernel = (void *)ep;
+	theKernel = (void *)images->ep;
 
 	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_AVR32,
 			&initrd_start, &initrd_end);
lib_blackfin/bootm.c +1 -18
index 54f69a9..f789e24 100644
@@ -38,29 +38,12 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 {
 	int	(*appl) (char *cmdline);
 	char	*cmdline;
-	ulong	ep = 0;
 
 #ifdef SHARED_RESOURCES
 	swap_to(FLASH);
 #endif
 
-	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		int ret = fit_image_get_entry (images->fit_hdr_os,
-				images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	appl = (int (*)(char *))ep;
+	appl = (int (*)(char *))images->ep;
 
 	printf("Starting Kernel at = %x\n", appl);
 	cmdline = make_command_line();
lib_m68k/bootm.c +1 -18
index b45203d..fe658fe 100644
@@ -57,7 +57,6 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
 	ulong cmd_start, cmd_end;
 	ulong bootmap_base;
 	bd_t  *kbd;
-	ulong ep = 0;
 	void  (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
 	struct lmb *lmb = images->lmb;
 
@@ -94,23 +93,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
 	}
 	set_clocks_in_mhz(kbd);
 
-	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		ret = fit_image_get_entry (images->fit_hdr_os,
-				images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
+	kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
 
 	/* find ramdisk */
 	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_M68K,
lib_microblaze/bootm.c +1 -18
index 68edcdb..baf6d77 100644
@@ -40,25 +40,8 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	/* First parameter is mapped to $r5 for kernel boot args */
 	void	(*theKernel) (char *);
 	char	*commandline = getenv ("bootargs");
-	ulong	ep = 0;
 
-	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		int ret = fit_image_get_entry (images->fit_hdr_os,
-				images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	theKernel = (void (*)(char *))ep;
+	theKernel = (void (*)(char *))images->ep;
 
 	show_boot_progress (15);
 
lib_mips/bootm.c +1 -17
index 53e8e19..7df6ce6 100644
@@ -49,7 +49,6 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 		     bootm_headers_t *images)
 {
 	ulong	initrd_start, initrd_end;
-	ulong	ep = 0;
 	void	(*theKernel) (int, char **, char **, int *);
 	char	*commandline = getenv ("bootargs");
 	char	env_buf[12];
@@ -57,22 +56,7 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	char	*cp;
 
 	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		ret = fit_image_get_entry (images->fit_hdr_os,
-				images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	theKernel = (void (*)(int, char **, char **, int *))ep;
+	theKernel = (void (*)(int, char **, char **, int *))images->ep;
 
 	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_MIPS,
 			&initrd_start, &initrd_end);
lib_nios2/bootm.c +1 -19
index 18cf773..c74b5d6 100644
@@ -30,25 +30,7 @@ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		bootm_headers_t *images)
 {
-	ulong	ep = 0;
-
-	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		int ret = fit_image_get_entry (images->fit_hdr_os,
-				images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	void (*kernel)(void) = (void (*)(void))ep;
+	void (*kernel)(void) = (void (*)(void))images->ep;
 
 	/* For now we assume the Microtronix linux ... which only
 	 * needs to be called ;-)
lib_ppc/bootm.c +3 -19
index 3cb17bf..b481c2a 100644
@@ -79,7 +79,6 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 
 	ulong	cmd_start, cmd_end, bootmap_base;
 	bd_t	*kbd;
-	ulong	ep = 0;
 	void	(*kernel)(bd_t *, ulong r4, ulong r5, ulong r6,
 			  ulong r7, ulong r8, ulong r9);
 	int	ret;
@@ -90,6 +89,9 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	char	*of_flat_tree = NULL;
 #endif
 
+	kernel = (void (*)(bd_t *, ulong, ulong, ulong,
+			   ulong, ulong, ulong))images->ep;
+
 	bootmap_base = getenv_bootm_low();
 	bootm_size = getenv_bootm_size();
 
@@ -151,24 +153,6 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		set_clocks_in_mhz(kbd);
 	}
 
-	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		ret = fit_image_get_entry (images->fit_hdr_os,
-				images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	kernel = (void (*)(bd_t *, ulong, ulong, ulong,
-			   ulong, ulong, ulong))ep;
 	/* find ramdisk */
 	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_PPC,
 			&rd_data_start, &rd_data_end);
lib_sh/bootm.c +1 -18
index 4ee7ff3..9d2c908 100644
@@ -62,26 +62,9 @@ static void hexdump (unsigned char *buf, int len)
 void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		     bootm_headers_t *images)
 {
-	ulong	ep = 0;
 	char	*bootargs = getenv("bootargs");
 
-	/* find kernel entry point */
-	if (images->legacy_hdr_valid) {
-		ep = image_get_ep (&images->legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		int ret = fit_image_get_entry (images->fit_hdr_os,
-				images->fit_noffset_os, &ep);
-		if (ret) {
-			puts ("Can't get entry point property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts ("Could not find kernel entry point!\n");
-		goto error;
-	}
-	void (*kernel) (void) = (void (*)(void))ep;
+	void (*kernel) (void) = (void (*)(void))images->ep;
 
 	/* Setup parameters */
 	memset(PARAM, 0, 0x1000);	/* Clear zero page */
lib_sparc/bootm.c +2 -10
index b1a3d98..ac15396 100644
@@ -87,7 +87,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 		    bootm_headers_t * images)
 {
 	char *bootargs;
-	ulong ep, load;
+	ulong load;
 	ulong initrd_start, initrd_end;
 	ulong rd_data_start, rd_data_end, rd_len;
 	unsigned int data, len, checksum;
@@ -97,17 +97,9 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	int ret;
 
 	if (images->legacy_hdr_valid) {
-		ep = image_get_ep(images->legacy_hdr_os);
 		load = image_get_load(images->legacy_hdr_os);
 #if defined(CONFIG_FIT)
 	} else if (images->fit_uname_os) {
-		int ret = fit_image_get_entry(images->fit_hdr_os,
-					      images->fit_noffset_os, &ep);
-		if (ret) {
-			puts("Can't get entry point property!\n");
-			goto error;
-		}
-
 		ret = fit_image_get_load(images->fit_hdr_os,
 					 images->fit_noffset_os, &load);
 		if (ret) {
@@ -124,7 +116,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	linux_hdr = (void *)load;
 
 	/* */
-	kernel = (void (*)(struct linux_romvec *, void *))ep;
+	kernel = (void (*)(struct linux_romvec *, void *))images->ep;
 
 	/* check for a SPARC kernel */
 	if ((linux_hdr->hdr[0] != 'H') ||
Signature · 1 line
1.5.5.1
author
#5 lore raw

PATCH 5/11 bootm: refactor ramdisk locating code

Move determing if we have a ramdisk and where its located into the common code. Keep track of the ramdisk start and end in the bootm_headers_t image struct.

---
 common/cmd_bootm.c |   38 ++++++++++++++++++++++++++++++++++++++
 include/image.h    |    2 ++
 lib_arm/bootm.c    |   10 ++--------
 lib_avr32/bootm.c  |   12 +++---------
 lib_i386/bootm.c   |    8 +-------
 lib_m68k/bootm.c   |   12 +++---------
 lib_mips/bootm.c   |   12 +++---------
 lib_ppc/bootm.c    |   16 +++++-----------
 lib_sparc/bootm.c  |   17 +++--------------
 9 files changed, 60 insertions(+), 67 deletions(-)
common/cmd_bootm.c +38 -0
index 3f63b84..56236b9 100644
@@ -116,6 +116,33 @@ void __board_lmb_reserve(struct lmb *lmb)
 }
 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
 
+#if defined(__ARM__)
+  #define IH_INITRD_ARCH IH_ARCH_ARM
+#elif defined(__avr32__)
+  #define IH_INITRD_ARCH IH_ARCH_AVR32
+#elif defined(__bfin__)
+  #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
+#elif defined(__I386__)
+  #define IH_INITRD_ARCH IH_ARCH_I386
+#elif defined(__M68K__)
+  #define IH_INITRD_ARCH IH_ARCH_M68K
+#elif defined(__microblaze__)
+  #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
+#elif defined(__mips__)
+  #define IH_INITRD_ARCH IH_ARCH_MIPS
+#elif defined(__nios__)
+  #define IH_INITRD_ARCH IH_ARCH_NIOS
+#elif defined(__nios2__)
+  #define IH_INITRD_ARCH IH_ARCH_NIOS2
+#elif defined(__PPC__)
+  #define IH_INITRD_ARCH IH_ARCH_PPC
+#elif defined(__sh__)
+  #define IH_INITRD_ARCH IH_ARCH_SH
+#elif defined(__sparc__)
+  #define IH_INITRD_ARCH IH_ARCH_SPARC
+#else
+# error Unknown CPU type
+#endif
 
 /*******************************************************************/
 /* bootm - boot application image from image in memory */
@@ -133,6 +160,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	ulong		load_start, load_end;
 	ulong		mem_start;
 	phys_size_t	mem_size;
+	int		ret;
 
 	struct lmb lmb;
 
@@ -222,6 +250,16 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		return 1;
 	}
 
+	if (os == IH_OS_LINUX) {
+		/* find ramdisk */
+		ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
+				&images.rd_start, &images.rd_end);
+		if (ret) {
+			puts ("Ramdisk image is corrupt\n");
+			return 1;
+		}
+	}
+
 	image_start = (ulong)os_hdr;
 	load_end = 0;
 	type_name = genimg_get_type_name (type);
include/image.h +2 -0
index e16c253..b8577a0 100644
@@ -221,6 +221,8 @@ typedef struct bootm_headers {
 
 	ulong		ep;		/* entry point of OS */
 
+	ulong		rd_start, rd_end;/* ramdisk start/end */
+
 	int		verify;		/* getenv("verify")[0] != 'n' */
 	struct lmb	*lmb;		/* for memory mgmt */
 } bootm_headers_t;
lib_arm/bootm.c +2 -8
index 5660a50..f9f702f 100644
@@ -61,7 +61,6 @@ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		     bootm_headers_t *images)
 {
-	ulong	initrd_start, initrd_end;
 	bd_t	*bd = gd->bd;
 	char	*s;
 	int	machid = bd->bi_arch_number;
@@ -80,11 +79,6 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		printf ("Using machid 0x%x from environment\n", machid);
 	}
 
-	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_ARM,
-			&initrd_start, &initrd_end);
-	if (ret)
-		goto error;
-
 	show_boot_progress (15);
 
 	debug ("## Transferring control to Linux (at address %08lx) ...\n",
@@ -111,8 +105,8 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	setup_commandline_tag (bd, commandline);
 #endif
 #ifdef CONFIG_INITRD_TAG
-	if (initrd_start && initrd_end)
-		setup_initrd_tag (bd, initrd_start, initrd_end);
+	if (images->rd_start && images->rd_end)
+		setup_initrd_tag (bd, images->rd_start, images->rd_end);
 #endif
 #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
 	setup_videolfb_tag ((gd_t *) gd);
lib_avr32/bootm.c +3 -9
index 7beab99..762701f 100644
@@ -176,7 +176,6 @@ static void setup_end_tag(struct tag *params)
 void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		    bootm_headers_t *images)
 {
-	ulong	initrd_start, initrd_end;
 	void	(*theKernel)(int magic, void *tagtable);
 	struct	tag *params, *params_start;
 	char	*commandline = getenv("bootargs");
@@ -184,20 +183,15 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 
 	theKernel = (void *)images->ep;
 
-	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_AVR32,
-			&initrd_start, &initrd_end);
-	if (ret)
-		goto error;
-
 	show_boot_progress (15);
 
 	params = params_start = (struct tag *)gd->bd->bi_boot_params;
 	params = setup_start_tag(params);
 	params = setup_memory_tags(params);
-	if (initrd_start) {
+	if (images->rd_start) {
 		params = setup_ramdisk_tag(params,
-					   PHYSADDR(initrd_start),
-					   PHYSADDR(initrd_end));
+					   PHYSADDR(images->rd_start),
+					   PHYSADDR(images->rd_end));
 	}
 	params = setup_commandline_tag(params, commandline);
 	params = setup_clock_tags(params);
lib_i386/bootm.c +1 -7
index 452eef7..8c0b225 100644
@@ -36,7 +36,6 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 {
 	void		*base_ptr;
 	ulong		os_data, os_len;
-	ulong		initrd_start, initrd_end;
 	image_header_t	*hdr;
 	int		ret;
 #if defined(CONFIG_FIT)
@@ -44,11 +43,6 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	size_t		len;
 #endif
 
-	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_I386,
-			&initrd_start, &initrd_end);
-	if (ret)
-		goto error;
-
 	if (images->legacy_hdr_valid) {
 		hdr = images->legacy_hdr_os;
 		if (image_check_type (hdr, IH_TYPE_MULTI)) {
@@ -76,7 +70,7 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	}
 
 	base_ptr = load_zimage ((void*)os_data, os_len,
-			initrd_start, initrd_end - initrd_start, 0);
+			images->rd_start, images->rd_end - images->rd_start, 0);
 
 	if (NULL == base_ptr) {
 		printf ("## Kernel loading failed ...\n");
lib_m68k/bootm.c +3 -9
index fe658fe..241721d 100644
@@ -50,7 +50,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
 {
 	ulong sp;
 
-	ulong rd_data_start, rd_data_end, rd_len;
+	ulong rd_len;
 	ulong initrd_start, initrd_end;
 	int ret;
 
@@ -95,14 +95,8 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
 
 	kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
 
-	/* find ramdisk */
-	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_M68K,
-			&rd_data_start, &rd_data_end);
-	if (ret)
-		goto error;
-
-	rd_len = rd_data_end - rd_data_start;
-	ret = boot_ramdisk_high (lmb, rd_data_start, rd_len,
+	rd_len = images->rd_end - images->rd_start;
+	ret = boot_ramdisk_high (lmb, images->rd_start, rd_len,
 			&initrd_start, &initrd_end);
 	if (ret)
 		goto error;
lib_mips/bootm.c +3 -9
index 7df6ce6..9869c33 100644
@@ -48,7 +48,6 @@ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 		     bootm_headers_t *images)
 {
-	ulong	initrd_start, initrd_end;
 	void	(*theKernel) (int, char **, char **, int *);
 	char	*commandline = getenv ("bootargs");
 	char	env_buf[12];
@@ -58,11 +57,6 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	/* find kernel entry point */
 	theKernel = (void (*)(int, char **, char **, int *))images->ep;
 
-	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_MIPS,
-			&initrd_start, &initrd_end);
-	if (ret)
-		goto error;
-
 	show_boot_progress (15);
 
 #ifdef DEBUG
@@ -82,10 +76,10 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 
 	linux_env_set ("memsize", env_buf);
 
-	sprintf (env_buf, "0x%08X", (uint) UNCACHED_SDRAM (initrd_start));
-	linux_env_set ("initrd_start", env_buf);
+	sprintf (env_buf, "0x%08X", (uint) UNCACHED_SDRAM (images->rd_start));
+	linux_env_set ("images->rd_start", env_buf);
 
-	sprintf (env_buf, "0x%X", (uint) (initrd_end - initrd_start));
+	sprintf (env_buf, "0x%X", (uint) (images->rd_end - images->rd_start));
 	linux_env_set ("initrd_size", env_buf);
 
 	sprintf (env_buf, "0x%08X", (uint) (gd->bd->bi_flashstart));
lib_ppc/bootm.c +5 -11
index b481c2a..942b891 100644
@@ -73,7 +73,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	ulong	sp;
 
 	ulong	initrd_start, initrd_end;
-	ulong	rd_data_start, rd_data_end, rd_len;
+	ulong	rd_len;
 	ulong	size;
 	phys_size_t bootm_size;
 
@@ -153,13 +153,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		set_clocks_in_mhz(kbd);
 	}
 
-	/* find ramdisk */
-	ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_PPC,
-			&rd_data_start, &rd_data_end);
-	if (ret)
-		goto error;
-
-	rd_len = rd_data_end - rd_data_start;
+	rd_len = images->rd_end - images->rd_start;
 
 #if defined(CONFIG_OF_LIBFDT)
 	ret = boot_relocate_fdt (lmb, bootmap_base,
@@ -171,7 +165,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	 */
 	if (of_size) {
 		/* pass in dummy initrd info, we'll fix up later */
-		if (fdt_chosen(of_flat_tree, rd_data_start, rd_data_end, 0) < 0) {
+		if (fdt_chosen(of_flat_tree, images->rd_start, images->rd_end, 0) < 0) {
 			fdt_error ("/chosen node create failed");
 			goto error;
 		}
@@ -222,7 +216,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 	}
 #endif	/* CONFIG_OF_LIBFDT */
 
-	ret = boot_ramdisk_high (lmb, rd_data_start, rd_len, &initrd_start, &initrd_end);
+	ret = boot_ramdisk_high (lmb, images->rd_start, rd_len, &initrd_start, &initrd_end);
 	if (ret)
 		goto error;
 
@@ -236,7 +230,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 		/* Look for the dummy entry and delete it */
 		for (j = 0; j < total; j++) {
 			fdt_get_mem_rsv(of_flat_tree, j, &addr, &size);
-			if (addr == rd_data_start) {
+			if (addr == images->rd_start) {
 				fdt_del_mem_rsv(of_flat_tree, j);
 				break;
 			}
lib_sparc/bootm.c +3 -14
index ac15396..71d34ba 100644
@@ -89,7 +89,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	char *bootargs;
 	ulong load;
 	ulong initrd_start, initrd_end;
-	ulong rd_data_start, rd_data_end, rd_len;
+	ulong rd_len;
 	unsigned int data, len, checksum;
 	unsigned int initrd_addr, kernend;
 	void (*kernel) (struct linux_romvec *, void *);
@@ -139,19 +139,8 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	 * extracted and is writeable.
 	 */
 
-	/*
-	 * Are we going to use an initrd image?
-	 */
-	ret = boot_get_ramdisk(argc, argv, images, IH_ARCH_SPARC,
-			       &rd_data_start, &rd_data_end);
-	if (ret) {
-		/* RAM disk found but was corrupt */
-		puts("RAM Disk corrupt\n");
-		goto error;
-	}
-
 	/* Calc length of RAM disk, if zero no ramdisk available */
-	rd_len = rd_data_end - rd_data_start;
+	rd_len = images->rd_end - images->rd_start;
 
 	if (rd_len) {
 
@@ -161,7 +150,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 		 */
 		lmb_reserve(lmb, CFG_RELOC_MONITOR_BASE, CFG_RAM_END);
 
-		ret = boot_ramdisk_high(lmb, rd_data_start, rd_len,
+		ret = boot_ramdisk_high(lmb, images->rd_start, rd_len,
 					&initrd_start, &initrd_end);
 		if (ret) {
 			puts("### Failed to relocate RAM disk\n");
Signature · 1 line
1.5.5.1
author
#6 lore raw

PATCH 6/11 bootm: refactor fdt locating and relocation code

Move the code that handles finding a device tree blob and relocating it (if needed) into common code so all arch's have access to it.

---
 common/cmd_bootm.c |   10 +
 common/image.c     |  502 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/image.h    |   13 ++
 lib_ppc/bootm.c    |  492 +--------------------------------------------------
 4 files changed, 533 insertions(+), 484 deletions(-)
common/cmd_bootm.c +10 -0
index 56236b9..918ea98 100644
@@ -258,6 +258,16 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 			puts ("Ramdisk image is corrupt\n");
 			return 1;
 		}
+
+#if defined(CONFIG_OF_LIBFDT)
+		/* find flattened device tree */
+		ret = boot_get_fdt (cmdtp, flag, argc, argv,
+				    &images, &images.ft_addr, &images.ft_len);
+		if (ret) {
+			puts ("Could not find a valid device tree\n");
+			return 1;
+		}
+#endif
 	}
 
 	image_start = (ulong)os_hdr;
common/image.c +502 -0

508 lines not on this page · raw message

include/image.h +13 -0
index b8577a0..04dd7d2 100644
@@ -223,6 +223,11 @@ typedef struct bootm_headers {
 
 	ulong		rd_start, rd_end;/* ramdisk start/end */
 
+#ifdef CONFIG_OF_LIBFDT
+	char		*ft_addr;	/* flat dev tree address */
+	ulong		ft_len;		/* length of flat device tree */
+#endif
+
 	int		verify;		/* getenv("verify")[0] != 'n' */
 	struct lmb	*lmb;		/* for memory mgmt */
 } bootm_headers_t;
@@ -273,6 +278,14 @@ ulong genimg_get_image (ulong img_addr);
 int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
 		uint8_t arch, ulong *rd_start, ulong *rd_end);
 
+
+#ifdef CONFIG_OF_LIBFDT
+int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
+		bootm_headers_t *images, char **of_flat_tree, ulong *of_size);
+int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base,
+		char **of_flat_tree, ulong *of_size);
+#endif
+
 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
 		  ulong *initrd_start, ulong *initrd_end);
lib_ppc/bootm.c +8 -484

534 lines not on this page · raw message

Signature · 1 line
1.5.5.1
author
#7 lore raw

PATCH 7/11 bootm: Set working fdt address as part of the bootm flow

Set the fdt working address so "fdt FOO" commands can be used as part of the bootm flow.

---
 common/cmd_bootm.c    |    9 +++++++++
 common/cmd_fdt.c      |    5 +++++
 common/image.c        |    1 +
 include/fdt_support.h |    2 ++
 4 files changed, 17 insertions(+), 0 deletions(-)
common/cmd_bootm.c +9 -0
index 918ea98..c5dbf76 100644
@@ -44,6 +44,13 @@
 #include <hush.h>
 #endif
 
+#if defined(CONFIG_OF_LIBFDT)
+#include <fdt.h>
+#include <libfdt.h>
+#include <fdt_support.h>
+#endif
+
+
 DECLARE_GLOBAL_DATA_PTR;
 
 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
@@ -267,6 +274,8 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 			puts ("Could not find a valid device tree\n");
 			return 1;
 		}
+
+		set_working_fdt_addr(images.ft_addr);
 #endif
 	}
 
common/cmd_fdt.c +5 -0
index d3b19dd..44acc34 100644
@@ -50,6 +50,11 @@ static int fdt_print(const char *pathp, char *prop, int depth);
  */
 struct fdt_header *working_fdt;
 
+void set_working_fdt_addr(void *addr)
+{
+	working_fdt = addr;
+}
+
 /*
  * Flattened Device Tree command, see the help for parameter definitions.
  */
common/image.c +1 -0
index e7cb57c..60e1c9d 100644
@@ -1245,6 +1245,7 @@ int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base,
 		*of_size = of_len;
 	}
 
+	set_working_fdt_addr(*of_flat_tree);
 	return 0;
 
 error:
include/fdt_support.h +2 -0
index a7c6326..761f85c 100644
@@ -68,5 +68,7 @@ void ft_cpu_setup(void *blob, bd_t *bd);
 void ft_pci_setup(void *blob, bd_t *bd);
 #endif
 
+void set_working_fdt_addr(void *addr);
+
 #endif /* ifdef CONFIG_OF_LIBFDT */
 #endif /* ifndef __FDT_SUPPORT_H */
Signature · 1 line
1.5.5.1
author
#8 lore raw

PATCH 8/11 bootm: move lmb into the bootm_headers_t structure

To allow for persistent state between future bootm subcommands we need the lmb to exist in a global state. Moving it into the bootm_headers_t allows us to do that.

---
 common/cmd_bootm.c |   11 ++++-------
 include/image.h    |    4 +++-
 lib_m68k/bootm.c   |    2 +-
 lib_ppc/bootm.c    |    2 +-
 lib_sparc/bootm.c  |    2 +-
 5 files changed, 10 insertions(+), 11 deletions(-)
common/cmd_bootm.c +4 -7
index c5dbf76..598f5af 100644
@@ -169,20 +169,17 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	phys_size_t	mem_size;
 	int		ret;
 
-	struct lmb lmb;
-
 	memset ((void *)&images, 0, sizeof (images));
 	images.verify = getenv_yesno ("verify");
-	images.lmb = &lmb;
 
-	lmb_init(&lmb);
+	lmb_init(&images.lmb);
 
 	mem_start = getenv_bootm_low();
 	mem_size = getenv_bootm_size();
 
-	lmb_add(&lmb, (phys_addr_t)mem_start, mem_size);
+	lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
 
-	board_lmb_reserve(&lmb);
+	board_lmb_reserve(&images.lmb);
 
 	/* get kernel image header, start address and length */
 	os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
@@ -388,7 +385,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 	show_boot_progress (8);
 
-	lmb_reserve(&lmb, load_start, (load_end - load_start));
+	lmb_reserve(&images.lmb, load_start, (load_end - load_start));
 
 	switch (os) {
 	default:			/* handled by (original) Linux case */
include/image.h +3 -1
index 04dd7d2..1975012 100644
@@ -229,7 +229,9 @@ typedef struct bootm_headers {
 #endif
 
 	int		verify;		/* getenv("verify")[0] != 'n' */
-	struct lmb	*lmb;		/* for memory mgmt */
+#ifndef USE_HOSTCC
+	struct lmb	lmb;		/* for memory mgmt */
+#endif
 } bootm_headers_t;
 
 /*
lib_m68k/bootm.c +1 -1
index 241721d..1c3b9c9 100644
@@ -58,7 +58,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
 	ulong bootmap_base;
 	bd_t  *kbd;
 	void  (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
-	struct lmb *lmb = images->lmb;
+	struct lmb *lmb = &images->lmb;
 
 	bootmap_base = getenv_bootm_low();
 
lib_ppc/bootm.c +1 -1
index 45f6a47..fb3cccc 100644
@@ -73,7 +73,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 			  ulong r7, ulong r8, ulong r9);
 	int	ret;
 	ulong	of_size = images->ft_len;
-	struct lmb *lmb = images->lmb;
+	struct lmb *lmb = &images->lmb;
 
 #if defined(CONFIG_OF_LIBFDT)
 	char	*of_flat_tree = images->ft_addr;
lib_sparc/bootm.c +1 -1
index 71d34ba..aac05e4 100644
@@ -93,7 +93,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	unsigned int data, len, checksum;
 	unsigned int initrd_addr, kernend;
 	void (*kernel) (struct linux_romvec *, void *);
-	struct lmb *lmb = images->lmb;
+	struct lmb *lmb = &images->lmb;
 	int ret;
 
 	if (images->legacy_hdr_valid) {
Signature · 1 line
1.5.5.1
author
#9 lore raw

PATCH 9/11 bootm: refactor image detection and os load steps

Created a bootm_start() that handles the parsing and detection of all the images that will be used by the bootm command (OS, ramdisk, fdt). As part of this we now tract all the relevant image offsets in the bootm_headers_t struct. This will allow us to have all the needed state for future sub-commands and lets us reduce a bit of arch specific code on SPARC.

Created a bootm_load_os() that deals with decompression and loading the OS image.

---
 common/cmd_bootm.c |  219 ++++++++++++++++++++++++++++++---------------------
 include/image.h    |    9 ++
 lib_sparc/bootm.c  |   19 +----
 3 files changed, 139 insertions(+), 108 deletions(-)
common/cmd_bootm.c +129 -90
index 598f5af..adab88f 100644
@@ -151,24 +151,16 @@ void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_
 # error Unknown CPU type
 #endif
 
-/*******************************************************************/
-/* bootm - boot application image from image in memory */
-/*******************************************************************/
-int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	ulong		iflag;
-	const char	*type_name;
-	uint		unc_len = CFG_BOOTM_LEN;
-	uint8_t		comp, type, os;
-
-	void		*os_hdr;
-	ulong		os_data, os_len;
-	ulong		image_start, image_end;
-	ulong		load_start, load_end;
 	ulong		mem_start;
 	phys_size_t	mem_size;
+	void		*os_hdr;
 	int		ret;
 
+	if (images.valid)
+		return 0;
+
 	memset ((void *)&images, 0, sizeof (images));
 	images.verify = getenv_yesno ("verify");
 
@@ -183,8 +175,8 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 	/* get kernel image header, start address and length */
 	os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
-			&images, &os_data, &os_len);
-	if (os_len == 0) {
+			&images, &images.os.image_start, &images.os.image_len);
+	if (images.os.image_len == 0) {
 		puts ("ERROR: can't get kernel image!\n");
 		return 1;
 	}
@@ -192,40 +184,40 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	/* get image parameters */
 	switch (genimg_get_format (os_hdr)) {
 	case IMAGE_FORMAT_LEGACY:
-		type = image_get_type (os_hdr);
-		comp = image_get_comp (os_hdr);
-		os = image_get_os (os_hdr);
+		images.os.type = image_get_type (os_hdr);
+		images.os.comp = image_get_comp (os_hdr);
+		images.os.os = image_get_os (os_hdr);
 
-		image_end = image_get_image_end (os_hdr);
-		load_start = image_get_load (os_hdr);
+		images.os.end = image_get_image_end (os_hdr);
+		images.os.load = image_get_load (os_hdr);
 		break;
 #if defined(CONFIG_FIT)
 	case IMAGE_FORMAT_FIT:
 		if (fit_image_get_type (images.fit_hdr_os,
-					images.fit_noffset_os, &type)) {
+					images.fit_noffset_os, &images.os.type)) {
 			puts ("Can't get image type!\n");
 			show_boot_progress (-109);
 			return 1;
 		}
 
 		if (fit_image_get_comp (images.fit_hdr_os,
-					images.fit_noffset_os, &comp)) {
+					images.fit_noffset_os, &images.os.comp)) {
 			puts ("Can't get image compression!\n");
 			show_boot_progress (-110);
 			return 1;
 		}
 
 		if (fit_image_get_os (images.fit_hdr_os,
-					images.fit_noffset_os, &os)) {
+					images.fit_noffset_os, &images.os.os)) {
 			puts ("Can't get image OS!\n");
 			show_boot_progress (-111);
 			return 1;
 		}
 
-		image_end = fit_get_end (images.fit_hdr_os);
+		images.os.end = fit_get_end (images.fit_hdr_os);
 
 		if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
-					&load_start)) {
+					&images.os.load)) {
 			puts ("Can't get image load address!\n");
 			show_boot_progress (-112);
 			return 1;
@@ -254,7 +246,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		return 1;
 	}
 
-	if (os == IH_OS_LINUX) {
+	if (images.os.os == IH_OS_LINUX) {
 		/* find ramdisk */
 		ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
 				&images.rd_start, &images.rd_end);
@@ -276,64 +268,52 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #endif
 	}
 
-	image_start = (ulong)os_hdr;
-	load_end = 0;
-	type_name = genimg_get_type_name (type);
-
-	/*
-	 * We have reached the point of no return: we are going to
-	 * overwrite all exception vector code, so we cannot easily
-	 * recover from any failures any more...
-	 */
-	iflag = disable_interrupts();
+	images.os.start = (ulong)os_hdr;
+	images.valid = 1;
 
-#if defined(CONFIG_CMD_USB)
-	/*
-	 * turn off USB to prevent the host controller from writing to the
-	 * SDRAM while Linux is booting. This could happen (at least for OHCI
-	 * controller), because the HCCA (Host Controller Communication Area)
-	 * lies within the SDRAM and the host controller writes continously to
-	 * this area (as busmaster!). The HccaFrameNumber is for example
-	 * updated every 1 ms within the HCCA structure in SDRAM! For more
-	 * details see the OpenHCI specification.
-	 */
-	usb_stop();
-#endif
+	return 0;
+}
 
+#define BOOTM_ERR_RESET		-1
+#define BOOTM_ERR_OVERLAP	-2
+#define BOOTM_ERR_UNIMPLEMENTED	-3
+static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
+{
+	uint8_t comp = os.comp;
+	ulong load = os.load;
+	ulong blob_start = os.start;
+	ulong blob_end = os.end;
+	ulong image_start = os.image_start;
+	ulong image_len = os.image_len;
+	uint		unc_len = CFG_BOOTM_LEN;
 
-#ifdef CONFIG_AMIGAONEG3SE
-	/*
-	 * We've possible left the caches enabled during
-	 * bios emulation, so turn them off again
-	 */
-	icache_disable();
-	dcache_disable();
-#endif
+	const char *type_name = genimg_get_type_name (os.type);
 
 	switch (comp) {
 	case IH_COMP_NONE:
-		if (load_start == (ulong)os_hdr) {
+		if (load == blob_start) {
 			printf ("   XIP %s ... ", type_name);
 		} else {
 			printf ("   Loading %s ... ", type_name);
 
-			memmove_wd ((void *)load_start,
-				   (void *)os_data, os_len, CHUNKSZ);
+			memmove_wd ((void *)load,
+				   (void *)image_start, image_len, CHUNKSZ);
 		}
-		load_end = load_start + os_len;
+		*load_end = load + image_len;
 		puts("OK\n");
 		break;
 	case IH_COMP_GZIP:
 		printf ("   Uncompressing %s ... ", type_name);
-		if (gunzip ((void *)load_start, unc_len,
-					(uchar *)os_data, &os_len) != 0) {
+		if (gunzip ((void *)load, unc_len,
+					(uchar *)image_start, &image_len) != 0) {
 			puts ("GUNZIP: uncompress or overwrite error "
 				"- must RESET board to recover\n");
-			show_boot_progress (-6);
-			do_reset (cmdtp, flag, argc, argv);
+			if (boot_progress)
+				show_boot_progress (-6);
+			return BOOTM_ERR_RESET;
 		}
 
-		load_end = load_start + os_len;
+		*load_end = load + image_len;
 		break;
 #ifdef CONFIG_BZIP2
 	case IH_COMP_BZIP2:
@@ -343,51 +323,110 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		 * use slower decompression algorithm which requires
 		 * at most 2300 KB of memory.
 		 */
-		int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
-					&unc_len, (char *)os_data, os_len,
+		int i = BZ2_bzBuffToBuffDecompress ((char*)load,
+					&unc_len, (char *)image_start, image_len,
 					CFG_MALLOC_LEN < (4096 * 1024), 0);
 		if (i != BZ_OK) {
 			printf ("BUNZIP2: uncompress or overwrite error %d "
 				"- must RESET board to recover\n", i);
-			show_boot_progress (-6);
-			do_reset (cmdtp, flag, argc, argv);
+			if (boot_progress)
+				show_boot_progress (-6);
+			return BOOTM_ERR_RESET;
 		}
 
-		load_end = load_start + unc_len;
+		*load_end = load + unc_len;
 		break;
 #endif /* CONFIG_BZIP2 */
 	default:
-		if (iflag)
-			enable_interrupts();
 		printf ("Unimplemented compression type %d\n", comp);
-		show_boot_progress (-7);
-		return 1;
+		return BOOTM_ERR_UNIMPLEMENTED;
 	}
 	puts ("OK\n");
-	debug ("   kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
-	show_boot_progress (7);
+	debug ("   kernel loaded@0x%08lx, end = 0x%08lx\n", load, load_end);
+	if (boot_progress)
+		show_boot_progress (7);
 
-	if ((load_start < image_end) && (load_end > image_start)) {
-		debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
-		debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
+	if ((load < blob_end) && (*load_end > blob_start)) {
+		debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
+		debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, load_end);
 
-		if (images.legacy_hdr_valid) {
-			if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
-				puts ("WARNING: legacy format multi component "
-					"image overwritten\n");
-		} else {
-			puts ("ERROR: new format image overwritten - "
-				"must RESET the board to recover\n");
-			show_boot_progress (-113);
+		return BOOTM_ERR_OVERLAP;
+	}
+
+	return 0;
+}
+
+/*******************************************************************/
+/* bootm - boot application image from image in memory */
+/*******************************************************************/
+int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+
+	ulong		iflag;
+	ulong		load_end = 0;
+	int		ret;
+
+	bootm_start(cmdtp, flag, argc, argv);
+
+	/*
+	 * We have reached the point of no return: we are going to
+	 * overwrite all exception vector code, so we cannot easily
+	 * recover from any failures any more...
+	 */
+	iflag = disable_interrupts();
+
+#if defined(CONFIG_CMD_USB)
+	/*
+	 * turn off USB to prevent the host controller from writing to the
+	 * SDRAM while Linux is booting. This could happen (at least for OHCI
+	 * controller), because the HCCA (Host Controller Communication Area)
+	 * lies within the SDRAM and the host controller writes continously to
+	 * this area (as busmaster!). The HccaFrameNumber is for example
+	 * updated every 1 ms within the HCCA structure in SDRAM! For more
+	 * details see the OpenHCI specification.
+	 */
+	usb_stop();
+#endif
+
+#ifdef CONFIG_AMIGAONEG3SE
+	/*
+	 * We've possible left the caches enabled during
+	 * bios emulation, so turn them off again
+	 */
+	icache_disable();
+	dcache_disable();
+#endif
+
+	ret = bootm_load_os(images.os, &load_end, 1);
+
+	if (ret < 0) {
+		if (ret == BOOTM_ERR_RESET)
 			do_reset (cmdtp, flag, argc, argv);
+		if (ret == BOOTM_ERR_OVERLAP) {
+			if (images.legacy_hdr_valid) {
+				if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
+					puts ("WARNING: legacy format multi component "
+						"image overwritten\n");
+			} else {
+				puts ("ERROR: new format image overwritten - "
+					"must RESET the board to recover\n");
+				show_boot_progress (-113);
+				do_reset (cmdtp, flag, argc, argv);
+			}
+		}
+		if (ret == BOOTM_ERR_UNIMPLEMENTED) {
+			if (iflag)
+				enable_interrupts();
+			show_boot_progress (-7);
+			return 1;
 		}
 	}
 
-	show_boot_progress (8);
+	lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
 
-	lmb_reserve(&images.lmb, load_start, (load_end - load_start));
+	show_boot_progress (8);
 
-	switch (os) {
+	switch (images.os.os) {
 	default:			/* handled by (original) Linux case */
 	case IH_OS_LINUX:
 #ifdef CONFIG_SILENT_CONSOLE
include/image.h +9 -0
index 1975012..4fa8425 100644
@@ -187,6 +187,13 @@ typedef struct image_header {
 	uint8_t		ih_name[IH_NMLEN];	/* Image Name		*/
 } image_header_t;
 
+typedef struct image_info {
+	ulong		start, end;		/* start/end of blob */
+	ulong		image_start, image_len; /* start of image within blob, len of image */
+	ulong		load;			/* load addr for the image */
+	uint8_t		comp, type, os;		/* compression, type of image, os type */
+} image_info_t;
+
 /*
  * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
  * routines.
@@ -219,6 +226,7 @@ typedef struct bootm_headers {
 #endif
 #endif
 
+	image_info_t	os;		/* os image info */
 	ulong		ep;		/* entry point of OS */
 
 	ulong		rd_start, rd_end;/* ramdisk start/end */
@@ -229,6 +237,7 @@ typedef struct bootm_headers {
 #endif
 
 	int		verify;		/* getenv("verify")[0] != 'n' */
+	int		valid;		/* set to 1 if we've set values in the header */
 #ifndef USE_HOSTCC
 	struct lmb	lmb;		/* for memory mgmt */
 #endif
lib_sparc/bootm.c +1 -18
index aac05e4..f3abdcf 100644
@@ -87,7 +87,6 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 		    bootm_headers_t * images)
 {
 	char *bootargs;
-	ulong load;
 	ulong initrd_start, initrd_end;
 	ulong rd_len;
 	unsigned int data, len, checksum;
@@ -96,24 +95,8 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	struct lmb *lmb = &images->lmb;
 	int ret;
 
-	if (images->legacy_hdr_valid) {
-		load = image_get_load(images->legacy_hdr_os);
-#if defined(CONFIG_FIT)
-	} else if (images->fit_uname_os) {
-		ret = fit_image_get_load(images->fit_hdr_os,
-					 images->fit_noffset_os, &load);
-		if (ret) {
-			puts("Can't get load address property!\n");
-			goto error;
-		}
-#endif
-	} else {
-		puts("Could not find kernel entry point!\n");
-		goto error;
-	}
-
 	/* Get virtual address of kernel start */
-	linux_hdr = (void *)load;
+	linux_hdr = (void *)images->os.load;
 
 	/* */
 	kernel = (void (*)(struct linux_romvec *, void *))images->ep;
Signature · 1 line
1.5.5.1
author
#10 lore raw

PATCH 10/11 fdt: refactor fdt resize code

Move the fdt resizing code out of ppc specific boot code and into common fdt support code.

---
 common/fdt_support.c  |   39 +++++++++++++++++++++++++++++++++++++++
 include/fdt_support.h |    1 +
 lib_ppc/bootm.c       |   32 ++++----------------------------
 3 files changed, 44 insertions(+), 28 deletions(-)
common/fdt_support.c +39 -0
index 93b144e..dadb294 100644
@@ -529,3 +529,42 @@ void fdt_fixup_crypto_node(void *blob, int sec_rev)
 		       fdt_strerror(err));
 }
 #endif /* defined(CONFIG_MPC83XX) || defined(CONFIG_MPC85xx) */
+
+/* Resize the fdt to its actual size + a bit of padding */
+int fdt_resize(void *blob)
+{
+	int i;
+	uint64_t addr, size;
+	int total, ret;
+	uint actualsize;
+
+	if (!blob)
+		return 0;
+
+	total = fdt_num_mem_rsv(blob);
+	for (i = 0; i < total; i++) {
+		fdt_get_mem_rsv(blob, i, &addr, &size);
+		if (addr == (uint64_t)(u32)blob) {
+			fdt_del_mem_rsv(blob, i);
+			break;
+		}
+	}
+
+	/* Calculate the actual size of the fdt */
+	actualsize = fdt_off_dt_strings(blob) +
+		fdt_size_dt_strings(blob);
+
+	/* Make it so the fdt ends on a page boundary */
+	actualsize = ALIGN(actualsize, 0x1000);
+	actualsize = actualsize - ((uint)blob & 0xfff);
+
+	/* Change the fdt header to reflect the correct size */
+	fdt_set_totalsize(blob, actualsize);
+
+	/* Add the new reservation */
+	ret = fdt_add_mem_rsv(blob, (uint)blob, actualsize);
+	if (ret < 0)
+		return ret;
+
+	return actualsize;
+}
include/fdt_support.h +1 -0
index 761f85c..b3f0adb 100644
@@ -69,6 +69,7 @@ void ft_pci_setup(void *blob, bd_t *bd);
 #endif
 
 void set_working_fdt_addr(void *addr);
+int fdt_resize(void *blob);
 
 #endif /* ifdef CONFIG_OF_LIBFDT */
 #endif /* ifndef __FDT_SUPPORT_H */
lib_ppc/bootm.c +4 -28
index fb3cccc..01d6499 100644
@@ -163,38 +163,14 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 
 	/* Fixup the fdt memreserve now that we know how big it is */
 	if (of_flat_tree) {
-		int j;
-		uint64_t addr, size;
-		int total = fdt_num_mem_rsv(of_flat_tree);
-		uint actualsize;
-
-		for (j = 0; j < total; j++) {
-			fdt_get_mem_rsv(of_flat_tree, j, &addr, &size);
-			if (addr == (uint64_t)(u32)of_flat_tree) {
-				fdt_del_mem_rsv(of_flat_tree, j);
-				break;
-			}
-		}
-
 		/* Delete the old LMB reservation */
 		lmb_free(lmb, (phys_addr_t)(u32)of_flat_tree,
 				(phys_size_t)fdt_totalsize(of_flat_tree));
 
-		/* Calculate the actual size of the fdt */
-		actualsize = fdt_off_dt_strings(of_flat_tree) +
-			fdt_size_dt_strings(of_flat_tree);
-
-		/* Make it so the fdt ends on a page boundary */
-		actualsize = ALIGN(actualsize, 0x1000);
-		actualsize = actualsize - ((uint)of_flat_tree & 0xfff);
-
-		/* Change the fdt header to reflect the correct size */
-		fdt_set_totalsize(of_flat_tree, actualsize);
-		of_size = actualsize;
-
-		/* Add the new reservation */
-		ret = fdt_add_mem_rsv(of_flat_tree, (uint)of_flat_tree,
-				of_size);
+		ret = fdt_resize(of_flat_tree);
+		if (ret < 0)
+			goto error;
+		of_size = ret;
 
 		/* Create a new LMB reservation */
 		lmb_reserve(lmb, (ulong)of_flat_tree, of_size);
Signature · 1 line
1.5.5.1
author
#11 lore raw

PATCH 11/11 fdt: refactor initrd related code

Created a new fdt_initrd() to deal with setting the initrd properties in the device tree and fixing up the mem reserve. We can use this both in the choosen node handling and lets us remove some duplicated code when we fixup the initrd info in bootm on PPC.

---
 common/fdt_support.c  |  109 ++++++++++++++++++++++++++++++-------------------
 include/fdt_support.h |    1 +
 lib_ppc/bootm.c       |   28 +------------
 3 files changed, 70 insertions(+), 68 deletions(-)
common/fdt_support.c +67 -42
index dadb294..4fc1915 100644
@@ -99,44 +99,85 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
 }
 #endif
 
-int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
+int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 {
 	int   nodeoffset;
-	int   err;
-	u32   tmp;		/* used to set 32 bit integer properties */
-	char  *str;		/* used to set string properties */
+	int   err, j, total;
+	u32   tmp;
 	const char *path;
+	uint64_t addr, size;
 
-	err = fdt_check_header(fdt);
-	if (err < 0) {
-		printf("fdt_chosen: %s\n", fdt_strerror(err));
-		return err;
+	/* Find the "chosen" node.  */
+	nodeoffset = fdt_path_offset (fdt, "/chosen");
+
+	/* If there is no "chosen" node in the blob return */
+	if (nodeoffset < 0) {
+		printf("fdt_initrd: %s\n", fdt_strerror(nodeoffset));
+		return nodeoffset;
 	}
 
-	if (initrd_start && initrd_end) {
-		uint64_t addr, size;
-		int  total = fdt_num_mem_rsv(fdt);
-		int  j;
+	/* just return if initrd_start/end aren't valid */
+	if ((initrd_start == 0) || (initrd_end == 0))
+		return 0;
 
-		/*
-		 * Look for an existing entry and update it.  If we don't find
-		 * the entry, we will j be the next available slot.
-		 */
-		for (j = 0; j < total; j++) {
-			err = fdt_get_mem_rsv(fdt, j, &addr, &size);
-			if (addr == initrd_start) {
-				fdt_del_mem_rsv(fdt, j);
-				break;
-			}
+	total = fdt_num_mem_rsv(fdt);
+
+	/*
+	 * Look for an existing entry and update it.  If we don't find
+	 * the entry, we will j be the next available slot.
+	 */
+	for (j = 0; j < total; j++) {
+		err = fdt_get_mem_rsv(fdt, j, &addr, &size);
+		if (addr == initrd_start) {
+			fdt_del_mem_rsv(fdt, j);
+			break;
 		}
+	}
 
-		err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1);
+	err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1);
+	if (err < 0) {
+		printf("fdt_initrd: %s\n", fdt_strerror(err));
+		return err;
+	}
+
+	path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
+	if ((path == NULL) || force) {
+		tmp = __cpu_to_be32(initrd_start);
+		err = fdt_setprop(fdt, nodeoffset,
+			"linux,initrd-start", &tmp, sizeof(tmp));
+		if (err < 0) {
+			printf("WARNING: "
+				"could not set linux,initrd-start %s.\n",
+				fdt_strerror(err));
+			return err;
+		}
+		tmp = __cpu_to_be32(initrd_end);
+		err = fdt_setprop(fdt, nodeoffset,
+			"linux,initrd-end", &tmp, sizeof(tmp));
 		if (err < 0) {
-			printf("fdt_chosen: %s\n", fdt_strerror(err));
+			printf("WARNING: could not set linux,initrd-end %s.\n",
+				fdt_strerror(err));
+
 			return err;
 		}
 	}
 
+	return 0;
+}
+
+int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
+{
+	int   nodeoffset;
+	int   err;
+	char  *str;		/* used to set string properties */
+	const char *path;
+
+	err = fdt_check_header(fdt);
+	if (err < 0) {
+		printf("fdt_chosen: %s\n", fdt_strerror(err));
+		return err;
+	}
+
 	/*
 	 * Find the "chosen" node.
 	 */
@@ -173,24 +214,8 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 					fdt_strerror(err));
 		}
 	}
-	if (initrd_start && initrd_end) {
-		path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
-		if ((path == NULL) || force) {
-			tmp = __cpu_to_be32(initrd_start);
-			err = fdt_setprop(fdt, nodeoffset,
-				"linux,initrd-start", &tmp, sizeof(tmp));
-			if (err < 0)
-				printf("WARNING: "
-					"could not set linux,initrd-start %s.\n",
-					fdt_strerror(err));
-			tmp = __cpu_to_be32(initrd_end);
-			err = fdt_setprop(fdt, nodeoffset,
-				"linux,initrd-end", &tmp, sizeof(tmp));
-			if (err < 0)
-				printf("WARNING: could not set linux,initrd-end %s.\n",
-					fdt_strerror(err));
-		}
-	}
+
+	fdt_initrd(fdt, initrd_start, initrd_end, force);
 
 #ifdef CONFIG_OF_STDOUT_VIA_ALIAS
 	path = fdt_getprop(fdt, nodeoffset, "linux,stdout-path", NULL);
include/fdt_support.h +1 -0
index b3f0adb..07cb7f6 100644
@@ -29,6 +29,7 @@
 #include <fdt.h>
 
 int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force);
+int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force);
 void do_fixup_by_path(void *fdt, const char *path, const char *prop,
 		      const void *val, int len, int create);
 void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
lib_ppc/bootm.c +2 -26
index 01d6499..d4c3a33 100644
@@ -183,32 +183,8 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 
 #if defined(CONFIG_OF_LIBFDT)
 	/* fixup the initrd now that we know where it should be */
-	if ((of_flat_tree) && (initrd_start && initrd_end)) {
-		uint64_t addr, size;
-		int  total = fdt_num_mem_rsv(of_flat_tree);
-		int  j;
-
-		/* Look for the dummy entry and delete it */
-		for (j = 0; j < total; j++) {
-			fdt_get_mem_rsv(of_flat_tree, j, &addr, &size);
-			if (addr == images->rd_start) {
-				fdt_del_mem_rsv(of_flat_tree, j);
-				break;
-			}
-		}
-
-		ret = fdt_add_mem_rsv(of_flat_tree, initrd_start,
-					initrd_end - initrd_start + 1);
-		if (ret < 0) {
-			printf("fdt_chosen: %s\n", fdt_strerror(ret));
-			goto error;
-		}
-
-		do_fixup_by_path_u32(of_flat_tree, "/chosen",
-					"linux,initrd-start", initrd_start, 0);
-		do_fixup_by_path_u32(of_flat_tree, "/chosen",
-					"linux,initrd-end", initrd_end, 0);
-	}
+	if ((of_flat_tree) && (initrd_start && initrd_end))
+		fdt_initrd(of_flat_tree, initrd_start, initrd_end, 1);
 #endif
 	debug ("## Transferring control to Linux (at address %08lx) ...\n",
 		(ulong)kernel);
Signature · 1 line
1.5.5.1
#12 lore raw

PATCH 9/11 bootm: refactor image detection and os load steps

In reply to Kumar Gala
Quoted 3 lines · Kumar Gala

Created a bootm_start() that handles the parsing and detection of all the images that will be used by the bootm command (OS, ramdisk, fdt). As part of this we now tract all the relevant image offsets in the bootm_headers_t

Pedantic: s/tract/track/

Best regards,
gvb

#13 lore raw

cover bootm refactoring

In reply to Kumar Gala

Dear Kumar Gala,

Quoted 5 lines · In message <[email protected]> you…

This patch set is a refactoring of the bootm functionality to get it ready for the sub-command functionality. Its a WIP but I wanted to get some early feedback to see if this is the right direction.

We do see some reduction of the arch specific code which is pretty nice.

What is the level of being "WIP"ish? Is this code still just intended for review, or does it compile, or does it actually run on any systems yet?

I mean, what should we do with it - review, create a branch in u-boot-testing for it, anything else ?

author
#14 lore raw

cover bootm refactoring

Quoted 12 lines · Wolfgang Denk

Dear Kumar Gala,

In message <[email protected]

Quoted 8 lines

you wrote:
This patch set is a refactoring of the bootm functionality to get it ready for the sub-command functionality. Its a WIP but I wanted to get
some early feedback to see if this is the right direction.

We do see some reduction of the arch specific code which is pretty nice.

Quoted 6 lines

What is the level of being "WIP"ish? Is this code still just intended for review, or does it compile, or does it actually run on any systems yet?

I mean, what should we do with it - review, create a branch in u-boot-testing for it, anything else ?

It compiles and runs. I was hoping for feedback if the direction is acceptable.

I'm adding a "boots" command that implements sub commands. Once I have a version of that working on PPC & Linux I'll post it and want to make sure the approach is acceptable before converting ALL other ARCHs and other OSes to match.

- k

#15 lore raw

cover bootm refactoring

Dear Kumar Gala,

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

I'm adding a "boots" command that implements sub commands. Once I

I saw it. Actually I don't like it. Why didn't you stick with the original plan to implement subcommands as part of bootm ?

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
There are three things I always forget. Names, faces -  the  third  I
can't remember.                                         - Italo Svevo
author
#16 lore raw

cover bootm refactoring

Quoted 9 lines · Wolfgang Denk

Dear Kumar Gala,

In message <B10531D5-A045-4A60-

Quoted 2 lines · A368-9ADA9590B5C3 at kernel.crashing.org> you wrote:

I'm adding a "boots" command that implements sub commands. Once I

I saw it. Actually I don't like it. Why didn't you stick with the original plan to implement subcommands as part of bootm ?

Can you be more precise about what you dont like. Just the new command, how its implemented, or something else? Also, what plan did we agree on?

I choose a new command because of my concern about how to distinguish the sub-command from a FIT identifier. But it looks like that might not be an issue.

Its easy enough to fold the boots subcommands into bootm. Is there something else that needs to be done?

- k

#17 lore raw

cover bootm refactoring

Quoted 10 lines · Kumar Gala
Quoted 7 lines · Wolfgang Denk

Dear Kumar Gala,

In message <B10531D5-A045-4A60-

Quoted 1 line · A368-9ADA9590B5C3 at kernel.crashing.org> you wrote:

I'm adding a "boots" command that implements sub commands. Once I

I saw it. Actually I don't like it. Why didn't you stick with the original plan to implement subcommands as part of bootm ?

Quoted 7 lines

Can you be more precise about what you dont like. Just the new command, how its implemented, or something else? Also, what plan did we agree on?

I choose a new command because of my concern about how to distinguish the sub-command from a FIT identifier. But it looks like that might not be an issue.

Hi Kumar,

The command "boots" is already taken.

$ grep loads common/*.c
    [snip]
common/cmd_load.c:      "loads   - load S-Record file over serial line\n",

Best regards,
gvb