]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/board_f.c
sandbox: Use os functions to read host device tree
[karo-tx-uboot.git] / common / board_f.c
index ab4242a77ea487cf17e68ae413d57a6c6c1a90e5..f285bad5388e74cc2170955b79e3a47aaf197dd5 100644 (file)
@@ -7,23 +7,7 @@
  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  * Marius Groeger <mgroeger@sysgo.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
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -165,13 +149,9 @@ static int display_text_info(void)
 #ifndef CONFIG_SANDBOX
        ulong bss_start, bss_end;
 
-#ifdef CONFIG_SYS_SYM_OFFSETS
-       bss_start = _bss_start_ofs + _TEXT_BASE;
-       bss_end = _bss_end_ofs + _TEXT_BASE;
-#else
        bss_start = (ulong)&__bss_start;
        bss_end = (ulong)&__bss_end;
-#endif
+
        debug("U-Boot code: %08X -> %08lX  BSS: -> %08lX\n",
              CONFIG_SYS_TEXT_BASE, bss_start, bss_end);
 #endif
@@ -239,17 +219,6 @@ static int show_dram_config(void)
        return 0;
 }
 
-ulong get_effective_memsize(void)
-{
-#ifndef        CONFIG_VERY_BIG_RAM
-       return gd->ram_size;
-#else
-       /* limit stack to what we can reasonable map */
-       return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
-               CONFIG_MAX_MEM_MAPPED : gd->ram_size);
-#endif
-}
-
 void __dram_init_banksize(void)
 {
 #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
@@ -261,11 +230,15 @@ void __dram_init_banksize(void)
 void dram_init_banksize(void)
        __attribute__((weak, alias("__dram_init_banksize")));
 
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
+#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
 static int init_func_i2c(void)
 {
        puts("I2C:   ");
+#ifdef CONFIG_SYS_I2C
+       i2c_init_all();
+#else
        i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+#endif
        puts("ready\n");
        return 0;
 }
@@ -291,8 +264,8 @@ static int zero_global_data(void)
 
 static int setup_mon_len(void)
 {
-#ifdef CONFIG_SYS_SYM_OFFSETS
-       gd->mon_len = _bss_end_ofs;
+#ifdef __ARM__
+       gd->mon_len = (ulong)&__bss_end - (ulong)_start;
 #elif defined(CONFIG_SANDBOX)
        gd->mon_len = (ulong)&_end - (ulong)_init;
 #else
@@ -309,45 +282,39 @@ __weak int arch_cpu_init(void)
 
 #ifdef CONFIG_OF_HOSTFILE
 
-#define CHECK(x)               err = (x); if (err) goto failed;
-
-/* Create an empty device tree blob */
-static int make_empty_fdt(void *fdt)
-{
-       int err;
-
-       CHECK(fdt_create(fdt, 256));
-       CHECK(fdt_finish_reservemap(fdt));
-       CHECK(fdt_begin_node(fdt, ""));
-       CHECK(fdt_end_node(fdt));
-       CHECK(fdt_finish(fdt));
-
-       return 0;
-failed:
-       printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
-       return -EACCES;
-}
-
 static int read_fdt_from_file(void)
 {
        struct sandbox_state *state = state_get_current();
+       const char *fname = state->fdt_fname;
        void *blob;
-       int size;
+       ssize_t size;
        int err;
+       int fd;
 
        blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
        if (!state->fdt_fname) {
-               err = make_empty_fdt(blob);
+               err = fdt_create_empty_tree(blob, 256);
                if (!err)
                        goto done;
-               return err;
+               printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
+               return -EINVAL;
        }
-       err = fs_set_blk_dev("host", NULL, FS_TYPE_SANDBOX);
-       if (err)
-               return err;
-       size = fs_read(state->fdt_fname, CONFIG_SYS_FDT_LOAD_ADDR, 0, 0);
-       if (size < 0)
+
+       size = os_get_filesize(fname);
+       if (size < 0) {
+               printf("Failed to file FDT file '%s'\n", fname);
+               return -ENOENT;
+       }
+       fd = os_open(fname, OS_O_RDONLY);
+       if (fd < 0) {
+               printf("Failed to open FDT file '%s'\n", fname);
+               return -EACCES;
+       }
+       if (os_read(fd, blob, size) != size) {
+               os_close(fd);
                return -EIO;
+       }
+       os_close(fd);
 
 done:
        gd->fdt_blob = blob;
@@ -359,9 +326,10 @@ done:
 #ifdef CONFIG_SANDBOX
 static int setup_ram_buf(void)
 {
-       gd->arch.ram_buf = os_malloc(CONFIG_SYS_SDRAM_SIZE);
-       assert(gd->arch.ram_buf);
-       gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
+       struct sandbox_state *state = state_get_current();
+
+       gd->arch.ram_buf = state->ram_buf;
+       gd->ram_size = state->ram_size;
 
        return 0;
 }
@@ -371,14 +339,10 @@ static int setup_fdt(void)
 {
 #ifdef CONFIG_OF_EMBED
        /* Get a pointer to the FDT */
-       gd->fdt_blob = _binary_dt_dtb_start;
+       gd->fdt_blob = __dtb_dt_begin;
 #elif defined CONFIG_OF_SEPARATE
        /* FDT is at end of image */
-# ifdef CONFIG_SYS_SYM_OFFSETS
-       gd->fdt_blob = (void *)(_end_ofs + CONFIG_SYS_TEXT_BASE);
-# else
        gd->fdt_blob = (ulong *)&_end;
-# endif
 #elif defined(CONFIG_OF_HOSTFILE)
        if (read_fdt_from_file()) {
                puts("Failed to read control FDT\n");
@@ -474,7 +438,7 @@ static int reserve_round_4k(void)
 static int reserve_mmu(void)
 {
        /* reserve TLB table */
-       gd->arch.tlb_size = 4096 * 4;
+       gd->arch.tlb_size = PGTABLE_SIZE;
        gd->relocaddr -= gd->arch.tlb_size;
 
        /* round down to next 64 kB limit */
@@ -626,7 +590,7 @@ static int reserve_stacks(void)
         * TODO(sjg@chromium.org): Perhaps create arch_reserve_stack()
         * to handle this and put in arch/xxx/lib/stack.c
         */
-# ifdef CONFIG_ARM
+# if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
 #  ifdef CONFIG_USE_IRQ
        gd->start_addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ);
        debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
@@ -672,7 +636,7 @@ static int setup_board_part1(void)
        bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;         /* size  of SRAM */
 #endif
 
-#if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
+#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
                defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
        bd->bi_immr_base = CONFIG_SYS_IMMR;     /* base  of IMMR register     */
 #endif
@@ -784,7 +748,7 @@ static int setup_reloc(void)
 }
 
 /* ARM calls relocate_code from its crt0.S */
-#if !defined(CONFIG_ARM)
+#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
 
 static int jump_to_copy(void)
 {
@@ -804,8 +768,6 @@ static int jump_to_copy(void)
         * (CPU cache)
         */
        board_init_f_r_trampoline(gd->start_addr_sp);
-#elif defined(CONFIG_SANDBOX)
-       board_init_r(gd->new_gd, 0);
 #else
        relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
 #endif
@@ -823,11 +785,6 @@ static int mark_bootstage(void)
 }
 
 static init_fnc_t init_sequence_f[] = {
-#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
-               !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
-               !defined(CONFIG_MPC86xx) && !defined(CONFIG_X86)
-       zero_global_data,
-#endif
 #ifdef CONFIG_SANDBOX
        setup_ram_buf,
 #endif
@@ -895,19 +852,17 @@ static init_fnc_t init_sequence_f[] = {
 #endif
        display_options,        /* say that we are here */
        display_text_info,      /* show debugging info if required */
-#if defined(CONFIG_8260)
+#if defined(CONFIG_MPC8260)
        prt_8260_rsr,
        prt_8260_clks,
-#endif /* CONFIG_8260 */
+#endif /* CONFIG_MPC8260 */
 #if defined(CONFIG_MPC83xx)
        prt_83xx_rsr,
 #endif
 #ifdef CONFIG_PPC
        checkcpu,
 #endif
-#if defined(CONFIG_DISPLAY_CPUINFO)
        print_cpuinfo,          /* display cpu info (and speed) */
-#endif
 #if defined(CONFIG_MPC5xxx)
        prt_mpc5xxx_clks,
 #endif /* CONFIG_MPC5xxx */
@@ -919,7 +874,7 @@ static init_fnc_t init_sequence_f[] = {
        misc_init_f,
 #endif
        INIT_FUNC_WATCHDOG_RESET
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
+#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
        init_func_i2c,
 #endif
 #if defined(CONFIG_HARD_SPI)
@@ -1007,7 +962,7 @@ static init_fnc_t init_sequence_f[] = {
        INIT_FUNC_WATCHDOG_RESET
        reloc_fdt,
        setup_reloc,
-#ifndef CONFIG_ARM
+#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
        jump_to_copy,
 #endif
        NULL,
@@ -1021,12 +976,24 @@ void board_init_f(ulong boot_flags)
        gd = &data;
 #endif
 
+       /*
+        * Clear global data before it is accessed at debug print
+        * in initcall_run_list. Otherwise the debug print probably
+        * get the wrong vaule of gd->have_console.
+        */
+#if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
+               !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
+               !defined(CONFIG_MPC86xx) && !defined(CONFIG_X86)
+       zero_global_data();
+#endif
+
        gd->flags = boot_flags;
+       gd->have_console = 0;
 
        if (initcall_run_list(init_sequence_f))
                hang();
 
-#ifndef CONFIG_ARM
+#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
        /* NOTREACHED - jump_to_copy() does not return */
        hang();
 #endif