summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.m@jp.panasonic.com>2014-04-18 17:41:04 +0900
committerTom Rini <trini@ti.com>2014-06-19 11:18:51 -0400
commitf18295d3837c282f10167502e25a964abb04acf7 (patch)
tree3515b13fbbea88e4d0cbccf452caca022af588c3 /common
parent739a01ed8e02c3b79a0f059d34b749bfab1a30df (diff)
downloadu-boot-imx-f18295d3837c282f10167502e25a964abb04acf7.zip
u-boot-imx-f18295d3837c282f10167502e25a964abb04acf7.tar.gz
u-boot-imx-f18295d3837c282f10167502e25a964abb04acf7.tar.bz2
fdt_support: fix an endian bug of fdt_initrd()
Data written to DTB must be converted to big endian order. It is usually done by using cpu_to_fdt32(), cpu_to_fdt64(), etc. fdt_initrd() invoked write_cell(), which always swaps byte order. It means the function only worked on little endian architectures. (On big endian architectures, the byte order should be kept as it is) This commit uses cpu_to_fdt32() and cpu_to_fdt64() and deletes write_cell(). Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com> Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/fdt_support.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/common/fdt_support.c b/common/fdt_support.c
index ae714e7..324d6b9 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -32,18 +32,6 @@ static int get_cells_len(const void *fdt, const char *nr_cells_name)
return 4;
}
-/*
- * Write a 4 or 8 byte big endian cell
- */
-static void write_cell(u8 *addr, u64 val, int size)
-{
- int shift = (size - 1) * 8;
- while (size-- > 0) {
- *addr++ = (val >> shift) & 0xff;
- shift -= 8;
- }
-}
-
/**
* fdt_getprop_u32_default_node - Return a node's property or a default
*
@@ -212,11 +200,21 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
}
#endif
+static inline int fdt_setprop_uxx(void *fdt, int nodeoffset, const char *name,
+ uint64_t val, int is_u64)
+{
+ if (is_u64)
+ return fdt_setprop_u64(fdt, nodeoffset, name, val);
+ else
+ return fdt_setprop_u32(fdt, nodeoffset, name, (uint32_t)val);
+}
+
+
int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)
{
- int nodeoffset, addr_cell_len;
+ int nodeoffset;
int err, j, total;
- fdt64_t tmp;
+ int is_u64;
uint64_t addr, size;
/* find or create "/chosen" node. */
@@ -248,19 +246,20 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)
return err;
}
- addr_cell_len = get_cells_len(fdt, "#address-cells");
+ is_u64 = (get_cells_len(fdt, "#address-cells") == 8);
+
+ err = fdt_setprop_uxx(fdt, nodeoffset, "linux,initrd-start",
+ (uint64_t)initrd_start, is_u64);
- write_cell((u8 *)&tmp, initrd_start, addr_cell_len);
- err = fdt_setprop(fdt, nodeoffset,
- "linux,initrd-start", &tmp, addr_cell_len);
if (err < 0) {
printf("WARNING: could not set linux,initrd-start %s.\n",
fdt_strerror(err));
return err;
}
- write_cell((u8 *)&tmp, initrd_end, addr_cell_len);
- err = fdt_setprop(fdt, nodeoffset,
- "linux,initrd-end", &tmp, addr_cell_len);
+
+ err = fdt_setprop_uxx(fdt, nodeoffset, "linux,initrd-end",
+ (uint64_t)initrd_end, is_u64);
+
if (err < 0) {
printf("WARNING: could not set linux,initrd-end %s.\n",
fdt_strerror(err));