mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* bootm work
@ 2011-11-28  8:02 Sascha Hauer
  2011-11-28  8:02 ` [PATCH 01/14] bootm: remove dead code Sascha Hauer
                   ` (13 more replies)
  0 siblings, 14 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

This series puts some work into the bootm command. My goal is to
turn bootm into the only boot command which can detect other image
types when necessary. I'm not quite there, but this is some useful
preparation.

Sascha Hauer (14):
      bootm: remove dead code
      factor out iminfo command
      compile in simple_strtoull
      introduce some env helpers
      armlinux: cleanup linux vars
      ARM bootm: remove now obsolete args
      bootm: handle initrds inline
      bootm: remove image handler options
      bootm: fix various memory leaks
      bootm: do not require -L after -r
      bootm: fix typo, update help str
      bootm relocate_image: honour load_address
      bootm: push relocate_image up to the generic command
      bootm: use initrd_address and initrd_size

 arch/arm/lib/armlinux.c            |  102 ++++++++----
 arch/arm/lib/bootm.c               |   36 -----
 arch/blackfin/lib/blackfin_linux.c |    3 -
 arch/nios2/lib/bootm.c             |    3 -
 arch/ppc/lib/ppclinux.c            |    3 -
 commands/Kconfig                   |    6 +
 commands/Makefile                  |    1 +
 commands/bootm.c                   |  305 +++++++-----------------------------
 commands/iminfo.c                  |   71 +++++++++
 common/env.c                       |   22 +++
 common/image.c                     |    3 +-
 include/boot.h                     |    6 +-
 include/common.h                   |    2 -
 include/environment.h              |    3 +
 include/image.h                    |    3 -
 lib/vsprintf.c                     |    2 -
 16 files changed, 237 insertions(+), 334 deletions(-)
 create mode 100644 commands/iminfo.c

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 01/14] bootm: remove dead code
  2011-11-28  8:02 bootm work Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 02/14] factor out iminfo command Sascha Hauer
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   47 -----------------------------------------------
 1 files changed, 0 insertions(+), 47 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 731b74d..2a4fde8 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -44,57 +44,10 @@
 #include <init.h>
 #include <asm-generic/memory_layout.h>
 
-/*
- *  Continue booting an OS image; caller already has:
- *  - copied image header to global variable `header'
- *  - checked header magic number, checksums (both header & image),
- *  - verified image architecture (PPC) and type (KERNEL or MULTI),
- *  - loaded (first part of) image to header load address,
- *  - disabled interrupts.
- */
-typedef void boot_os_Fcn(struct command *cmdtp, int flag,
-			  int	argc, char *argv[],
-			  ulong	addr,		/* of image to boot */
-			  ulong	*len_ptr,	/* multi-file image length table */
-			  int	verify);	/* getenv("verify")[0] != 'n' */
-
 #ifndef CFG_BOOTM_LEN
 #define CFG_BOOTM_LEN	0x800000	/* use 8MByte as default max gunzip size */
 #endif
 
