]> Git Repo - J-u-boot.git/blobdiff - common/board_f.c
common: board_f: change calculation of gd->mon_len to fix s5p4418 reloc
[J-u-boot.git] / common / board_f.c
index 5f1711181c7b8f444031089ed0c7eb4b3e50eb6d..8bada6ff2eec121aa69650bb844c8740ae12d835 100644 (file)
@@ -28,7 +28,6 @@
 #include <i2c.h>
 #include <init.h>
 #include <initcall.h>
-#include <lcd.h>
 #include <log.h>
 #include <malloc.h>
 #include <mapmem.h>
@@ -125,11 +124,11 @@ static int display_text_info(void)
 #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
        ulong bss_start, bss_end, text_base;
 
-       bss_start = (ulong)&__bss_start;
-       bss_end = (ulong)&__bss_end;
+       bss_start = (ulong)__bss_start;
+       bss_end = (ulong)__bss_end;
 
-#ifdef CONFIG_SYS_TEXT_BASE
-       text_base = CONFIG_SYS_TEXT_BASE;
+#ifdef CONFIG_TEXT_BASE
+       text_base = CONFIG_TEXT_BASE;
 #else
        text_base = CONFIG_SYS_MONITOR_BASE;
 #endif
@@ -146,20 +145,28 @@ static int print_resetinfo(void)
 {
        struct udevice *dev;
        char status[256];
+       bool status_printed = false;
        int ret;
 
-       ret = uclass_first_device_err(UCLASS_SYSRESET, &dev);
-       if (ret) {
-               debug("%s: No sysreset device found (error: %d)\n",
-                     __func__, ret);
-               /* Not all boards have sysreset drivers available during early
-                * boot, so don't fail if one can't be found.
-                */
-               return 0;
-       }
+       /*
+        * Not all boards have sysreset drivers available during early
+        * boot, so don't fail if one can't be found.
+        */
+       for (ret = uclass_first_device_check(UCLASS_SYSRESET, &dev); dev;
+            ret = uclass_next_device_check(&dev)) {
+               if (ret) {
+                       debug("%s: %s sysreset device (error: %d)\n",
+                             __func__, dev->name, ret);
+                       continue;
+               }
 
-       if (!sysreset_get_status(dev, status, sizeof(status)))
-               printf("%s", status);
+               if (!sysreset_get_status(dev, status, sizeof(status))) {
+                       printf("%s%s", status_printed ? " " : "", status);
+                       status_printed = true;
+               }
+       }
+       if (status_printed)
+               printf("\n");
 
        return 0;
 }
@@ -273,28 +280,26 @@ static int init_func_i2c(void)
 }
 #endif
 
-#if defined(CONFIG_VID)
-__weak int init_func_vid(void)
-{
-       return 0;
-}
-#endif
-
 static int setup_mon_len(void)
 {
-#if defined(__ARM__) || defined(__MICROBLAZE__)
-       gd->mon_len = (ulong)&__bss_end - (ulong)_start;
+#if defined(CONFIG_ARCH_NEXELL)
+       gd->mon_len = (ulong)__bss_end - (ulong)__image_copy_start;
+#elif defined(__ARM__) || defined(__MICROBLAZE__)
+       gd->mon_len = (ulong)__bss_end - (ulong)_start;
+#elif defined(CONFIG_SANDBOX) && !defined(__riscv)
+       gd->mon_len = (ulong)_end - (ulong)_init;
 #elif defined(CONFIG_SANDBOX)
+       /* gcc does not provide _init in crti.o on RISC-V */
        gd->mon_len = 0;
 #elif defined(CONFIG_EFI_APP)
-       gd->mon_len = (ulong)&_end - (ulong)_init;
+       gd->mon_len = (ulong)_end - (ulong)_init;
 #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
        gd->mon_len = CONFIG_SYS_MONITOR_LEN;
 #elif defined(CONFIG_SH) || defined(CONFIG_RISCV)
-       gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
+       gd->mon_len = (ulong)(__bss_end) - (ulong)(_start);
 #elif defined(CONFIG_SYS_MONITOR_BASE)
-       /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
-       gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
+       /* TODO: use (ulong)__bss_end - (ulong)__text_start; ? */
+       gd->mon_len = (ulong)__bss_end - CONFIG_SYS_MONITOR_BASE;
 #endif
        return 0;
 }
