Allow overriding defined partitions in the device tree blob
using partition info defined in the 'mtdparts' environment
variable.
Signed-off-by: Anatolij Gustschin ag...@denx.de
Cc: Gerald Van Baren vanba...@cideas.com
---
Changes since first version:
- in fdt_fixup_mtdparts() check the presence of mtdparts
environment variable and don't proceed with initialisation
if the variable is not defined (suppresses warning while booting).
common/cmd_mtdparts.c |2 +-
common/fdt_support.c| 219 +++
include/fdt_support.h |2 +
include/jffs2/load_kernel.h |1 +
include/mtd_node.h | 11 ++
5 files changed, 234 insertions(+), 1 deletions(-)
create mode 100644 include/mtd_node.h
diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 20fed2a..0b5f747 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -776,7 +776,7 @@ static int device_del(struct mtd_device *dev)
* @param num device number
* @return NULL if requested device does not exist
*/
-static struct mtd_device* device_find(u8 type, u8 num)
+struct mtd_device *device_find(u8 type, u8 num)
{
struct list_head *entry;
struct mtd_device *dev_tmp;
diff --git a/common/fdt_support.c b/common/fdt_support.c
index f89a3ee..b7d4fe5 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -757,3 +757,222 @@ int fdt_fixup_nor_flash_size(void *blob, int cs, u32 size)
return -1;
}
#endif
+
+#ifdef CONFIG_FDT_FIXUP_PARTITIONS
+#include jffs2/load_kernel.h
+#include mtd_node.h
+
+struct reg_cell {
+ unsigned int r0;
+ unsigned int r1;
+};
+
+int fdt_del_subnodes(const void *blob, int parent_offset)
+{
+ int off, ndepth;
+ int ret;
+
+ for (ndepth = 0, off = fdt_next_node(blob, parent_offset, ndepth);
+(off = 0) (ndepth 0);
+off = fdt_next_node(blob, off, ndepth)) {
+ if (ndepth == 1) {
+ debug(delete %s: offset: %x\n,
+ fdt_get_name(blob, off, 0), off);
+ ret = fdt_del_node((void *)blob, off);
+ if (ret 0) {
+ printf(Can't delete node: %s\n,
+ fdt_strerror(ret));
+ return ret;
+ } else {
+ ndepth = 0;
+ off = parent_offset;
+ }
+ }
+ }
+ return 0;
+}
+
+int fdt_increase_size(void *fdt, int add_len)
+{
+ int newlen;
+
+ newlen = fdt_totalsize(fdt) + add_len;
+
+ /* Open in place with a new len */
+ return fdt_open_into(fdt, fdt, newlen);
+}
+
+int fdt_del_partitions(void *blob, int parent_offset)
+{
+ const void *prop;
+ int ndepth = 0;
+ int off;
+ int ret;
+
+ off = fdt_next_node(blob, parent_offset, ndepth);
+ if (off 0 ndepth == 1) {
+ prop = fdt_getprop(blob, off, label, NULL);
+ if (prop == NULL) {
+ /*
+* Could not find label property, nand {}; node?
+* Check subnode, delete partitions there if any.
+*/
+ return fdt_del_partitions(blob, off);
+ } else {
+ ret = fdt_del_subnodes(blob, parent_offset);
+ if (ret 0) {
+ printf(Can't remove subnodes: %s\n,
+ fdt_strerror(ret));
+ return ret;
+ }
+ }
+ }
+ return 0;
+}
+
+int fdt_node_set_part_info(void *blob, int parent_offset,
+ struct mtd_device *dev)
+{
+ struct list_head *pentry;
+ struct part_info *part;
+ struct reg_cell cell;
+ int off, ndepth = 0;
+ int part_num, ret;
+ char buf[64];
+
+ ret = fdt_del_partitions(blob, parent_offset);
+ if (ret 0)
+ return ret;
+
+ /*
+* Check if it is nand {}; subnode, adjust
+* the offset in this case
+*/
+ off = fdt_next_node(blob, parent_offset, ndepth);
+ if (off 0 ndepth == 1)
+ parent_offset = off;
+
+ part_num = 0;
+ list_for_each_prev(pentry, dev-parts) {
+ int newoff;
+
+ part = list_entry(pentry, struct part_info, link);
+
+ debug(%2d: %-20s0x%08x\t0x%08x\t%d\n,
+ part_num, part-name, part-size,
+ part-offset, part-mask_flags);
+
+ sprintf(buf, partit...@%x, part-offset);
+add_sub:
+ ret = fdt_add_subnode(blob, parent_offset, buf);
+ if (ret == -FDT_ERR_NOSPACE) {
+ ret = fdt_increase_size(blob, 512);
+ if