-#ifdef CONFIG_SILENT_CONSOLE
-static void
-fixup_silent_linux ()
-{
-	char buf[256], *start, *end;
-	char *cmdline = getenv ("bootargs");
-
-	/* Only fix cmdline when requested */
-	if (!(gd->flags & GD_FLG_SILENT))
-		return;
-
-	debug ("before silent fix-up: %s\n", cmdline);
-	if (cmdline) {
-		if ((start = strstr (cmdline, "console=")) != NULL) {
-			end = strchr (start, ' ');
-			strncpy (buf, cmdline, (start - cmdline + 8));
-			if (end)
-				strcpy (buf + (start - cmdline + 8), end);
-			else
-				buf[start - cmdline + 8] = '\0';
-		} else {
-			strcpy (buf, cmdline);
-			strcat (buf, " console=");
-		}
-	} else {
-		strcpy (buf, "console=");
-	}
-
-	setenv ("bootargs", buf);
-	debug ("after silent fix-up: %s\n", buf);
-}
-#endif /* CONFIG_SILENT_CONSOLE */
-
 struct image_handle_data* image_handle_data_get_by_num(struct image_handle* handle, int num)
 {
 	if (!handle || num < 0 || num >= handle->nb_data_entries)
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 02/14] factor out iminfo command
  2011-11-28  8:02 bootm work Sascha Hauer
  2011-11-28  8:02 ` [PATCH 01/14] bootm: remove dead code Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 03/14] compile in simple_strtoull Sascha Hauer
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

The rests of U-Boots iminfo command are sitting in commands/bootm.c and
are in a nonusable state. Factor it out to its own file and make it work
again.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/Kconfig  |    6 ++++
 commands/Makefile |    1 +
 commands/bootm.c  |   79 -----------------------------------------------------
 commands/iminfo.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c    |    2 +-
 include/image.h   |    3 --
 6 files changed, 79 insertions(+), 83 deletions(-)
 create mode 100644 commands/iminfo.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 18ab840..6c526f2 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -309,6 +309,12 @@ config CMD_BOOTM_SHOW_TYPE
 	depends on CMD_BOOTM
 	prompt "show image information"
 
+config CMD_IMINFO
+	bool
+	prompt "iminfo"
+	help
+	  Show information about uImages
+
 config CMD_BOOTZ
 	tristate
 	default y
diff --git a/commands/Makefile b/commands/Makefile
index 5c51916..02d1451 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_CMD_BOOTM)		+= bootm.o
+obj-$(CONFIG_CMD_IMINFO)	+= iminfo.o
 obj-$(CONFIG_CMD_LINUX16)	+= linux16.o
 obj-$(CONFIG_CMD_LOADB)		+= loadb.o xyzModem.o
 obj-$(CONFIG_CMD_LOADY)		+= loadb.o xyzModem.o
diff --git a/commands/bootm.c b/commands/bootm.c
index 2a4fde8..823d387 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -318,85 +318,6 @@ BAREBOX_CMD_START(bootm)
 	BAREBOX_CMD_HELP(cmd_bootm_help)
 BAREBOX_CMD_END
 
-/**
- * @page bootm_command
-
-\todo What does bootm do, what kind of image does it boot?
-
- */
-
-#ifdef CONFIG_CMD_IMI
-static int do_iminfo(struct command *cmdtp, int argc, char *argv[])
-{
-	int	arg;
-	ulong	addr;
-	int     rcode=0;
-
-	if (argc < 2) {
-		return image_info (load_addr);
-	}
-
-	for (arg=1; arg <argc; ++arg) {
-		addr = simple_strtoul(argv[arg], NULL, 16);
-		if (image_info (addr) != 0) rcode = 1;
-	}
-	return rcode;
-}
-
-static int image_info (ulong addr)
-{
-	ulong	data, len, checksum;
-	image_header_t *hdr = &header;
-
-	printf ("\n## Checking Image at %08lx ...\n", addr);
-
-	/* Copy header so we can blank CRC field for re-calculation */
-	memmove (&header, (char *)addr, image_get_header_size());
-
-	if (image_get_magic(hdr) != IH_MAGIC) {
-		puts ("   Bad Magic Number\n");
-		return 1;
-	}
-
-	data = (ulong)&header;
-	len  = image_get_header_size();
-
-	checksum = image_get_hcrc(hdr);
-	hdr->ih_hcrc = 0;
-
-	if (crc32 (0, (uchar *)data, len) != checksum) {
-		puts ("   Bad Header Checksum\n");
-		return 1;
-	}
-
-	/* for multi-file images we need the data part, too */
-	print_image_hdr ((image_header_t *)addr);
-
-	data = addr + image_get_header_size();
-	len  = image_get_size(hdr);
-
-	puts ("   Verifying Checksum ... ");
-	if (crc32 (0, (uchar *)data, len) != image_get_dcrc(hdr)) {
-		puts ("   Bad Data CRC\n");
-		return 1;
-	}
-	puts ("OK\n");
-	return 0;
-}
-
-BAREBOX_CMD_HELP_START(iminfo)
-BAREBOX_CMD_HELP_USAGE("iminfo\n")
-BAREBOX_CMD_HELP_SHORT("Print header information for an application image.\n")
-BAREBOX_CMD_HELP_END
-
-BAREBOX_CMD_START(iminfo)
-	.cmd		= do_iminfo,
-	.usage		= "print header information for an application image",
-	BAREBOX_CMD_HELP(cmd_iminfo_help)
-BAREBOX_CMD_END
-
-#endif	/* CONFIG_CMD_IMI */
-
 #ifdef CONFIG_BZLIB
 void bz_internal_error(int errcode)
 {
diff --git a/commands/iminfo.c b/commands/iminfo.c
new file mode 100644
index 0000000..2fde9bc
--- /dev/null
+++ b/commands/iminfo.c
@@ -0,0 +1,71 @@
+#include <common.h>
+#include <command.h>
+#include <image.h>
+#include <fs.h>
+#include <malloc.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static int image_info(image_header_t *hdr)
+{
+	u32 len, checksum;
+
+	if (image_get_magic(hdr) != IH_MAGIC) {
+		puts ("   Bad Magic Number\n");
+		return 1;
+	}
+
+	len = image_get_header_size();
+
+	checksum = image_get_hcrc(hdr);
+	hdr->ih_hcrc = 0;
+
+	if (crc32 (0, hdr, len) != checksum) {
+		puts ("   Bad Header Checksum\n");
+		return 1;
+	}
+
+	image_print_contents(hdr, NULL);
+
+	return 0;
+}
+
+static int do_iminfo(struct command *cmdtp, int argc, char *argv[])
+{
+	int rcode = 1;
+	int fd;
+	int ret;
+	image_header_t hdr;
+
+	if (argc != 2)
+		return COMMAND_ERROR_USAGE;
+
+	fd = open(argv[1], O_RDONLY);
+	if (fd < 0) {
+		perror("open");
+		return 1;
+	}
+
+	ret = read(fd, &hdr, sizeof(image_header_t));
+	if (ret != sizeof(image_header_t))
+		goto err_out;
+
+	printf("Image at %s:\n", argv[1]);
+	image_info(&hdr);
+
+err_out:
+	close(fd);
+
+	return rcode;
+}
+
+BAREBOX_CMD_HELP_START(iminfo)
+BAREBOX_CMD_HELP_USAGE("iminfo\n")
+BAREBOX_CMD_HELP_SHORT("Print header information for an application image.\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(iminfo)
+	.cmd		= do_iminfo,
+	.usage		= "print header information for an application image",
+	BAREBOX_CMD_HELP(cmd_iminfo_help)
+BAREBOX_CMD_END
diff --git a/common/image.c b/common/image.c
index 4a6402d..939fe4b 100644
--- a/common/image.c
+++ b/common/image.c
@@ -290,7 +290,7 @@ void image_print_contents(const image_header_t *hdr, void *data)
 	printf ("%sEntry Point:  %08x\n", p, image_get_ep(hdr));
 
 	type = image_get_type(hdr);
-	if (type == IH_TYPE_MULTI || type == IH_TYPE_SCRIPT) {
+	if (data && (type == IH_TYPE_MULTI || type == IH_TYPE_SCRIPT)) {
 		int i;
 		ulong img_data, len;
 		ulong count = image_multi_count(data);
diff --git a/include/image.h b/include/image.h
index 691bf2d..f3a9949 100644
--- a/include/image.h
+++ b/include/image.h
@@ -335,9 +335,6 @@ void image_print_size(uint32_t size);
 
 void image_print_contents(const image_header_t *hdr, void *data);
 
-/* commamds/bootm.c */
-void	print_image_hdr (image_header_t *hdr);
-
 /*
  * Load an image into memory. Returns a pointer to the loaded
  * image.
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 03/14] compile in simple_strtoull
  2011-11-28  8:02 bootm work Sascha Hauer
  2011-11-28  8:02 ` [PATCH 01/14] bootm: remove dead code Sascha Hauer
  2011-11-28  8:02 ` [PATCH 02/14] factor out iminfo command Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 04/14] introduce some env helpers Sascha Hauer
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/common.h |    2 --
 lib/vsprintf.c   |    2 --
 2 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/include/common.h b/include/common.h
index d63ad02..68ccbd9 100644
--- a/include/common.h
+++ b/include/common.h
@@ -115,9 +115,7 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
 
 /* lib_generic/vsprintf.c */
 ulong	simple_strtoul(const char *cp,char **endp,unsigned int base);
-#ifdef CFG_64BIT_VSPRINTF
 unsigned long long	simple_strtoull(const char *cp,char **endp,unsigned int base);
-#endif
 long	simple_strtol(const char *cp,char **endp,unsigned int base);
 
 /* lib_generic/crc32.c */
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 54e162f..4165f97 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -56,7 +56,6 @@ long simple_strtol(const char *cp,char **endp,unsigned int base)
 }
 EXPORT_SYMBOL(simple_strtol);
 
-#ifdef CFG_64BIT_STRTOUL
 unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int base)
 {
 	unsigned long long result = 0, value;
@@ -84,7 +83,6 @@ unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int ba
 		*endp = (char *) cp;
 	return result;
 }
-#endif /* CFG_64BIT_STRTOUL */
 
 /* we use this so that we can do without the ctype library */
 #define is_digit(c)	((c) >= '0' && (c) <= '9')
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 04/14] introduce some env helpers
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (2 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 03/14] compile in simple_strtoull Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 05/14] armlinux: cleanup linux vars Sascha Hauer
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/env.c          |   22 ++++++++++++++++++++++
 include/environment.h |    3 +++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/common/env.c b/common/env.c
index 05ed714..e57a520 100644
--- a/common/env.c
+++ b/common/env.c
@@ -251,3 +251,25 @@ int export(const char *varname)
 	return 0;
 }
 EXPORT_SYMBOL(export);
+
+void export_env_ull(const char *name, unsigned long long val)
+{
+	char *valstr = asprintf("%lld", val);
+
+	setenv(name, valstr);
+	export(name);
+
+	kfree(valstr);
+}
+EXPORT_SYMBOL(export_env_ull);
+
+unsigned long long getenv_ull(const char *name)
+{
+	const char *valstr = getenv(name);
+
+	if (!valstr)
+		return 0;
+
+	return simple_strtoull(valstr, NULL, 0);
+}
+EXPORT_SYMBOL(getenv_ull);
diff --git a/include/environment.h b/include/environment.h
index da032e2..6d38755 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -59,6 +59,9 @@ static inline int setenv(const char *var, const char *val)
 }
 #endif
 
+void export_env_ull(const char *name, unsigned long long val);
+unsigned long long getenv_ull(const char *name);
+
 int env_pop_context(void);
 int env_push_context(void);
 
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 05/14] armlinux: cleanup linux vars
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (3 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 04/14] introduce some env helpers Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28 11:03   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-11-28  8:02 ` [PATCH 06/14] ARM bootm: remove now obsolete args Sascha Hauer
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

arch_number is currently exported to the environment but not read back
on boot time which is rather confusing. system_rev and system_serial
are not exported to the environment but can be set in board specific
code.
This patch exports all these variables to the environment and reads them
back on boot time. All variables get a armlinux_ prefix, so the
arch_number environment variable gets renamed.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/armlinux.c |   92 +++++++++++++++++++++++++++++++++--------------
 1 files changed, 65 insertions(+), 27 deletions(-)

diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
index d8ca477..ebe4137 100644
--- a/arch/arm/lib/armlinux.c
+++ b/arch/arm/lib/armlinux.c
@@ -45,11 +45,67 @@
 #include <asm/system.h>
 
 static struct tag *params;
-static int armlinux_architecture = 0;
 static void *armlinux_bootparams = NULL;
 