@@ -321,14 +326,14 @@ __weak int mach_cpu_init(void)
 }
 
 /* Get the top of usable RAM */
-__weak phys_size_t board_get_usable_ram_top(phys_size_t total_size)
+__weak phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
 {
-#if defined(CONFIG_SYS_SDRAM_BASE) && CONFIG_SYS_SDRAM_BASE > 0
+#if defined(CFG_SYS_SDRAM_BASE) && CFG_SYS_SDRAM_BASE > 0
        /*
         * Detect whether we have so much RAM that it goes past the end of our
         * 32-bit address space. If so, clip the usable RAM so it doesn't.
         */
-       if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
+       if (gd->ram_top < CFG_SYS_SDRAM_BASE)
                /*
                 * Will wrap back to top of 32-bit space when reservations
                 * are made.
@@ -363,8 +368,8 @@ static int setup_dest_addr(void)
         */
        gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
 #endif
-#ifdef CONFIG_SYS_SDRAM_BASE
-       gd->ram_base = CONFIG_SYS_SDRAM_BASE;
+#ifdef CFG_SYS_SDRAM_BASE
+       gd->ram_base = CFG_SYS_SDRAM_BASE;
 #endif
        gd->ram_top = gd->ram_base + get_effective_memsize();
        gd->ram_top = board_get_usable_ram_top(gd->mon_len);
@@ -374,19 +379,19 @@ static int setup_dest_addr(void)
        return arch_setup_dest_addr();
 }
 
-#ifdef CONFIG_PRAM
+#ifdef CFG_PRAM
 /* reserve protected RAM */
 static int reserve_pram(void)
 {
        ulong reg;
 
-       reg = env_get_ulong("pram", 10, CONFIG_PRAM);
+       reg = env_get_ulong("pram", 10, CFG_PRAM);
        gd->relocaddr -= (reg << 10);           /* size is in kB */
        debug("Reserving %ldk for protected RAM at %08lx\n", reg,
              gd->relocaddr);
        return 0;
 }
-#endif /* CONFIG_PRAM */
+#endif /* CFG_PRAM */
 
 /* Round memory pointer down to next 4 kB limit */
 static int reserve_round_4k(void)
@@ -400,24 +405,58 @@ __weak int arch_reserve_mmu(void)
        return 0;
 }
 
+static int reserve_video_from_videoblob(void)
+{
+       if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && spl_phase() > PHASE_SPL) {
+               struct video_handoff *ho;
+               int ret = 0;
+
+               ho = bloblist_find(BLOBLISTT_U_BOOT_VIDEO, sizeof(*ho));
+               if (!ho)
+                       return log_msg_ret("Missing video bloblist", -ENOENT);
+
+               ret = video_reserve_from_bloblist(ho);
+               if (ret)
+                       return log_msg_ret("Invalid Video handoff info", ret);
+
+               /* Sanity check fb from blob is before current relocaddr */
+               if (likely(gd->relocaddr > (unsigned long)ho->fb))
+                       gd->relocaddr = ho->fb;
+       }
+
+       return 0;
+}
+
+/*
+ * Check if any bloblist received specifying reserved areas from previous stage and adjust
+ * gd->relocaddr accordingly, so that we start reserving after pre-reserved areas
+ * from previous stage.
+ *
+ * NOTE:
+ * IT is recommended that all bloblists from previous stage are reserved from ram_top
+ * as next stage will simply start reserving further regions after them.
+ */
+static int setup_relocaddr_from_bloblist(void)
+{
+       reserve_video_from_videoblob();
+
+       return 0;
+}
+
 static int reserve_video(void)
 {
-#ifdef CONFIG_DM_VIDEO
-       ulong addr;
-       int ret;
+       if (CONFIG_IS_ENABLED(VIDEO)) {
+               ulong addr;
+               int ret;
 
-       addr = gd->relocaddr;
-       ret = video_reserve(&addr);
-       if (ret)
-               return ret;
-       debug("Reserving %luk for video at: %08lx\n",
-             ((unsigned long)gd->relocaddr - addr) >> 10, addr);
-       gd->relocaddr = addr;
-#elif defined(CONFIG_LCD)
-       /* reserve memory for LCD display (always full pages) */
-       gd->relocaddr = lcd_setmem(gd->relocaddr);
-       gd->fb_base = gd->relocaddr;
-#endif
+               addr = gd->relocaddr;
+               ret = video_reserve(&addr);
+               if (ret)
+                       return ret;
+               debug("Reserving %luk for video at: %08lx\n",
+                     ((unsigned long)gd->relocaddr - addr) >> 10, addr);
+               gd->relocaddr = addr;
+       }
 
        return 0;
 }
