]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - common/fdt_support.c
correct a syntax typo in at91_matrix.h
[people/ms/u-boot.git] / common / fdt_support.c
index a79bc085b205a042ec146e255481d1e7cb934fc2..f89a3eef6670ccc9bb91f436801b73e355f08f52 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <stdio_dev.h>
 #include <linux/ctype.h>
 #include <linux/types.h>
 #include <asm/global_data.h>
@@ -90,6 +91,23 @@ int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
 }
 
 #ifdef CONFIG_OF_STDOUT_VIA_ALIAS
+
+#ifdef CONFIG_SERIAL_MULTI
+static void fdt_fill_multisername(char *sername, size_t maxlen)
+{
+       const char *outname = stdio_devices[stdout]->name;
+
+       if (strcmp(outname, "serial") > 0)
+               strncpy(sername, outname, maxlen);
+
+       /* eserial? */
+       if (strcmp(outname + 1, "serial") > 0)
+               strncpy(sername, outname + 1, maxlen);
+}
+#else
+static inline void fdt_fill_multisername(char *sername, size_t maxlen) {}
+#endif /* CONFIG_SERIAL_MULTI */
+
 static int fdt_fixup_stdout(void *fdt, int chosenoff)
 {
        int err = 0;
@@ -98,7 +116,9 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
        char sername[9] = { 0 };
        const char *path;
 
-       sprintf(sername, "serial%d", CONFIG_CONS_INDEX - 1);
+       fdt_fill_multisername(sername, sizeof(sername) - 1);
+       if (!sername[0])
+               sprintf(sername, "serial%d", CONFIG_CONS_INDEX - 1);
 
        err = node = fdt_path_offset(fdt, "/aliases");
        if (node >= 0) {
@@ -495,7 +515,7 @@ void fdt_fixup_dr_usb(void *blob, bd_t *bd)
 }
 #endif /* CONFIG_HAS_FSL_DR_USB */
 
-#if defined(CONFIG_MPC83XX) || defined(CONFIG_MPC85xx)
+#if defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx)
 /*
  * update crypto node properties to a specified revision of the SEC
  * called with sec_rev == 0 if not on an mpc8xxxE processor
@@ -580,7 +600,7 @@ void fdt_fixup_crypto_node(void *blob, int sec_rev)
                printf("WARNING: could not set crypto property: %s\n",
                       fdt_strerror(err));
 }
-#endif /* defined(CONFIG_MPC83XX) || defined(CONFIG_MPC85xx) */
+#endif /* defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx) */
 
 /* Resize the fdt to its actual size + a bit of padding */
 int fdt_resize(void *blob)
@@ -604,10 +624,11 @@ int fdt_resize(void *blob)
 
        /*
         * Calculate the actual size of the fdt
-        * plus the size needed for fdt_add_mem_rsv
+        * plus the size needed for two fdt_add_mem_rsv, one
+        * for the fdt itself and one for a possible initrd
         */
        actualsize = fdt_off_dt_strings(blob) +
-               fdt_size_dt_strings(blob) + sizeof(struct fdt_reserve_entry);
+               fdt_size_dt_strings(blob) + 2*sizeof(struct fdt_reserve_entry);
 
        /* Make it so the fdt ends on a page boundary */
        actualsize = ALIGN(actualsize + ((uint)blob & 0xfff), 0x1000);
@@ -625,7 +646,7 @@ int fdt_resize(void *blob)
 }
 
 #ifdef CONFIG_PCI
-#define CONFIG_SYS_PCI_NR_INBOUND_WIN 3
+#define CONFIG_SYS_PCI_NR_INBOUND_WIN 4
 
 #define FDT_PCI_PREFETCH       (0x40000000)
 #define FDT_PCI_MEM32          (0x02000000)
@@ -646,8 +667,8 @@ int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose) {
        for (r = 0; r < hose->region_count; r++) {
                u64 bus_start, phys_start, size;
 
-               /* skip if !PCI_REGION_MEMORY */
-               if (!(hose->regions[r].flags & PCI_REGION_MEMORY))
+               /* skip if !PCI_REGION_SYS_MEMORY */
+               if (!(hose->regions[r].flags & PCI_REGION_SYS_MEMORY))
                        continue;
 
                bus_start = (u64)hose->regions[r].bus_start;
@@ -655,7 +676,7 @@ int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose) {
                size = (u64)hose->regions[r].size;
 
                dma_range[0] = 0;
-               if (size > 0x100000000ull)
+               if (size >= 0x100000000ull)
                        dma_range[0] |= FDT_PCI_MEM64;
                else
                        dma_range[0] |= FDT_PCI_MEM32;
@@ -692,3 +713,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