-static unsigned int system_rev;
-static u64 system_serial;
+#ifndef CONFIG_ENVIRONMENT_VARIABLES
+static int armlinux_architecture;
+static u32 armlinux_system_rev;
+static u64 armlinux_system_serial;
+#endif
+
+void armlinux_set_architecture(int architecture)
+{
+#ifdef CONFIG_ENVIRONMENT_VARIABLES
+	export_env_ull("armlinux_architecture", architecture);
+#else
+	armlinux_architecture = architecture;
+#endif
+}
+
+int armlinux_get_architecture(void)
+{
+#ifdef CONFIG_ENVIRONMENT_VARIABLES
+	return getenv_ull("armlinux_architecture");
+#else
+	return armlinux_architecture;
+#endif
+}
+
+void armlinux_set_revision(unsigned int rev)
+{
+#ifdef CONFIG_ENVIRONMENT_VARIABLES
+	export_env_ull("armlinux_system_rev", rev);
+#else
+	return armlinux_system_rev;
+#endif
+}
+
+unsigned int armlinux_get_revision(void)
+{
+#ifdef CONFIG_ENVIRONMENT_VARIABLES
+	return getenv_ull("armlinux_system_rev");
+#else
+	return armlinux_system_rev;
+#endif
+}
+
+void armlinux_set_serial(u64 serial)
+{
+#ifdef CONFIG_ENVIRONMENT_VARIABLES
+	export_env_ull("armlinux_system_serial", serial);
+#else
+	armlinux_system_serial = serial;
+#endif
+}
+
+u64 armlinux_get_serial(void)
+{
+#ifdef CONFIG_ENVIRONMENT_VARIABLES
+	return getenv_ull("armlinux_system_serial");
+#else
+	return armlinux_system_serial;
+#endif
+}
 
 static void setup_start_tag(void)
 {
@@ -117,6 +173,8 @@ static void setup_commandline_tag(const char *commandline, int swap)
 
 static void setup_revision_tag(void)
 {
+	u32 system_rev = armlinux_get_revision();
+
 	if (system_rev) {
 		params->hdr.tag = ATAG_REVISION;
 		params->hdr.size = tag_size(tag_revision);
@@ -129,6 +187,8 @@ static void setup_revision_tag(void)
 
 static void setup_serial_tag(void)
 {
+	u64 system_serial = armlinux_get_serial();
+
 	if (system_serial) {
 		params->hdr.tag = ATAG_SERIAL;
 		params->hdr.size = tag_size(tag_serialnr);
@@ -176,7 +236,7 @@ static void setup_tags(struct image_data *data, int swap)
 	setup_end_tag();
 
 	printf("commandline: %s\n"
-	       "arch_number: %d\n", commandline, armlinux_architecture);
+	       "arch_number: %d\n", commandline, armlinux_get_architecture());
 
 }
 
@@ -185,28 +245,6 @@ void armlinux_set_bootparams(void *params)
 	armlinux_bootparams = params;
 }
 
-void armlinux_set_architecture(int architecture)
-{
-	char *arch_number = asprintf("%d", architecture);
-
-	armlinux_architecture = architecture;
-
-	setenv("arch_number", arch_number);
-	export("arch_number");
-
-	kfree(arch_number);
-}
-
-void armlinux_set_revision(unsigned int rev)
-{
-	system_rev = rev;
-}
-
-void armlinux_set_serial(u64 serial)
-{
-	system_serial = serial;
-}
-
 void start_linux(void *adr, int swap, struct image_data *data)
 {
 	void (*kernel)(int zero, int arch, void *params) = adr;
@@ -229,5 +267,5 @@ void start_linux(void *adr, int swap, struct image_data *data)
 		__asm__ __volatile__("mcr p15, 0, %0, c1, c0" :: "r" (reg));
 	}
 
-	kernel(0, armlinux_architecture, params);
+	kernel(0, armlinux_get_architecture(), params);
 }
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 06/14] ARM bootm: remove now obsolete args
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (4 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 05/14] armlinux: cleanup linux vars Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 07/14] bootm: handle initrds inline Sascha Hauer
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Now that the arch_number and system_rev variables can be set from
the environment we don't need the old bootm command line switch
mechanism anymore.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/bootm.c |   29 -----------------------------
 1 files changed, 0 insertions(+), 29 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 87bf3b3..a104aaa 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -44,36 +44,7 @@ static int do_bootm_linux(struct image_data *data)
 	return -1;
 }
 