@@ -473,8 +512,8 @@ static int reserve_noncached(void)
 {
        /*
         * The value of gd->start_addr_sp must match the value of malloc_start
-        * calculated in boatrd_f.c:initr_malloc(), which is passed to
-        * board_r.c:mem_malloc_init() and then used by
+        * calculated in board_r.c:initr_malloc(), which is passed to
+        * dlmalloc.c:mem_malloc_init() and then used by
         * cache.c:noncached_init()
         *
         * These calculations must match the code in cache.c:noncached_init()
@@ -628,8 +667,6 @@ static int init_post(void)
 static int reloc_fdt(void)
 {
        if (!IS_ENABLED(CONFIG_OF_EMBED)) {
-               if (gd->flags & GD_FLG_SKIP_RELOC)
-                       return 0;
                if (gd->new_fdt) {
                        memcpy(gd->new_fdt, gd->fdt_blob,
                               fdt_totalsize(gd->fdt_blob));
@@ -671,13 +708,10 @@ static int reloc_bloblist(void)
                return 0;
        }
        if (gd->new_bloblist) {
-               int size = CONFIG_BLOBLIST_SIZE;
-
                debug("Copying bloblist from %p to %p, size %x\n",
-                     gd->bloblist, gd->new_bloblist, size);
-               bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
-                              gd->bloblist, size);
-               gd->bloblist = gd->new_bloblist;
+                     gd->bloblist, gd->new_bloblist, gd->bloblist->total_size);
+               return bloblist_reloc(gd->new_bloblist,
+                                     CONFIG_BLOBLIST_SIZE_RELOC);
        }
 #endif
 
@@ -687,7 +721,7 @@ static int reloc_bloblist(void)
 static int setup_reloc(void)
 {
        if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
-#ifdef CONFIG_SYS_TEXT_BASE
+#ifdef CONFIG_TEXT_BASE
 #ifdef ARM
                gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
 #elif defined(CONFIG_MICROBLAZE)
@@ -697,9 +731,9 @@ static int setup_reloc(void)
                 * On all ColdFire arch cpu, monitor code starts always
                 * just after the default vector table location, so at 0x400
                 */
-               gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
+               gd->reloc_off = gd->relocaddr - (CONFIG_TEXT_BASE + 0x400);
 #elif !defined(CONFIG_SANDBOX)
-               gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
+               gd->reloc_off = gd->relocaddr - CONFIG_TEXT_BASE;
 #endif
 #endif
        }
@@ -726,8 +760,7 @@ static int fix_fdt(void)
 #endif
 
 /* ARM calls relocate_code from its crt0.S */
