All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling
@ 2013-05-08 18:05 Simon Glass
  2013-05-08 18:05 ` [U-Boot] [PATCH v3 02/12] image: Remove remaining #ifdefs in image-fit.c Simon Glass
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:05 UTC (permalink / raw)
  To: u-boot

The fit_handle_file() function is quite long - split out the part that
loads and checks a FIT into its own function. We will use this
function for storing public keys into a destination FDT file.

The error handling is currently a bit repetitive - tidy it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3: None
Changes in v2:
- Fix spelling of quite
- Add comment about why mkimage needs to open FIT with O_RDWR
- Fix checkpatch checks about parenthesis alignment

 tools/fit_image.c | 96 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 57 insertions(+), 39 deletions(-)

diff --git a/tools/fit_image.c b/tools/fit_image.c
index 8f51159..cc123dd 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -47,6 +47,48 @@ static int fit_check_image_types (uint8_t type)
 		return EXIT_FAILURE;
 }
 
+int mmap_fdt(struct mkimage_params *params, const char *fname, void **blobp,
+		struct stat *sbuf)
+{
+	void *ptr;
+	int fd;
+
+	/* Load FIT blob into memory (we need to write hashes/signatures) */
+	fd = open(fname, O_RDWR | O_BINARY);
+
+	if (fd < 0) {
+		fprintf(stderr, "%s: Can't open %s: %s\n",
+			params->cmdname, fname, strerror(errno));
+		unlink(fname);
+		return -1;
+	}
+
+	if (fstat(fd, sbuf) < 0) {
+		fprintf(stderr, "%s: Can't stat %s: %s\n",
+			params->cmdname, fname, strerror(errno));
+		unlink(fname);
+		return -1;
+	}
+
+	ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+	if (ptr == MAP_FAILED) {
+		fprintf(stderr, "%s: Can't read %s: %s\n",
+			params->cmdname, fname, strerror(errno));
+		unlink(fname);
+		return -1;
+	}
+
+	/* check if ptr has a valid blob */
+	if (fdt_check_header(ptr)) {
+		fprintf(stderr, "%s: Invalid FIT blob\n", params->cmdname);
+		unlink(fname);
+		return -1;
+	}
+
+	*blobp = ptr;
+	return fd;
+}
+
 /**
  * fit_handle_file - main FIT file processing function
  *
@@ -65,7 +107,7 @@ static int fit_handle_file (struct mkimage_params *params)
 	char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN];
 	int tfd;
 	struct stat sbuf;
-	unsigned char *ptr;
+	void *ptr;
 
 	/* Flattened Image Tree (FIT) format  handling */
 	debug ("FIT format handling\n");
@@ -87,57 +129,25 @@ static int fit_handle_file (struct mkimage_params *params)
 	if (system (cmd) == -1) {
 		fprintf (stderr, "%s: system(%s) failed: %s\n",
 				params->cmdname, cmd, strerror(errno));
-		unlink (tmpfile);
-		return (EXIT_FAILURE);
-	}
-
-	/* load FIT blob into memory */
-	tfd = open (tmpfile, O_RDWR|O_BINARY);
-
-	if (tfd < 0) {
-		fprintf (stderr, "%s: Can't open %s: %s\n",
-				params->cmdname, tmpfile, strerror(errno));
-		unlink (tmpfile);
-		return (EXIT_FAILURE);
-	}
-
-	if (fstat (tfd, &sbuf) < 0) {
-		fprintf (stderr, "%s: Can't stat %s: %s\n",
-				params->cmdname, tmpfile, strerror(errno));
-		unlink (tmpfile);
-		return (EXIT_FAILURE);
-	}
-
-	ptr = mmap (0, sbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED,
-				tfd, 0);
-	if (ptr == MAP_FAILED) {
-		fprintf (stderr, "%s: Can't read %s: %s\n",
-				params->cmdname, tmpfile, strerror(errno));
-		unlink (tmpfile);
-		return (EXIT_FAILURE);
+		goto err_system;
 	}
 
-	/* check if ptr has a valid blob */
-	if (fdt_check_header (ptr)) {
-		fprintf (stderr, "%s: Invalid FIT blob\n", params->cmdname);
-		unlink (tmpfile);
-		return (EXIT_FAILURE);
-	}
+	tfd = mmap_fdt(params, tmpfile, &ptr, &sbuf);
+	if (tfd < 0)
+		goto err_mmap;
 
 	/* set hashes for images in the blob */
 	if (fit_add_verification_data(ptr)) {
 		fprintf (stderr, "%s Can't add hashes to FIT blob",
 				params->cmdname);
-		unlink (tmpfile);
-		return (EXIT_FAILURE);
+		goto err_add_hashes;
 	}
 
 	/* add a timestamp at offset 0 i.e., root  */
 	if (fit_set_timestamp (ptr, 0, sbuf.st_mtime)) {
 		fprintf (stderr, "%s: Can't add image timestamp\n",
 				params->cmdname);
-		unlink (tmpfile);
-		return (EXIT_FAILURE);
+		goto err_add_timestamp;
 	}
 	debug ("Added timestamp successfully\n");
 
@@ -153,6 +163,14 @@ static int fit_handle_file (struct mkimage_params *params)
 		return (EXIT_FAILURE);
 	}
 	return (EXIT_SUCCESS);
+
+err_add_timestamp:
+err_add_hashes:
+	munmap(ptr, sbuf.st_size);
+err_mmap:
+err_system:
+	unlink(tmpfile);
+	return -1;
 }
 
 static int fit_check_params (struct mkimage_params *params)
-- 
1.8.2.1

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

* [U-Boot] [PATCH v3 02/12] image: Remove remaining #ifdefs in image-fit.c
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
@ 2013-05-08 18:05 ` Simon Glass
  2013-05-08 18:05 ` [U-Boot] [PATCH v3 03/12] image: Add CONFIG_FIT_SPL_PRINT to control FIT image printing in SPL Simon Glass
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:05 UTC (permalink / raw)
  To: u-boot

There are only two left. One is unnecessary and the other can be moved
to the header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3: None
Changes in v2:
- Add new patch to remove #ifdefs in image-fit.c

 common/image-fit.c | 9 ++-------
 common/image.c     | 7 +------
 include/image.h    | 2 ++
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 9516abf..ec7b038 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -149,11 +149,8 @@ void fit_print_contents(const void *fit)
 	const char *p;
 	time_t timestamp;
 
-#ifdef USE_HOSTCC
-	p = "";
-#else
-	p = "   ";
-#endif
+	/* Indent string is defined in header image.h */
+	p = IMAGE_INDENT_STRING;
 
 	/* Root node properties */
 	ret = fit_get_desc(fit, 0, &desc);
@@ -1463,7 +1460,6 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
  *     1, on success
  *     0, on failure
  */
-#ifndef USE_HOSTCC
 int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
 			int verify)
 {
@@ -1492,4 +1488,3 @@ int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
 	bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK);
 	return 1;
 }
-#endif /* USE_HOSTCC */
diff --git a/common/image.c b/common/image.c
index 564ed90..d249758 100644
--- a/common/image.c
+++ b/common/image.c
@@ -296,12 +296,7 @@ void image_print_contents(const void *ptr)
 	const image_header_t *hdr = (const image_header_t *)ptr;
 	const char *p;
 
-#ifdef USE_HOSTCC
-	p = "";
-#else
-	p = "   ";
-#endif
-
+	p = IMAGE_INDENT_STRING;
 	printf("%sImage Name:   %.*s\n", p, IH_NMLEN, image_get_name(hdr));
 	if (IMAGE_ENABLE_TIMESTAMP) {
 		printf("%sCreated:      ", p);
diff --git a/include/image.h b/include/image.h
index df020ff..27c977e 100644
--- a/include/image.h
+++ b/include/image.h
@@ -44,6 +44,7 @@
 #define CONFIG_FIT_VERBOSE	1 /* enable fit_format_{error,warning}() */
 
 #define IMAGE_ENABLE_IGNORE	0
+#define IMAGE_INDENT_STRING	""
 
 #else
 
@@ -53,6 +54,7 @@
 
 /* Take notice of the 'ignore' property for hashes */
 #define IMAGE_ENABLE_IGNORE	1
+#define IMAGE_INDENT_STRING	"   "
 
 #endif /* USE_HOSTCC */
 
-- 
1.8.2.1

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

* [U-Boot] [PATCH v3 03/12] image: Add CONFIG_FIT_SPL_PRINT to control FIT image printing in SPL
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
  2013-05-08 18:05 ` [U-Boot] [PATCH v3 02/12] image: Remove remaining #ifdefs in image-fit.c Simon Glass