-static int image_handle_cmdline_parse(struct image_data *data, int opt,
-		char *optarg)
-{
-	int ret = 1;
-	int no;
-
-	switch (opt) {
-	case 'a':
-		no = simple_strtoul(optarg, NULL, 0);
-		armlinux_set_architecture(no);
-		ret = 0;
-		break;
-	case 'R':
-		no = simple_strtoul(optarg, NULL, 0);
-		armlinux_set_revision(no);
-		ret = 0;
-		break;
-	default:
-		break;
-	}
-
-	return ret;
-}
-
 static struct image_handler handler = {
-	.cmdline_options = "a:R:",
-	.cmdline_parse = image_handle_cmdline_parse,
-	.help_string = " -a <arch>        use architecture number <arch>\n"
-		       " -R <system_rev>  use system revison <system_rev>\n",
-
 	.bootm = do_bootm_linux,
 	.image_type = IH_OS_LINUX,
 };
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 07/14] bootm: handle initrds inline
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (5 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 06/14] ARM bootm: remove now obsolete args Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-12-06 15:08   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-11-28  8:02 ` [PATCH 08/14] bootm: remove image handler options Sascha Hauer
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   78 +++++++++++++++++++----------------------------------
 1 files changed, 28 insertions(+), 50 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 823d387..17139f7 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -141,55 +141,6 @@ static struct image_handle *get_fake_image_handle(struct image_data *data, int n
 	return handle;
 }
 
-static int initrd_handler_parse_options(struct image_data *data, int opt,
-		char *optarg)
-{
-	uint32_t initrd_start;
-
-	switch(opt) {
-	case 'L':
-		if (!data->initrd) {
-			eprintf("Warning -L ingnored. Specify the initrd first\n");
-			break;
-		}
-		initrd_start = simple_strtoul(optarg, NULL, 0);
-		printf("initrd_start=0x%x\n", initrd_start);
-		data->initrd->header.ih_load = cpu_to_uimage(initrd_start);
-		break;
-	case 'r':
-		printf("use initrd %s\n", optarg);
-		/* check for multi image @<num> */
-		if (optarg[0] == '@') {
-			int num = simple_strtol(optarg + 1, NULL, 0);
-
-			data->initrd = get_fake_image_handle(data, num);
-		} else {
-			data->initrd = map_image(optarg, data->verify);
-		}
-		if (!data->initrd)
-			return -1;
-		break;
-	default:
-		return 1;
-	}
-
-	return 0;
-}
-
-static struct image_handler initrd_handler = {
-	.cmdline_options = "r:L:",
-	.cmdline_parse = initrd_handler_parse_options,
-	.help_string = " -r <initrd>    specify an initrd image\n"
-		       " -L <load addr> specify initrd load address",
-};
-
-static int initrd_register_image_handler(void)
-{
-	return register_image_handler(&initrd_handler);
-}
-
-late_initcall(initrd_register_image_handler);
-
 static int handler_parse_options(struct image_data *data, int opt, char *optarg)
 {
 	struct image_handler *handler;
@@ -216,13 +167,14 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 	struct image_handle *os_handle, *initrd_handle = NULL;
 	struct image_handler *handler;
 	struct image_data data;
+	u32 initrd_start;
 	char options[53]; /* worst case: whole alphabet with colons */
 
 	memset(&data, 0, sizeof(struct image_data));
 	data.verify = 1;
 
 	/* Collect options from registered handlers */
-	strcpy(options, "nh");
+	strcpy(options, "nhr:L:");
 	list_for_each_entry(handler, &handler_list, list) {
 		if (handler->cmdline_options)
 			strcat(options, handler->cmdline_options);
@@ -242,6 +194,28 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 			}
 
 			return 0;
+		case 'L':
+			if (!data.initrd) {
+				eprintf("Warning -L ingnored. Specify the initrd first\n");
+				break;
+			}
+			initrd_start = simple_strtoul(optarg, NULL, 0);
+			printf("initrd_start=0x%x\n", initrd_start);
+			data.initrd->header.ih_load = cpu_to_uimage(initrd_start);
+			break;
+		case 'r':
+			printf("use initrd %s\n", optarg);
+			/* check for multi image @<num> */
+			if (optarg[0] == '@') {
+				int num = simple_strtol(optarg + 1, NULL, 0);
+
+				data.initrd = get_fake_image_handle(&data, num);
+			} else {
+				data.initrd = map_image(optarg, data.verify);
+			}
+			if (!data.initrd)
+				return -1;
+			break;
 		default:
 			break;
 		}
@@ -269,6 +243,8 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 		switch(opt) {
 		case 'h':
 		case 'n':
+		case 'L':
+		case 'r':
 			break;
 		default:
 			if (!handler_parse_options(&data, opt, optarg))
@@ -310,6 +286,8 @@ BAREBOX_CMD_HELP_START(bootm)
 BAREBOX_CMD_HELP_USAGE("bootm [-n] image\n")
 BAREBOX_CMD_HELP_SHORT("Boot an application image.\n")
 BAREBOX_CMD_HELP_OPT  ("-n",  "Do not verify the image (speeds up boot process)\n")
+BAREBOX_CMD_HELP_OPT  ("-r <initrd>","specify an initrd image\n")
+BAREBOX_CMD_HELP_OPT  ("-L <load addr>","specify initrd load address")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(bootm)
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 08/14] bootm: remove image handler options
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (6 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 07/14] bootm: handle initrds inline Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 09/14] bootm: fix various memory leaks Sascha Hauer
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   55 +-----------------------------------------------------
 include/boot.h   |    4 ---
 2 files changed, 1 insertions(+), 58 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 17139f7..316ed1f 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -141,25 +141,6 @@ static struct image_handle *get_fake_image_handle(struct image_data *data, int n
 	return handle;
 }
 
-static int handler_parse_options(struct image_data *data, int opt, char *optarg)
-{
-	struct image_handler *handler;
-	int ret;
-
-	list_for_each_entry(handler, &handler_list, list) {
-		if (!handler->cmdline_parse)
-			continue;
-
-		ret = handler->cmdline_parse(data, opt, optarg);
-		if (ret > 0)
-			continue;
-
-		return ret;
-	}
-
-	return -1;
-}
-
 static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 {
 	int	opt;
@@ -168,32 +149,15 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 	struct image_handler *handler;
 	struct image_data data;
 	u32 initrd_start;
-	char options[53]; /* worst case: whole alphabet with colons */
 
 	memset(&data, 0, sizeof(struct image_data));
 	data.verify = 1;
 
-	/* Collect options from registered handlers */
-	strcpy(options, "nhr:L:");
-	list_for_each_entry(handler, &handler_list, list) {
-		if (handler->cmdline_options)
-			strcat(options, handler->cmdline_options);
-	}
-
-	while((opt = getopt(argc, argv, options)) > 0) {
+	while ((opt = getopt(argc, argv, "nr:L:")) > 0) {
 		switch(opt) {
 		case 'n':
 			data.verify = 0;
 			break;
-		case 'h':
-			printf("bootm advanced options:\n");
-
-			list_for_each_entry(handler, &handler_list, list) {
-				if (handler->help_string)
-					printf("%s\n", handler->help_string);
-			}
-
-			return 0;
 		case 'L':
 			if (!data.initrd) {
 				eprintf("Warning -L ingnored. Specify the initrd first\n");
@@ -237,23 +201,6 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 		goto err_out;
 	}
 
-	optind = 0;
-
-	while((opt = getopt(argc, argv, options)) > 0) {
-		switch(opt) {
-		case 'h':
-		case 'n':
-		case 'L':
-		case 'r':
-			break;
-		default:
-			if (!handler_parse_options(&data, opt, optarg))
-				continue;
-
-			return 1;
-		}
-	}
-
 	/*
 	 * We have reached the point of no return: we are going to
 	 * overwrite all exception vector code, so we cannot easily
diff --git a/include/boot.h b/include/boot.h
index 623f443..4901598 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -14,10 +14,6 @@ struct image_data {
 struct image_handler {
 	struct list_head list;
 
-	char *cmdline_options;
-	int (*cmdline_parse)(struct image_data *data, int opt, char *optarg);
-	char *help_string;
-
 	int image_type;
 	int (*bootm)(struct image_data *data);
 };
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 09/14] bootm: fix various memory leaks
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (7 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 08/14] bootm: remove image handler options Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 10/14] bootm: do not require -L after -r Sascha Hauer
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   19 +++++++++++--------
 common/image.c   |    1 +
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 316ed1f..c62df4f 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -145,10 +145,11 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 {
 	int	opt;
 	image_header_t *os_header;
-	struct image_handle *os_handle, *initrd_handle = NULL;
+	struct image_handle *os_handle = NULL;
 	struct image_handler *handler;
 	struct image_data data;
 	u32 initrd_start;
+	int ret = 1;
 
 	memset(&data, 0, sizeof(struct image_data));
 	data.verify = 1;
@@ -178,19 +179,21 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 				data.initrd = map_image(optarg, data.verify);
 			}
 			if (!data.initrd)
-				return -1;
+				goto err_out;
 			break;
 		default:
 			break;
 		}
 	}
 
-	if (optind == argc)
-		return COMMAND_ERROR_USAGE;
+	if (optind == argc) {
+		ret = COMMAND_ERROR_USAGE;
+		goto err_out;
+	}
 
 	os_handle = map_image(argv[optind], data.verify);
 	if (!os_handle)
-		return 1;
+		goto err_out;
 	data.os = os_handle;
 
 	os_header = &os_handle->header;
@@ -224,9 +227,9 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 err_out:
 	if (os_handle)
 		unmap_image(os_handle);
-	if (initrd_handle)
-		unmap_image(initrd_handle);
-	return 1;
+	if (data.initrd)
+		unmap_image(data.initrd);
+	return ret;
 }
 
 BAREBOX_CMD_HELP_START(bootm)
diff --git a/common/image.c b/common/image.c
index 939fe4b..d68889b 100644
--- a/common/image.c
+++ b/common/image.c
@@ -404,6 +404,7 @@ err_out:
 	close(fd);
 	if (handle->flags & IH_MALLOC)
 		free(handle->data);
+	free(handle->data_entries);
 	free(handle);
 	return NULL;
 }
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 10/14] bootm: do not require -L after -r
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (8 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 09/14] bootm: fix various memory leaks Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 11/14] bootm: fix typo, update help str Sascha Hauer
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   13 +++++--------
 include/boot.h   |    1 +
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index c62df4f..86470c2 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -148,11 +148,11 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 	struct image_handle *os_handle = NULL;
 	struct image_handler *handler;
 	struct image_data data;
-	u32 initrd_start;
 	int ret = 1;
 
 	memset(&data, 0, sizeof(struct image_data));
 	data.verify = 1;
+	data.initrd_address = ~0;
 
 	while ((opt = getopt(argc, argv, "nr:L:")) > 0) {
 		switch(opt) {
@@ -160,13 +160,7 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 			data.verify = 0;
 			break;
 		case 'L':
-			if (!data.initrd) {
-				eprintf("Warning -L ingnored. Specify the initrd first\n");
-				break;
-			}
-			initrd_start = simple_strtoul(optarg, NULL, 0);
-			printf("initrd_start=0x%x\n", initrd_start);
-			data.initrd->header.ih_load = cpu_to_uimage(initrd_start);
+			data.initrd_address = simple_strtoul(optarg, NULL, 0);
 			break;
 		case 'r':
 			printf("use initrd %s\n", optarg);
@@ -186,6 +180,9 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 		}
 	}
 
+	if (data.initrd && data.initrd_address != ~0)
+		data.initrd->header.ih_load = cpu_to_uimage(data.initrd_address);
+
 	if (optind == argc) {
 		ret = COMMAND_ERROR_USAGE;
 		goto err_out;
diff --git a/include/boot.h b/include/boot.h
index 4901598..b22514b 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -9,6 +9,7 @@ struct image_data {
 	struct image_handle *initrd;
 	const char *oftree;
 	int verify;
+	unsigned long initrd_address;
 };
 
 struct image_handler {
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 11/14] bootm: fix typo, update help str
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (9 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 10/14] bootm: do not require -L after -r Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28 11:00   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-11-28  8:02 ` [PATCH 12/14] bootm relocate_image: honour load_address Sascha Hauer
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 86470c2..0458919 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -44,9 +44,7 @@
 #include <init.h>
 #include <asm-generic/memory_layout.h>
 
