public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor
@ 2013-01-10 14:58 Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 01/22] sandbox: Allow -c argument to provide a command list Simon Glass
                   ` (22 more replies)
  0 siblings, 23 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

In creating a new feature[*] I found that the image code includes quite
a bit of duplication in places. In particular the code to load a kernel,
FDT and ramdisk is all fairly similar, but subtly different.

This series introduces a new function fit_image_load() which loads an image
from a FIT and supports the various features. For the bootstage updates,
these are standardised so that each file has its own range and the events
within that range have corresponding numbers. This means that the boot
progress numbers will change slightly with this series.

The image.c file is still very long. Rather than perpetuate the #ifdefs
in the code I have split out the image.c code that is dependent on
CONFIG_OF_LIBFDT into image-fdt.c.

Several architectures have their own way of setting up a ramdisk and FDT
for booting. An attempt is made here to unify these by providing a function
image_setup_linux() to handle the overall task, and image_setup_fdt() to set
up the FDT.

For ARM, the bootm code is a maze of #ifdefs, which means that many boards
compile the code differently and it takes longer to detect breakages. To get
around this, some defines are added to ARM's bootm.h to permit the use of
if() instead of #ifdef, making use of the compiler's dead code elimination.

Also this series introduces a very basic test of image loading using sandbox.
Some patches add bootm support for sandbox, and also a 'sb save' command to
save memory to a host file (used to check that the bootm actually worked).

A test program for sandbox is added as a basic sanity check of image loading
as performed by bootm.

This series depends on the verified boot series since it builds on the
clean-up in that. You can get this series from:

   http://git.denx.de/u-boot-x86.git

branch name 'image'.

* The new feature is support for FIT booting on x86, will get back to this
later.


Simon Glass (22):
  sandbox: Allow -c argument to provide a command list
  sandbox: Support 'source' command
  fs: Add support for saving data to filesystems
  sandbox: fs: Add support for saving files to host filesystem
  image: Split libfdt code into image-fdt.c
  image: Add device tree setup to image library
  arm: Refactor bootm to reduce #ifdefs
  arm: Use image_setup_linux() instead of local code
  powerpc: Use image_setup_linux() instead of local code
  m68k: Use image_setup_linux() instead of local code
  sparc: Use image_setup_linux() instead of local code
  bootstage: Introduce sub-IDs for use with image loading
  mkimage: Add map_sysmem() and IH_ARCH_DEFAULT to simplfy building
  image: Introduce fit_image_load() to load images from FITs
  image: Use fit_image_load() to load ramdisk
  image: Use fit_image_load() to load FDT
  sandbox: Adjust bootm command to work with sandbox
  image: Use fit_image_load() to load kernel
  sandbox: image: Adjust FIT image printing to work with sandbox
  bootstage: Remove unused entries related to kernel/ramdisk/fdt load
  sandbox: image: Create a test for loading FIT images
  WIP: sandbox: config: Remove boot command

 arch/arm/include/asm/bootm.h      |   54 +++-
 arch/arm/include/asm/u-boot-arm.h |    2 -
 arch/arm/lib/Makefile             |    1 +
 arch/arm/lib/bootm-fdt.c          |   52 +++
 arch/arm/lib/bootm.c              |  145 +-------
 arch/m68k/lib/bootm.c             |   15 +-
 arch/powerpc/lib/bootm.c          |   84 +-----
 arch/sandbox/cpu/start.c          |    2 +-
 arch/sparc/lib/bootm.c            |   13 +-
 common/Makefile                   |    1 +
 common/cmd_bootm.c                |  182 ++--------
 common/cmd_sandbox.c              |   18 +-
 common/cmd_source.c               |   11 +-
 common/image-fdt.c                |  512 +++++++++++++++++++++++++
 common/image-fit.c                |  293 +++++++++++-----
 common/image.c                    |  738 ++++---------------------------------
 fs/fs.c                           |   75 ++++
 fs/sandbox/sandboxfs.c            |   33 ++
 include/bootstage.h               |   51 ++--
 include/common.h                  |    9 +
 include/configs/sandbox.h         |    1 -
 include/fdt_support.h             |    2 -
 include/fs.h                      |    2 +
 include/image.h                   |  145 +++++++-
 include/lmb.h                     |    2 -
 include/sandboxfs.h               |    1 +
 test/image/test-fit.py            |  422 +++++++++++++++++++++
 tools/mkimage.h                   |   12 +
 28 files changed, 1674 insertions(+), 1204 deletions(-)
 create mode 100644 arch/arm/lib/bootm-fdt.c
 create mode 100644 common/image-fdt.c
 create mode 100755 test/image/test-fit.py

-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 01/22] sandbox: Allow -c argument to provide a command list
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-11 11:06   ` Marek Vasut
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 02/22] sandbox: Support 'source' command Simon Glass
                   ` (21 subsequent siblings)
  22 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

This allows passing of entire scripts to sandbox with the -c argument,
which is useful for testing. Commands can be delimited with a newline
or semicolon.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/sandbox/cpu/start.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 8589da2..ce47e7e 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -90,7 +90,7 @@ int sandbox_main_loop_init(void)
 
 	/* Execute command if required */
 	if (state->cmd) {
-		run_command(state->cmd, 0);
+		run_command_list(state->cmd, -1, 0);
 		os_exit(state->exit_type);
 	}
 
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 02/22] sandbox: Support 'source' command
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 01/22] sandbox: Allow -c argument to provide a command list Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-11 11:07   ` Marek Vasut
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 03/22] fs: Add support for saving data to filesystems Simon Glass
                   ` (20 subsequent siblings)
  22 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Enhance the source command to work with sandbox, by using map_sysmem() to
convert a ulong address into a pointer.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/cmd_source.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/common/cmd_source.c b/common/cmd_source.c
index 6a82fb2..0417898 100644
--- a/common/cmd_source.c
+++ b/common/cmd_source.c
@@ -36,6 +36,7 @@
 #include <image.h>
 #include <malloc.h>
 #include <asm/byteorder.h>
+#include <asm/io.h>
 #if defined(CONFIG_8xx)
 #include <mpc8xx.h>
 #endif
@@ -44,9 +45,10 @@ int
 source (ulong addr, const char *fit_uname)
 {
 	ulong		len;
-	image_header_t	*hdr;
+	const image_header_t *hdr;
 	ulong		*data;
 	int		verify;
+	const void *buf;
 #if defined(CONFIG_FIT)
 	const void*	fit_hdr;
 	int		noffset;
@@ -56,9 +58,10 @@ source (ulong addr, const char *fit_uname)
 
 	verify = getenv_yesno ("verify");
 
-	switch (genimg_get_format ((void *)addr)) {
+	buf = map_sysmem(addr, 0);
+	switch (genimg_get_format(buf)) {
 	case IMAGE_FORMAT_LEGACY:
-		hdr = (image_header_t *)addr;
+		hdr = buf;
 
 		if (!image_check_magic (hdr)) {
 			puts ("Bad magic number\n");
@@ -104,7 +107,7 @@ source (ulong addr, const char *fit_uname)
 			return 1;
 		}
 
-		fit_hdr = (const void *)addr;
+		fit_hdr = buf;
 		if (!fit_check_format (fit_hdr)) {
 			puts ("Bad FIT image format\n");
 			return 1;
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 03/22] fs: Add support for saving data to filesystems
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 01/22] sandbox: Allow -c argument to provide a command list Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 02/22] sandbox: Support 'source' command Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-11 11:08   ` Marek Vasut
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 04/22] sandbox: fs: Add support for saving files to host filesystem Simon Glass
                   ` (19 subsequent siblings)
  22 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Add a new method for saving that filesystems can implement. This mirrors the
existing load method.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 fs/fs.c      |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/fs.h |    2 +
 2 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 6f5063c..eee7e23 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -47,6 +47,12 @@ static inline int fs_read_unsupported(const char *filename, void *buf,
 	return -1;
 }
 
+static inline int fs_write_unsupported(const char *filename, void *buf,
+				      int offset, int len)
+{
+	return -1;
+}
+
 static inline void fs_close_unsupported(void)
 {
 }
@@ -57,6 +63,7 @@ struct fstype_info {
 		     disk_partition_t *fs_partition);
 	int (*ls)(const char *dirname);
 	int (*read)(const char *filename, void *buf, int offset, int len);
+	int (*write)(const char *filename, void *buf, int offset, int len);
 	void (*close)(void);
 };
 
@@ -94,6 +101,7 @@ static struct fstype_info fstypes[] = {
 		.close = fs_close_unsupported,
 		.ls = fs_ls_unsupported,
 		.read = fs_read_unsupported,
+		.write = fs_write_unsupported,
 	},
 };
 
@@ -125,6 +133,7 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
 			info->close += gd->reloc_off;
 			info->ls += gd->reloc_off;
 			info->read += gd->reloc_off;
+			info->write += gd->reloc_off;
 		}
 		relocated = 1;
 	}
@@ -196,6 +205,30 @@ int fs_read(const char *filename, ulong addr, int offset, int len)
 	return ret;
 }
 
+int fs_write(const char *filename, ulong addr, int offset, int len)
+{
+	struct fstype_info *info = fs_get_info(fs_type);
+	void *buf;
+	int ret;
+
+	/*
+	 * We don't actually know how many bytes are being read, since len==0
+	 * means read the whole file.
+	 */
+	buf = map_sysmem(addr, len);
+	ret = info->write(filename, buf, offset, len);
+	unmap_sysmem(buf);
+
+	/* If we requested a specific number of bytes, check we got it */
+	if (ret >= 0 && len && ret != len) {
+		printf("** Unable to write file %s **\n", filename);
+		ret = -1;
+	}
+	fs_close();
+
+	return ret;
+}
+
 int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		int fstype, int cmdline_base)
 {
@@ -277,3 +310,44 @@ int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 
 	return 0;
 }
+
+int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
+		int fstype, int cmdline_base)
+{
+	unsigned long addr;
+	const char *filename;
+	unsigned long bytes;
+	unsigned long pos;
+	int len;
+	unsigned long time;
+
+	if (argc < 6 || argc > 7)
+		return CMD_RET_USAGE;
+
+	if (fs_set_blk_dev(argv[1], argv[2], fstype))
+		return 1;
+
+	filename = argv[3];
+	addr = simple_strtoul(argv[4], NULL, cmdline_base);
+	bytes = simple_strtoul(argv[5], NULL, cmdline_base);
+	if (argc >= 7)
+		pos = simple_strtoul(argv[6], NULL, cmdline_base);
+	else
+		pos = 0;
+
+	time = get_timer(0);
+	len = fs_write(filename, addr, pos, bytes);
+	time = get_timer(time);
+	if (len <= 0)
+		return 1;
+
+	printf("%d bytes written in %lu ms", len, time);
+	if (time > 0) {
+		puts(" (");
+		print_size(len / time * 1000, "/s");
+		puts(")");
+	}
+	puts("\n");
+
+	return 0;
+}
diff --git a/include/fs.h b/include/fs.h
index b6d69e5..c837bae 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -62,5 +62,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		int fstype, int cmdline_base);
 int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		int fstype);
+int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
+		int fstype, int cmdline_base);
 
 #endif /* _FS_H */
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 04/22] sandbox: fs: Add support for saving files to host filesystem
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (2 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 03/22] fs: Add support for saving data to filesystems Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-11 11:09   ` Marek Vasut
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 05/22] image: Split libfdt code into image-fdt.c Simon Glass
                   ` (18 subsequent siblings)
  22 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

This allows write of files from the host filesystem in sandbox. There is
currently no concept of overwriting the file and removing its existing
contents - all writing is done on top of what is there. This means that
writing 10 bytes to the start of a 1KB file will only update those 10
bytes, not truncate the file to 10 byte slong.

If the file does not exist it is created.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/cmd_sandbox.c   |   18 ++++++++++++++----
 fs/fs.c                |    1 +
 fs/sandbox/sandboxfs.c |   33 +++++++++++++++++++++++++++++++++
 include/sandboxfs.h    |    1 +
 4 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c
index 206a486..a28a844 100644
--- a/common/cmd_sandbox.c
+++ b/common/cmd_sandbox.c
@@ -32,9 +32,16 @@ static int do_sandbox_ls(cmd_tbl_t *cmdtp, int flag, int argc,
 	return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
 }
 
+static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc,
+			   char * const argv[])
+{
+	return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX, 16);
+}
+
 static cmd_tbl_t cmd_sandbox_sub[] = {
-	U_BOOT_CMD_MKENT(load, 3, 0, do_sandbox_load, "", ""),
+	U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""),
 	U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""),
+	U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""),
 };
 
 static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -56,8 +63,11 @@ static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
 }
 
 U_BOOT_CMD(
-	sb,	6,	1,	do_sandbox,
+	sb,	8,	1,	do_sandbox,
 	"Miscellaneous sandbox commands",
-	"load host <addr> <filename> [<bytes> <offset>]  - load a file from host\n"
-	"sb ls host <filename>      - save a file to host"
+	"load host <dev> <addr> <filename> [<bytes> <offset>]  - "
+		"load a file from host\n"
+	"sb ls host <filename>                      - list files on host\n"
+	"sb save host <dev> <filename> <addr> <bytes> [<offset>] - "
+		"save a file to host\n"
 );
diff --git a/fs/fs.c b/fs/fs.c
index eee7e23..99e516a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -93,6 +93,7 @@ static struct fstype_info fstypes[] = {
 		.close = sandbox_fs_close,
 		.ls = sandbox_fs_ls,
 		.read = fs_read_sandbox,
+		.write = fs_write_sandbox,
 	},
 #endif
 	{
diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c
index 02d26ff..89769e8 100644
--- a/fs/sandbox/sandboxfs.c
+++ b/fs/sandbox/sandboxfs.c
@@ -48,6 +48,26 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos,
 	return size;
 }
 
+long sandbox_fs_write_at(const char *filename, unsigned long pos,
+			 void *buffer, unsigned long towrite)
+{
+	ssize_t size;
+	int fd, ret;
+
+	fd = os_open(filename, OS_O_RDWR | OS_O_CREAT);
+	if (fd < 0)
+		return fd;
+	ret = os_lseek(fd, pos, OS_SEEK_SET);
+	if (ret == -1) {
+		os_close(fd);
+		return ret;
+	}
+	size = os_write(fd, buffer, towrite);
+	os_close(fd);
+
+	return size;
+}
+
 int sandbox_fs_ls(const char *dirname)
 {
 	struct os_dirent_node *head, *node;
@@ -81,3 +101,16 @@ int fs_read_sandbox(const char *filename, void *buf, int offset, int len)
 
 	return len_read;
 }
+
+int fs_write_sandbox(const char *filename, void *buf, int offset, int len)
+{
+	int len_written;
+
+	len_written = sandbox_fs_write_at(filename, offset, buf, len);
+	if (len_written == -1) {
+		printf("** Unable to write file %s **\n", filename);
+		return -1;
+	}
+
+	return len_written;
+}
diff --git a/include/sandboxfs.h b/include/sandboxfs.h
index f5213ac..8ea8cb7 100644
--- a/include/sandboxfs.h
+++ b/include/sandboxfs.h
@@ -26,5 +26,6 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos,
 void sandbox_fs_close(void);
 int sandbox_fs_ls(const char *dirname);
 int fs_read_sandbox(const char *filename, void *buf, int offset, int len);
+int fs_write_sandbox(const char *filename, void *buf, int offset, int len);
 
 #endif
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 05/22] image: Split libfdt code into image-fdt.c
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (3 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 04/22] sandbox: fs: Add support for saving files to host filesystem Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 06/22] image: Add device tree setup to image library Simon Glass
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

The image file is still very large, and some of the code is only used when
libfdt is in use. Move this code into a new file.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/Makefile    |    1 +
 common/image-fdt.c |  608 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     |  566 ------------------------------------------------
 3 files changed, 609 insertions(+), 566 deletions(-)
 create mode 100644 common/image-fdt.c

diff --git a/common/Makefile b/common/Makefile
index 8208b0b..b688a91 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -223,6 +223,7 @@ COBJS-$(CONFIG_BOUNCE_BUFFER) += bouncebuf.o
 COBJS-y += console.o
 COBJS-y += dlmalloc.o
 COBJS-y += image.o
+COBJS-$(CONFIG_OF_LIBFDT) += image-fdt.o
 COBJS-$(CONFIG_FIT) += image-fit.o
 COBJS-$(CONFIG_FIT_SIGNATURE) += image-sig.o
 COBJS-y += memsize.o
diff --git a/common/image-fdt.c b/common/image-fdt.c
new file mode 100644
index 0000000..1c88a16
--- /dev/null
+++ b/common/image-fdt.c
@@ -0,0 +1,608 @@
+/*
+ * Copyright (c) 2013, Google Inc.
+ *
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2006
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <fdt_support.h>
+#include <errno.h>
+#include <image.h>
+#include <libfdt.h>
+#include <asm/io.h>
+
+#ifndef CONFIG_SYS_FDT_PAD
+#define CONFIG_SYS_FDT_PAD 0x3000
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static void fdt_error(const char *msg)
+{
+	puts("ERROR: ");
+	puts(msg);
+	puts(" - must RESET the board to recover.\n");
+}
+
+static const image_header_t *image_get_fdt(ulong fdt_addr)
+{
+	const image_header_t *fdt_hdr = map_sysmem(fdt_addr, 0);
+
+	image_print_contents(fdt_hdr);
+
+	puts("   Verifying Checksum ... ");
+	if (!image_check_hcrc(fdt_hdr)) {
+		fdt_error("fdt header checksum invalid");
+		return NULL;
+	}
+
+	if (!image_check_dcrc(fdt_hdr)) {
+		fdt_error("fdt checksum invalid");
+		return NULL;
+	}
+	puts("OK\n");
+
+	if (!image_check_type(fdt_hdr, IH_TYPE_FLATDT)) {
+		fdt_error("uImage is not a fdt");
+		return NULL;
+	}
+	if (image_get_comp(fdt_hdr) != IH_COMP_NONE) {
+		fdt_error("uImage is compressed");
+		return NULL;
+	}
+	if (fdt_check_header((char *)image_get_data(fdt_hdr)) != 0) {
+		fdt_error("uImage data is not a fdt");
+		return NULL;
+	}
+	return fdt_hdr;
+}
+
+/**
+ * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
+ * @lmb: pointer to lmb handle, will be used for memory mgmt
+ * @fdt_blob: pointer to fdt blob base address
+ *
+ * Adds the memreserve regions in the dtb to the lmb block.  Adding the
+ * memreserve regions prevents u-boot from using them to store the initrd
+ * or the fdt blob.
+ */
+void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
+{
+	uint64_t addr, size;
+	int i, total;
+
+	if (fdt_check_header(fdt_blob) != 0)
+		return;
+
+	total = fdt_num_mem_rsv(fdt_blob);
+	for (i = 0; i < total; i++) {
+		if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
+			continue;
+		printf("   reserving fdt memory region: addr=%llx size=%llx\n",
+			(unsigned long long)addr, (unsigned long long)size);
+		lmb_reserve(lmb, addr, size);
+	}
+}
+
+/**
+ * boot_relocate_fdt - relocate flat device tree
+ * @lmb: pointer to lmb handle, will be used for memory mgmt
+ * @of_flat_tree: pointer to a char* variable, will hold fdt start address
+ * @of_size: pointer to a ulong variable, will hold fdt length
+ *
+ * boot_relocate_fdt() allocates a region of memory within the bootmap and
+ * relocates the of_flat_tree into that region, even if the fdt is already in
+ * the bootmap.  It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
+ * bytes.
+ *
+ * of_flat_tree and of_size are set to final (after relocation) values
+ *
+ * returns:
+ *      0 - success
+ *      1 - failure
+ */
+int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
+{
+	void	*fdt_blob = *of_flat_tree;
+	void	*of_start = NULL;
+	char	*fdt_high;
+	ulong	of_len = 0;
+	int	err;
+	int	disable_relocation = 0;
+
+	/* nothing to do */
+	if (*of_size == 0)
+		return 0;
+
+	if (fdt_check_header(fdt_blob) != 0) {
+		fdt_error("image is not a fdt");
+		goto error;
+	}
+
+	/* position on a 4K boundary before the alloc_current */
+	/* Pad the FDT by a specified amount */
+	of_len = *of_size + CONFIG_SYS_FDT_PAD;
+
+	/* If fdt_high is set use it to select the relocation address */
+	fdt_high = getenv("fdt_high");
+	if (fdt_high) {
+		void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
+
+		if (((ulong) desired_addr) == ~0UL) {
+			/* All ones means use fdt in place */
+			of_start = fdt_blob;
+			lmb_reserve(lmb, (ulong)of_start, of_len);
+			disable_relocation = 1;
+		} else if (desired_addr) {
+			of_start =
+			    (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
+							   (ulong)desired_addr);
+			if (of_start == NULL) {
+				puts("Failed using fdt_high value for"
+					" Device Tree");
+				goto error;
+			}
+		} else {
+			of_start =
+			    (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
+		}
+	} else {
+		of_start =
+		    (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
+						   getenv_bootm_mapsize()
+						   + getenv_bootm_low());
+	}
+
+	if (of_start == NULL) {
+		puts("device tree - allocation error\n");
+		goto error;
+	}
+
+	if (disable_relocation) {
+		/*
+		 * We assume there is space after the existing fdt to use
+		 * for padding
+		 */
+		fdt_set_totalsize(of_start, of_len);
+		printf("   Using Device Tree in place at %p, end %p\n",
+		       of_start, of_start + of_len - 1);
+	} else {
+		debug("## device tree@%p ... %p (len=%ld [0x%lX])\n",
+			fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
+
+		printf("   Loading Device Tree to %p, end %p ... ",
+			of_start, of_start + of_len - 1);
+
+		err = fdt_open_into(fdt_blob, of_start, of_len);
+		if (err != 0) {
+			fdt_error("fdt move failed");
+			goto error;
+		}
+		puts("OK\n");
+	}
+
+	*of_flat_tree = of_start;
+	*of_size = of_len;
+
+	set_working_fdt_addr(*of_flat_tree);
+	return 0;
+
+error:
+	return 1;
+}
+
+#if defined(CONFIG_FIT)
+/**
+ * fit_check_fdt - verify FIT format FDT subimage
+ * @fit_hdr: pointer to the FIT  header
+ * fdt_noffset: FDT subimage node offset within FIT image
+ * @verify: data CRC verification flag
+ *
+ * fit_check_fdt() verifies integrity of the FDT subimage and from
+ * specified FIT image.
+ *
+ * returns:
+ *     1, on success
+ *     0, on failure
+ */
+static int fit_check_fdt(const void *fit, int fdt_noffset, int verify)
+{
+	fit_image_print(fit, fdt_noffset, "   ");
+
+	if (verify) {
+		puts("   Verifying Hash Integrity ... ");
+		if (!fit_image_verify(fit, fdt_noffset)) {
+			fdt_error("Bad Data Hash");
+			return 0;
+		}
+		puts("OK\n");
+	}
+
+	if (!fit_image_check_type(fit, fdt_noffset, IH_TYPE_FLATDT)) {
+		fdt_error("Not a FDT image");
+		return 0;
+	}
+
+	if (!fit_image_check_comp(fit, fdt_noffset, IH_COMP_NONE)) {
+		fdt_error("FDT image is compressed");
+		return 0;
+	}
+
+	return 1;
+}
+#endif
+
+/**
+ * boot_get_fdt - main fdt handling routine
+ * @argc: command argument count
+ * @argv: command argument list
+ * @images: pointer to the bootm images structure
+ * @of_flat_tree: pointer to a char* variable, will hold fdt start address
+ * @of_size: pointer to a ulong variable, will hold fdt length
+ *
+ * boot_get_fdt() is responsible for finding a valid flat device tree image.
+ * Curently supported are the following ramdisk sources:
+ *      - multicomponent kernel/ramdisk image,
+ *      - commandline provided address of decicated ramdisk image.
+ *
+ * returns:
+ *     0, if fdt image was found and valid, or skipped
+ *     of_flat_tree and of_size are set to fdt start address and length if
+ *     fdt image is found and valid
+ *
+ *     1, if fdt image is found but corrupted
+ *     of_flat_tree and of_size are set to 0 if no fdt exists
+ */
+int boot_get_fdt(int flag, int argc, char * const argv[],
+		bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
+{
+	const image_header_t *fdt_hdr;
+	ulong		fdt_addr;
+	char		*fdt_blob = NULL;
+	ulong		image_start, image_data, image_end;
+	ulong		load_start, load_end;
+	void		*buf;
+#if defined(CONFIG_FIT)
+	void		*fit_hdr;
+	const char	*fit_uname_config = NULL;
+	const char	*fit_uname_fdt = NULL;
+	ulong		default_addr;
+	int		cfg_noffset;
+	int		fdt_noffset;
+	const void	*data;
+	size_t		size;
+#endif
+
+	*of_flat_tree = NULL;
+	*of_size = 0;
+
+	if (argc > 3 || genimg_has_config(images)) {
+#if defined(CONFIG_FIT)
+		if (argc > 3) {
+			/*
+			 * If the FDT blob comes from the FIT image and the
+			 * FIT image address is omitted in the command line
+			 * argument, try to use ramdisk or os FIT image
+			 * address or default load address.
+			 */
+			if (images->fit_uname_rd)
+				default_addr = (ulong)images->fit_hdr_rd;
+			else if (images->fit_uname_os)
+				default_addr = (ulong)images->fit_hdr_os;
+			else
+				default_addr = load_addr;
+
+			if (fit_parse_conf(argv[3], default_addr,
+						&fdt_addr, &fit_uname_config)) {
+				debug("*  fdt: config '%s' from image at "
+						"0x%08lx\n",
+						fit_uname_config, fdt_addr);
+			} else if (fit_parse_subimage(argv[3], default_addr,
+						&fdt_addr, &fit_uname_fdt)) {
+				debug("*  fdt: subimage '%s' from image at "
+						"0x%08lx\n",
+						fit_uname_fdt, fdt_addr);
+			} else
+#endif
+			{
+				fdt_addr = simple_strtoul(argv[3], NULL, 16);
+				debug("*  fdt: cmdline image address = "
+						"0x%08lx\n",
+						fdt_addr);
+			}
+#if defined(CONFIG_FIT)
+		} else {
+			/* use FIT configuration provided in first bootm
+			 * command argument
+			 */
+			fdt_addr = map_to_sysmem(images->fit_hdr_os);
+			fit_uname_config = images->fit_uname_cfg;
+			debug("*  fdt: using config '%s' from image "
+					"at 0x%08lx\n",
+					fit_uname_config, fdt_addr);
+
+			/*
+			 * Check whether configuration has FDT blob defined,
+			 * if not quit silently.
+			 */
+			fit_hdr = images->fit_hdr_os;
+			cfg_noffset = fit_conf_get_node(fit_hdr,
+					fit_uname_config);
+			if (cfg_noffset < 0) {
+				debug("*  fdt: no such config\n");
+				return 0;
+			}
+
+			fdt_noffset = fit_conf_get_fdt_node(fit_hdr,
+					cfg_noffset);
+			if (fdt_noffset < 0) {
+				debug("*  fdt: no fdt in config\n");
+				return 0;
+			}
+		}
+#endif
+
+		debug("## Checking for 'FDT'/'FDT Image' at %08lx\n",
+				fdt_addr);
+
+		/* copy from dataflash if needed */
+		fdt_addr = genimg_get_image(fdt_addr);
+
+		/*
+		 * Check if there is an FDT image@the
+		 * address provided in the second bootm argument
+		 * check image type, for FIT images get a FIT node.
+		 */
+		buf = map_sysmem(fdt_addr, 0);
+		switch (genimg_get_format(buf)) {
+		case IMAGE_FORMAT_LEGACY:
+			/* verify fdt_addr points to a valid image header */
+			printf("## Flattened Device Tree from Legacy Image "
+					"at %08lx\n",
+					fdt_addr);
+			fdt_hdr = image_get_fdt(fdt_addr);
+			if (!fdt_hdr)
+				goto error;
+
+			/*
+			 * move image data to the load address,
+			 * make sure we don't overwrite initial image
+			 */
+			image_start = (ulong)fdt_hdr;
+			image_data = (ulong)image_get_data(fdt_hdr);
+			image_end = image_get_image_end(fdt_hdr);
+
+			load_start = image_get_load(fdt_hdr);
+			load_end = load_start + image_get_data_size(fdt_hdr);
+
+			if (load_start == image_start ||
+			    load_start == image_data) {
+				fdt_blob = (char *)image_data;
+				break;
+			}
+
+			if ((load_start < image_end) &&
+					(load_end > image_start)) {
+				fdt_error("fdt overwritten");
+				goto error;
+			}
+
+			debug("   Loading FDT from 0x%08lx to 0x%08lx\n",
+					image_data, load_start);
+
+			memmove((void *)load_start,
+					(void *)image_data,
+					image_get_data_size(fdt_hdr));
+
+			fdt_blob = (char *)load_start;
+			break;
+		case IMAGE_FORMAT_FIT:
+			/*
+			 * This case will catch both: new uImage format
+			 * (libfdt based) and raw FDT blob (also libfdt
+			 * based).
+			 */
+#if defined(CONFIG_FIT)
+			/* check FDT blob vs FIT blob */
+			if (fit_check_format(buf)) {
+				/*
+				 * FIT image
+				 */
+				fit_hdr = buf;
+				printf("## Flattened Device Tree from FIT "
+						"Image at %08lx\n",
+						fdt_addr);
+
+				if (!fit_uname_fdt) {
+					/*
+					 * no FDT blob image node unit name,
+					 * try to get config node first. If
+					 * config unit node name is NULL
+					 * fit_conf_get_node() will try to
+					 * find default config node
+					 */
+					cfg_noffset = fit_conf_get_node(fit_hdr,
+							fit_uname_config);
+
+					if (cfg_noffset < 0) {
+						fdt_error("Could not find "
+							    "configuration "
+							    "node\n");
+						goto error;
+					}
+
+					fit_uname_config = fdt_get_name(fit_hdr,
+							cfg_noffset, NULL);
+					printf("   Using '%s' configuration\n",
+							fit_uname_config);
+
+					fdt_noffset = fit_conf_get_fdt_node(
+							fit_hdr,
+							cfg_noffset);
+					fit_uname_fdt = fit_get_name(fit_hdr,
+							fdt_noffset, NULL);
+				} else {
+					/*
+					 * get FDT component image node
+					 * offset
+					 */
+					fdt_noffset = fit_image_get_node(
+								fit_hdr,
+								fit_uname_fdt);
+				}
+				if (fdt_noffset < 0) {
+					fdt_error("Could not find subimage "
+							"node\n");
+					goto error;
+				}
+
+				printf("   Trying '%s' FDT blob subimage\n",
+						fit_uname_fdt);
+
+				if (!fit_check_fdt(fit_hdr, fdt_noffset,
+							images->verify))
+					goto error;
+
+				/* get ramdisk image data address and length */
+				if (fit_image_get_data(fit_hdr, fdt_noffset,
+							&data, &size)) {
+					fdt_error("Could not find FDT "
+							"subimage data");
+					goto error;
+				}
+
+				/*
+				 * verify that image data is a proper FDT
+				 * blob
+				 */
+				if (fdt_check_header((char *)data) != 0) {
+					fdt_error("Subimage data is not a FTD");
+					goto error;
+				}
+
+				/*
+				 * move image data to the load address,
+				 * make sure we don't overwrite initial image
+				 */
+				image_start = (ulong)fit_hdr;
+				image_end = fit_get_end(fit_hdr);
+
+				if (fit_image_get_load(fit_hdr, fdt_noffset,
+							&load_start) == 0) {
+					load_end = load_start + size;
+
+					if ((load_start < image_end) &&
+						(load_end > image_start)) {
+						fdt_error("FDT overwritten");
+						goto error;
+					}
+
+					printf("   Loading FDT from 0x%08lx "
+							"to 0x%08lx\n",
+							(ulong)data,
+							load_start);
+
+					memmove((void *)load_start,
+							(void *)data, size);
+
+					fdt_blob = (char *)load_start;
+				} else {
+					fdt_blob = (char *)data;
+				}
+
+				images->fit_hdr_fdt = fit_hdr;
+				images->fit_uname_fdt = fit_uname_fdt;
+				images->fit_noffset_fdt = fdt_noffset;
+				break;
+			} else
+#endif
+			{
+				/*
+				 * FDT blob
+				 */
+				fdt_blob = buf;
+				debug("*  fdt: raw FDT blob\n");
+				printf("## Flattened Device Tree blob at "
+					"%08lx\n", (long)fdt_addr);
+			}
+			break;
+		default:
+			puts("ERROR: Did not find a cmdline Flattened Device "
+				"Tree\n");
+			goto error;
+		}
+
+		printf("   Booting using the fdt blob at 0x%p\n", fdt_blob);
+
+	} else if (images->legacy_hdr_valid &&
+			image_check_type(&images->legacy_hdr_os_copy,
+						IH_TYPE_MULTI)) {
+
+		ulong fdt_data, fdt_len;
+
+		/*
+		 * Now check if we have a legacy multi-component image,
+		 * get second entry data start address and len.
+		 */
+		printf("## Flattened Device Tree from multi "
+			"component Image at %08lX\n",
+			(ulong)images->legacy_hdr_os);
+
+		image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
+					&fdt_len);
+		if (fdt_len) {
+
+			fdt_blob = (char *)fdt_data;
+			printf("   Booting using the fdt at 0x%p\n", fdt_blob);
+
+			if (fdt_check_header(fdt_blob) != 0) {
+				fdt_error("image is not a fdt");
+				goto error;
+			}
+
+			if (fdt_totalsize(fdt_blob) != fdt_len) {
+				fdt_error("fdt size != image size");
+				goto error;
+			}
+		} else {
+			debug("## No Flattened Device Tree\n");
+			return 0;
+		}
+	} else {
+		debug("## No Flattened Device Tree\n");
+		return 0;
+	}
+
+	*of_flat_tree = fdt_blob;
+	*of_size = fdt_totalsize(fdt_blob);
+	debug("   of_flat_tree at 0x%08lx size 0x%08lx\n",
+			(ulong)*of_flat_tree, *of_size);
+
+	return 0;
+
+error:
+	*of_flat_tree = NULL;
+	*of_size = 0;
+	return 1;
+}
diff --git a/common/image.c b/common/image.c
index 88172cc..aa2818e 100644
--- a/common/image.c
+++ b/common/image.c
@@ -1150,572 +1150,6 @@ error:
 }
 #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
 
-#ifdef CONFIG_OF_LIBFDT
-static void fdt_error(const char *msg)
-{
-	puts("ERROR: ");
-	puts(msg);
-	puts(" - must RESET the board to recover.\n");
-}
-
-static const image_header_t *image_get_fdt(ulong fdt_addr)
-{
-	const image_header_t *fdt_hdr = map_sysmem(fdt_addr, 0);
-
-	image_print_contents(fdt_hdr);
-
-	puts("   Verifying Checksum ... ");
-	if (!image_check_hcrc(fdt_hdr)) {
-		fdt_error("fdt header checksum invalid");
-		return NULL;
-	}
-
-	if (!image_check_dcrc(fdt_hdr)) {
-		fdt_error("fdt checksum invalid");
-		return NULL;
-	}
-	puts("OK\n");
-
-	if (!image_check_type(fdt_hdr, IH_TYPE_FLATDT)) {
-		fdt_error("uImage is not a fdt");
-		return NULL;
-	}
-	if (image_get_comp(fdt_hdr) != IH_COMP_NONE) {
-		fdt_error("uImage is compressed");
-		return NULL;
-	}
-	if (fdt_check_header((char *)image_get_data(fdt_hdr)) != 0) {
-		fdt_error("uImage data is not a fdt");
-		return NULL;
-	}
-	return fdt_hdr;
-}
-
-/**
- * fit_check_fdt - verify FIT format FDT subimage
- * @fit_hdr: pointer to the FIT  header
- * fdt_noffset: FDT subimage node offset within FIT image
- * @verify: data CRC verification flag
- *
- * fit_check_fdt() verifies integrity of the FDT subimage and from
- * specified FIT image.
- *
- * returns:
- *     1, on success
- *     0, on failure
- */
-#if defined(CONFIG_FIT)
-static int fit_check_fdt(const void *fit, int fdt_noffset, int verify)
-{
-	fit_image_print(fit, fdt_noffset, "   ");
-
-	if (verify) {
-		puts("   Verifying Hash Integrity ... ");
-		if (!fit_image_verify(fit, fdt_noffset)) {
-			fdt_error("Bad Data Hash");
-			return 0;
-		}
-		puts("OK\n");
-	}
-
-	if (!fit_image_check_type(fit, fdt_noffset, IH_TYPE_FLATDT)) {
-		fdt_error("Not a FDT image");
-		return 0;
-	}
-
-	if (!fit_image_check_comp(fit, fdt_noffset, IH_COMP_NONE)) {
-		fdt_error("FDT image is compressed");
-		return 0;
-	}
-
-	return 1;
-}
-#endif /* CONFIG_FIT */
-
-#ifndef CONFIG_SYS_FDT_PAD
-#define CONFIG_SYS_FDT_PAD 0x3000
-#endif
-
-#if defined(CONFIG_OF_LIBFDT)
-/**
- * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
- * @lmb: pointer to lmb handle, will be used for memory mgmt
- * @fdt_blob: pointer to fdt blob base address
- *
- * Adds the memreserve regions in the dtb to the lmb block.  Adding the
- * memreserve regions prevents u-boot from using them to store the initrd
- * or the fdt blob.
- */
-void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
-{
-	uint64_t addr, size;
-	int i, total;
-
-	if (fdt_check_header(fdt_blob) != 0)
-		return;
-
-	total = fdt_num_mem_rsv(fdt_blob);
-	for (i = 0; i < total; i++) {
-		if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
-			continue;
-		printf("   reserving fdt memory region: addr=%llx size=%llx\n",
-			(unsigned long long)addr, (unsigned long long)size);
-		lmb_reserve(lmb, addr, size);
-	}
-}
-
-/**
- * boot_relocate_fdt - relocate flat device tree
- * @lmb: pointer to lmb handle, will be used for memory mgmt
- * @of_flat_tree: pointer to a char* variable, will hold fdt start address
- * @of_size: pointer to a ulong variable, will hold fdt length
- *
- * boot_relocate_fdt() allocates a region of memory within the bootmap and
- * relocates the of_flat_tree into that region, even if the fdt is already in
- * the bootmap.  It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
- * bytes.
- *
- * of_flat_tree and of_size are set to final (after relocation) values
- *
- * returns:
- *      0 - success
- *      1 - failure
- */
-int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
-{
-	void	*fdt_blob = *of_flat_tree;
-	void	*of_start = NULL;
-	char	*fdt_high;
-	ulong	of_len = 0;
-	int	err;
-	int	disable_relocation = 0;
-
-	/* nothing to do */
-	if (*of_size == 0)
-		return 0;
-
-	if (fdt_check_header(fdt_blob) != 0) {
-		fdt_error("image is not a fdt");
-		goto error;
-	}
-
-	/* position on a 4K boundary before the alloc_current */
-	/* Pad the FDT by a specified amount */
-	of_len = *of_size + CONFIG_SYS_FDT_PAD;
-
-	/* If fdt_high is set use it to select the relocation address */
-	fdt_high = getenv("fdt_high");
-	if (fdt_high) {
-		void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
-
-		if (((ulong) desired_addr) == ~0UL) {
-			/* All ones means use fdt in place */
-			of_start = fdt_blob;
-			lmb_reserve(lmb, (ulong)of_start, of_len);
-			disable_relocation = 1;
-		} else if (desired_addr) {
-			of_start =
-			    (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
-							   (ulong)desired_addr);
-			if (of_start == NULL) {
-				puts("Failed using fdt_high value for Device Tree");
-				goto error;
-			}
-		} else {
-			of_start =
-			    (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
-		}
-	} else {
-		of_start =
-		    (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
-						   getenv_bootm_mapsize()
-						   + getenv_bootm_low());
-	}
-
-	if (of_start == NULL) {
-		puts("device tree - allocation error\n");
-		goto error;
-	}
-
-	if (disable_relocation) {
-		/* We assume there is space after the existing fdt to use for padding */
-		fdt_set_totalsize(of_start, of_len);
-		printf("   Using Device Tree in place at %p, end %p\n",
-		       of_start, of_start + of_len - 1);
-	} else {
-		debug("## device tree@%p ... %p (len=%ld [0x%lX])\n",
-			fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
-
-		printf("   Loading Device Tree to %p, end %p ... ",
-			of_start, of_start + of_len - 1);
-
-		err = fdt_open_into(fdt_blob, of_start, of_len);
-		if (err != 0) {
-			fdt_error("fdt move failed");
-			goto error;
-		}
-		puts("OK\n");
-	}
-
-	*of_flat_tree = of_start;
-	*of_size = of_len;
-
-	set_working_fdt_addr(*of_flat_tree);
-	return 0;
-
-error:
-	return 1;
-}
-#endif /* CONFIG_OF_LIBFDT */
-
-/**
- * boot_get_fdt - main fdt handling routine
- * @argc: command argument count
- * @argv: command argument list
- * @images: pointer to the bootm images structure
- * @of_flat_tree: pointer to a char* variable, will hold fdt start address
- * @of_size: pointer to a ulong variable, will hold fdt length
- *
- * boot_get_fdt() is responsible for finding a valid flat device tree image.
- * Curently supported are the following ramdisk sources:
- *      - multicomponent kernel/ramdisk image,
- *      - commandline provided address of decicated ramdisk image.
- *
- * returns:
- *     0, if fdt image was found and valid, or skipped
- *     of_flat_tree and of_size are set to fdt start address and length if
- *     fdt image is found and valid
- *
- *     1, if fdt image is found but corrupted
- *     of_flat_tree and of_size are set to 0 if no fdt exists
- */
-int boot_get_fdt(int flag, int argc, char * const argv[],
-		bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
-{
-	const image_header_t *fdt_hdr;
-	ulong		fdt_addr;
-	char		*fdt_blob = NULL;
-	ulong		image_start, image_data, image_end;
-	ulong		load_start, load_end;
-	void		*buf;
-#if defined(CONFIG_FIT)
-	void		*fit_hdr;
-	const char	*fit_uname_config = NULL;
-	const char	*fit_uname_fdt = NULL;
-	ulong		default_addr;
-	int		cfg_noffset;
-	int		fdt_noffset;
-	const void	*data;
-	size_t		size;
-#endif
-
-	*of_flat_tree = NULL;
-	*of_size = 0;
-
-	if (argc > 3 || genimg_has_config(images)) {
-#if defined(CONFIG_FIT)
-		if (argc > 3) {
-			/*
-			 * If the FDT blob comes from the FIT image and the
-			 * FIT image address is omitted in the command line
-			 * argument, try to use ramdisk or os FIT image
-			 * address or default load address.
-			 */
-			if (images->fit_uname_rd)
-				default_addr = (ulong)images->fit_hdr_rd;
-			else if (images->fit_uname_os)
-				default_addr = (ulong)images->fit_hdr_os;
-			else
-				default_addr = load_addr;
-
-			if (fit_parse_conf(argv[3], default_addr,
-						&fdt_addr, &fit_uname_config)) {
-				debug("*  fdt: config '%s' from image at "
-						"0x%08lx\n",
-						fit_uname_config, fdt_addr);
-			} else if (fit_parse_subimage(argv[3], default_addr,
-						&fdt_addr, &fit_uname_fdt)) {
-				debug("*  fdt: subimage '%s' from image at "
-						"0x%08lx\n",
-						fit_uname_fdt, fdt_addr);
-			} else
-#endif
-			{
-				fdt_addr = simple_strtoul(argv[3], NULL, 16);
-				debug("*  fdt: cmdline image address = "
-						"0x%08lx\n",
-						fdt_addr);
-			}
-#if defined(CONFIG_FIT)
-		} else {
-			/* use FIT configuration provided in first bootm
-			 * command argument
-			 */
-			fdt_addr = map_to_sysmem(images->fit_hdr_os);
-			fit_uname_config = images->fit_uname_cfg;
-			debug("*  fdt: using config '%s' from image "
-					"at 0x%08lx\n",
-					fit_uname_config, fdt_addr);
-
-			/*
-			 * Check whether configuration has FDT blob defined,
-			 * if not quit silently.
-			 */
-			fit_hdr = images->fit_hdr_os;
-			cfg_noffset = fit_conf_get_node(fit_hdr,
-					fit_uname_config);
-			if (cfg_noffset < 0) {
-				debug("*  fdt: no such config\n");
-				return 0;
-			}
-
-			fdt_noffset = fit_conf_get_fdt_node(fit_hdr,
-					cfg_noffset);
-			if (fdt_noffset < 0) {
-				debug("*  fdt: no fdt in config\n");
-				return 0;
-			}
-		}
-#endif
-
-		debug("## Checking for 'FDT'/'FDT Image' at %08lx\n",
-				fdt_addr);
-
-		/* copy from dataflash if needed */
-		fdt_addr = genimg_get_image(fdt_addr);
-
-		/*
-		 * Check if there is an FDT image@the
-		 * address provided in the second bootm argument
-		 * check image type, for FIT images get a FIT node.
-		 */
-		buf = map_sysmem(fdt_addr, 0);
-		switch (genimg_get_format(buf)) {
-		case IMAGE_FORMAT_LEGACY:
-			/* verify fdt_addr points to a valid image header */
-			printf("## Flattened Device Tree from Legacy Image "
-					"at %08lx\n",
-					fdt_addr);
-			fdt_hdr = image_get_fdt(fdt_addr);
-			if (!fdt_hdr)
-				goto error;
-
-			/*
-			 * move image data to the load address,
-			 * make sure we don't overwrite initial image
-			 */
-			image_start = (ulong)fdt_hdr;
-			image_data = (ulong)image_get_data(fdt_hdr);
-			image_end = image_get_image_end(fdt_hdr);
-
-			load_start = image_get_load(fdt_hdr);
-			load_end = load_start + image_get_data_size(fdt_hdr);
-
-			if (load_start == image_start ||
-			    load_start == image_data) {
-				fdt_blob = (char *)image_data;
-				break;
-			}
-
-			if ((load_start < image_end) && (load_end > image_start)) {
-				fdt_error("fdt overwritten");
-				goto error;
-			}
-
-			debug("   Loading FDT from 0x%08lx to 0x%08lx\n",
-					image_data, load_start);
-
-			memmove((void *)load_start,
-					(void *)image_data,
-					image_get_data_size(fdt_hdr));
-
-			fdt_blob = (char *)load_start;
-			break;
-		case IMAGE_FORMAT_FIT:
-			/*
-			 * This case will catch both: new uImage format
-			 * (libfdt based) and raw FDT blob (also libfdt
-			 * based).
-			 */
-#if defined(CONFIG_FIT)
-			/* check FDT blob vs FIT blob */
-			if (fit_check_format(buf)) {
-				/*
-				 * FIT image
-				 */
-				fit_hdr = buf;
-				printf("## Flattened Device Tree from FIT "
-						"Image at %08lx\n",
-						fdt_addr);
-
-				if (!fit_uname_fdt) {
-					/*
-					 * no FDT blob image node unit name,
-					 * try to get config node first. If
-					 * config unit node name is NULL
-					 * fit_conf_get_node() will try to
-					 * find default config node
-					 */
-					cfg_noffset = fit_conf_get_node(fit_hdr,
-							fit_uname_config);
-
-					if (cfg_noffset < 0) {
-						fdt_error("Could not find "
-							    "configuration "
-							    "node\n");
-						goto error;
-					}
-
-					fit_uname_config = fdt_get_name(fit_hdr,
-							cfg_noffset, NULL);
-					printf("   Using '%s' configuration\n",
-							fit_uname_config);
-
-					fdt_noffset = fit_conf_get_fdt_node(
-							fit_hdr,
-							cfg_noffset);
-					fit_uname_fdt = fit_get_name(fit_hdr,
-							fdt_noffset, NULL);
-				} else {
-					/* get FDT component image node offset */
-					fdt_noffset = fit_image_get_node(
-								fit_hdr,
-								fit_uname_fdt);
-				}
-				if (fdt_noffset < 0) {
-					fdt_error("Could not find subimage "
-							"node\n");
-					goto error;
-				}
-
-				printf("   Trying '%s' FDT blob subimage\n",
-						fit_uname_fdt);
-
-				if (!fit_check_fdt(fit_hdr, fdt_noffset,
-							images->verify))
-					goto error;
-
-				/* get ramdisk image data address and length */
-				if (fit_image_get_data(fit_hdr, fdt_noffset,
-							&data, &size)) {
-					fdt_error("Could not find FDT "
-							"subimage data");
-					goto error;
-				}
-
-				/* verift that image data is a proper FDT blob */
-				if (fdt_check_header((char *)data) != 0) {
-					fdt_error("Subimage data is not a FTD");
-					goto error;
-				}
-
-				/*
-				 * move image data to the load address,
-				 * make sure we don't overwrite initial image
-				 */
-				image_start = (ulong)fit_hdr;
-				image_end = fit_get_end(fit_hdr);
-
-				if (fit_image_get_load(fit_hdr, fdt_noffset,
-							&load_start) == 0) {
-					load_end = load_start + size;
-
-					if ((load_start < image_end) &&
-							(load_end > image_start)) {
-						fdt_error("FDT overwritten");
-						goto error;
-					}
-
-					printf("   Loading FDT from 0x%08lx "
-							"to 0x%08lx\n",
-							(ulong)data,
-							load_start);
-
-					memmove((void *)load_start,
-							(void *)data, size);
-
-					fdt_blob = (char *)load_start;
-				} else {
-					fdt_blob = (char *)data;
-				}
-
-				images->fit_hdr_fdt = fit_hdr;
-				images->fit_uname_fdt = fit_uname_fdt;
-				images->fit_noffset_fdt = fdt_noffset;
-				break;
-			} else
-#endif
-			{
-				/*
-				 * FDT blob
-				 */
-				fdt_blob = buf;
-				debug("*  fdt: raw FDT blob\n");
-				printf("## Flattened Device Tree blob at "
-					"%08lx\n", (long)fdt_addr);
-			}
-			break;
-		default:
-			puts("ERROR: Did not find a cmdline Flattened Device "
-				"Tree\n");
-			goto error;
-		}
-
-		printf("   Booting using the fdt blob at 0x%p\n", fdt_blob);
-
-	} else if (images->legacy_hdr_valid &&
-			image_check_type(&images->legacy_hdr_os_copy,
-						IH_TYPE_MULTI)) {
-
-		ulong fdt_data, fdt_len;
-
-		/*
-		 * Now check if we have a legacy multi-component image,
-		 * get second entry data start address and len.
-		 */
-		printf("## Flattened Device Tree from multi "
-			"component Image at %08lX\n",
-			(ulong)images->legacy_hdr_os);
-
-		image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
-					&fdt_len);
-		if (fdt_len) {
-
-			fdt_blob = (char *)fdt_data;
-			printf("   Booting using the fdt at 0x%p\n", fdt_blob);
-
-			if (fdt_check_header(fdt_blob) != 0) {
-				fdt_error("image is not a fdt");
-				goto error;
-			}
-
-			if (fdt_totalsize(fdt_blob) != fdt_len) {
-				fdt_error("fdt size != image size");
-				goto error;
-			}
-		} else {
-			debug("## No Flattened Device Tree\n");
-			return 0;
-		}
-	} else {
-		debug("## No Flattened Device Tree\n");
-		return 0;
-	}
-
-	*of_flat_tree = fdt_blob;
-	*of_size = fdt_totalsize(fdt_blob);
-	debug("   of_flat_tree at 0x%08lx size 0x%08lx\n",
-			(ulong)*of_flat_tree, *of_size);
-
-	return 0;
-
-error:
-	*of_flat_tree = NULL;
-	*of_size = 0;
-	return 1;
-}
-#endif /* CONFIG_OF_LIBFDT */
-
 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
 /**
  * boot_get_cmdline - allocate and initialize kernel cmdline
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 06/22] image: Add device tree setup to image library
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (4 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 05/22] image: Split libfdt code into image-fdt.c Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 07/22] arm: Refactor bootm to reduce #ifdefs Simon Glass
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

This seems to be a common function for several architectures, so create
a common function rather than duplicating the code in each arch.

Also make an attempt to avoid introducing #ifdefs in the new code, partly
by removing useless #ifdefs around function declarations in the image.h
header.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/image-fdt.c    |   62 +++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c        |   50 +++++++++++++++++++++++++++++++++++++++
 include/common.h      |    9 +++++++
 include/fdt_support.h |    2 -
 include/image.h       |   62 +++++++++++++++++++++++++++++++++++++++++-------
 include/lmb.h         |    2 -
 6 files changed, 174 insertions(+), 13 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index 1c88a16..e317735 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -606,3 +606,65 @@ error:
 	*of_size = 0;
 	return 1;
 }
+
+/*
+ * Verify the device tree.
+ *
+ * This function is called after all device tree fix-ups have been enacted,
+ * so that the final device tree can be verified.  The definition of "verified"
+ * is up to the specific implementation.  However, it generally means that the
+ * addresses of some of the devices in the device tree are compared with the
+ * actual addresses at which U-Boot has placed them.
+ *
+ * Returns 1 on success, 0 on failure.  If 0 is returned, U-boot will halt the
+ * boot process.
+ */
+__weak int ft_verify_fdt(void *fdt)
+{
+	return 1;
+}
+
+__weak int arch_fixup_memory_node(void *blob)
+{
+	return 0;
+}
+
+int image_setup_libfdt(bootm_headers_t *images, void *blob,
+		       int of_size, struct lmb *lmb)
+{
+	ulong *initrd_start = &images->initrd_start;
+	ulong *initrd_end = &images->initrd_end;
+	int ret;
+
+	if (fdt_chosen(blob, 1) < 0) {
+		puts("ERROR: /chosen node create failed");
+		puts(" - must RESET the board to recover.\n");
+		return -1;
+	}
+	arch_fixup_memory_node(blob);
+	if (IMAAGE_OF_BOARD_SETUP)
+		ft_board_setup(blob, gd->bd);
+	fdt_fixup_ethernet(blob);
+
+	/* Delete the old LMB reservation */
+	lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
+			(phys_size_t)fdt_totalsize(blob));
+
+	ret = fdt_resize(blob);
+	if (ret < 0)
+		return ret;
+	of_size = ret;
+
+	if (*initrd_start && *initrd_end) {
+		of_size += FDT_RAMDISK_OVERHEAD;
+		fdt_set_totalsize(blob, of_size);
+	}
+	/* Create a new LMB reservation */
+	lmb_reserve(lmb, (ulong)blob, of_size);
+
+	fdt_initrd(blob, *initrd_start, *initrd_end, 1);
+	if (!ft_verify_fdt(blob))
+		return -1;
+
+	return 0;
+}
diff --git a/common/image.c b/common/image.c
index aa2818e..a5bae46 100644
--- a/common/image.c
+++ b/common/image.c
@@ -71,6 +71,10 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
 
 #include <u-boot/crc.h>
 
+#ifndef CONFIG_SYS_BARGSIZE
+#define CONFIG_SYS_BARGSIZE 512
+#endif
+
 static const table_entry_t uimage_arch[] = {
 	{	IH_ARCH_INVALID,	NULL,		"Invalid ARCH",	},
 	{	IH_ARCH_ALPHA,		"alpha",	"Alpha",	},
@@ -1223,4 +1227,50 @@ int boot_get_kbd(struct lmb *lmb, bd_t **kbd)
 	return 0;
 }
 #endif /* CONFIG_SYS_BOOT_GET_KBD */
+
+#ifdef CONFIG_LMB
+int image_setup_linux(bootm_headers_t *images)
+{
+	ulong of_size = images->ft_len;
+	char **of_flat_tree = &images->ft_addr;
+	ulong *initrd_start = &images->initrd_start;
+	ulong *initrd_end = &images->initrd_end;
+	struct lmb *lmb = &images->lmb;
+	ulong rd_len;
+	int ret;
+
+	if (IMAGE_ENABLE_OF_LIBFDT)
+		boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
+
+	if (IMAGE_BOOT_GET_CMDLINE) {
+		ret = boot_get_cmdline(lmb, &images->cmdline_start,
+				&images->cmdline_end);
+		if (ret) {
+			puts("ERROR with allocation of cmdline\n");
+			return ret;
+		}
+	}
+	if (IMAGE_ENABLE_RAMDISK_HIGH) {
+		rd_len = images->rd_end - images->rd_start;
+		ret = boot_ramdisk_high(lmb, images->rd_start, rd_len,
+				initrd_start, initrd_end);
+		if (ret)
+			return ret;
+	}
+
+	if (IMAGE_ENABLE_OF_LIBFDT) {
+		ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
+		if (ret)
+			return ret;
+	}
+
+	if (IMAGE_ENABLE_OF_LIBFDT && of_size) {
+		ret = image_setup_libfdt(images, *of_flat_tree, of_size, lmb);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+#endif /* CONFIG_LMB */
 #endif /* !USE_HOSTCC */
diff --git a/include/common.h b/include/common.h
index a25f4a8..3fbebaf 100644
--- a/include/common.h
+++ b/include/common.h
@@ -312,6 +312,15 @@ int mac_read_from_eeprom(void);
 extern u8 _binary_dt_dtb_start[];	/* embedded device tree blob */
 int set_cpu_clk_info(void);
 
+/* arch/$(ARCH)/lib/bootm.c */
+/**
+ * arch_fixup_memory_node() - Write arch-specific memory information to fdt
+ *
+ * @blob	FDT blob to write to
+ * @return 0 if ok, or -ve FDT_ERR_... on failure
+ */
+int arch_fixup_memory_node(void *blob);
+
 /* common/flash.c */
 void flash_perror (int);
 
diff --git a/include/fdt_support.h b/include/fdt_support.h
index 4b9f84a..71ac168 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -78,11 +78,9 @@ static inline void fdt_fixup_crypto_node(void *blob, int sec_rev) {}
 int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose);
 #endif
 
-#ifdef CONFIG_OF_BOARD_SETUP
 void ft_board_setup(void *blob, bd_t *bd);
 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);
 int fdt_resize(void *blob);
diff --git a/include/image.h b/include/image.h
index 589c949..6e7baf9 100644
--- a/include/image.h
+++ b/include/image.h
@@ -36,6 +36,9 @@
 #include "compiler.h"
 #include <asm/byteorder.h>
 
+/* Define this to avoid #ifdefs later on */
+struct lmb;
+
 #ifdef USE_HOSTCC
 
 /* new uImage format support enabled on host */
@@ -66,6 +69,31 @@
 #define CONFIG_SHA1		/* and SHA1 */
 #endif
 
+#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
+#define IMAGE_ENABLE_RAMDISK_HIGH	1
+#else
+#define IMAGE_ENABLE_RAMDISK_HIGH	0
+#endif
+
+#ifdef CONFIG_OF_LIBFDT
+# define IMAGE_ENABLE_OF_LIBFDT	1
+#else
+# define IMAGE_ENABLE_OF_LIBFDT	0
+
+#endif
+
+#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
+#define IMAGE_BOOT_GET_CMDLINE		1
+#else
+#define IMAGE_BOOT_GET_CMDLINE		0
+#endif
+
+#ifdef CONFIG_OF_BOARD_SETUP
+#define IMAAGE_OF_BOARD_SETUP		1
+#else
+#define IMAAGE_OF_BOARD_SETUP		0
+#endif
+
 /*
  * Operating System Codes
  */
@@ -248,9 +276,7 @@ typedef struct bootm_headers {
 
 	ulong		rd_start, rd_end;/* ramdisk start/end */
 
-#ifdef CONFIG_OF_LIBFDT
 	char		*ft_addr;	/* flat dev tree address */
-#endif
 	ulong		ft_len;		/* length of flat device tree */
 
 	ulong		initrd_start;
@@ -358,21 +384,14 @@ ulong genimg_get_image(ulong img_addr);
 int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
 		uint8_t arch, ulong *rd_start, ulong *rd_end);
 
-
-#ifdef CONFIG_OF_LIBFDT
 int boot_get_fdt(int flag, int argc, char * const argv[],
 		bootm_headers_t *images, char **of_flat_tree, ulong *of_size);
 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
 int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
-#endif
 
-#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
 int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
 		  ulong *initrd_start, ulong *initrd_end);
-#endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
-#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
 int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
-#endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
 #ifdef CONFIG_SYS_BOOT_GET_KBD
 int boot_get_kbd(struct lmb *lmb, bd_t **kbd);
 #endif /* CONFIG_SYS_BOOT_GET_KBD */
@@ -514,6 +533,31 @@ static inline int image_check_target_arch(const image_header_t *hdr)
 }
 #endif /* USE_HOSTCC */
 
+/**
+ * Set up properties in the FDT
+ *
+ * This sets up properties in the FDT that is to be passed to linux.
+ *
+ * @images:	Images information
+ * @blob:	FDT to update
+ * @of_size:	Size of the FDT
+ * @lmb:	Points to logical memory block structure
+ * @return 0 if ok, <0 on failure
+ */
+int image_setup_libfdt(bootm_headers_t *images, void *blob,
+		       int of_size, struct lmb *lmb);
+
+/**
+ * Set up the FDT to use for booting a kernel
+ *
+ * This performs ramdisk setup, sets up the FDT if required, and adds
+ * paramters to the FDT if libfdt is available.
+ *
+ * @param images	Images information
+ * @return 0 if ok, <0 on failure
+ */
+int image_setup_linux(bootm_headers_t *images);
+
 /*******************************************************************/
 /* New uImage format specific code (prefixed with fit_) */
 /*******************************************************************/
diff --git a/include/lmb.h b/include/lmb.h
index 5d1f4b6..43082a3 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -1,7 +1,6 @@
 #ifndef _LINUX_LMB_H
 #define _LINUX_LMB_H
 #ifdef __KERNEL__
-#ifdef CONFIG_LMB
 
 #include <asm/types.h>
 /*
@@ -57,7 +56,6 @@ lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
 void board_lmb_reserve(struct lmb *lmb);
 void arch_lmb_reserve(struct lmb *lmb);
 
-#endif /* CONFIG_LMB */
 #endif /* __KERNEL__ */
 
 #endif /* _LINUX_LMB_H */
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 07/22] arm: Refactor bootm to reduce #ifdefs
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (5 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 06/22] image: Add device tree setup to image library Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-11 11:10   ` Marek Vasut
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 08/22] arm: Use image_setup_linux() instead of local code Simon Glass
                   ` (15 subsequent siblings)
  22 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

With fewer #ifdefs the code is more readable and more of the code is
compiled for all boards. Add defines in the header file to control
what features are enabled, and then use if() instead of #ifdef.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/arm/include/asm/bootm.h      |   54 +++++++++++++++++++++++-
 arch/arm/include/asm/u-boot-arm.h |    2 -
 arch/arm/lib/bootm.c              |   83 ++++++++----------------------------
 3 files changed, 71 insertions(+), 68 deletions(-)

diff --git a/arch/arm/include/asm/bootm.h b/arch/arm/include/asm/bootm.h
index db2ff94..2c4fa19 100644
--- a/arch/arm/include/asm/bootm.h
+++ b/arch/arm/include/asm/bootm.h
@@ -1,4 +1,7 @@
-/* Copyright (C) 2011
+/*
+ * Copyright (c) 2013, Google Inc.
+ *
+ * Copyright (C) 2011
  * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -19,8 +22,55 @@
 #ifndef ARM_BOOTM_H
 #define ARM_BOOTM_H
 
-#ifdef CONFIG_USB_DEVICE
 extern void udc_disconnect(void);
+
+#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
+		defined(CONFIG_CMDLINE_TAG) || \
+		defined(CONFIG_INITRD_TAG) || \
+		defined(CONFIG_SERIAL_TAG) || \
+		defined(CONFIG_REVISION_TAG)
+# define BOOTM_ENABLE_TAGS		1
+#else
+# define BOOTM_ENABLE_TAGS		0
+#endif
+
+#ifdef CONFIG_SETUP_MEMORY_TAGS
+# define BOOTM_ENABLE_MEMORY_TAGS	1
+#else
+# define BOOTM_ENABLE_MEMORY_TAGS	0
+#endif
+
+#ifdef CONFIG_CMDLINE_TAG
+ #define BOOTM_ENABLE_CMDLINE_TAG	1
+#else
+ #define BOOTM_ENABLE_CMDLINE_TAG	0
+#endif
+
+#ifdef CONFIG_INITRD_TAG
+ #define BOOTM_ENABLE_INITRD_TAG	1
+#else
+ #define BOOTM_ENABLE_INITRD_TAG	0
+#endif
+
+#ifdef CONFIG_SERIAL_TAG
+ #define BOOTM_ENABLE_SERIAL_TAG	1
+void get_board_serial(struct tag_serialnr *serialnr);
+#else
+ #define BOOTM_ENABLE_SERIAL_TAG	0
+static inline void get_board_serial(struct tag_serialnr *serialnr)
+{
+}
+#endif
+
+#ifdef CONFIG_REVISION_TAG
+ #define BOOTM_ENABLE_REVISION_TAG	1
+u32 get_board_rev(void);
+#else
+ #define BOOTM_ENABLE_REVISION_TAG	0
+static inline u32 get_board_rev(void)
+{
+	return 0;
+}
 #endif
 
 #endif
diff --git a/arch/arm/include/asm/u-boot-arm.h b/arch/arm/include/asm/u-boot-arm.h
index 9f3cae5..9032c13 100644
--- a/arch/arm/include/asm/u-boot-arm.h
+++ b/arch/arm/include/asm/u-boot-arm.h
@@ -58,8 +58,6 @@ int	arch_early_init_r(void);
 int	board_init(void);
 int	dram_init (void);
 void	dram_init_banksize (void);
-void	setup_serial_tag (struct tag **params);
-void	setup_revision_tag (struct tag **params);
 
 /* cpu/.../interrupt.c */
 int	arch_interrupt_init	(void);
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 1bd2730..78fc013 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -38,13 +38,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
-	defined(CONFIG_CMDLINE_TAG) || \
-	defined(CONFIG_INITRD_TAG) || \
-	defined(CONFIG_SERIAL_TAG) || \
-	defined(CONFIG_REVISION_TAG)
 static struct tag *params;
-#endif
 
 static ulong get_sp(void)
 {
@@ -110,11 +104,6 @@ static void announce_and_cleanup(void)
 	cleanup_before_linux();
 }
 
-#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
-	defined(CONFIG_CMDLINE_TAG) || \
-	defined(CONFIG_INITRD_TAG) || \
-	defined(CONFIG_SERIAL_TAG) || \
-	defined(CONFIG_REVISION_TAG)
 static void setup_start_tag (bd_t *bd)
 {
 	params = (struct tag *)bd->bi_boot_params;
@@ -128,9 +117,7 @@ static void setup_start_tag (bd_t *bd)
 
 	params = tag_next (params);
 }
-#endif
 
-#ifdef CONFIG_SETUP_MEMORY_TAGS
 static void setup_memory_tags(bd_t *bd)
 {
 	int i;
@@ -145,9 +132,7 @@ static void setup_memory_tags(bd_t *bd)
 		params = tag_next (params);
 	}
 }
-#endif
 
-#ifdef CONFIG_CMDLINE_TAG
 static void setup_commandline_tag(bd_t *bd, char *commandline)
 {
 	char *p;
@@ -172,9 +157,7 @@ static void setup_commandline_tag(bd_t *bd, char *commandline)
 
 	params = tag_next (params);
 }
-#endif
 
-#ifdef CONFIG_INITRD_TAG
 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
 {
 	/* an ATAG_INITRD node tells the kernel where the compressed
@@ -188,14 +171,11 @@ static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
 
 	params = tag_next (params);
 }
-#endif
 
-#ifdef CONFIG_SERIAL_TAG
-void setup_serial_tag(struct tag **tmp)
+static void setup_serial_tag(struct tag **tmp)
 {
 	struct tag *params = *tmp;
 	struct tag_serialnr serialnr;
-	void get_board_serial(struct tag_serialnr *serialnr);
 
 	get_board_serial(&serialnr);
 	params->hdr.tag = ATAG_SERIAL;
@@ -205,13 +185,10 @@ void setup_serial_tag(struct tag **tmp)
 	params = tag_next (params);
 	*tmp = params;
 }
-#endif
 
-#ifdef CONFIG_REVISION_TAG
-void setup_revision_tag(struct tag **in_params)
+static void setup_revision_tag(struct tag **in_params)
 {
 	u32 rev = 0;
-	u32 get_board_rev(void);
 
 	rev = get_board_rev();
 	params->hdr.tag = ATAG_REVISION;
@@ -219,19 +196,12 @@ void setup_revision_tag(struct tag **in_params)
 	params->u.revision.rev = rev;
 	params = tag_next (params);
 }
-#endif
 
-#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
-	defined(CONFIG_CMDLINE_TAG) || \
-	defined(CONFIG_INITRD_TAG) || \
-	defined(CONFIG_SERIAL_TAG) || \
-	defined(CONFIG_REVISION_TAG)
 static void setup_end_tag(bd_t *bd)
 {
 	params->hdr.tag = ATAG_NONE;
 	params->hdr.size = 0;
 }
-#endif
 
 #ifdef CONFIG_OF_LIBFDT
 static int create_fdt(bootm_headers_t *images)
@@ -275,50 +245,37 @@ __weak void setup_board_tags(struct tag **in_params) {}
 /* Subcommand: PREP */
 static void boot_prep_linux(bootm_headers_t *images)
 {
-#ifdef CONFIG_CMDLINE_TAG
 	char *commandline = getenv("bootargs");
-#endif
 
+	if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
 #ifdef CONFIG_OF_LIBFDT
-	if (images->ft_len) {
 		debug("using: FDT\n");
 		if (create_fdt(images)) {
 			printf("FDT creation failed! hanging...");
 			hang();
 		}
-	} else
 #endif
-	{
-#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
-	defined(CONFIG_CMDLINE_TAG) || \
-	defined(CONFIG_INITRD_TAG) || \
-	defined(CONFIG_SERIAL_TAG) || \
-	defined(CONFIG_REVISION_TAG)
+	} else if (BOOTM_ENABLE_TAGS) {
 		debug("using: ATAGS\n");
 		setup_start_tag(gd->bd);
-#ifdef CONFIG_SERIAL_TAG
-		setup_serial_tag(&params);
-#endif
-#ifdef CONFIG_CMDLINE_TAG
-		setup_commandline_tag(gd->bd, commandline);
-#endif
-#ifdef CONFIG_REVISION_TAG
-		setup_revision_tag(&params);
-#endif
-#ifdef CONFIG_SETUP_MEMORY_TAGS
-		setup_memory_tags(gd->bd);
-#endif
-#ifdef CONFIG_INITRD_TAG
-		if (images->rd_start && images->rd_end)
-			setup_initrd_tag(gd->bd, images->rd_start,
-			images->rd_end);
-#endif
+		if (BOOTM_ENABLE_SERIAL_TAG)
+			setup_serial_tag(&params);
+		if (BOOTM_ENABLE_CMDLINE_TAG)
+			setup_commandline_tag(gd->bd, commandline);
+		if (BOOTM_ENABLE_REVISION_TAG)
+			setup_revision_tag(&params);
+		if (BOOTM_ENABLE_MEMORY_TAGS)
+			setup_memory_tags(gd->bd);
+		if (BOOTM_ENABLE_INITRD_TAG) {
+			if (images->rd_start && images->rd_end)
+				setup_initrd_tag(gd->bd, images->rd_start,
+				images->rd_end);
+		}
 		setup_board_tags(&params);
 		setup_end_tag(gd->bd);
-#else /* all tags */
+	} else {
 		printf("FDT and ATAGS support not compiled in - hanging\n");
 		hang();
-#endif /* all tags */
 	}
 }
 
@@ -343,11 +300,9 @@ static void boot_jump_linux(bootm_headers_t *images)
 	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
 	announce_and_cleanup();
 
-#ifdef CONFIG_OF_LIBFDT
-	if (images->ft_len)
+	if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
 		r2 = (unsigned long)images->ft_addr;
 	else
-#endif
 		r2 = gd->bd->bi_boot_params;
 
 	kernel_entry(0, machid, r2);
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 08/22] arm: Use image_setup_linux() instead of local code
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (6 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 07/22] arm: Refactor bootm to reduce #ifdefs Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-11 11:11   ` Marek Vasut
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 09/22] powerpc: " Simon Glass
                   ` (14 subsequent siblings)
  22 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Use the common FDT setup function that is now available in image. Move
the FDT-specific code to a new bootm-fdt.c and remove unused headers
from bootm.c.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/arm/lib/Makefile    |    1 +
 arch/arm/lib/bootm-fdt.c |   52 ++++++++++++++++++++++++++++++++++++++
 arch/arm/lib/bootm.c     |   62 +---------------------------------------------
 3 files changed, 54 insertions(+), 61 deletions(-)
 create mode 100644 arch/arm/lib/bootm-fdt.c

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 3422ac1..eca8964 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -39,6 +39,7 @@ GLCOBJS	+= div0.o
 ifndef CONFIG_SPL_BUILD
 COBJS-y	+= board.o
 COBJS-y	+= bootm.o
+COBJS-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
 COBJS-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
 COBJS-y	+= interrupts.o
 COBJS-y	+= reset.o
diff --git a/arch/arm/lib/bootm-fdt.c b/arch/arm/lib/bootm-fdt.c
new file mode 100644
index 0000000..93888f8
--- /dev/null
+++ b/arch/arm/lib/bootm-fdt.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013, Google Inc.
+ *
+ * Copyright (C) 2011
+ * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
+ *  - Added prep subcommand support
+ *  - Reorganized source - modeled after powerpc version
+ *
+ * (C) Copyright 2002
+ * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
+ * Marius Groeger <mgroeger@sysgo.de>
+ *
+ * Copyright (C) 2001  Erik Mouw (J.A.K.Mouw at its.tudelft.nl)
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <fdt_support.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int arch_fixup_memory_node(void *blob)
+{
+	bd_t *bd = gd->bd;
+	int bank;
+	u64 start[CONFIG_NR_DRAM_BANKS];
+	u64 size[CONFIG_NR_DRAM_BANKS];
+
+	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
+		start[bank] = bd->bi_dram[bank].start;
+		size[bank] = bd->bi_dram[bank].size;
+	}
+
+	return fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
+}
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 78fc013..0b7a5bb 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -22,17 +22,11 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307	 USA
- *
  */
 
 #include <common.h>
 #include <command.h>
 #include <image.h>
-#include <u-boot/zlib.h>
-#include <asm/byteorder.h>
-#include <fdt.h>
-#include <libfdt.h>
-#include <fdt_support.h>
 #include <asm/bootm.h>
 #include <linux/compiler.h>
 
@@ -70,23 +64,6 @@ void arch_lmb_reserve(struct lmb *lmb)
 		    gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size - sp);
 }
 
-#ifdef CONFIG_OF_LIBFDT
-static int fixup_memory_node(void *blob)
-{
-	bd_t	*bd = gd->bd;
-	int bank;
-	u64 start[CONFIG_NR_DRAM_BANKS];
-	u64 size[CONFIG_NR_DRAM_BANKS];
-
-	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-		start[bank] = bd->bi_dram[bank].start;
-		size[bank] = bd->bi_dram[bank].size;
-	}
-
-	return fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
-}
-#endif
-
 static void announce_and_cleanup(void)
 {
 	printf("\nStarting kernel ...\n\n");
@@ -203,43 +180,6 @@ static void setup_end_tag(bd_t *bd)
 	params->hdr.size = 0;
 }
 
-#ifdef CONFIG_OF_LIBFDT
-static int create_fdt(bootm_headers_t *images)
-{
-	ulong of_size = images->ft_len;
-	char **of_flat_tree = &images->ft_addr;
-	ulong *initrd_start = &images->initrd_start;
-	ulong *initrd_end = &images->initrd_end;
-	struct lmb *lmb = &images->lmb;
-	ulong rd_len;
-	int ret;
-
-	debug("using: FDT\n");
-
-	boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
-
-	rd_len = images->rd_end - images->rd_start;
-	ret = boot_ramdisk_high(lmb, images->rd_start, rd_len,
-			initrd_start, initrd_end);
-	if (ret)
-		return ret;
-
-	ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
-	if (ret)
-		return ret;
-
-	fdt_chosen(*of_flat_tree, 1);
-	fixup_memory_node(*of_flat_tree);
-	fdt_fixup_ethernet(*of_flat_tree);
-	fdt_initrd(*of_flat_tree, *initrd_start, *initrd_end, 1);
-#ifdef CONFIG_OF_BOARD_SETUP
-	ft_board_setup(*of_flat_tree, gd->bd);
-#endif
-
-	return 0;
-}
-#endif
-
 __weak void setup_board_tags(struct tag **in_params) {}
 
 /* Subcommand: PREP */
@@ -250,7 +190,7 @@ static void boot_prep_linux(bootm_headers_t *images)
 	if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
 #ifdef CONFIG_OF_LIBFDT
 		debug("using: FDT\n");
-		if (create_fdt(images)) {
+		if (image_setup_linux(images)) {
 			printf("FDT creation failed! hanging...");
 			hang();
 		}
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 09/22] powerpc: Use image_setup_linux() instead of local code
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (7 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 08/22] arm: Use image_setup_linux() instead of local code Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-11 11:11   ` Marek Vasut
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 10/22] m68k: " Simon Glass
                   ` (13 subsequent siblings)
  22 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Rather than having similar code in powerpc, use image_setup_linux() which
should be common across all architectures that use the FDT.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/powerpc/lib/bootm.c |   84 +---------------------------------------------
 1 files changed, 1 insertions(+), 83 deletions(-)

diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c
index 7088293..3091af7 100644
--- a/arch/powerpc/lib/bootm.c
+++ b/arch/powerpc/lib/bootm.c
@@ -222,101 +222,19 @@ static int boot_bd_t_linux(bootm_headers_t *images)
 	return ret;
 }
 
-/*
- * Verify the device tree.
- *
- * This function is called after all device tree fix-ups have been enacted,
- * so that the final device tree can be verified.  The definition of "verified"
- * is up to the specific implementation.  However, it generally means that the
- * addresses of some of the devices in the device tree are compared with the
- * actual addresses at which U-Boot has placed them.
- *
- * Returns 1 on success, 0 on failure.  If 0 is returned, U-boot will halt the
- * boot process.
- */
-static int __ft_verify_fdt(void *fdt)
-{
-	return 1;
-}
-__attribute__((weak, alias("__ft_verify_fdt"))) int ft_verify_fdt(void *fdt);
-
 static int boot_body_linux(bootm_headers_t *images)
 {
-	ulong rd_len;
-	struct lmb *lmb = &images->lmb;
-	ulong *initrd_start = &images->initrd_start;
-	ulong *initrd_end = &images->initrd_end;
-#if defined(CONFIG_OF_LIBFDT)
-	ulong of_size = images->ft_len;
-	char **of_flat_tree = &images->ft_addr;
-#endif
-
 	int ret;
 
-#if defined(CONFIG_OF_LIBFDT)
-	boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
-#endif
-
-	/* allocate space and init command line */
-	ret = boot_cmdline_linux(images);
-	if (ret)
-		return ret;
-
 	/* allocate space for kernel copy of board info */
 	ret = boot_bd_t_linux(images);
 	if (ret)
 		return ret;
 
-	rd_len = images->rd_end - images->rd_start;
-	ret = boot_ramdisk_high (lmb, images->rd_start, rd_len, initrd_start, initrd_end);
-	if (ret)
-		return ret;
-
-#if defined(CONFIG_OF_LIBFDT)
-	ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
+	ret = image_setup_linux(images);
 	if (ret)
 		return ret;
 
-	/*
-	 * Add the chosen node if it doesn't exist, add the env and bd_t
-	 * if the user wants it (the logic is in the subroutines).
-	 */
-	if (of_size) {
-		if (fdt_chosen(*of_flat_tree, 1) < 0) {
-			puts ("ERROR: ");
-			puts ("/chosen node create failed");
-			puts (" - must RESET the board to recover.\n");
-			return -1;
-		}
-#ifdef CONFIG_OF_BOARD_SETUP
-		/* Call the board-specific fixup routine */
-		ft_board_setup(*of_flat_tree, gd->bd);
-#endif
-
-		/* Delete the old LMB reservation */
-		lmb_free(lmb, (phys_addr_t)(u32)*of_flat_tree,
-				(phys_size_t)fdt_totalsize(*of_flat_tree));
-
-		ret = fdt_resize(*of_flat_tree);
-		if (ret < 0)
-			return ret;
-		of_size = ret;
-
-		if (*initrd_start && *initrd_end) {
-			of_size += FDT_RAMDISK_OVERHEAD;
-			fdt_set_totalsize(*of_flat_tree, of_size);
-		}
-		/* Create a new LMB reservation */
-		lmb_reserve(lmb, (ulong)*of_flat_tree, of_size);
-
-		/* fixup the initrd now that we know where it should be */
-		if (*initrd_start && *initrd_end)
-			fdt_initrd(*of_flat_tree, *initrd_start, *initrd_end, 1);
-
-		if (!ft_verify_fdt(*of_flat_tree))
-			return -1;
-	}
-#endif	/* CONFIG_OF_LIBFDT */
 	return 0;
 }
 
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 10/22] m68k: Use image_setup_linux() instead of local code
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (8 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 09/22] powerpc: " Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-11 11:11   ` Marek Vasut
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 11/22] sparc: " Simon Glass
                   ` (12 subsequent siblings)
  22 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Rather than having similar code in m68k, use image_setup_linux() which
should be common across all architectures that use the FDT.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/m68k/lib/bootm.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c
index d506d0c..56b6512 100644
--- a/arch/m68k/lib/bootm.c
+++ b/arch/m68k/lib/bootm.c
@@ -78,13 +78,6 @@ int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *ima
 	if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
 		return 1;
 
-	/* allocate space and init command line */
-	ret = boot_get_cmdline (lmb, &cmd_start, &cmd_end);
-	if (ret) {
-		puts("ERROR with allocation of cmdline\n");
-		goto error;
-	}
-
 	/* allocate space for kernel copy of board info */
 	ret = boot_get_kbd (lmb, &kbd);
 	if (ret) {
@@ -93,14 +86,12 @@ int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *ima
 	}
 	set_clocks_in_mhz(kbd);
 
-	kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
-
-	rd_len = images->rd_end - images->rd_start;
-	ret = boot_ramdisk_high (lmb, images->rd_start, rd_len,
-			&initrd_start, &initrd_end);
+	ret = image_setup_linux(images);
 	if (ret)
 		goto error;
 
+	kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
+
 	debug("## Transferring control to Linux (at address %08lx) ...\n",
 	      (ulong) kernel);
 
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 11/22] sparc: Use image_setup_linux() instead of local code
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (9 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 10/22] m68k: " Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 12/22] bootstage: Introduce sub-IDs for use with image loading Simon Glass
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Sparc only really sets up the ramdisk, but we should still use
image_setup_linux() so that setup is common across all architectures
that use the FDT.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/sparc/lib/bootm.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/sparc/lib/bootm.c b/arch/sparc/lib/bootm.c
index bcc6358..472f9ac 100644
--- a/arch/sparc/lib/bootm.c
+++ b/arch/sparc/lib/bootm.c
@@ -131,17 +131,16 @@ int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * im
 	 * extracted and is writeable.
 	 */
 
+	ret = image_setup_boot(images);
+	if (ret) {
+		puts("### Failed to relocate RAM disk\n");
+		goto error;
+	}
+
 	/* Calc length of RAM disk, if zero no ramdisk available */
 	rd_len = images->rd_end - images->rd_start;
 
 	if (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");
-			goto error;
-		}
-
 		/* Update SPARC kernel header so that Linux knows
 		 * what is going on and where to find RAM disk.
 		 *
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 12/22] bootstage: Introduce sub-IDs for use with image loading
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (10 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 11/22] sparc: " Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 13/22] mkimage: Add map_sysmem() and IH_ARCH_DEFAULT to simplfy building Simon Glass
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Loading a ramdisk, kernel or FDT goes through similar stages. Create
a block of IDs for each task, and define a consistent numbering within
the block. This will allow use of common code for image loading.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 include/bootstage.h |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/include/bootstage.h b/include/bootstage.h
index 08bf2b0..f577ba8 100644
--- a/include/bootstage.h
+++ b/include/bootstage.h
@@ -37,6 +37,24 @@ enum bootstage_flags {
 	BOOTSTAGEF_ALLOC	= 1 << 1,	/* Allocate an id */
 };
 
+/* bootstate sub-IDs used for kernel and ramdisk ranges */
+enum {
+	BOOTSTAGE_SUB_FORMAT,
+	BOOTSTAGE_SUB_FORMAT_OK,
+	BOOTSTAGE_SUB_NO_UNIT_NAME,
+	BOOTSTAGE_SUB_UNIT_NAME,
+	BOOTSTAGE_SUB_SUBNODE,
+
+	BOOTSTAGE_SUB_CHECK,
+	BOOTSTAGE_SUB_HASH = 5,
+	BOOTSTAGE_SUB_CHECK_ARCH = 5,
+	BOOTSTAGE_SUB_CHECK_ALL,
+	BOOTSTAGE_SUB_GET_DATA,
+	BOOTSTAGE_SUB_CHECK_ALL_OK = 7,
+	BOOTSTAGE_SUB_GET_DATA_OK,
+	BOOTSTAGE_SUB_LOAD,
+};
+
 /*
  * A list of boot stages that we know about. Each of these indicates the
  * state that we are at, and the action that we are about to perform. For
@@ -137,10 +155,12 @@ enum bootstage_id {
 	BOOTSTAGE_ID_NET_DONE_ERR,
 	BOOTSTAGE_ID_NET_DONE,
 
+	BOOTSTAGE_ID_FIT_FDT_START = 90,
 	/*
 	 * Boot stages related to loading a FIT image. Some of these are a
 	 * bit wonky.
 	 */
+	BOOTSTAGE_ID_FIT_KERNEL_START = 100,
 	BOOTSTAGE_ID_FIT_FORMAT = 100,
 	BOOTSTAGE_ID_FIT_NO_UNIT_NAME,
 	BOOTSTAGE_ID_FIT_UNIT_NAME,
@@ -161,6 +181,8 @@ enum bootstage_id {
 	BOOTSTAGE_ID_FIT_LOADADDR,
 	BOOTSTAGE_ID_OVERWRITTEN,
 
+	/* Next 10 IDs used by BOOTSTAGE_SUB_... */
+	BOOTSTAGE_ID_FIT_RD_START = 120,	/* Ramdisk stages */
 	BOOTSTAGE_ID_FIT_RD_FORMAT = 120,
 	BOOTSTAGE_ID_FIT_RD_FORMAT_OK,
 	BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME,
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 13/22] mkimage: Add map_sysmem() and IH_ARCH_DEFAULT to simplfy building
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (11 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 12/22] bootstage: Introduce sub-IDs for use with image loading Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 14/22] image: Introduce fit_image_load() to load images from FITs Simon Glass
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

These are not actually used in mkimage itself, but the image code (which
is common with mkimage) does use them. To avoid #ifdefs in the image code
just for mkimage, define dummy version of these here. The compiler will
eliminate the dead code anyway.

A better way to handle this might be to split out more things from common.h
so that mkimage can include them. At present any file that mkimage uses
has to be very careful what headers it includes.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 tools/mkimage.h |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/tools/mkimage.h b/tools/mkimage.h
index d82be17..1d9984e 100644
--- a/tools/mkimage.h
+++ b/tools/mkimage.h
@@ -44,12 +44,24 @@
 
 #define ARRAY_SIZE(x)		(sizeof(x) / sizeof((x)[0]))
 
+static inline void *map_sysmem(ulong paddr, unsigned long len)
+{
+	return (void *)(uintptr_t)paddr;
+}
+
+static inline ulong map_to_sysmem(void *ptr)
+{
+	return (ulong)(uintptr_t)ptr;
+}
+
 #define MKIMAGE_TMPFILE_SUFFIX		".tmp"
 #define MKIMAGE_MAX_TMPFILE_LEN		256
 #define MKIMAGE_DEFAULT_DTC_OPTIONS	"-I dts -O dtb -p 500"
 #define MKIMAGE_MAX_DTC_CMDLINE_LEN	512
 #define MKIMAGE_DTC			"dtc"   /* assume dtc is in $PATH */
 
+#define IH_ARCH_DEFAULT		IH_ARCH_INVALID
+
 /*
  * This structure defines all such variables those are initialized by
  * mkimage main core and need to be referred by image type specific
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 14/22] image: Introduce fit_image_load() to load images from FITs
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (12 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 13/22] mkimage: Add map_sysmem() and IH_ARCH_DEFAULT to simplfy building Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 15/22] image: Use fit_image_load() to load ramdisk Simon Glass
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

At present code to load an image from a FIT is duplicated in the three
places where it is needed (kernel, fdt, ramdisk).

The differences between these different code copies is fairly minor.
Create a new function in the fit code which can handle any of the
requirements of those cases.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/image-fit.c |  221 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/image.h    |   77 ++++++++++++++++++-
 2 files changed, 296 insertions(+), 2 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 9f17924..ef736f3 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -32,6 +32,7 @@
 #else
 #include <common.h>
 #include <errno.h>
+#include <asm/io.h>
 DECLARE_GLOBAL_DATA_PTR;
 #endif /* !USE_HOSTCC*/
 
@@ -1491,6 +1492,22 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
 		printf("%s  FDT:          %s\n", p, uname);
 }
 
+int fit_image_select(const void *fit, int rd_noffset, int verify)
+{
+	fit_image_print(fit, rd_noffset, "   ");
+
+	if (verify) {
+		puts("   Verifying Hash Integrity ... ");
+		if (!fit_image_verify(fit, rd_noffset)) {
+			puts("Bad Data Hash\n");
+			return -EACCES;
+		}
+		puts("OK\n");
+	}
+
+	return 0;
+}
+
 /**
  * fit_check_ramdisk - verify FIT format ramdisk subimage
  * @fit_hdr: pointer to the FIT ramdisk header
@@ -1533,3 +1550,207 @@ int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
 	bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK);
 	return 1;
 }
+
+int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
+			ulong addr)
+{
+	int cfg_noffset;
+	void *fit_hdr;
+	int noffset;
+
+	debug("*  %s: using config '%s' from image at 0x%08lx\n",
+	      prop_name, images->fit_uname_cfg, addr);
+
+	/* Check whether configuration has this property defined */
+	fit_hdr = map_sysmem(addr, 0);
+	cfg_noffset = fit_conf_get_node(fit_hdr, images->fit_uname_cfg);
+	if (cfg_noffset < 0) {
+		debug("*  %s: no such config\n", prop_name);
+		return -ENOENT;
+	}
+
+	noffset = fit_conf_get_prop_node(fit_hdr, cfg_noffset, prop_name);
+	if (noffset < 0) {
+		debug("*  %s: no %s in config\n", prop_name, prop_name);
+		return -ENOLINK;
+	}
+
+	return noffset;
+}
+
+int fit_image_load(bootm_headers_t *images, const char *prop_name, ulong addr,
+		   const char **fit_unamep, const char *fit_uname_config,
+		   int arch, int image_type, int bootstage_id,
+		   enum fit_load_op load_op, ulong *datap, ulong *lenp)
+{
+	int cfg_noffset, noffset;
+	const char *fit_uname;
+	const void *fit;
+	const void *buf;
+	size_t size;
+	int type_ok, os_ok;
+	ulong load, data, len;
+	int ret;
+
+	fit = map_sysmem(addr, 0);
+	fit_uname = fit_unamep ? *fit_unamep : NULL;
+	printf("## Loading %s from FIT Image@%08lx ...\n", prop_name, addr);
+
+	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_FORMAT);
+	if (!fit_check_format(fit)) {
+		printf("Bad FIT %s image format!\n", prop_name);
+		bootstage_error(bootstage_id + BOOTSTAGE_SUB_FORMAT);
+		return -ENOEXEC;
+	}
+	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_FORMAT_OK);
+	if (fit_uname) {
+		/* get ramdisk component image node offset */
+		bootstage_mark(bootstage_id + BOOTSTAGE_SUB_UNIT_NAME);
+		noffset = fit_image_get_node(fit, fit_uname);
+	} else {
+		/*
+		 * no image node unit name, try to get config
+		 * node first. If config unit node name is NULL
+		 * fit_conf_get_node() will try to find default config node
+		 */
+		bootstage_mark(bootstage_id + BOOTSTAGE_SUB_NO_UNIT_NAME);
+		if (IMAGE_ENABLE_BEST_MATCH && !fit_uname_config) {
+			cfg_noffset = fit_conf_find_compat(fit, gd_fdt_blob());
+		} else {
+			cfg_noffset = fit_conf_get_node(fit,
+							fit_uname_config);
+		}
+		if (cfg_noffset < 0) {
+			puts("Could not find configuration node\n");
+			bootstage_error(bootstage_id +
+					BOOTSTAGE_SUB_NO_UNIT_NAME);
+			return -ENOENT;
+		}
+		fit_uname_config = fdt_get_name(fit, cfg_noffset, NULL);
+		printf("   Using '%s' configuration\n", fit_uname_config);
+		if (image_type == IH_TYPE_KERNEL) {
+			/* Remember (and possibly verify) this config */
+			images->fit_uname_cfg = fit_uname_config;
+			if (IMAGE_ENABLE_VERIFY && images->verify) {
+				puts("   Verifying Hash Integrity ... ");
+				if (!fit_config_verify(fit, cfg_noffset)) {
+					puts("Bad Data Hash\n");
+					bootstage_error(bootstage_id +
+						BOOTSTAGE_SUB_HASH);
+					return -EACCES;
+				}
+				puts("OK\n");
+			}
+			bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
+		}
+
+		noffset = fit_conf_get_prop_node(fit, cfg_noffset,
+						 prop_name);
+		fit_uname = fit_get_name(fit, noffset, NULL);
+	}
+	if (noffset < 0) {
+		puts("Could not find subimage node\n");
+		bootstage_error(bootstage_id + BOOTSTAGE_SUB_SUBNODE);
+		return -ENOENT;
+	}
+
+	printf("   Trying '%s' %s subimage\n", fit_uname, prop_name);
+
+	ret = fit_image_select(fit, noffset, images->verify);
+	if (ret) {
+		bootstage_error(bootstage_id + BOOTSTAGE_SUB_HASH);
+		return ret;
+	}
+
+	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH);
+	if (!fit_image_check_target_arch(fit, noffset)) {
+		puts("Unsupported Architecture\n");
+		bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH);
+		return -ENOEXEC;
+	}
+
+	if (image_type == IH_TYPE_FLATDT &&
+			!fit_image_check_comp(fit, noffset, IH_COMP_NONE)) {
+		puts("FDT image is compressed");
+		return -EPROTONOSUPPORT;
+	}
+
+	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL);
+	type_ok = fit_image_check_type(fit, noffset, image_type) ||
+		(image_type == IH_TYPE_KERNEL &&
+			fit_image_check_type(fit, noffset,
+					     IH_TYPE_KERNEL_NOLOAD));
+	os_ok = image_type == IH_TYPE_FLATDT ||
+		fit_image_check_os(fit, noffset, IH_OS_LINUX);
+	if (!type_ok || !os_ok) {
+		printf("No Linux %s %s Image\n", genimg_get_arch_name(arch),
+			genimg_get_type_name(image_type));
+		bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL);
+		return -EIO;
+	}
+
+	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL_OK);
+
+	/* get image data address and length */
+	if (fit_image_get_data(fit, noffset, &buf, &size)) {
+		printf("Could not find %s subimage data!\n", prop_name);
+		bootstage_error(bootstage_id + BOOTSTAGE_SUB_GET_DATA);
+		return -ENOMEDIUM;
+	}
+	len = (ulong)size;
+
+	/* verify that image data is a proper FDT blob */
+	if (image_type == IH_TYPE_FLATDT &&
+			fdt_check_header((char *)buf)) {
+		puts("Subimage data is not a FDT");
+		return -ENOEXEC;
+	}
+
+	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_GET_DATA_OK);
+
+	data = map_to_sysmem((char *)buf);
+
+	if (load_op == FIT_LOAD_IGNORED) {
+		/* Don't load */
+	} else if (fit_image_get_load(fit, noffset, &load)) {
+		if (load_op == FIT_LOAD_REQUIRED) {
+			printf("Can't get %s subimage load address!\n",
+			       prop_name);
+			bootstage_error(bootstage_id + BOOTSTAGE_SUB_LOAD);
+			return -EBADF;
+		}
+	} else {
+		ulong image_start, image_end;
+		ulong load_end;
+		void *dst;
+
+		/*
+		 * move image data to the load address,
+		 * make sure we don't overwrite initial image
+		 */
+		image_start = addr;
+		image_end = addr + fit_get_size(fit);
+
+		load_end = load + len;
+		if (image_type != IH_TYPE_KERNEL &&
+				load < image_end && load_end > image_start) {
+			printf("Error: %s overwritten\n", prop_name);
+			return -EXDEV;
+		}
+
+		printf("   Loading %s from 0x%08lx to 0x%08lx\n",
+			prop_name, data, load);
+
+		dst = map_sysmem(load, len);
+		memmove(dst, buf, len);
+		data = load;
+	}
+	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_LOAD);
+
+	*datap = data;
+	*lenp = len;
+	if (fit_unamep)
+		*fit_unamep = (char *)fit_uname;
+
+	return noffset;
+}
diff --git a/include/image.h b/include/image.h
index 6e7baf9..2546cd9 100644
--- a/include/image.h
+++ b/include/image.h
@@ -371,6 +371,13 @@ void genimg_print_size(uint32_t size);
 #endif
 void genimg_print_time(time_t timestamp);
 
+/* What to do with a image load address ('load = <> 'in the FIT) */
+enum fit_load_op {
+	FIT_LOAD_IGNORED,	/* Ignore load address */
+	FIT_LOAD_OPTIONAL,	/* Can be provided, but optional */
+	FIT_LOAD_REQUIRED,	/* Must be provided */
+};
+
 #ifndef USE_HOSTCC
 /* Image format types, returned by _get_format() routine */
 #define IMAGE_FORMAT_INVALID	0x00
@@ -384,6 +391,68 @@ ulong genimg_get_image(ulong img_addr);
 int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
 		uint8_t arch, ulong *rd_start, ulong *rd_end);
 
+/**
+ * fit_image_load() - load an image from a FIT
+ *
+ * This deals with all aspects of loading an image from a FIT, including
+ * selecting the right image based on configuration, verifying it, printing
+ * out progress messages, checking the type/arch/os and optionally copying it
+ * to the right load address.
+ *
+ * @param images	Boot images structure
+ * @param prop_name	Property name to look up (FIT_..._PROP)
+ * @param addr		Address of FIT in memory
+ * @param fit_unamep	On entry this is the requested image name
+ *			(e.g. "kernel at 1") or NULL to use the default. On exit
+ *			points to the selected image name
+ * @param fit_uname_config	Requested configuration name, or NULL for the
+ *			default
+ * @param arch		Expected architecture (IH_ARCH_...)
+ * @param image_type	Required image type (IH_TYPE_...). If this is
+ *			IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD
+ *			also.
+ * @param bootstage_id	ID of starting bootstage to use for progress updates.
+ *			This will be added to the BOOTSTAGE_SUB values when
+ *			calling bootstage_mark()
+ * @param load_op	Decribes what to do with the load address
+ * @param datap		Returns address of loaded image
+ * @param lenp		Returns length of loaded image
+ */
+int fit_image_load(bootm_headers_t *images, const char *prop_name, ulong addr,
+		   const char **fit_unamep, const char *fit_uname_config,
+		   int arch, int image_type, int bootstage_id,
+		   enum fit_load_op load_op, ulong *datap, ulong *lenp);
+
+/**
+ * fit_get_node_from_config() - Look up an image a FIT by type
+ *
+ * This looks in the selected conf@ node (images->fit_uname_cfg) for a
+ * particular image type (e.g. "kernel") and then finds the image that is
+ * referred to.
+ *
+ * For example, for something like:
+ *
+ * images {
+ *	kernel at 1 {
+ *		...
+ *	};
+ * };
+ * configurations {
+ *	conf at 1 {
+ *		kernel = "kernel at 1";
+ *	};
+ * };
+ *
+ * the function will return the node offset of the kernel at 1 node, assuming
+ * that conf at 1 is the chosen configuration.
+ *
+ * @param images	Boot images structure
+ * @param prop_name	Property name to look up (FIT_..._PROP)
+ * @param addr		Address of FIT in memory
+ */
+int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
+			ulong addr);
+
 int boot_get_fdt(int flag, int argc, char * const argv[],
 		bootm_headers_t *images, char **of_flat_tree, ulong *of_size);
 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
@@ -744,6 +813,12 @@ int calculate_hash(const void *data, int data_len, const char *algo,
 # endif
 #endif
 
+#ifdef CONFIG_FIT_BEST_MATCH
+#define IMAGE_ENABLE_BEST_MATCH	1
+#else
+#define IMAGE_ENABLE_BEST_MATCH	10
+#endif
+
 /* Information passed to the signing routines */
 struct image_sign_info {
 	const char *keydir;		/* Directory conaining keys */
@@ -873,12 +948,10 @@ int fit_image_check_sig(const void *fit, int noffset, const void *data,
 struct image_region *fit_region_make_list(const void *fit,
 		struct fdt_region *fdt_regions, int count);
 
-#ifndef USE_HOSTCC
 static inline int fit_image_check_target_arch(const void *fdt, int node)
 {
 	return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
 }
-#endif /* USE_HOSTCC */
 
 #ifdef CONFIG_FIT_VERBOSE
 #define fit_unsupported(msg)	printf("! %s:%d " \
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 15/22] image: Use fit_image_load() to load ramdisk
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (13 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 14/22] image: Introduce fit_image_load() to load images from FITs Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 16/22] image: Use fit_image_load() to load FDT Simon Glass
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Use the new common code to load a ramdisk. The functionality should not
change.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/image-fit.c |   62 --------------------------
 common/image.c     |  122 +++++++---------------------------------------------
 include/image.h    |    1 -
 3 files changed, 16 insertions(+), 169 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index ef736f3..84462ec 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1412,25 +1412,6 @@ int fit_conf_get_kernel_node(const void *fit, int noffset)
 }
 
 /**
- * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
- * a given configuration
- * @fit: pointer to the FIT format image header
- * @noffset: configuration node offset
- *
- * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
- * configuration FIT_KERNEL_PROP property and translates it to the node
- * offset.
- *
- * returns:
- *     image node offset when found (>=0)
- *     negative number on failure (FDT_ERR_* code)
- */
-int fit_conf_get_ramdisk_node(const void *fit, int noffset)
-{
-	return fit_conf_get_prop_node(fit, noffset, FIT_RAMDISK_PROP);
-}
-
-/**
  * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
  * a given configuration
  * @fit: pointer to the FIT format image header
@@ -1508,49 +1489,6 @@ int fit_image_select(const void *fit, int rd_noffset, int verify)
 	return 0;
 }
 
-/**
- * fit_check_ramdisk - verify FIT format ramdisk subimage
- * @fit_hdr: pointer to the FIT ramdisk header
- * @rd_noffset: ramdisk subimage node offset within FIT image
- * @arch: requested ramdisk image architecture type
- * @verify: data CRC verification flag
- *
- * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
- * specified FIT image.
- *
- * returns:
- *     1, on success
- *     0, on failure
- */
-int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
-			int verify)
-{
-	fit_image_print(fit, rd_noffset, "   ");
-
-	if (verify) {
-		puts("   Verifying Hash Integrity ... ");
-		if (!fit_image_verify(fit, rd_noffset)) {
-			puts("Bad Data Hash\n");
-			bootstage_error(BOOTSTAGE_ID_FIT_RD_HASH);
-			return 0;
-		}
-		puts("OK\n");
-	}
-
-	bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
-	if (!fit_image_check_os(fit, rd_noffset, IH_OS_LINUX) ||
-	    !fit_image_check_arch(fit, rd_noffset, arch) ||
-	    !fit_image_check_type(fit, rd_noffset, IH_TYPE_RAMDISK)) {
-		printf("No Linux %s Ramdisk Image\n",
-				genimg_get_arch_name(arch));
-		bootstage_error(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
-		return 0;
-	}
-
-	bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK);
-	return 1;
-}
-
 int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
 			ulong addr)
 {
diff --git a/common/image.c b/common/image.c
index a5bae46..26b9653 100644
--- a/common/image.c
+++ b/common/image.c
@@ -52,6 +52,7 @@
 
 #include <u-boot/md5.h>
 #include <sha1.h>
+#include <asm/errno.h>
 #include <asm/io.h>
 
 #ifdef CONFIG_CMD_BDI
@@ -810,14 +811,10 @@ int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
 	char *end;
 #endif
 #if defined(CONFIG_FIT)
-	void		*fit_hdr;
 	const char	*fit_uname_config = NULL;
 	const char	*fit_uname_ramdisk = NULL;
 	ulong		default_addr;
 	int		rd_noffset;
-	int		cfg_noffset;
-	const void	*data;
-	size_t		size;
 #endif
 
 	*rd_start = 0;
@@ -865,32 +862,16 @@ int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
 #if defined(CONFIG_FIT)
 		} else {
 			/* use FIT configuration provided in first bootm
-			 * command argument
+			 * command argument. If the property is not defined,
+			 * quit silently.
 			 */
 			rd_addr = map_to_sysmem(images->fit_hdr_os);
-			fit_uname_config = images->fit_uname_cfg;
-			debug("*  ramdisk: using config '%s' from image "
-					"at 0x%08lx\n",
-					fit_uname_config, rd_addr);
-
-			/*
-			 * Check whether configuration has ramdisk defined,
-			 * if not, don't try to use it, quit silently.
-			 */
-			fit_hdr = images->fit_hdr_os;
-			cfg_noffset = fit_conf_get_node(fit_hdr,
-							fit_uname_config);
-			if (cfg_noffset < 0) {
-				debug("*  ramdisk: no such config\n");
-				return 1;
-			}
-
-			rd_noffset = fit_conf_get_ramdisk_node(fit_hdr,
-								cfg_noffset);
-			if (rd_noffset < 0) {
-				debug("*  ramdisk: no ramdisk in config\n");
+			rd_noffset = fit_get_node_from_config(images,
+					FIT_RAMDISK_PROP, rd_addr);
+			if (rd_noffset == -ENOLINK)
 				return 0;
-			}
+			else if (rd_noffset < 0)
+				return 1;
 		}
 #endif
 
@@ -921,87 +902,16 @@ int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
 			break;
 #if defined(CONFIG_FIT)
 		case IMAGE_FORMAT_FIT:
-			fit_hdr = buf;
-			printf("## Loading init Ramdisk from FIT "
-					"Image@%08lx ...\n", rd_addr);
-
-			bootstage_mark(BOOTSTAGE_ID_FIT_RD_FORMAT);
-			if (!fit_check_format(fit_hdr)) {
-				puts("Bad FIT ramdisk image format!\n");
-				bootstage_error(
-					BOOTSTAGE_ID_FIT_RD_FORMAT);
+			rd_noffset = fit_image_load(images, FIT_RAMDISK_PROP,
+					rd_addr, &fit_uname_ramdisk,
+					fit_uname_config, arch,
+					IH_TYPE_RAMDISK,
+					BOOTSTAGE_ID_FIT_RD_START,
+					FIT_LOAD_REQUIRED, &rd_data, &rd_len);
+			if (rd_noffset < 0)
 				return 1;
-			}
-			bootstage_mark(BOOTSTAGE_ID_FIT_RD_FORMAT_OK);
-
-			if (!fit_uname_ramdisk) {
-				/*
-				 * no ramdisk image node unit name, try to get config
-				 * node first. If config unit node name is NULL
-				 * fit_conf_get_node() will try to find default config node
-				 */
-				bootstage_mark(
-					BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME);
-				cfg_noffset = fit_conf_get_node(fit_hdr,
-							fit_uname_config);
-				if (cfg_noffset < 0) {
-					puts("Could not find configuration "
-						"node\n");
-					bootstage_error(
-					BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME);
-					return 1;
-				}
-				fit_uname_config = fdt_get_name(fit_hdr,
-							cfg_noffset, NULL);
-				printf("   Using '%s' configuration\n",
-					fit_uname_config);
-
-				rd_noffset = fit_conf_get_ramdisk_node(fit_hdr,
-							cfg_noffset);
-				fit_uname_ramdisk = fit_get_name(fit_hdr,
-							rd_noffset, NULL);
-			} else {
-				/* get ramdisk component image node offset */
-				bootstage_mark(
-					BOOTSTAGE_ID_FIT_RD_UNIT_NAME);
-				rd_noffset = fit_image_get_node(fit_hdr,
-						fit_uname_ramdisk);
-			}
-			if (rd_noffset < 0) {
-				puts("Could not find subimage node\n");
-				bootstage_error(BOOTSTAGE_ID_FIT_RD_SUBNODE);
-				return 1;
-			}
-
-			printf("   Trying '%s' ramdisk subimage\n",
-				fit_uname_ramdisk);
-
-			bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK);
-			if (!fit_check_ramdisk(fit_hdr, rd_noffset, arch,
-						images->verify))
-				return 1;
-
-			/* get ramdisk image data address and length */
-			if (fit_image_get_data(fit_hdr, rd_noffset, &data,
-						&size)) {
-				puts("Could not find ramdisk subimage data!\n");
-				bootstage_error(BOOTSTAGE_ID_FIT_RD_GET_DATA);
-				return 1;
-			}
-			bootstage_mark(BOOTSTAGE_ID_FIT_RD_GET_DATA_OK);
-
-			rd_data = (ulong)data;
-			rd_len = size;
-
-			if (fit_image_get_load(fit_hdr, rd_noffset, &rd_load)) {
-				puts("Can't get ramdisk subimage load "
-					"address!\n");
-				bootstage_error(BOOTSTAGE_ID_FIT_RD_LOAD);
-				return 1;
-			}
-			bootstage_mark(BOOTSTAGE_ID_FIT_RD_LOAD);
 
-			images->fit_hdr_rd = fit_hdr;
+			images->fit_hdr_rd = map_sysmem(rd_addr, 0);
 			images->fit_uname_rd = fit_uname_ramdisk;
 			images->fit_noffset_rd = rd_noffset;
 			break;
diff --git a/include/image.h b/include/image.h
index 2546cd9..5357fe3 100644
--- a/include/image.h
+++ b/include/image.h
@@ -761,7 +761,6 @@ int fit_check_format(const void *fit);
 int fit_conf_find_compat(const void *fit, const void *fdt);
 int fit_conf_get_node(const void *fit, const char *conf_uname);
 int fit_conf_get_kernel_node(const void *fit, int noffset);
-int fit_conf_get_ramdisk_node(const void *fit, int noffset);
 int fit_conf_get_fdt_node(const void *fit, int noffset);
 
 /**
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 16/22] image: Use fit_image_load() to load FDT
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (14 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 15/22] image: Use fit_image_load() to load ramdisk Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 17/22] sandbox: Adjust bootm command to work with sandbox Simon Glass
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Use the new common code to load a flat device tree. Also fix up a few casts
so that this code works with sandbox. Other than that the functionality
should not change.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/cmd_bootm.c |    4 +-
 common/image-fdt.c |  214 +++++++---------------------------------------------
 common/image-fit.c |   19 -----
 include/image.h    |    6 +-
 4 files changed, 33 insertions(+), 210 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index d71ffb5..33320cb 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -295,7 +295,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 
 #if defined(CONFIG_OF_LIBFDT)
 		/* find flattened device tree */
-		ret = boot_get_fdt(flag, argc, argv, &images,
+		ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
 				   &images.ft_addr, &images.ft_len);
 		if (ret) {
 			puts("Could not find a valid device tree\n");
@@ -1609,7 +1609,7 @@ static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
 
 #if defined(CONFIG_OF_LIBFDT)
 	/* find flattened device tree */
-	ret = boot_get_fdt(flag, argc, argv, images,
+	ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, images,
 			   &images->ft_addr, &images->ft_len);
 	if (ret) {
 		puts("Could not find a valid device tree\n");
diff --git a/common/image-fdt.c b/common/image-fdt.c
index e317735..d4bcad8 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -212,51 +212,11 @@ error:
 	return 1;
 }
 
-#if defined(CONFIG_FIT)
-/**
- * fit_check_fdt - verify FIT format FDT subimage
- * @fit_hdr: pointer to the FIT  header
- * fdt_noffset: FDT subimage node offset within FIT image
- * @verify: data CRC verification flag
- *
- * fit_check_fdt() verifies integrity of the FDT subimage and from
- * specified FIT image.
- *
- * returns:
- *     1, on success
- *     0, on failure
- */
-static int fit_check_fdt(const void *fit, int fdt_noffset, int verify)
-{
-	fit_image_print(fit, fdt_noffset, "   ");
-
-	if (verify) {
-		puts("   Verifying Hash Integrity ... ");
-		if (!fit_image_verify(fit, fdt_noffset)) {
-			fdt_error("Bad Data Hash");
-			return 0;
-		}
-		puts("OK\n");
-	}
-
-	if (!fit_image_check_type(fit, fdt_noffset, IH_TYPE_FLATDT)) {
-		fdt_error("Not a FDT image");
-		return 0;
-	}
-
-	if (!fit_image_check_comp(fit, fdt_noffset, IH_COMP_NONE)) {
-		fdt_error("FDT image is compressed");
-		return 0;
-	}
-
-	return 1;
-}
-#endif
-
 /**
  * boot_get_fdt - main fdt handling routine
  * @argc: command argument count
  * @argv: command argument list
+ * @arch: architecture (IH_ARCH_...)
  * @images: pointer to the bootm images structure
  * @of_flat_tree: pointer to a char* variable, will hold fdt start address
  * @of_size: pointer to a ulong variable, will hold fdt length
@@ -274,24 +234,20 @@ static int fit_check_fdt(const void *fit, int fdt_noffset, int verify)
  *     1, if fdt image is found but corrupted
  *     of_flat_tree and of_size are set to 0 if no fdt exists
  */
-int boot_get_fdt(int flag, int argc, char * const argv[],
+int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 		bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
 {
 	const image_header_t *fdt_hdr;
 	ulong		fdt_addr;
 	char		*fdt_blob = NULL;
 	ulong		image_start, image_data, image_end;
-	ulong		load_start, load_end;
+	ulong		load, load_end;
 	void		*buf;
 #if defined(CONFIG_FIT)
-	void		*fit_hdr;
 	const char	*fit_uname_config = NULL;
 	const char	*fit_uname_fdt = NULL;
 	ulong		default_addr;
-	int		cfg_noffset;
 	int		fdt_noffset;
-	const void	*data;
-	size_t		size;
 #endif
 
 	*of_flat_tree = NULL;
@@ -337,32 +293,14 @@ int boot_get_fdt(int flag, int argc, char * const argv[],
 			 * command argument
 			 */
 			fdt_addr = map_to_sysmem(images->fit_hdr_os);
-			fit_uname_config = images->fit_uname_cfg;
-			debug("*  fdt: using config '%s' from image "
-					"at 0x%08lx\n",
-					fit_uname_config, fdt_addr);
-
-			/*
-			 * Check whether configuration has FDT blob defined,
-			 * if not quit silently.
-			 */
-			fit_hdr = images->fit_hdr_os;
-			cfg_noffset = fit_conf_get_node(fit_hdr,
-					fit_uname_config);
-			if (cfg_noffset < 0) {
-				debug("*  fdt: no such config\n");
-				return 0;
-			}
-
-			fdt_noffset = fit_conf_get_fdt_node(fit_hdr,
-					cfg_noffset);
-			if (fdt_noffset < 0) {
-				debug("*  fdt: no fdt in config\n");
+			fdt_noffset = fit_get_node_from_config(images,
+					FIT_FDT_PROP, fdt_addr);
+			if (fdt_noffset == -ENOLINK)
 				return 0;
-			}
+			else if (fdt_noffset < 0)
+				return 1;
 		}
 #endif
-
 		debug("## Checking for 'FDT'/'FDT Image'@%08lx\n",
 				fdt_addr);
 
@@ -393,29 +331,28 @@ int boot_get_fdt(int flag, int argc, char * const argv[],
 			image_data = (ulong)image_get_data(fdt_hdr);
 			image_end = image_get_image_end(fdt_hdr);
 
-			load_start = image_get_load(fdt_hdr);
-			load_end = load_start + image_get_data_size(fdt_hdr);
+			load = image_get_load(fdt_hdr);
+			load_end = load + image_get_data_size(fdt_hdr);
 
-			if (load_start == image_start ||
-			    load_start == image_data) {
+			if (load == image_start ||
+			    load == image_data) {
 				fdt_blob = (char *)image_data;
 				break;
 			}
 
-			if ((load_start < image_end) &&
-					(load_end > image_start)) {
+			if ((load < image_end) && (load_end > image_start)) {
 				fdt_error("fdt overwritten");
 				goto error;
 			}
 
 			debug("   Loading FDT from 0x%08lx to 0x%08lx\n",
-					image_data, load_start);
+					image_data, load);
 
-			memmove((void *)load_start,
+			memmove((void *)load,
 					(void *)image_data,
 					image_get_data_size(fdt_hdr));
 
-			fdt_blob = (char *)load_start;
+			fdt_addr = load;
 			break;
 		case IMAGE_FORMAT_FIT:
 			/*
@@ -426,114 +363,20 @@ int boot_get_fdt(int flag, int argc, char * const argv[],
 #if defined(CONFIG_FIT)
 			/* check FDT blob vs FIT blob */
 			if (fit_check_format(buf)) {
-				/*
-				 * FIT image
-				 */
-				fit_hdr = buf;
-				printf("## Flattened Device Tree from FIT "
-						"Image at %08lx\n",
-						fdt_addr);
+				ulong load, len;
 
-				if (!fit_uname_fdt) {
-					/*
-					 * no FDT blob image node unit name,
-					 * try to get config node first. If
-					 * config unit node name is NULL
-					 * fit_conf_get_node() will try to
-					 * find default config node
-					 */
-					cfg_noffset = fit_conf_get_node(fit_hdr,
-							fit_uname_config);
-
-					if (cfg_noffset < 0) {
-						fdt_error("Could not find "
-							    "configuration "
-							    "node\n");
-						goto error;
-					}
-
-					fit_uname_config = fdt_get_name(fit_hdr,
-							cfg_noffset, NULL);
-					printf("   Using '%s' configuration\n",
-							fit_uname_config);
-
-					fdt_noffset = fit_conf_get_fdt_node(
-							fit_hdr,
-							cfg_noffset);
-					fit_uname_fdt = fit_get_name(fit_hdr,
-							fdt_noffset, NULL);
-				} else {
-					/*
-					 * get FDT component image node
-					 * offset
-					 */
-					fdt_noffset = fit_image_get_node(
-								fit_hdr,
-								fit_uname_fdt);
-				}
-				if (fdt_noffset < 0) {
-					fdt_error("Could not find subimage "
-							"node\n");
-					goto error;
-				}
-
-				printf("   Trying '%s' FDT blob subimage\n",
-						fit_uname_fdt);
-
-				if (!fit_check_fdt(fit_hdr, fdt_noffset,
-							images->verify))
-					goto error;
-
-				/* get ramdisk image data address and length */
-				if (fit_image_get_data(fit_hdr, fdt_noffset,
-							&data, &size)) {
-					fdt_error("Could not find FDT "
-							"subimage data");
-					goto error;
-				}
+				fdt_noffset = fit_image_load(images,
+					FIT_FDT_PROP,
+					fdt_addr, &fit_uname_fdt,
+					fit_uname_config,
+					arch, IH_TYPE_FLATDT,
+					BOOTSTAGE_ID_FIT_FDT_START,
+					FIT_LOAD_OPTIONAL, &load, &len);
 
-				/*
-				 * verify that image data is a proper FDT
-				 * blob
-				 */
-				if (fdt_check_header((char *)data) != 0) {
-					fdt_error("Subimage data is not a FTD");
-					goto error;
-				}
-
-				/*
-				 * move image data to the load address,
-				 * make sure we don't overwrite initial image
-				 */
-				image_start = (ulong)fit_hdr;
-				image_end = fit_get_end(fit_hdr);
-
-				if (fit_image_get_load(fit_hdr, fdt_noffset,
-							&load_start) == 0) {
-					load_end = load_start + size;
-
-					if ((load_start < image_end) &&
-						(load_end > image_start)) {
-						fdt_error("FDT overwritten");
-						goto error;
-					}
-
-					printf("   Loading FDT from 0x%08lx "
-							"to 0x%08lx\n",
-							(ulong)data,
-							load_start);
-
-					memmove((void *)load_start,
-							(void *)data, size);
-
-					fdt_blob = (char *)load_start;
-				} else {
-					fdt_blob = (char *)data;
-				}
-
-				images->fit_hdr_fdt = fit_hdr;
+				images->fit_hdr_fdt = map_sysmem(fdt_addr, 0);
 				images->fit_uname_fdt = fit_uname_fdt;
 				images->fit_noffset_fdt = fdt_noffset;
+				fdt_addr = load;
 				break;
 			} else
 #endif
@@ -541,7 +384,6 @@ int boot_get_fdt(int flag, int argc, char * const argv[],
 				/*
 				 * FDT blob
 				 */
-				fdt_blob = buf;
 				debug("*  fdt: raw FDT blob\n");
 				printf("## Flattened Device Tree blob at "
 					"%08lx\n", (long)fdt_addr);
@@ -553,8 +395,8 @@ int boot_get_fdt(int flag, int argc, char * const argv[],
 			goto error;
 		}
 
-		printf("   Booting using the fdt blob at 0x%p\n", fdt_blob);
-
+		printf("   Booting using the fdt blob at %#08lx\n", fdt_addr);
+		fdt_blob = map_sysmem(fdt_addr, 0);
 	} else if (images->legacy_hdr_valid &&
 			image_check_type(&images->legacy_hdr_os_copy,
 						IH_TYPE_MULTI)) {
diff --git a/common/image-fit.c b/common/image-fit.c
index 84462ec..5d07861 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1412,25 +1412,6 @@ int fit_conf_get_kernel_node(const void *fit, int noffset)
 }
 
 /**
- * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
- * a given configuration
- * @fit: pointer to the FIT format image header
- * @noffset: configuration node offset
- *
- * fit_conf_get_fdt_node() retrives fdt image node unit name from
- * configuration FIT_KERNEL_PROP property and translates it to the node
- * offset.
- *
- * returns:
- *     image node offset when found (>=0)
- *     negative number on failure (FDT_ERR_* code)
- */
-int fit_conf_get_fdt_node(const void *fit, int noffset)
-{
-	return fit_conf_get_prop_node(fit, noffset, FIT_FDT_PROP);
-}
-
-/**
  * fit_conf_print - prints out the FIT configuration details
  * @fit: pointer to the FIT format image header
  * @noffset: offset of the configuration node
diff --git a/include/image.h b/include/image.h
index 5357fe3..e19a92d 100644
--- a/include/image.h
+++ b/include/image.h
@@ -453,8 +453,9 @@ int fit_image_load(bootm_headers_t *images, const char *prop_name, ulong addr,
 int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
 			ulong addr);
 
-int boot_get_fdt(int flag, int argc, char * const argv[],
-		bootm_headers_t *images, char **of_flat_tree, ulong *of_size);
+int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
+		 bootm_headers_t *images,
+		 char **of_flat_tree, ulong *of_size);
 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
 int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
 
@@ -761,7 +762,6 @@ int fit_check_format(const void *fit);
 int fit_conf_find_compat(const void *fit, const void *fdt);
 int fit_conf_get_node(const void *fit, const char *conf_uname);
 int fit_conf_get_kernel_node(const void *fit, int noffset);
-int fit_conf_get_fdt_node(const void *fit, int noffset);
 
 /**
  * fit_conf_get_prop_node() - Get node refered to by a configuration
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 17/22] sandbox: Adjust bootm command to work with sandbox
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (15 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 16/22] image: Use fit_image_load() to load FDT Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 18/22] image: Use fit_image_load() to load kernel Simon Glass
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Use map_sysmem() when converting from addresses to pointers, so that
bootm can be used with sandbox.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/cmd_bootm.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 33320cb..2dbf4df 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -325,12 +325,15 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 	ulong image_len = os.image_len;
 	__maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
 	int no_overlap = 0;
+	void *load_buf, *image_buf;
 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
 	int ret;
 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
 
 	const char *type_name = genimg_get_type_name(os.type);
 
+	load_buf = map_sysmem(load, image_len);
+	image_buf = map_sysmem(image_start, image_len);
 	switch (comp) {
 	case IH_COMP_NONE:
 		if (load == blob_start || load == image_start) {
@@ -338,8 +341,7 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 			no_overlap = 1;
 		} else {
 			printf("   Loading %s ... ", type_name);
-			memmove_wd((void *)load, (void *)image_start,
-					image_len, CHUNKSZ);
+			memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
 		}
 		*load_end = load + image_len;
 		puts("OK\n");
@@ -347,8 +349,7 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 #ifdef CONFIG_GZIP
 	case IH_COMP_GZIP:
 		printf("   Uncompressing %s ... ", type_name);
-		if (gunzip((void *)load, unc_len,
-				(uchar *)image_start, &image_len) != 0) {
+		if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
 			puts("GUNZIP: uncompress, out-of-mem or overwrite "
 				"error - must RESET board to recover\n");
 			if (boot_progress)
@@ -367,9 +368,9 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 		 * use slower decompression algorithm which requires
 		 * at most 2300 KB of memory.
 		 */
-		int i = BZ2_bzBuffToBuffDecompress((char *)load,
-					&unc_len, (char *)image_start, image_len,
-					CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
+		int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
+			image_buf, image_len,
+			CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
 		if (i != BZ_OK) {
 			printf("BUNZIP2: uncompress or overwrite error %d "
 				"- must RESET board to recover\n", i);
@@ -386,9 +387,8 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 		SizeT lzma_len = unc_len;
 		printf("   Uncompressing %s ... ", type_name);
 
-		ret = lzmaBuffToBuffDecompress(
-			(unsigned char *)load, &lzma_len,
-			(unsigned char *)image_start, image_len);
+		ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
+					       image_buf, image_len);
 		unc_len = lzma_len;
 		if (ret != SZ_OK) {
 			printf("LZMA: uncompress or overwrite error %d "
@@ -404,9 +404,8 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 	case IH_COMP_LZO:
 		printf("   Uncompressing %s ... ", type_name);
 
-		ret = lzop_decompress((const unsigned char *)image_start,
-					  image_len, (unsigned char *)load,
-					  &unc_len);
+		ret = lzop_decompress(image_buf, image_len, load_buf,
+				      &unc_len);
 		if (ret != LZO_E_OK) {
 			printf("LZO: uncompress or overwrite error %d "
 			      "- must RESET board to recover\n", ret);
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 18/22] image: Use fit_image_load() to load kernel
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (16 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 17/22] sandbox: Adjust bootm command to work with sandbox Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 19/22] sandbox: image: Adjust FIT image printing to work with sandbox Simon Glass
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Use the new common code to load a kernel. The functionality should not
change.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/cmd_bootm.c |  153 +++-------------------------------------------------
 common/image-fit.c |   19 -------
 include/image.h    |    1 -
 3 files changed, 8 insertions(+), 165 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 2dbf4df..58eec83 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -88,11 +88,6 @@ static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 static void fixup_silent_linux(void);
 #endif
 
-static image_header_t *image_get_kernel(ulong img_addr, int verify);
-#if defined(CONFIG_FIT)
-static int fit_check_kernel(const void *fit, int os_noffset, int verify);
-#endif
-
 static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
 				char * const argv[], bootm_headers_t *images,
 				ulong *os_data, ulong *os_len);
@@ -778,54 +773,6 @@ static image_header_t *image_get_kernel(ulong img_addr, int verify)
 }
 
 /**
- * fit_check_kernel - verify FIT format kernel subimage
- * @fit_hdr: pointer to the FIT image header
- * os_noffset: kernel subimage node offset within FIT image
- * @verify: data CRC verification flag
- *
- * fit_check_kernel() verifies integrity of the kernel subimage and from
- * specified FIT image.
- *
- * returns:
- *     1, on success
- *     0, on failure
- */
-#if defined(CONFIG_FIT)
-static int fit_check_kernel(const void *fit, int os_noffset, int verify)
-{
-	fit_image_print(fit, os_noffset, "   ");
-
-	if (verify) {
-		puts("   Verifying Hash Integrity ... ");
-		if (!fit_image_verify(fit, os_noffset)) {
-			puts("Bad Data Hash\n");
-			bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH);
-			return 0;
-		}
-		puts("OK\n");
-	}
-	bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH);
-
-	if (!fit_image_check_target_arch(fit, os_noffset)) {
-		puts("Unsupported Architecture\n");
-		bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH);
-		return 0;
-	}
-
-	bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
-	if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) &&
-	    !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) {
-		puts("Not a kernel image\n");
-		bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
-		return 0;
-	}
-
-	bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED);
-	return 1;
-}
-#endif /* CONFIG_FIT */
-
-/**
  * boot_get_kernel - find kernel image
  * @os_data: pointer to a ulong variable, will hold os data start address
  * @os_len: pointer to a ulong variable, will hold os data length
@@ -845,12 +792,8 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
 	ulong		img_addr;
 	const void *buf;
 #if defined(CONFIG_FIT)
-	const void	*fit_hdr;
 	const char	*fit_uname_config = NULL;
 	const char	*fit_uname_kernel = NULL;
-	const void	*data;
-	size_t		len;
-	int		cfg_noffset;
 	int		os_noffset;
 #endif
 
@@ -927,96 +870,16 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
 		break;
 #if defined(CONFIG_FIT)
 	case IMAGE_FORMAT_FIT:
-		fit_hdr = buf;
-		printf("## Booting kernel from FIT Image at %08lx ...\n",
-				img_addr);
-
-		if (!fit_check_format(fit_hdr)) {
-			puts("Bad FIT kernel image format!\n");
-			bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
+		os_noffset = fit_image_load(images, FIT_KERNEL_PROP,
+				img_addr,
+				&fit_uname_kernel, fit_uname_config,
+				IH_ARCH_DEFAULT, IH_TYPE_KERNEL,
+				BOOTSTAGE_ID_FIT_KERNEL_START,
+				FIT_LOAD_IGNORED, os_data, os_len);
+		if (os_noffset < 0)
 			return NULL;
-		}
-		bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
-
-		if (!fit_uname_kernel) {
-			/*
-			 * no kernel image node unit name, try to get config
-			 * node first. If config unit node name is NULL
-			 * fit_conf_get_node() will try to find default config
-			 * node
-			 */
-			bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
-#ifdef CONFIG_FIT_BEST_MATCH
-			if (fit_uname_config)
-				cfg_noffset =
-					fit_conf_get_node(fit_hdr,
-							  fit_uname_config);
-			else
-				cfg_noffset =
-					fit_conf_find_compat(fit_hdr,
-							     gd->fdt_blob);
-#else
-			cfg_noffset = fit_conf_get_node(fit_hdr,
-							fit_uname_config);
-#endif
-			if (cfg_noffset < 0) {
-				bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
-				return NULL;
-			}
-			/* save configuration uname provided in the first
-			 * bootm argument
-			 */
-			images->fit_uname_cfg = fdt_get_name(fit_hdr,
-								cfg_noffset,
-								NULL);
-			printf("   Using '%s' configuration\n",
-				images->fit_uname_cfg);
-			if (IMAGE_ENABLE_VERIFY && images->verify) {
-				puts("   Verifying Hash Integrity ... ");
-				if (!fit_config_verify(fit_hdr,
-						cfg_noffset)) {
-					puts("Bad Data Hash\n");
-					bootstage_error(
-						BOOTSTAGE_ID_FIT_CHECK_HASH);
-					return NULL;
-				}
-				puts("OK\n");
-			}
-
-			bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
-
-			os_noffset = fit_conf_get_kernel_node(fit_hdr,
-								cfg_noffset);
-			fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
-							NULL);
-		} else {
-			/* get kernel component image node offset */
-			bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
-			os_noffset = fit_image_get_node(fit_hdr,
-							fit_uname_kernel);
-		}
-		if (os_noffset < 0) {
-			bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
-			return NULL;
-		}
-
-		printf("   Trying '%s' kernel subimage\n", fit_uname_kernel);
-
-		bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
-		if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
-			return NULL;
-
-		/* get kernel image data address and length */
-		if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
-			puts("Could not find kernel subimage data!\n");
-			bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
-			return NULL;
-		}
-		bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
 
-		*os_len = len;
-		*os_data = (ulong)data;
-		images->fit_hdr_os = (void *)fit_hdr;
+		images->fit_hdr_os = map_sysmem(img_addr, 0);
 		images->fit_uname_os = fit_uname_kernel;
 		images->fit_noffset_os = os_noffset;
 		break;
diff --git a/common/image-fit.c b/common/image-fit.c
index 5d07861..ef21112 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1393,25 +1393,6 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
 }
 
 /**
- * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
- * a given configuration
- * @fit: pointer to the FIT format image header
- * @noffset: configuration node offset
- *
- * fit_conf_get_kernel_node() retrives kernel image node unit name from
- * configuration FIT_KERNEL_PROP property and translates it to the node
- * offset.
- *
- * returns:
- *     image node offset when found (>=0)
- *     negative number on failure (FDT_ERR_* code)
- */
-int fit_conf_get_kernel_node(const void *fit, int noffset)
-{
-	return fit_conf_get_prop_node(fit, noffset, FIT_KERNEL_PROP);
-}
-
-/**
  * fit_conf_print - prints out the FIT configuration details
  * @fit: pointer to the FIT format image header
  * @noffset: offset of the configuration node
diff --git a/include/image.h b/include/image.h
index e19a92d..e5f2f06 100644
--- a/include/image.h
+++ b/include/image.h
@@ -761,7 +761,6 @@ int fit_check_format(const void *fit);
 
 int fit_conf_find_compat(const void *fit, const void *fdt);
 int fit_conf_get_node(const void *fit, const char *conf_uname);
-int fit_conf_get_kernel_node(const void *fit, int noffset);
 
 /**
  * fit_conf_get_prop_node() - Get node refered to by a configuration
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 19/22] sandbox: image: Adjust FIT image printing to work with sandbox
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (17 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 18/22] image: Use fit_image_load() to load kernel Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 20/22] bootstage: Remove unused entries related to kernel/ramdisk/fdt load Simon Glass
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Use map_sysmem() to convert from address to pointer, so that sandbox can
print FIT information without crashing.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/image-fit.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index ef21112..9f3ece2 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -373,7 +373,7 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
 	if (ret)
 		printf("unavailable\n");
 	else
-		printf("0x%08lx\n", (ulong)data);
+		printf("0x%08lx\n", (ulong)map_to_sysmem((char *)data));
 #endif
 
 	printf("%s  Data Size:    ", p);
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 20/22] bootstage: Remove unused entries related to kernel/ramdisk/fdt load
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (18 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 19/22] sandbox: image: Adjust FIT image printing to work with sandbox Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 21/22] sandbox: image: Create a test for loading FIT images Simon Glass
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

Now that the code for loading these three images from a FIT is common, we
don't need individual boostage IDs for each of them.

Note: there are some minor changes in the bootstage numbering, particuarly
for kernel loading. I don't believe this matters.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 include/bootstage.h |   29 +++--------------------------
 1 files changed, 3 insertions(+), 26 deletions(-)

diff --git a/include/bootstage.h b/include/bootstage.h
index f577ba8..2a28e23 100644
--- a/include/bootstage.h
+++ b/include/bootstage.h
@@ -161,20 +161,10 @@ enum bootstage_id {
 	 * bit wonky.
 	 */
 	BOOTSTAGE_ID_FIT_KERNEL_START = 100,
-	BOOTSTAGE_ID_FIT_FORMAT = 100,
-	BOOTSTAGE_ID_FIT_NO_UNIT_NAME,
-	BOOTSTAGE_ID_FIT_UNIT_NAME,
-	BOOTSTAGE_ID_FIT_CONFIG,
-	BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE,
-	BOOTSTAGE_ID_FIT_CHECK_HASH = 104,
-
-	BOOTSTAGE_ID_FIT_CHECK_ARCH,
-	BOOTSTAGE_ID_FIT_CHECK_KERNEL,
-	BOOTSTAGE_ID_FIT_CHECKED,
-
-	BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR = 107,
-	BOOTSTAGE_ID_FIT_KERNEL_INFO,
+
+	BOOTSTAGE_ID_FIT_CONFIG = 110,
 	BOOTSTAGE_ID_FIT_TYPE,
+	BOOTSTAGE_ID_FIT_KERNEL_INFO,
 
 	BOOTSTAGE_ID_FIT_COMPRESSION,
 	BOOTSTAGE_ID_FIT_OS,
@@ -183,19 +173,6 @@ enum bootstage_id {
 
 	/* Next 10 IDs used by BOOTSTAGE_SUB_... */
 	BOOTSTAGE_ID_FIT_RD_START = 120,	/* Ramdisk stages */
-	BOOTSTAGE_ID_FIT_RD_FORMAT = 120,
-	BOOTSTAGE_ID_FIT_RD_FORMAT_OK,
-	BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME,
-	BOOTSTAGE_ID_FIT_RD_UNIT_NAME,
-	BOOTSTAGE_ID_FIT_RD_SUBNODE,
-
-	BOOTSTAGE_ID_FIT_RD_CHECK,
-	BOOTSTAGE_ID_FIT_RD_HASH = 125,
-	BOOTSTAGE_ID_FIT_RD_CHECK_ALL,
-	BOOTSTAGE_ID_FIT_RD_GET_DATA,
-	BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK = 127,
-	BOOTSTAGE_ID_FIT_RD_GET_DATA_OK,
-	BOOTSTAGE_ID_FIT_RD_LOAD,
 
 	BOOTSTAGE_ID_IDE_FIT_READ = 140,
 	BOOTSTAGE_ID_IDE_FIT_READ_OK,
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 21/22] sandbox: image: Create a test for loading FIT images
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (19 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 20/22] bootstage: Remove unused entries related to kernel/ramdisk/fdt load Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 22/22] WIP: sandbox: config: Remove boot command Simon Glass
  2013-03-09 21:43 ` [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

The image code is fairly complex with various different options. It would
be useful to have comprehensive tests for this.

As a start, create a script which tries out loading a kernel/ramdisk/fdt
from a FIT and checks that the images appear in the right place in memory.

This uses sandbox which now supports bootm and related features.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 test/image/test-fit.py |  422 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 422 insertions(+), 0 deletions(-)
 create mode 100755 test/image/test-fit.py

diff --git a/test/image/test-fit.py b/test/image/test-fit.py
new file mode 100755
index 0000000..c4e8211
--- /dev/null
+++ b/test/image/test-fit.py
@@ -0,0 +1,422 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2013, Google Inc.
+#
+# Sanity check of the FIT handling in U-Boot
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+# To run this:
+#
+# make O=sandbox sandbox_config
+# make O=sandbox
+# ./test/image/test-fit.py -u sandbox/u-boot
+
+import doctest
+from optparse import OptionParser
+import os
+import shutil
+import struct
+import sys
+import tempfile
+
+# The 'command' library in patman is convenient for running commands
+base_path = os.path.dirname(sys.argv[0])
+patman = os.path.join(base_path, '../../tools/patman')
+sys.path.append(patman)
+
+import command
+
+# Define a base ITS which we can adjust using % and a dictionary
+base_its = '''
+/dts-v1/;
+
+/ {
+        description = "Chrome OS kernel image with one or more FDT blobs";
+        #address-cells = <1>;
+
+        images {
+                kernel at 1 {
+                        data = /incbin/("%(kernel)s");
+                        type = "kernel";
+                        arch = "sandbox";
+                        os = "linux";
+                        compression = "none";
+                        load = <0x40000>;
+                        entry = <0x8>;
+                };
+                fdt at 1 {
+                        description = "snow";
+                        data = /incbin/("u-boot.dtb");
+                        type = "flat_dt";
+                        arch = "sandbox";
+                        %(fdt_load)s
+                        compression = "none";
+                        signature at 1 {
+                                algo = "sha1,rsa2048";
+                                key-name-hint = "dev";
+                        };
+                };
+                ramdisk at 1 {
+                        description = "snow";
+                        data = /incbin/("%(ramdisk)s");
+                        type = "ramdisk";
+                        arch = "sandbox";
+                        os = "linux";
+                        %(ramdisk_load)s
+                        compression = "none";
+                };
+        };
+        configurations {
+                default = "conf at 1";
+                conf at 1 {
+                        kernel = "kernel at 1";
+                        fdt = "fdt at 1";
+                        %(ramdisk_config)s
+                };
+        };
+};
+'''
+
+# Define a base FDT - currently we don't use anything in this
+base_fdt = '''
+/dts-v1/;
+
+/ {
+        model = "Sandbox Verified Boot Test";
+        compatible = "sandbox";
+
+};
+'''
+
+# This is the U-Boot script that is run for each test. First load the fit,
+# then do the 'bootm' command, then save out memory from the places where
+# we expect 'bootm' to write things. Then quit.
+base_script = '''
+sb load host 0 %(fit_addr)x %(fit)s
+fdt addr %(fit_addr)x
+bootm start %(fit_addr)x
+bootm loados
+sb save host 0 %(kernel_out)s %(kernel_addr)x %(kernel_size)x
+sb save host 0 %(fdt_out)s %(fdt_addr)x %(fdt_size)x
+sb save host 0 %(ramdisk_out)s %(ramdisk_addr)x %(ramdisk_size)x
+reset
+'''
+
+def make_fname(leaf):
+    """Make a temporary filename
+
+    Args:
+        leaf: Leaf name of file to create (within temporary directory)
+    Return:
+        Temporary filename
+    """
+    global base_dir
+
+    return os.path.join(base_dir, leaf)
+
+def filesize(fname):
+    """Get the size of a file
+
+    Args:
+        fname: Filename to check
+    Return:
+        Size of file in bytes
+    """
+    return os.stat(fname).st_size
+
+def read_file(fname):
+    """Read the contents of a file
+
+    Args:
+        fname: Filename to read
+    Returns:
+        Contents of file as a string
+    """
+    with open(fname, 'r') as fd:
+        return fd.read()
+
+def make_dtb():
+    """Make a sample .dts file and compile it to a .dtb
+
+    Returns:
+        Filename of .dtb file created
+    """
+    src = make_fname('u-boot.dts')
+    dtb = make_fname('u-boot.dtb')
+    with open(src, 'w') as fd:
+        print >>fd, base_fdt
+    command.Output('dtc', src, '-O', 'dtb', '-o', dtb)
+    return dtb
+
+def make_its(params):
+    """Make a sample .its file with parameters embedded
+
+    Args:
+        params: Dictionary containing parameters to embed in the %() strings
+    Returns:
+        Filename of .its file created
+    """
+    its = make_fname('test.its')
+    with open(its, 'w') as fd:
+        print >>fd, base_its % params
+    return its
+
+def make_fit(mkimage, params):
+    """Make a sample .fit file ready for loading
+
+    This creates a .its script with the selected parameters and uses mkimage to
+    turn this into a .fit image.
+
+    Args:
+        mkimage: Filename of 'mkimage' utility
+        params: Dictionary containing parameters to embed in the %() strings
+    Return:
+        Filename of .fit file created
+    """
+    fit = make_fname('test.fit')
+    its = make_its(params)
+    command.Output(mkimage, '-f', its, fit)
+    with open(make_fname('u-boot.dts'), 'w') as fd:
+        print >>fd, base_fdt
+    return fit
+
+def make_kernel():
+    """Make a sample kernel with test data
+
+    Returns:
+        Filename of kernel created
+    """
+    fname = make_fname('test-kernel.bin')
+    data = ''
+    for i in range(100):
+        data += 'this kernel %d is unlikely to boot\n' % i
+    with open(fname, 'w') as fd:
+        print >>fd, data
+    return fname
+
+def make_ramdisk():
+    """Make a sample ramdisk with test data
+
+    Returns:
+        Filename of ramdisk created
+    """
+    fname = make_fname('test-ramdisk.bin')
+    data = ''
+    for i in range(100):
+        data += 'ramdisk %d was seldom used in the middle ages\n' % i
+    with open(fname, 'w') as fd:
+        print >>fd, data
+    return fname
+
+def find_matching(text, match):
+    """Find a match in a line of text, and return the unmatched line portion
+
+    This is used to extract a part of a line from some text. The match string
+    is used to locate the line - we use the first line that contains that
+    match text.
+
+    Once we find a match, we discard the match string itself from the line,
+    and return what remains.
+
+    TODO: If this function becomes more generally useful, we could change it
+    to use regex and return groups.
+
+    Args:
+        text: Text to check (each line separated by \n)
+        match: String to search for
+    Return:
+        String containing unmatched portion of line
+    Exceptions:
+        ValueError: If match is not found
+
+    >>> find_matching('first line:10\\nsecond_line:20', 'first line:')
+    '10'
+    >>> find_matching('first line:10\\nsecond_line:20', 'second linex')
+    Traceback (most recent call last):
+      ...
+    ValueError: Test aborted
+    >>> find_matching('first line:10\\nsecond_line:20', 'second_line:')
+    '20'
+    """
+    for line in text.splitlines():
+        pos = line.find(match)
+        if pos != -1:
+            return line[:pos] + line[pos + len(match):]
+
+    print "Expected '%s' but not found in output:"
+    print text
+    raise ValueError('Test aborted')
+
+def set_test(name):
+    """Set the name of the current test and print a message
+
+    Args:
+        name: Name of test
+    """
+    global test_name
+
+    test_name = name
+    print name
+
+def fail(msg):
+    """Raise an error with a helpful failure message
+
+    Args:
+        msg: Message to display
+    """
+    raise ValueError("Test '%s' failed: %s" % (test_name, msg))
+
+def run_fit_test(mkimage, u_boot):
+    """Basic sanity check of FIT loading in U-Boot
+
+    TODO: Almost everything:
+       - hash algorithms - invalid hash/contents should be detected
+       - signature algorithms - invalid sig/contents should be detected
+       - compression
+       - checking that errors are detected like:
+            - image overwriting
+            - missing images
+            - invalid configurations
+            - incorrect os/arch/type fields
+            - empty data
+            - images too large/small
+            - invalid FDT (e.g. putting a random binary in instead)
+       - default configuration selection
+       - bootm command line parameters should have desired effect
+       - run code coverage to make sure we are testing all the code
+    """
+    global test_name
+
+    # Set up invariant files
+    control_dtb = make_dtb()
+    kernel = make_kernel()
+    ramdisk = make_ramdisk()
+    kernel_out = make_fname('kernel-out.bin')
+    fdt_out = make_fname('fdt-out.dtb')
+    ramdisk_out = make_fname('ramdisk-out.bin')
+
+    # Set up basic parameters with default values
+    params = {
+        'fit_addr' : 0x1000,
+
+        'kernel' : kernel,
+        'kernel_out' : kernel_out,
+        'kernel_addr' : 0x40000,
+        'kernel_size' : filesize(kernel),
+
+        'fdt_out' : fdt_out,
+        'fdt_addr' : 0x80000,
+        'fdt_size' : filesize(control_dtb),
+        'fdt_load' : '',
+
+        'ramdisk' : ramdisk,
+        'ramdisk_out' : ramdisk_out,
+        'ramdisk_addr' : 0xc0000,
+        'ramdisk_size' : filesize(ramdisk),
+        'ramdisk_load' : '',
+        'ramdisk_config' : '',
+    }
+
+    # Make a basic FIT and a script to load it
+    fit = make_fit(mkimage, params)
+    params['fit'] = fit
+    cmd = base_script % params
+
+    # First check that we can load a kernel
+    # We could perhaps reduce duplication with some loss of readability
+    set_test('Kernel load')
+    stdout = command.Output(u_boot, '-d', control_dtb, '-c', cmd)
+    if read_file(kernel) != read_file(kernel_out):
+        fail('Kernel not loaded')
+    if read_file(control_dtb) == read_file(fdt_out):
+        fail('FDT loaded but should be ignored')
+    if read_file(ramdisk) == read_file(ramdisk_out):
+        fail('Ramdisk loaded but should not be')
+
+    # Find out the offset in the FIT where U-Boot has found the FDT
+    line = find_matching(stdout, 'Booting using the fdt blob at ')
+    fit_offset = int(line, 16) - params['fit_addr']
+    fdt_magic = struct.pack('>L', 0xd00dfeed)
+    data = read_file(fit)
+
+    # Now find where it actually is in the FIT (skip the first word)
+    real_fit_offset = data.find(fdt_magic, 4)
+    if fit_offset != real_fit_offset:
+        fail('U-Boot loaded FDT from offset %#x, FDT is actually at %#x' %
+                (fit_offset, real_fit_offset))
+
+    # Now a kernel and an FDT
+    set_test('Kernel + FDT load')
+    params['fdt_load'] = 'load = <%#x>;' % params['fdt_addr']
+    fit = make_fit(mkimage, params)
+    stdout = command.Output(u_boot, '-d', control_dtb, '-c', cmd)
+    if read_file(kernel) != read_file(kernel_out):
+        fail('Kernel not loaded')
+    if read_file(control_dtb) != read_file(fdt_out):
+        fail('FDT not loaded')
+    if read_file(ramdisk) == read_file(ramdisk_out):
+        fail('Ramdisk loaded but should not be')
+
+    # Try a ramdisk
+    set_test('Kernel + FDT + Ramdisk load')
+    params['ramdisk_config'] = 'ramdisk = "ramdisk at 1";'
+    params['ramdisk_load'] = 'load = <%#x>;' % params['ramdisk_addr']
+    fit = make_fit(mkimage, params)
+    stdout = command.Output(u_boot, '-d', control_dtb, '-c', cmd)
+    if read_file(ramdisk) != read_file(ramdisk_out):
+        fail('Ramdisk not loaded')
+
+def run_tests():
+    """Parse options, run the FIT tests and print the result"""
+    global base_path, base_dir
+
+    # Work in a temporary directory
+    base_dir = tempfile.mkdtemp()
+    parser = OptionParser()
+    parser.add_option('-u', '--u-boot',
+            default=os.path.join(base_path, 'u-boot'),
+            help='Select U-Boot sandbox binary')
+    parser.add_option('-k', '--keep', action='store_true',
+            help="Don't delete temporary directory even when tests pass")
+    parser.add_option('-t', '--selftest', action='store_true',
+            help='Run internal self tests')
+    (options, args) = parser.parse_args()
+
+    # Find the path to U-Boot, and assume mkimage is in its tools/mkimage dir
+    base_path = os.path.dirname(options.u_boot)
+    mkimage = os.path.join(base_path, 'tools/mkimage')
+
+    # There are a few doctests - handle these here
+    if options.selftest:
+        doctest.testmod()
+        return
+
+    title = 'FIT Tests'
+    print title, '\n', '=' * len(title)
+
+    run_fit_test(mkimage, options.u_boot)
+
+    print '\nTests passed'
+    print 'Caveat: this is only a sanity check - test coverage is poor'
+
+    # Remove the tempoerary directory unless we are asked to keep it
+    if options.keep:
+        print "Output files are in '%s'" % base_dir
+    else:
+        shutil.rmtree(base_dir)
+
+run_tests()
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 22/22] WIP: sandbox: config: Remove boot command
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (20 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 21/22] sandbox: image: Create a test for loading FIT images Simon Glass
@ 2013-01-10 14:58 ` Simon Glass
  2013-03-09 21:43 ` [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-10 14:58 UTC (permalink / raw)
  To: u-boot

We don't really need this now that we can provide a script to sandbox using
-c.

This is a test commit only - please do not apply.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 include/configs/sandbox.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index baf892a..3d69b85 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -120,7 +120,6 @@
 					"stderr=serial\0" \
 					CONFIG_SANDBOX_ENV
 
-#define CONFIG_BOOTCOMMAND	"run test"
 #define CONFIG_BOOTDELAY	0		/* -1 to disable auto boot */
 
 #endif
-- 
1.7.7.3

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

* [U-Boot] [RFC PATCH 01/22] sandbox: Allow -c argument to provide a command list
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 01/22] sandbox: Allow -c argument to provide a command list Simon Glass
@ 2013-01-11 11:06   ` Marek Vasut
  0 siblings, 0 replies; 35+ messages in thread
From: Marek Vasut @ 2013-01-11 11:06 UTC (permalink / raw)
  To: u-boot

Dear Simon Glass,

> This allows passing of entire scripts to sandbox with the -c argument,
> which is useful for testing. Commands can be delimited with a newline
> or semicolon.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Marek Vasut <marex@denx.de>

> ---
>  arch/sandbox/cpu/start.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
> index 8589da2..ce47e7e 100644
> --- a/arch/sandbox/cpu/start.c
> +++ b/arch/sandbox/cpu/start.c
> @@ -90,7 +90,7 @@ int sandbox_main_loop_init(void)
> 
>  	/* Execute command if required */
>  	if (state->cmd) {
> -		run_command(state->cmd, 0);
> +		run_command_list(state->cmd, -1, 0);
>  		os_exit(state->exit_type);
>  	}

Best regards,
Marek Vasut

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

* [U-Boot] [RFC PATCH 02/22] sandbox: Support 'source' command
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 02/22] sandbox: Support 'source' command Simon Glass
@ 2013-01-11 11:07   ` Marek Vasut
  0 siblings, 0 replies; 35+ messages in thread