@ 2013-05-08 18:05 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 04/12] image: Split libfdt code into image-fdt.c Simon Glass
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:05 UTC (permalink / raw)
  To: u-boot

This code is very large, and in SPL it isn't always useful to print
out image information (in fact there might not even be a console
active). So disable this feature unless this option is set.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3: None
Changes in v2:
- Add new patch to control FIT image printing in SPL
- Fix checkpatch warnings about space after cast

 README             |  6 ++++++
 common/image-fit.c |  8 +++++---
 include/image.h    | 33 +++++++++++++++++++++++++++++++--
 3 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/README b/README
index 0d37d56..f68a839 100644
--- a/README
+++ b/README
@@ -2996,6 +2996,12 @@ FIT uImage format:
 		use an arch-specific makefile fragment instead, for
 		example if more than one image needs to be produced.
 
+		CONFIG_FIT_SPL_PRINT
+		Printing information about a FIT image adds quite a bit of
+		code to SPL. So this is normally disabled in SPL. Use this
+		option to re-enable it. This will affect the output of the
+		bootm command when booting a FIT image.
+
 Modem Support:
 --------------
 
diff --git a/common/image-fit.c b/common/image-fit.c
index ec7b038..254feec 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -124,6 +124,7 @@ static void fit_get_debug(const void *fit, int noffset,
 	      fdt_strerror(err));
 }
 