-#ifndef CFG_BOOTM_LEN
 #define CFG_BOOTM_LEN	0x800000	/* use 8MByte as default max gunzip size */
-#endif
 
 struct image_handle_data* image_handle_data_get_by_num(struct image_handle* handle, int num)
 {
@@ -121,7 +119,7 @@ int register_image_handler(struct image_handler *handler)
 
 /*
  * generate a image_handle from a multi_image
- * this image_handle can be free by unmap_image
+ * this image_handle can be freed by unmap_image
  */
 static struct image_handle *get_fake_image_handle(struct image_data *data, int num)
 {
@@ -230,7 +228,7 @@ err_out:
 }
 
 BAREBOX_CMD_HELP_START(bootm)
-BAREBOX_CMD_HELP_USAGE("bootm [-n] image\n")
+BAREBOX_CMD_HELP_USAGE("bootm [OPTIONS] image\n")
 BAREBOX_CMD_HELP_SHORT("Boot an application image.\n")
 BAREBOX_CMD_HELP_OPT  ("-n",  "Do not verify the image (speeds up boot process)\n")
 BAREBOX_CMD_HELP_OPT  ("-r <initrd>","specify an initrd image\n")
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 12/14] bootm relocate_image: honour load_address
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (10 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 11/14] bootm: fix typo, update help str Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 13/14] bootm: push relocate_image up to the generic command Sascha Hauer
  2011-11-28  8:02 ` [PATCH 14/14] bootm: use initrd_address and initrd_size Sascha Hauer
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

the uImage should be relocated to load_address. This is handled correctly
in gzip/bzip2 compressed images, but not in uncompressed images. fix this.
Also, when a variable is not used once without casting to another type it
probably means that its type is wrong.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 0458919..c400ab5 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -44,7 +44,7 @@
 #include <init.h>
 #include <asm-generic/memory_layout.h>
 
-#define CFG_BOOTM_LEN	0x800000	/* use 8MByte as default max gunzip size */
+#define BOOTM_LEN	0x800000	/* use 8MByte as default max gunzip size */
 
 struct image_handle_data* image_handle_data_get_by_num(struct image_handle* handle, int num)
 {
@@ -59,28 +59,28 @@ int relocate_image(struct image_handle *handle, void *load_address)
 	image_header_t *hdr = &handle->header;
 	unsigned long len  = image_get_size(hdr);
 	struct image_handle_data *iha;
-	unsigned long data;
+	void *data;
 
 #if defined CONFIG_CMD_BOOTM_ZLIB || defined CONFIG_CMD_BOOTM_BZLIB
-	uint	unc_len = CFG_BOOTM_LEN;
+	uint	unc_len = BOOTM_LEN;
 #endif
 
 	iha = image_handle_data_get_by_num(handle, 0);
-	data = (unsigned long)(iha->data);
+	data = iha->data;
 
 	switch (image_get_comp(hdr)) {
 	case IH_COMP_NONE:
-		if(image_get_load(hdr) == data) {
+		if (load_address == data) {
 			printf ("   XIP ... ");
 		} else {
-			memmove ((void *) image_get_load(hdr), (uchar *)data, len);
+			memmove(load_address, data, len);
 		}
 		break;
 #ifdef CONFIG_CMD_BOOTM_ZLIB
 	case IH_COMP_GZIP:
 		printf ("   Uncompressing ... ");
 		if (gunzip (load_address, unc_len,
-			    (uchar *)data, &len) != 0)
+			    data, &len) != 0)
 			return -1;
 		break;
 #endif
@@ -93,7 +93,7 @@ int relocate_image(struct image_handle *handle, void *load_address)
 		 * at most 2300 KB of memory.
 		 */
 		if (BZ2_bzBuffToBuffDecompress (load_address,
-						&unc_len, (char *)data, len,
+						&unc_len, data, len,
 						MALLOC_SIZE < (4096 * 1024), 0)
 						!= BZ_OK)
 			return -1;
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 13/14] bootm: push relocate_image up to the generic command
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (11 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 12/14] bootm relocate_image: honour load_address Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  2011-11-28  8:02 ` [PATCH 14/14] bootm: use initrd_address and initrd_size Sascha Hauer
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

All handlers used to just relocate the image without any checks, so
we are doomed if we write outside of SDRAM or will overwrite ourselves.
Move the relocation up to the generic part where we have a chance
of catching these issues.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/bootm.c               |    7 -------
 arch/blackfin/lib/blackfin_linux.c |    3 ---
 arch/nios2/lib/bootm.c             |    3 ---
 arch/ppc/lib/ppclinux.c            |    3 ---
 commands/bootm.c                   |   17 +++++++++++++++++
 5 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index a104aaa..5b85ba9 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -29,13 +29,6 @@ static int do_bootm_linux(struct image_data *data)
 	debug("## Transferring control to Linux (at address 0x%p) ...\n",
 	       theKernel);
 
-	if (relocate_image(data->os, (void *)image_get_load(os_header)))
-		return -1;
-
-	if (data->initrd)
-		if (relocate_image(data->initrd, (void *)image_get_load(&data->initrd->header)))
-			return -1;
-
 	/* we assume that the kernel is in place */
 	printf("\nStarting kernel %s...\n\n", data->initrd ? "with initrd " : "");
 
diff --git a/arch/blackfin/lib/blackfin_linux.c b/arch/blackfin/lib/blackfin_linux.c
index a20cf55..9da9ec4 100644
--- a/arch/blackfin/lib/blackfin_linux.c
+++ b/arch/blackfin/lib/blackfin_linux.c
@@ -50,9 +50,6 @@ static int do_bootm_linux(struct image_data *idata)
 	appl = (int (*)(char *))image_get_ep(os_header);
 	printf("Starting Kernel at 0x%p\n", appl);
 
-	if (relocate_image(os_handle, (void *)image_get_load(os_header)))
-		return -1;
-
 	icache_disable();
 
 	strncpy(cmdlinedest, cmdline, 0x1000);
diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c
index c38243f..b5b344f 100644
--- a/arch/nios2/lib/bootm.c
+++ b/arch/nios2/lib/bootm.c
@@ -43,9 +43,6 @@ static int do_bootm_linux(struct image_data *idata)
 
 	kernel = (void (*)(int, int, int, const char *))ntohl(os_header->ih_ep);
 
-	if (relocate_image(idata->os, (void *)ntohl(os_header->ih_load)))
-		return -1;
-
 	/* kernel parameters passing
 	 * r4 : NIOS magic
 	 * r5 : initrd start
diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c
index 531c215..471b303 100644
--- a/arch/ppc/lib/ppclinux.c
+++ b/arch/ppc/lib/ppclinux.c
@@ -200,9 +200,6 @@ static int do_bootm_linux(struct image_data *idata)
 
 	kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep(os_header); /* FIXME */
 