From: Marek Vasut @ 2013-01-11 11:07 UTC (permalink / raw)
  To: u-boot

Dear Simon Glass,

> Enhance the source command to work with sandbox, by using map_sysmem() to
> convert a ulong address into a pointer.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut

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

* [U-Boot] [RFC PATCH 03/22] fs: Add support for saving data to filesystems
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 03/22] fs: Add support for saving data to filesystems Simon Glass
@ 2013-01-11 11:08   ` Marek Vasut
  2013-01-11 14:26     ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Marek Vasut @ 2013-01-11 11:08 UTC (permalink / raw)
  To: u-boot

Dear Simon Glass,

> Add a new method for saving that filesystems can implement. This mirrors
> the existing load method.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Marek Vasut <marex@denx.de>

btw what about fat write support, can this map somehow on it?

Best regards,
Marek Vasut

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

* [U-Boot] [RFC PATCH 04/22] sandbox: fs: Add support for saving files to host filesystem
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 04/22] sandbox: fs: Add support for saving files to host filesystem Simon Glass
@ 2013-01-11 11:09   ` Marek Vasut
  0 siblings, 0 replies; 35+ messages in thread
From: Marek Vasut @ 2013-01-11 11:09 UTC (permalink / raw)
  To: u-boot

Dear Simon Glass,