+#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_FIT_SPL_PRINT)
 /**
  * fit_print_contents - prints out the contents of the FIT format image
  * @fit: pointer to the FIT format image header
@@ -402,6 +403,7 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
 		}
 	}
 }
+#endif
 
 /**
  * fit_get_desc - get node description property
@@ -852,16 +854,16 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
 int calculate_hash(const void *data, int data_len, const char *algo,
 			uint8_t *value, int *value_len)
 {
-	if (strcmp(algo, "crc32") == 0) {
+	if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) {
 		*((uint32_t *)value) = crc32_wd(0, data, data_len,
 							CHUNKSZ_CRC32);
 		*((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value));
 		*value_len = 4;
-	} else if (strcmp(algo, "sha1") == 0) {
+	} else if (IMAGE_ENABLE_SHA1 && strcmp(algo, "sha1") == 0) {
 		sha1_csum_wd((unsigned char *)data, data_len,
 			     (unsigned char *)value, CHUNKSZ_SHA1);
 		*value_len = 20;
-	} else if (strcmp(algo, "md5") == 0) {
+	} else if (IMAGE_ENABLE_MD5 && strcmp(algo, "md5") == 0) {
 		md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
 		*value_len = 16;
 	} else {
diff --git a/include/image.h b/include/image.h
index 27c977e..bfce861 100644
--- a/include/image.h
+++ b/include/image.h
@@ -61,8 +61,37 @@
 #if defined(CONFIG_FIT)
 #include <libfdt.h>
 #include <fdt_support.h>
-#define CONFIG_MD5		/* FIT images need MD5 support */
-#define CONFIG_SHA1		/* and SHA1 */
+# ifdef CONFIG_SPL_BUILD
+#  ifdef CONFIG_SPL_CRC32_SUPPORT
+#   define IMAGE_ENABLE_CRC32	1
+#  endif
+#  ifdef CONFIG_SPL_MD5_SUPPORT
+#   define IMAGE_ENABLE_MD5	1
+#  endif
+#  ifdef CONFIG_SPL_SHA1_SUPPORT
+#   define IMAGE_ENABLE_SHA1	1
+#  endif
+# else
+#  define CONFIG_CRC32		/* FIT images need CRC32 support */
+#  define CONFIG_MD5		/* and MD5 */
+#  define CONFIG_SHA1		/* and SHA1 */
+#  define IMAGE_ENABLE_CRC32	1
+#  define IMAGE_ENABLE_MD5	1
+#  define IMAGE_ENABLE_SHA1	1
+# endif
+
+#ifndef IMAGE_ENABLE_CRC32
+#define IMAGE_ENABLE_CRC32	0
+#endif
+
+#ifndef IMAGE_ENABLE_MD5
+#define IMAGE_ENABLE_MD5	0
+#endif
+
+#ifndef IMAGE_ENABLE_SHA1
+#define IMAGE_ENABLE_SHA1	0
+#endif
+
 #endif
 
 /*
-- 
1.8.2.1

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

* [U-Boot] [PATCH v3 04/12] image: Split libfdt code into image-fdt.c
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
  2013-05-08 18:05 ` [U-Boot] [PATCH v3 02/12] image: Remove remaining #ifdefs in image-fit.c Simon Glass
  2013-05-08 18:05 ` [U-Boot] [PATCH v3 03/12] image: Add CONFIG_FIT_SPL_PRINT to control FIT image printing in SPL Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 05/12] image: Add device tree setup to image library Simon Glass
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 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>
---
Changes in v3: None
Changes in v2:
- Fix checkpatch checks about parenthesis alignment
- Fix checkpatch warnings about split strings

 common/Makefile    |   1 +
 common/image-fdt.c | 591 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     | 566 --------------------------------------------------
 3 files changed, 592 insertions(+), 566 deletions(-)
 create mode 100644 common/image-fdt.c

diff --git a/common/Makefile b/common/Makefile
index ea53bed..444d546 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -230,6 +230,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-y += memsize.o
 COBJS-y += stdio.o
diff --git a/common/image-fdt.c b/common/image-fdt.c
new file mode 100644
index 0000000..8e8f35c
--- /dev/null
+++ b/common/image-fdt.c
@@ -0,0 +1,591 @@
+/*
+ * 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 at 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@%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 d249758..0792fdc 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.8.2.1

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

* [U-Boot] [PATCH v3 05/12] image: Add device tree setup to image library
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (2 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 04/12] image: Split libfdt code into image-fdt.c Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 06/12] arm: Refactor bootm to reduce #ifdefs Simon Glass
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 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>
---
Changes in v3:
- Adjust indenting of #ifdefs

Changes in v2:
- Fix checkpatch checks about parenthesis alignment

 common/image-fdt.c    | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c        | 50 +++++++++++++++++++++++++++++++++++++++++
 include/common.h      | 10 +++++++++
 include/fdt_support.h |  2 --
 include/image.h       | 61 ++++++++++++++++++++++++++++++++++++++++++--------
 include/lmb.h         |  2 --
 6 files changed, 174 insertions(+), 13 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index 8e8f35c..158c9cf 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -589,3 +589,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 0792fdc..e91c89e 100644
--- a/common/image.c
+++ b/common/image.c
@@ -70,6 +70,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 fd2495f..985ae53 100644
--- a/include/common.h
+++ b/include/common.h
@@ -323,6 +323,16 @@ int update_flash_size(int flash_size);
  */
 void board_show_dram(ulong size);
 