-	if (relocate_image(idata->os, (void *)image_get_load(os_header)))
-		return -1;
-
 #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
 	unlock_ram_in_cache();
 #endif
diff --git a/commands/bootm.c b/commands/bootm.c
index c400ab5..027dd37 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -207,6 +207,23 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 
 	puts ("OK\n");
 
+	/*
+	 * FIXME: we do not check at all whether
+	 * - we will write the image to sdram
+	 * - we overwrite ourselves
+	 * - kernel and initrd overlap
+	 */
+	ret = relocate_image(data.os, (void *)image_get_load(os_header));
+	if (ret)
+		goto err_out;
+
+	if (data.initrd) {
+		ret = relocate_image(data.initrd,
+				(void *)image_get_load(&data.initrd->header));
+		if (ret)
+			goto err_out;
+	}
+
 	/* loop through the registered handlers */
 	list_for_each_entry(handler, &handler_list, list) {
 		if (image_get_os(os_header) == handler->image_type) {
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 14/14] bootm: use initrd_address and initrd_size
  2011-11-28  8:02 bootm work Sascha Hauer
                   ` (12 preceding siblings ...)
  2011-11-28  8:02 ` [PATCH 13/14] bootm: push relocate_image up to the generic command Sascha Hauer
@ 2011-11-28  8:02 ` Sascha Hauer
  13 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28  8:02 UTC (permalink / raw)
  To: barebox

Make these fields in struct image_data the reference for image handlers

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/armlinux.c |   10 +++++-----
 commands/bootm.c        |   11 ++++++-----
 include/boot.h          |    1 +
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
index ebe4137..6c001e7 100644
--- a/arch/arm/lib/armlinux.c
+++ b/arch/arm/lib/armlinux.c
@@ -200,7 +200,7 @@ static void setup_serial_tag(void)
 	}
 }
 
-static void setup_initrd_tag(image_header_t *header)
+static void setup_initrd_tag(unsigned long start, unsigned long size)
 {
 	/* an ATAG_INITRD node tells the kernel where the compressed
 	 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
@@ -208,8 +208,8 @@ static void setup_initrd_tag(image_header_t *header)
 	params->hdr.tag = ATAG_INITRD2;
 	params->hdr.size = tag_size(tag_initrd);
 
-	params->u.initrd.start = image_get_load(header);
-	params->u.initrd.size = image_get_data_size(header);
+	params->u.initrd.start = start;
+	params->u.initrd.size = size;
 
 	params = tag_next(params);
 }
@@ -228,8 +228,8 @@ static void setup_tags(struct image_data *data, int swap)
 	setup_memory_tags();
 	setup_commandline_tag(commandline, swap);
 
-	if (data && data->initrd)
-		setup_initrd_tag (&data->initrd->header);
+	if (data && (data->initrd_size > 0))
+		setup_initrd_tag(data->initrd_address, data->initrd_size);
 
 	setup_revision_tag();
 	setup_serial_tag();
diff --git a/commands/bootm.c b/commands/bootm.c
index 027dd37..b9f85a8 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -178,9 +178,6 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 		}
 	}
 
-	if (data.initrd && data.initrd_address != ~0)
-		data.initrd->header.ih_load = cpu_to_uimage(data.initrd_address);
-
 	if (optind == argc) {
 		ret = COMMAND_ERROR_USAGE;
 		goto err_out;
@@ -218,8 +215,12 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 		goto err_out;
 
 	if (data.initrd) {
-		ret = relocate_image(data.initrd,
-				(void *)image_get_load(&data.initrd->header));
+		if (data.initrd && data.initrd_address == ~0)
+			data.initrd_address = uimage_to_cpu(data.initrd->header.ih_load);
+
+		data.initrd_size = image_get_data_size(&data.initrd->header);
+
+		ret = relocate_image(data.initrd, (void *)data.initrd_address);
 		if (ret)
 			goto err_out;
 	}
diff --git a/include/boot.h b/include/boot.h
index b22514b..b67e034 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -10,6 +10,7 @@ struct image_data {
 	const char *oftree;
 	int verify;
 	unsigned long initrd_address;
+	unsigned long initrd_size;
 };
 
 struct image_handler {
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 11/14] bootm: fix typo, update help str
  2011-11-28  8:02 ` [PATCH 11/14] bootm: fix typo, update help str Sascha Hauer
@ 2011-11-28 11:00   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 25+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-11-28 11:00 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 09:02 Mon 28 Nov     , Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  commands/bootm.c |    6 ++----
>  1 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/commands/bootm.c b/commands/bootm.c
> index 86470c2..0458919 100644
> --- a/commands/bootm.c
> +++ b/commands/bootm.c
> @@ -44,9 +44,7 @@
>  #include <init.h>
>  #include <asm-generic/memory_layout.h>
>  
> -#ifndef CFG_BOOTM_LEN
>  #define CFG_BOOTM_LEN	0x800000	/* use 8MByte as default max gunzip size */
> -#endif
why do you rempve this too in this patch?

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 05/14] armlinux: cleanup linux vars
  2011-11-28  8:02 ` [PATCH 05/14] armlinux: cleanup linux vars Sascha Hauer
@ 2011-11-28 11:03   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-11-28 11:12     ` Sascha Hauer
  0 siblings, 1 reply; 25+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-11-28 11:03 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 09:02 Mon 28 Nov     , Sascha Hauer wrote:
> arch_number is currently exported to the environment but not read back
> on boot time which is rather confusing. system_rev and system_serial
> are not exported to the environment but can be set in board specific
> code.
> This patch exports all these variables to the environment and reads them
> back on boot time. All variables get a armlinux_ prefix, so the
> arch_number environment variable gets renamed.
I'm using it so please do not remove the old arch_number

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 05/14] armlinux: cleanup linux vars
  2011-11-28 11:03   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-11-28 11:12     ` Sascha Hauer
  2011-11-29  4:38       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 25+ messages in thread
From: Sascha Hauer @ 2011-11-28 11:12 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Nov 28, 2011 at 12:03:31PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 09:02 Mon 28 Nov     , Sascha Hauer wrote:
> > arch_number is currently exported to the environment but not read back
> > on boot time which is rather confusing. system_rev and system_serial
> > are not exported to the environment but can be set in board specific
> > code.
> > This patch exports all these variables to the environment and reads them
> > back on boot time. All variables get a armlinux_ prefix, so the
> > arch_number environment variable gets renamed.
> I'm using it so please do not remove the old arch_number

I'm not removing it, just changing the name. Can't you update the name
in your environment?

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 05/14] armlinux: cleanup linux vars
  2011-11-28 11:12     ` Sascha Hauer
@ 2011-11-29  4:38       ` Jean-Christophe PLAGNIOL-VILLARD
  2011-11-29  7:23         ` Robert Schwebel
  0 siblings, 1 reply; 25+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-11-29  4:38 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 12:12 Mon 28 Nov     , Sascha Hauer wrote:
> On Mon, Nov 28, 2011 at 12:03:31PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 09:02 Mon 28 Nov     , Sascha Hauer wrote:
> > > arch_number is currently exported to the environment but not read back
> > > on boot time which is rather confusing. system_rev and system_serial
> > > are not exported to the environment but can be set in board specific
> > > code.
> > > This patch exports all these variables to the environment and reads them
> > > back on boot time. All variables get a armlinux_ prefix, so the
> > > arch_number environment variable gets renamed.
> > I'm using it so please do not remove the old arch_number
> 
> I'm not removing it, just changing the name. Can't you update the name
> in your environment?
no :(

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 05/14] armlinux: cleanup linux vars
  2011-11-29  4:38       ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-11-29  7:23         ` Robert Schwebel
  2011-11-29  8:13           ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 25+ messages in thread
From: Robert Schwebel @ 2011-11-29  7:23 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Tue, Nov 29, 2011 at 05:38:29AM +0100, Jean-Christophe
PLAGNIOL-VILLARD wrote:
> > > I'm using it so please do not remove the old arch_number
> >
> > I'm not removing it, just changing the name. Can't you update the
> > name in your environment?
>
> no :(

Huh? You are able to exchange your bootloader against a new one, but you
are not able to exchange your environment as well? Can you explain that
a bit more detailed?

rsc
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 05/14] armlinux: cleanup linux vars
  2011-11-29  7:23         ` Robert Schwebel