-#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
-               !CONFIG_IS_ENABLED(X86_64)
+#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
 
 static int jump_to_copy(void)
 {
@@ -749,7 +782,11 @@ static int jump_to_copy(void)
         * (CPU cache)
         */
        arch_setup_gd(gd->new_gd);
-       board_init_f_r_trampoline(gd->start_addr_sp);
+# if CONFIG_IS_ENABLED(X86_64)
+               board_init_f_r_trampoline64(gd->new_gd, gd->start_addr_sp);
+# else
+               board_init_f_r_trampoline(gd->start_addr_sp);
+# endif
 #else
        relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
 #endif
@@ -786,7 +823,7 @@ static int initf_bootstage(void)
 
 static int initf_dm(void)
 {
-#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
+#if defined(CONFIG_DM) && CONFIG_IS_ENABLED(SYS_MALLOC_F)
        int ret;
 
        bootstage_start(BOOTSTAGE_ID_ACCUM_DM_F, "dm_f");
@@ -821,11 +858,6 @@ __weak int clear_bss(void)
        return 0;
 }
 
-static int misc_init_f(void)
-{
-       return event_notify_null(EVT_MISC_INIT_F);
-}
-
 static const init_fnc_t init_sequence_f[] = {
        setup_mon_len,
 #ifdef CONFIG_OF_CONTROL
@@ -837,18 +869,13 @@ static const init_fnc_t init_sequence_f[] = {
        initf_malloc,
        log_init,
        initf_bootstage,        /* uses its own timer, so does not need DM */
-       cyclic_init,
        event_init,
-#ifdef CONFIG_BLOBLIST
-       bloblist_init,
-#endif
+       bloblist_maybe_init,
        setup_spl_handoff,
 #if defined(CONFIG_CONSOLE_RECORD_INIT_F)
        console_record_init,
 #endif
-#if defined(CONFIG_HAVE_FSP)
-       arch_fsp_init,
-#endif
+       INITCALL_EVENT(EVT_FSP_INIT_F),
        arch_cpu_init,          /* basic arch cpu dependent setup */
        mach_cpu_init,          /* SoC/machine dependent CPU setup */
        initf_dm,
@@ -859,7 +886,7 @@ static const init_fnc_t init_sequence_f[] = {
        /* get CPU and bus clocks according to the environment variable */
        get_clocks,             /* get CPU and bus clocks (etc.) */
 #endif
-#if !defined(CONFIG_M68K)
+#if !defined(CONFIG_M68K) || (defined(CONFIG_M68K) && !defined(CONFIG_MCFTMR))
        timer_init,             /* initialize timer */
 #endif
 #if defined(CONFIG_BOARD_POSTCLK_INIT)
@@ -885,13 +912,10 @@ static const init_fnc_t init_sequence_f[] = {
        show_board_info,
 #endif
        INIT_FUNC_WATCHDOG_INIT
-       misc_init_f,
+       INITCALL_EVENT(EVT_MISC_INIT_F),
        INIT_FUNC_WATCHDOG_RESET
 #if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
        init_func_i2c,
-#endif
-#if defined(CONFIG_VID) && !defined(CONFIG_SPL)
-       init_func_vid,
 #endif
        announce_dram_init,
        dram_init,              /* configure available RAM banks */
@@ -899,9 +923,9 @@ static const init_fnc_t init_sequence_f[] = {
        post_init_f,
 #endif
        INIT_FUNC_WATCHDOG_RESET
-#if defined(CONFIG_SYS_DRAM_TEST)
+#if defined(CFG_SYS_DRAM_TEST)
        testdram,
-#endif /* CONFIG_SYS_DRAM_TEST */
+#endif /* CFG_SYS_DRAM_TEST */
        INIT_FUNC_WATCHDOG_RESET
 
 #ifdef CONFIG_POST
@@ -924,10 +948,11 @@ static const init_fnc_t init_sequence_f[] = {
 #ifdef CONFIG_OF_BOARD_FIXUP
        fix_fdt,
 #endif
-#ifdef CONFIG_PRAM
+#ifdef CFG_PRAM
        reserve_pram,
 #endif
        reserve_round_4k,
+       setup_relocaddr_from_bloblist,
        arch_reserve_mmu,
        reserve_video,
        reserve_trace,
@@ -955,8 +980,17 @@ static const init_fnc_t init_sequence_f[] = {
        do_elf_reloc_fixups,
 #endif
        clear_bss,
-#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
-               !CONFIG_IS_ENABLED(X86_64)
+       /*
+        * Deregister all cyclic functions before relocation, so that
+        * gd->cyclic_list does not contain any references to pre-relocation
+        * devices. Drivers will register their cyclic functions anew when the
+        * devices are probed again.
+        *
+        * This should happen as late as possible so that the window where a
+        * watchdog device is not serviced is as small as possible.
+        */
+       cyclic_unregister_all,
+#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
        jump_to_copy,
 #endif
        NULL,
This page took 0.039073 seconds and 4 git commands to generate.