]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fdt: Add fdt_fixup_nor_flash_size() to fixup NOR FLASH size in dtb
authorStefan Roese <sr@denx.de>
Wed, 21 Oct 2009 09:59:52 +0000 (11:59 +0200)
committerStefan Roese <sr@denx.de>
Fri, 23 Oct 2009 13:55:23 +0000 (15:55 +0200)
This function can be used to update the size in the "reg" property
of the NOR FLASH device nodes. This is necessary for boards with
non-fixed NOR FLASH sizes.

Signed-off-by: Stefan Roese <sr@denx.de>
Acked-by: Gerald Van Baren <vanbaren@cideas.com>
Acked-by: Wolfgang Denk <wd@denx.de>
common/fdt_support.c
include/fdt_support.h

index 89164a12d73d7569021f14493f31c07c12fb7b7b..40ff00a154454ca9a57a09311589fd72c45a34e5 100644 (file)
@@ -692,3 +692,47 @@ int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose) {
        return 0;
 }
 #endif
+
+#ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
+/*
+ * This function can be used to update the size in the "reg" property
+ * of the NOR FLASH device nodes. This is necessary for boards with
+ * non-fixed NOR FLASH sizes.
+ */
+int fdt_fixup_nor_flash_size(void *blob, int cs, u32 size)
+{
+       char compat[][16] = { "cfi-flash", "jedec-flash" };
+       int off;
+       int len;
+       struct fdt_property *prop;
+       u32 *reg;
+       int i;
+
+       for (i = 0; i < 2; i++) {
+               off = fdt_node_offset_by_compatible(blob, -1, compat[i]);
+               while (off != -FDT_ERR_NOTFOUND) {
+                       /*
+                        * Found one compatible node, now check if this one
+                        * has the correct CS
+                        */
+                       prop = fdt_get_property_w(blob, off, "reg", &len);
+                       if (prop) {
+                               reg = (u32 *)&prop->data[0];
+                               if (reg[0] == cs) {
+                                       reg[2] = size;
+                                       fdt_setprop(blob, off, "reg", reg,
+                                                   3 * sizeof(u32));
+
+                                       return 0;
+                               }
+                       }
+
+                       /* Move to next compatible node */
+                       off = fdt_node_offset_by_compatible(blob, off,
+                                                           compat[i]);
+               }
+       }
+
+       return -1;
+}
+#endif
index 16734c5352831f1465d68c517ec656da93398e18..0a9dd0dd84e9411e5c80be36b6697ea223ccf876 100644 (file)
@@ -79,5 +79,7 @@ void ft_pci_setup(void *blob, bd_t *bd);
 void set_working_fdt_addr(void *addr);
 int fdt_resize(void *blob);
 
+int fdt_fixup_nor_flash_size(void *blob, int cs, u32 size);
+
 #endif /* ifdef CONFIG_OF_LIBFDT */
 #endif /* ifndef __FDT_SUPPORT_H */