@ 2011-11-29  8:13           ` Jean-Christophe PLAGNIOL-VILLARD
  2011-11-29 10:09             ` Sascha Hauer
  0 siblings, 1 reply; 25+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-11-29  8:13 UTC (permalink / raw)
  To: Robert Schwebel; +Cc: barebox

On 08:23 Tue 29 Nov     , Robert Schwebel wrote:
> On Tue, Nov 29, 2011 at 05:38:29AM +0100, Jean-Christophe
> PLAGNIOL-VILLARD wrote:
> > > > I'm using it so please do not remove the old arch_number
> > >
> > > I'm not removing it, just changing the name. Can't you update the
> > > name in your environment?
> >
> > no :(
> 
> Huh? You are able to exchange your bootloader against a new one, but you
> are not able to exchange your environment as well? Can you explain that
> a bit more detailed?

env in otp

contain box uniq info that can not be changed after prod

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 05/14] armlinux: cleanup linux vars
  2011-11-29  8:13           ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-11-29 10:09             ` Sascha Hauer
  0 siblings, 0 replies; 25+ messages in thread
From: Sascha Hauer @ 2011-11-29 10:09 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Tue, Nov 29, 2011 at 09:13:54AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 08:23 Tue 29 Nov     , Robert Schwebel wrote:
> > On Tue, Nov 29, 2011 at 05:38:29AM +0100, Jean-Christophe
> > PLAGNIOL-VILLARD wrote:
> > > > > I'm using it so please do not remove the old arch_number
> > > >
> > > > I'm not removing it, just changing the name. Can't you update the
> > > > name in your environment?
> > >
> > > no :(
> > 
> > Huh? You are able to exchange your bootloader against a new one, but you
> > are not able to exchange your environment as well? Can you explain that
> > a bit more detailed?
> 
> env in otp
> 
> contain box uniq info that can not be changed after prod

You can still set a compatibility variable in your board specific code.

Besides, with putting the environment in otp you also say that
We can't change the behaviour of commands at all because you programmed
this into your hardware. Do you really want that we are doomed with
what we have now forever? No, please not.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 07/14] bootm: handle initrds inline
  2011-11-28  8:02 ` [PATCH 07/14] bootm: handle initrds inline Sascha Hauer
@ 2011-12-06 15:08   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-12-07  9:19     ` Sascha Hauer
  0 siblings, 1 reply; 25+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-12-06 15:08 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

[-- Attachment #1: Type: text/plain, Size: 3356 bytes --]

On 09:02 Mon 28 Nov     , Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  commands/bootm.c |   78 +++++++++++++++++++----------------------------------
>  1 files changed, 28 insertions(+), 50 deletions(-)
> 
> diff --git a/commands/bootm.c b/commands/bootm.c
> index 823d387..17139f7 100644
> --- a/commands/bootm.c
> +++ b/commands/bootm.c
> @@ -141,55 +141,6 @@ static struct image_handle *get_fake_image_handle(struct image_data *data, int n
>  	return handle;
>  }
>  
> -static int initrd_handler_parse_options(struct image_data *data, int opt,
> -		char *optarg)
> -{
> -	uint32_t initrd_start;
> -
> -	switch(opt) {
> -	case 'L':
> -		if (!data->initrd) {
> -			eprintf("Warning -L ingnored. Specify the initrd first\n");
> -			break;
> -		}
> -		initrd_start = simple_strtoul(optarg, NULL, 0);
> -		printf("initrd_start=0x%x\n", initrd_start);
> -		data->initrd->header.ih_load = cpu_to_uimage(initrd_start);
> -		break;
> -	case 'r':
> -		printf("use initrd %s\n", optarg);
> -		/* check for multi image @<num> */
> -		if (optarg[0] == '@') {
> -			int num = simple_strtol(optarg + 1, NULL, 0);
> -
> -			data->initrd = get_fake_image_handle(data, num);
> -		} else {
> -			data->initrd = map_image(optarg, data->verify);
> -		}
> -		if (!data->initrd)
> -			return -1;
> -		break;
> -	default:
> -		return 1;
> -	}
> -
> -	return 0;
> -}
> -
> -static struct image_handler initrd_handler = {
> -	.cmdline_options = "r:L:",
> -	.cmdline_parse = initrd_handler_parse_options,
> -	.help_string = " -r <initrd>    specify an initrd image\n"
> -		       " -L <load addr> specify initrd load address",
> -};
> -
> -static int initrd_register_image_handler(void)
> -{
> -	return register_image_handler(&initrd_handler);
> -}
> -
> -late_initcall(initrd_register_image_handler);
> -
>  static int handler_parse_options(struct image_data *data, int opt, char *optarg)
>  {
>  	struct image_handler *handler;
> @@ -216,13 +167,14 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
>  	struct image_handle *os_handle, *initrd_handle = NULL;
>  	struct image_handler *handler;
>  	struct image_data data;
> +	u32 initrd_start;
>  	char options[53]; /* worst case: whole alphabet with colons */
>  
>  	memset(&data, 0, sizeof(struct image_data));
>  	data.verify = 1;
>  
>  	/* Collect options from registered handlers */
> -	strcpy(options, "nh");
> +	strcpy(options, "nhr:L:");
>  	list_for_each_entry(handler, &handler_list, list) {
>  		if (handler->cmdline_options)
>  			strcat(options, handler->cmdline_options);
> @@ -242,6 +194,28 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
>  			}
>  
>  			return 0;
> +		case 'L':
> +			if (!data.initrd) {
> +				eprintf("Warning -L ingnored. Specify the initrd first\n");
> +				break;
> +			}
> +			initrd_start = simple_strtoul(optarg, NULL, 0);
> +			printf("initrd_start=0x%x\n", initrd_start);
> +			data.initrd->header.ih_load = cpu_to_uimage(initrd_start);
> +			break;
> +		case 'r':
> +			printf("use initrd %s\n", optarg);
> +			/* check for multi image @<num> */
> +			if (optarg[0] == '@') {
> +				int num = simple_strtol(optarg + 1, NULL, 0);
> +
> +				data.initrd = get_fake_image_handle(&data, num);
this can not work

get_fake_image_handle expect the uImage is mapped

attached patch fix it

Best Regards,
J.

[-- Attachment #2: 0001-bootm-fix-initrd-multi-image-support.patch --]
[-- Type: text/x-diff, Size: 1864 bytes --]

From b7b35f53686f5ee0e35caf195adc97b88d393c71 Mon Sep 17 00:00:00 2001
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Date: Tue, 6 Dec 2011 23:09:37 +0800
Subject: [PATCH 1/1] bootm: fix initrd multi-image support

the -L option use get_fake_image_handle expect the uImage is mapped

so move is after the uImage is mapped

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/bootm.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index d796914..c7ce42e 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -141,6 +141,7 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 	struct image_handler *handler;
 	struct image_data data;
 	int ret = 1;
+	int initrd_num = 0;
 	char options[53]; /* worst case: whole alphabet with colons */
 
 	memset(&data, 0, sizeof(struct image_data));
@@ -175,14 +176,12 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 			printf("use initrd %s\n", optarg);
 			/* check for multi image @<num> */
 			if (optarg[0] == '@') {
-				int num = simple_strtol(optarg + 1, NULL, 0);
-
-				data.initrd = get_fake_image_handle(&data, num);
+				initrd_num = simple_strtol(optarg + 1, NULL, 0);
 			} else {
 				data.initrd = map_image(optarg, data.verify);
+				if (!data.initrd)
+					goto err_out;
 			}
-			if (!data.initrd)
-				goto err_out;
 			break;
 		default:
 			break;
@@ -201,6 +200,12 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 
 	os_header = &os_handle->header;
 
+	if (initrd_num) {
+		data.initrd = get_fake_image_handle(&data, initrd_num);
+		if (!data.initrd)
+			goto err_out;
+	}
+
 	if (image_get_arch(os_header) != IH_ARCH) {
 		printf("Unsupported Architecture 0x%x\n",
 		       image_get_arch(os_header));
-- 
1.7.7


[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 07/14] bootm: handle initrds inline
  2011-12-06 15:08   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-12-07  9:19     ` Sascha Hauer
  2011-12-07 13:26       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 25+ messages in thread