+/**
+ * arch_fixup_memory_node() - Write arch-specific memory information to fdt
+ *
+ * Defined in arch/$(ARCH)/lib/bootm.c
+ *
+ * @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 2cccc35..8f07a67 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 bfce861..b8cc523 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 */
@@ -92,6 +95,30 @@
 #define IMAGE_ENABLE_SHA1	0
 #endif
 
+#endif /* CONFIG_FIT */
+
+#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
 
 /*
@@ -280,9 +307,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;
@@ -390,21 +415,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 */
@@ -546,6 +564,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.8.2.1

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

* [U-Boot] [PATCH v3 06/12] arm: Refactor bootm to reduce #ifdefs
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (3 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 05/12] image: Add device tree setup to image library Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 07/12] arm: Use image_setup_linux() instead of local code Simon Glass
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 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>
---
Changes in v3: None
Changes in v2:
- Fix checkpatch checks about parenthesis alignment

 arch/arm/include/asm/bootm.h      | 54 ++++++++++++++++++++++++-
 arch/arm/include/asm/u-boot-arm.h |  2 -
 arch/arm/lib/bootm.c              | 84 ++++++++++-----------------------------
 common/cmd_bootm.c                |  2 +-
 4 files changed, 73 insertions(+), 69 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 f16861a..c01eef3 100644
--- a/arch/arm/include/asm/u-boot-arm.h
+++ b/arch/arm/include/asm/u-boot-arm.h
@@ -54,8 +54,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 f3b30c5..08c11b7 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -37,13 +37,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)
 {
@@ -109,11 +103,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;
@@ -127,9 +116,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;
@@ -144,9 +131,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;
@@ -171,9 +156,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
@@ -187,14 +170,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;
@@ -204,13 +184,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;
@@ -218,19 +195,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)
@@ -274,50 +244,38 @@ __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 */
 	}
 }
 
@@ -342,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);
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index b9b2979..dd6cafa 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -276,7 +276,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 #if defined(CONFIG_FIT)
 	} else if (images.fit_uname_os) {
 		ret = fit_image_get_entry(images.fit_hdr_os,
-				images.fit_noffset_os, &images.ep);
+					  images.fit_noffset_os, &images.ep);
 		if (ret) {
 			puts("Can't get entry point property!\n");
 			return 1;
-- 
1.8.2.1

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

* [U-Boot] [PATCH v3 07/12] arm: Use image_setup_linux() instead of local code
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (4 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 06/12] arm: Refactor bootm to reduce #ifdefs Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 08/12] powerpc: " Simon Glass
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 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>
---
Changes in v3: None
Changes in v2: None

 arch/arm/lib/Makefile    |  1 +
 arch/arm/lib/bootm-fdt.c | 52 +++++++++++++++++++++++++++++++++++++++++++
 arch/arm/lib/bootm.c     | 57 +-----------------------------------------------
 3 files changed, 54 insertions(+), 56 deletions(-)
 create mode 100644 arch/arm/lib/bootm-fdt.c

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 6ae161a..5b2cb61 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -45,6 +45,7 @@ endif
 COBJS-y += bss.o
 
 COBJS-y	+= bootm.o
+COBJS-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
 COBJS-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
 SOBJS-$(CONFIG_USE_ARCH_MEMSET) += memset.o
 SOBJS-$(CONFIG_USE_ARCH_MEMCPY) += memcpy.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 08c11b7..1b6e0ac 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -22,7 +22,6 @@
  * 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>
@@ -69,23 +68,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");
@@ -202,43 +184,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 */
@@ -249,7 +194,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.8.2.1

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

* [U-Boot] [PATCH v3 08/12] powerpc: Use image_setup_linux() instead of local code
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (5 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 07/12] arm: Use image_setup_linux() instead of local code Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 09/12] m68k: " Simon Glass
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 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>
---
Changes in v3: None
Changes in v2: None

 arch/powerpc/lib/bootm.c | 84 +-----------------------------------------------
 1 file changed, 1 insertion(+), 83 deletions(-)

diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c
index 0119a7b..340b545 100644
--- a/arch/powerpc/lib/bootm.c
+++ b/arch/powerpc/lib/bootm.c
@@ -220,101 +220,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.8.2.1

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

* [U-Boot] [PATCH v3 09/12] m68k: Use image_setup_linux() instead of local code
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (6 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 08/12] powerpc: " Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 10/12] sparc: " Simon Glass
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 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>
---
Changes in v3: None
Changes in v2: None

 arch/m68k/lib/bootm.c | 15 +++------------
 1 file 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.8.2.1

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

* [U-Boot] [PATCH v3 10/12] sparc: Use image_setup_linux() instead of local code
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (7 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 09/12] m68k: " Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 11/12] buildman: Allow conflicting tags to avoid spurious errors Simon Glass
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 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.

Cover-letter
Introduce a common image_setup_linux() function
This series continues the work to tidy up the image code. Each
architecture has its own code for setting up ready for booting linux.
An attempt is made here to unify these in a single image_setup_linux()
function.

The part of the image code that deals with FDT is split into image-fdt.c
and a few tweaks are added to make FIT images more viable in SPL.
END
Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3:
- Split the image_setup_linux() commits into their own series

Changes in v2: None

 arch/sparc/lib/bootm.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/arch/sparc/lib/bootm.c b/arch/sparc/lib/bootm.c
index bcc6358..1a9343c 100644
--- a/arch/sparc/lib/bootm.c
+++ b/arch/sparc/lib/bootm.c
@@ -95,10 +95,8 @@ void arch_lmb_reserve(struct lmb *lmb)
 int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * images)
 {
 	char *bootargs;
-	ulong initrd_start, initrd_end;
 	ulong rd_len;
 	void (*kernel) (struct linux_romvec *, void *);
-	struct lmb *lmb = &images->lmb;
 	int ret;
 
 	if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
@@ -131,24 +129,23 @@ int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * im
 	 * extracted and is writeable.
 	 */
 
+	ret = image_setup_linux(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.
 		 *
 		 * Set INITRD Image address relative to RAM Start
 		 */
 		linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image =
-		    initrd_start - CONFIG_SYS_RAM_BASE;
+			images->initrd_start - CONFIG_SYS_RAM_BASE;
 		linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = rd_len;
 		/* Clear READ ONLY flag if set to non-zero */
 		linux_hdr->hdr_input.ver_0203.root_flags = 1;
-- 
1.8.2.1

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

* [U-Boot] [PATCH v3 11/12] buildman: Allow conflicting tags to avoid spurious errors
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (8 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 10/12] sparc: " Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 12/12] buildman: Produce a sensible error message when branch is missing Simon Glass
  2013-05-15 12:48 ` [U-Boot] [U-Boot, v3, 01/12] mkimage: Put FIT loading in function and tidy error handling Tom Rini
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 UTC (permalink / raw)
  To: u-boot

Conflicting tags can prevent buildman from building two series which exist
one after the other in a branch. There is no reason not to allow this sort
of workflow with buildman, so ignore conflicting tags in buildman.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3: None
Changes in v2: None

 tools/buildman/control.py | 5 +++++
 tools/patman/series.py    | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 8d7b9b5..1ce8b6f 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -137,6 +137,11 @@ def DoBuildman(options, args):
     upstream_commit = gitutil.GetUpstream(options.git_dir, options.branch)
     series = patchstream.GetMetaDataForList(upstream_commit, options.git_dir,
             1)
+    # Conflicting tags are not a problem for buildman, since it does not use
+    # then. For example, Series-version is not useful for buildman. On the
+    # other hand conflicting tags will cause an error. So allow later tags
+    # to overwrite earlier ones.
+    series.allow_overwrite = True
     series = patchstream.GetMetaDataForList(range_expr, options.git_dir, None,
             series)
 
diff --git a/tools/patman/series.py b/tools/patman/series.py
index 783b3dd..85ed316 100644
--- a/tools/patman/series.py
+++ b/tools/patman/series.py
@@ -40,6 +40,7 @@ class Series(dict):
         notes: List of lines in the notes
         changes: (dict) List of changes for each version, The key is
             the integer version number
+        allow_overwrite: Allow tags to overwrite an existing tag
     """
     def __init__(self):
         self.cc = []
@@ -49,6 +50,7 @@ class Series(dict):
         self.cover = None
         self.notes = []
         self.changes = {}
+        self.allow_overwrite = False
 
         # Written in MakeCcFile()
         #  key: name of patch file
@@ -72,7 +74,7 @@ class Series(dict):
         """
         # If we already have it, then add to our list
         name = name.replace('-', '_')
-        if name in self:
+        if name in self and not self.allow_overwrite:
             values = value.split(',')
             values = [str.strip() for str in values]
             if type(self[name]) != type([]):
-- 
1.8.2.1

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

* [U-Boot] [PATCH v3 12/12] buildman: Produce a sensible error message when branch is missing
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (9 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 11/12] buildman: Allow conflicting tags to avoid spurious errors Simon Glass
@ 2013-05-08 18:06 ` Simon Glass
  2013-05-15 12:48 ` [U-Boot] [U-Boot, v3, 01/12] mkimage: Put FIT loading in function and tidy error handling Tom Rini
  11 siblings, 0 replies; 13+ messages in thread
From: Simon Glass @ 2013-05-08 18:06 UTC (permalink / raw)
  To: u-boot

Rather than a backtrace, produce a nice error message when an invalid
branch is provided to buildman.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3: None
Changes in v2: None

 tools/buildman/control.py |  4 ++++
 tools/patman/gitutil.py   | 21 +++++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 1ce8b6f..85a4a34 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -111,6 +111,10 @@ def DoBuildman(options, args):
             print col.Color(col.RED, str)
             sys.exit(1)
         count = gitutil.CountCommitsInBranch(options.git_dir, options.branch)
+        if count is None:
+            str = "Branch '%s' not found or has no upstream" % options.branch
+            print col.Color(col.RED, str)
+            sys.exit(1)
         count += 1   # Build upstream commit also
 
     if not count:
diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py
index e31da15..b7f6739 100644
--- a/tools/patman/gitutil.py
+++ b/tools/patman/gitutil.py
@@ -56,10 +56,14 @@ def GetUpstream(git_dir, branch):
     Returns:
         Name of upstream branch (e.g. 'upstream/master') or None if none
     """
-    remote = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
-            'branch.%s.remote' % branch)
-    merge = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
-            'branch.%s.merge' % branch)
+    try:
+        remote = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
+                                       'branch.%s.remote' % branch)
+        merge = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
+                                      'branch.%s.merge' % branch)
+    except:
+        return None
+
     if remote == '.':
         return merge
     elif remote and merge:
@@ -78,9 +82,11 @@ def GetRangeInBranch(git_dir, branch, include_upstream=False):
         branch: Name of branch
     Return:
         Expression in the form 'upstream..branch' which can be used to
-        access the commits.
+        access the commits. If the branch does not exist, returns None.
     """
     upstream = GetUpstream(git_dir, branch)
+    if not upstream:
+        return None
     return '%s%s..%s' % (upstream, '~' if include_upstream else '', branch)
 
 def CountCommitsInBranch(git_dir, branch, include_upstream=False):
@@ -90,9 +96,12 @@ def CountCommitsInBranch(git_dir, branch, include_upstream=False):
         git_dir: Directory containing git repo
         branch: Name of branch
     Return:
-        Number of patches that exist on top of the branch
+        Number of patches that exist on top of the branch, or None if the
+        branch does not exist.
     """
     range_expr = GetRangeInBranch(git_dir, branch, include_upstream)
+    if not range_expr:
+        return None
     pipe = [['git', '--git-dir', git_dir, 'log', '--oneline', '--no-decorate',
              range_expr],
             ['wc', '-l']]
-- 
1.8.2.1

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

* [U-Boot] [U-Boot, v3, 01/12] mkimage: Put FIT loading in function and tidy error handling
  2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
                   ` (10 preceding siblings ...)
  2013-05-08 18:06 ` [U-Boot] [PATCH v3 12/12] buildman: Produce a sensible error message when branch is missing Simon Glass
@ 2013-05-15 12:48 ` Tom Rini
  11 siblings, 0 replies; 13+ messages in thread
From: Tom Rini @ 2013-05-15 12:48 UTC (permalink / raw)
  To: u-boot

On Wed, May 08, 2013 at 08:05:57AM -0000, Simon Glass wrote:

> The fit_handle_file() function is quite long - split out the part that
> loads and checks a FIT into its own function. We will use this
> function for storing public keys into a destination FDT file.
> 
> The error handling is currently a bit repetitive - tidy it.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, along with the rest of the series, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130515/9e32b33c/attachment.pgp>

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

end of thread, other threads:[~2013-05-15 12:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-08 18:05 [U-Boot] [PATCH v3 01/12] mkimage: Put FIT loading in function and tidy error handling Simon Glass
2013-05-08 18:05 ` [U-Boot] [PATCH v3 02/12] image: Remove remaining #ifdefs in image-fit.c Simon Glass
2013-05-08 18:05 ` [U-Boot] [PATCH v3 03/12] image: Add CONFIG_FIT_SPL_PRINT to control FIT image printing in SPL Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 04/12] image: Split libfdt code into image-fdt.c Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 05/12] image: Add device tree setup to image library Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 06/12] arm: Refactor bootm to reduce #ifdefs Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 07/12] arm: Use image_setup_linux() instead of local code Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 08/12] powerpc: " Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 09/12] m68k: " Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 10/12] sparc: " Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 11/12] buildman: Allow conflicting tags to avoid spurious errors Simon Glass
2013-05-08 18:06 ` [U-Boot] [PATCH v3 12/12] buildman: Produce a sensible error message when branch is missing Simon Glass
2013-05-15 12:48 ` [U-Boot] [U-Boot, v3, 01/12] mkimage: Put FIT loading in function and tidy error handling Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.