> This allows write of files from the host filesystem in sandbox. There is
> currently no concept of overwriting the file and removing its existing
> contents - all writing is done on top of what is there. This means that
> writing 10 bytes to the start of a 1KB file will only update those 10
> bytes, not truncate the file to 10 byte slong.
> 
> If the file does not exist it is created.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut

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

* [U-Boot] [RFC PATCH 07/22] arm: Refactor bootm to reduce #ifdefs
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 07/22] arm: Refactor bootm to reduce #ifdefs Simon Glass
@ 2013-01-11 11:10   ` Marek Vasut
  2013-01-11 15:42     ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Marek Vasut @ 2013-01-11 11:10 UTC (permalink / raw)
  To: u-boot

Dear Simon Glass,

> With fewer #ifdefs the code is more readable and more of the code is
> compiled for all boards. Add defines in the header file to control
> what features are enabled, and then use if() instead of #ifdef.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Did you try building it with ELDK 4.2 and check if there's no size growth?

Best regards,
Marek Vasut

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

* [U-Boot] [RFC PATCH 09/22] powerpc: Use image_setup_linux() instead of local code
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 09/22] powerpc: " Simon Glass
@ 2013-01-11 11:11   ` Marek Vasut
  0 siblings, 0 replies; 35+ messages in thread
From: Marek Vasut @ 2013-01-11 11:11 UTC (permalink / raw)
  To: u-boot

Dear Simon Glass,

> Rather than having similar code in powerpc, use image_setup_linux() which
> should be common across all architectures that use the FDT.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut

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

* [U-Boot] [RFC PATCH 08/22] arm: Use image_setup_linux() instead of local code
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 08/22] arm: Use image_setup_linux() instead of local code Simon Glass
@ 2013-01-11 11:11   ` Marek Vasut
  0 siblings, 0 replies; 35+ messages in thread
From: Marek Vasut @ 2013-01-11 11:11 UTC (permalink / raw)
  To: u-boot

Dear Simon Glass,

> Use the common FDT setup function that is now available in image. Move
> the FDT-specific code to a new bootm-fdt.c and remove unused headers
> from bootm.c.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut

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

* [U-Boot] [RFC PATCH 10/22] m68k: Use image_setup_linux() instead of local code
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 10/22] m68k: " Simon Glass
@ 2013-01-11 11:11   ` Marek Vasut
  0 siblings, 0 replies; 35+ messages in thread
From: Marek Vasut @ 2013-01-11 11:11 UTC (permalink / raw)
  To: u-boot

Dear Simon Glass,

> Rather than having similar code in m68k, use image_setup_linux() which
> should be common across all architectures that use the FDT.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut

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

* [U-Boot] [RFC PATCH 03/22] fs: Add support for saving data to filesystems
  2013-01-11 11:08   ` Marek Vasut
@ 2013-01-11 14:26     ` Simon Glass
  2013-01-11 15:20       ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2013-01-11 14:26 UTC (permalink / raw)
  To: u-boot

Hi Marek,

On Fri, Jan 11, 2013 at 3:08 AM, Marek Vasut <marex@denx.de> wrote:
> Dear Simon Glass,
>
>> Add a new method for saving that filesystems can implement. This mirrors
>> the existing load method.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>
> Reviewed-by: Marek Vasut <marex@denx.de>
>
> btw what about fat write support, can this map somehow on it?

Thanks for reviews.

There is also ext4, am hoping that others might help with this?

Regards,
Simon

>
> Best regards,
> Marek Vasut

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

* [U-Boot] [RFC PATCH 03/22] fs: Add support for saving data to filesystems
  2013-01-11 14:26     ` Simon Glass
@ 2013-01-11 15:20       ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-11 15:20 UTC (permalink / raw)
  To: u-boot

Hi,

On Fri, Jan 11, 2013 at 6:26 AM, Simon Glass <sjg@chromium.org> wrote:
> Hi Marek,
>
> On Fri, Jan 11, 2013 at 3:08 AM, Marek Vasut <marex@denx.de> wrote:
>> Dear Simon Glass,
>>
>>> Add a new method for saving that filesystems can implement. This mirrors
>>> the existing load method.
>>>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>
>> Reviewed-by: Marek Vasut <marex@denx.de>
>>
>> btw what about fat write support, can this map somehow on it?
>
> Thanks for reviews.
>
> There is also ext4, am hoping that others might help with this?

One thing I meant to put in the cover letter was that we might need a
generic CONFIG to enable write support. A lot of people don't want it,
and perhaps rather than having fat write, ext4 writes, etc. we have a
global write support CONFIG.

>
> Regards,
> Simon
>
>>
>> Best regards,
>> Marek Vasut

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

* [U-Boot] [RFC PATCH 07/22] arm: Refactor bootm to reduce #ifdefs
  2013-01-11 11:10   ` Marek Vasut
@ 2013-01-11 15:42     ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-01-11 15:42 UTC (permalink / raw)
  To: u-boot

Hi Marek,

On Fri, Jan 11, 2013 at 3:10 AM, Marek Vasut <marex@denx.de> wrote:
> Dear Simon Glass,
>
>> With fewer #ifdefs the code is more readable and more of the code is
>> compiled for all boards. Add defines in the header file to control
>> what features are enabled, and then use if() instead of #ifdef.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>
> Did you try building it with ELDK 4.2 and check if there's no size growth?

buildman says:

08: arm: Refactor bootm to reduce #ifdefs
       arm: (285 boards)   spl/u-boot-spl:text -0.0   text -7.9   bss +1.0

so no size growth there with 4.4.1 (the numbers are changes in bytes
for that section averaged over all boards).

The code is basically equivalent, just using a compile-time check instead.

gcc version 4.4.1 (Sourcery G++ Lite 2010q1-202)

>
> Best regards,
> Marek Vasut

Regards,
Simon

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

* [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor
  2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
                   ` (21 preceding siblings ...)
  2013-01-10 14:58 ` [U-Boot] [RFC PATCH 22/22] WIP: sandbox: config: Remove boot command Simon Glass
@ 2013-03-09 21:43 ` Simon Glass
  22 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2013-03-09 21:43 UTC (permalink / raw)
  To: u-boot

Hi,

On Thu, Jan 10, 2013 at 6:58 AM, Simon Glass <sjg@chromium.org> wrote:

> In creating a new feature[*] I found that the image code includes quite
> a bit of duplication in places. In particular the code to load a kernel,
> FDT and ramdisk is all fairly similar, but subtly different.
>
> This series introduces a new function fit_image_load() which loads an image
> from a FIT and supports the various features. For the bootstage updates,
> these are standardised so that each file has its own range and the events
> within that range have corresponding numbers. This means that the boot
> progress numbers will change slightly with this series.
>
> The image.c file is still very long. Rather than perpetuate the #ifdefs
> in the code I have split out the image.c code that is dependent on
> CONFIG_OF_LIBFDT into image-fdt.c.
>
> Several architectures have their own way of setting up a ramdisk and FDT
> for booting. An attempt is made here to unify these by providing a function
> image_setup_linux() to handle the overall task, and image_setup_fdt() to
> set
> up the FDT.
>
> For ARM, the bootm code is a maze of #ifdefs, which means that many boards
> compile the code differently and it takes longer to detect breakages. To
> get
> around this, some defines are added to ARM's bootm.h to permit the use of
> if() instead of #ifdef, making use of the compiler's dead code elimination.
>
> Also this series introduces a very basic test of image loading using
> sandbox.
> Some patches add bootm support for sandbox, and also a 'sb save' command to
> save memory to a host file (used to check that the bootm actually worked).
>
> A test program for sandbox is added as a basic sanity check of image
> loading
> as performed by bootm.
>
> This series depends on the verified boot series since it builds on the
> clean-up in that. You can get this series from:
>
>    http://git.denx.de/u-boot-x86.git
>
> branch name 'image'.
>

Has anyone taken a look at this series? It is mostly a clean-up, but does
also introduces basic tests for FIT.

Regards,
Simon

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

end of thread, other threads:[~2013-03-09 21:43 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-10 14:58 [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 01/22] sandbox: Allow -c argument to provide a command list Simon Glass
2013-01-11 11:06   ` Marek Vasut
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 02/22] sandbox: Support 'source' command Simon Glass
2013-01-11 11:07   ` Marek Vasut
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 03/22] fs: Add support for saving data to filesystems Simon Glass
2013-01-11 11:08   ` Marek Vasut
2013-01-11 14:26     ` Simon Glass
2013-01-11 15:20       ` Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 04/22] sandbox: fs: Add support for saving files to host filesystem Simon Glass
2013-01-11 11:09   ` Marek Vasut
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 05/22] image: Split libfdt code into image-fdt.c Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 06/22] image: Add device tree setup to image library Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 07/22] arm: Refactor bootm to reduce #ifdefs Simon Glass
2013-01-11 11:10   ` Marek Vasut
2013-01-11 15:42     ` Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 08/22] arm: Use image_setup_linux() instead of local code Simon Glass
2013-01-11 11:11   ` Marek Vasut
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 09/22] powerpc: " Simon Glass
2013-01-11 11:11   ` Marek Vasut
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 10/22] m68k: " Simon Glass
2013-01-11 11:11   ` Marek Vasut
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 11/22] sparc: " Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 12/22] bootstage: Introduce sub-IDs for use with image loading Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 13/22] mkimage: Add map_sysmem() and IH_ARCH_DEFAULT to simplfy building Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 14/22] image: Introduce fit_image_load() to load images from FITs Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 15/22] image: Use fit_image_load() to load ramdisk Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 16/22] image: Use fit_image_load() to load FDT Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 17/22] sandbox: Adjust bootm command to work with sandbox Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 18/22] image: Use fit_image_load() to load kernel Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 19/22] sandbox: image: Adjust FIT image printing to work with sandbox Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 20/22] bootstage: Remove unused entries related to kernel/ramdisk/fdt load Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 21/22] sandbox: image: Create a test for loading FIT images Simon Glass
2013-01-10 14:58 ` [U-Boot] [RFC PATCH 22/22] WIP: sandbox: config: Remove boot command Simon Glass
2013-03-09 21:43 ` [U-Boot] [RFC PATCH 0/22] RFC: image: Reduce code duplication and refactor Simon Glass

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