From: Sascha Hauer @ 2011-12-07  9:19 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Tue, Dec 06, 2011 at 04:08:20PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 09:02 Mon 28 Nov     , Sascha Hauer wrote:
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> > +
> > +				data.initrd = get_fake_image_handle(&data, num);
> this can not work
> 
> get_fake_image_handle expect the uImage is mapped

Yes, you're right.

> 
> attached patch fix it
> 

How about the following instead? I think it's a bit cleaner to
completely move the initrd code out of the option parsing.

Sascha

From 5128a2d2badace6102dc5461408ceaa47d0e9cc1 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Tue, 6 Dec 2011 08:44:05 +0100
Subject: [PATCH] bootm: factor out initrd code from option parser

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 859ec28..f97a842 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -121,6 +121,7 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 	struct image_handle *os_handle = NULL;
 	struct image_handler *handler;
 	struct image_data data;
+	const char *initrdname = NULL;
 	int ret = 1;
 
 	memset(&data, 0, sizeof(struct image_data));
@@ -136,17 +137,7 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 			data.initrd_address = simple_strtoul(optarg, NULL, 0);
 			break;
 		case 'r':
-			printf("use initrd %s\n", optarg);
-			/* check for multi image @<num> */
-			if (optarg[0] == '@') {
-				int num = simple_strtol(optarg + 1, NULL, 0);
-
-				data.initrd = get_fake_image_handle(&data, num);
-			} else {
-				data.initrd = map_image(optarg, data.verify);
-			}
-			if (!data.initrd)
-				goto err_out;
+			initrdname = optarg;
 			break;
 		default:
 			break;
@@ -171,6 +162,19 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
 		goto err_out;
 	}
 
+	if (initrdname) {
+		/* check for multi image @<num> */
+		if (initrdname[0] == '@') {
+			int num = simple_strtol(optarg + 1, NULL, 0);
+
+			data.initrd = get_fake_image_handle(&data, num);
+		} else {
+			data.initrd = map_image(optarg, data.verify);
+		}
+		if (!data.initrd)
+			goto err_out;
+	}
+
 	/*
 	 * We have reached the point of no return: we are going to
 	 * overwrite all exception vector code, so we cannot easily
-- 
1.7.7.3


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 07/14] bootm: handle initrds inline
  2011-12-07  9:19     ` Sascha Hauer
@ 2011-12-07 13:26       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 25+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-12-07 13:26 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 10:19 Wed 07 Dec     , Sascha Hauer wrote:
> On Tue, Dec 06, 2011 at 04:08:20PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 09:02 Mon 28 Nov     , Sascha Hauer wrote:
> > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > > ---
> > > +
> > > +				data.initrd = get_fake_image_handle(&data, num);
> > this can not work
> > 
> > get_fake_image_handle expect the uImage is mapped
> 
> Yes, you're right.
> 
> > 
> > attached patch fix it
> > 
> 
> How about the following instead? I think it's a bit cleaner to
> completely move the initrd code out of the option parsing.
> 
> Sascha
> 
> >From 5128a2d2badace6102dc5461408ceaa47d0e9cc1 Mon Sep 17 00:00:00 2001
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Date: Tue, 6 Dec 2011 08:44:05 +0100
> Subject: [PATCH] bootm: factor out initrd code from option parser
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  commands/bootm.c |   26 +++++++++++++++-----------
>  1 files changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/commands/bootm.c b/commands/bootm.c
> index 859ec28..f97a842 100644
> --- a/commands/bootm.c
> +++ b/commands/bootm.c
> @@ -121,6 +121,7 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
>  	struct image_handle *os_handle = NULL;
>  	struct image_handler *handler;
>  	struct image_data data;
> +	const char *initrdname = NULL;
>  	int ret = 1;
>  
>  	memset(&data, 0, sizeof(struct image_data));
> @@ -136,17 +137,7 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
>  			data.initrd_address = simple_strtoul(optarg, NULL, 0);
>  			break;
>  		case 'r':
> -			printf("use initrd %s\n", optarg);
> -			/* check for multi image @<num> */
> -			if (optarg[0] == '@') {
> -				int num = simple_strtol(optarg + 1, NULL, 0);
> -
> -				data.initrd = get_fake_image_handle(&data, num);
> -			} else {
> -				data.initrd = map_image(optarg, data.verify);
> -			}
> -			if (!data.initrd)
> -				goto err_out;
> +			initrdname = optarg;
>  			break;
>  		default:
>  			break;
> @@ -171,6 +162,19 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
>  		goto err_out;
>  	}
>  
> +	if (initrdname) {
> +		/* check for multi image @<num> */
> +		if (initrdname[0] == '@') {
> +			int num = simple_strtol(optarg + 1, NULL, 0);
> +
> +			data.initrd = get_fake_image_handle(&data, num);
> +		} else {
> +			data.initrd = map_image(optarg, data.verify);
> +		}
> +		if (!data.initrd)
> +			goto err_out;
> +	}
> +
ok

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2011-12-07 13:30 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-28  8:02 bootm work Sascha Hauer
2011-11-28  8:02 ` [PATCH 01/14] bootm: remove dead code Sascha Hauer
2011-11-28  8:02 ` [PATCH 02/14] factor out iminfo command Sascha Hauer
2011-11-28  8:02 ` [PATCH 03/14] compile in simple_strtoull Sascha Hauer
2011-11-28  8:02 ` [PATCH 04/14] introduce some env helpers Sascha Hauer
2011-11-28  8:02 ` [PATCH 05/14] armlinux: cleanup linux vars Sascha Hauer
2011-11-28 11:03   ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-28 11:12     ` Sascha Hauer
2011-11-29  4:38       ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-29  7:23         ` Robert Schwebel
2011-11-29  8:13           ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-29 10:09             ` Sascha Hauer
2011-11-28  8:02 ` [PATCH 06/14] ARM bootm: remove now obsolete args Sascha Hauer
2011-11-28  8:02 ` [PATCH 07/14] bootm: handle initrds inline Sascha Hauer
2011-12-06 15:08   ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-07  9:19     ` Sascha Hauer
2011-12-07 13:26       ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-28  8:02 ` [PATCH 08/14] bootm: remove image handler options Sascha Hauer
2011-11-28  8:02 ` [PATCH 09/14] bootm: fix various memory leaks Sascha Hauer
2011-11-28  8:02 ` [PATCH 10/14] bootm: do not require -L after -r Sascha Hauer
2011-11-28  8:02 ` [PATCH 11/14] bootm: fix typo, update help str Sascha Hauer
2011-11-28 11:00   ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-28  8:02 ` [PATCH 12/14] bootm relocate_image: honour load_address Sascha Hauer
2011-11-28  8:02 ` [PATCH 13/14] bootm: push relocate_image up to the generic command Sascha Hauer
2011-11-28  8:02 ` [PATCH 14/14] bootm: use initrd_address and initrd_size Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox