watchdog: Implement generic watchdog_reset() version
[oweals/u-boot.git] / common / board_r.c
index adc1f1937ed1fd9bec0b1b6080e658a1f4f52fb0..150e8cd424f64b6ebe435bf817f0483492d9a153 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2011 The Chromium OS Authors.
  * (C) Copyright 2002-2006
@@ -6,8 +7,6 @@
  * (C) Copyright 2002
  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  * Marius Groeger <mgroeger@sysgo.de>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #endif
 #include <command.h>
 #include <console.h>
-#ifdef CONFIG_HAS_DATAFLASH
-#include <dataflash.h>
-#endif
 #include <dm.h>
 #include <environment.h>
 #include <fdtdec.h>
 #include <ide.h>
 #include <initcall.h>
-#include <init_helpers.h>
-#ifdef CONFIG_PS2KBD
-#include <keyboard.h>
-#endif
 #if defined(CONFIG_CMD_KGDB)
 #include <kgdb.h>
 #endif
-#include <logbuff.h>
 #include <malloc.h>
 #include <mapmem.h>
 #ifdef CONFIG_BITBANGMII
@@ -45,7 +36,6 @@
 #include <onenand_uboot.h>
 #include <scsi.h>
 #include <serial.h>
-#include <spi.h>
 #include <stdio_dev.h>
 #include <timer.h>
 #include <trace.h>
 #include <dm/root.h>
 #include <linux/compiler.h>
 #include <linux/err.h>
-#ifdef CONFIG_AVR32
-#include <asm/arch/mmu.h>
-#endif
 #include <efi_loader.h>
+#include <wdt.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -133,7 +121,7 @@ static int initr_reloc_global_data(void)
 {
 #ifdef __ARM__
        monitor_flash_len = _end - __image_copy_start;
-#elif defined(CONFIG_NDS32)
+#elif defined(CONFIG_NDS32) || defined(CONFIG_RISCV)
        monitor_flash_len = (ulong)&_end - (ulong)&_start;
 #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
        monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
@@ -152,24 +140,28 @@ static int initr_reloc_global_data(void)
         */
        fixup_cpu();
 #endif
-#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
+#if !defined(CONFIG_ENV_ADDR) || defined(ENV_IS_EMBEDDED)
        /*
-        * Some systems need to relocate the env_addr pointer early because the
-        * location it points to will get invalidated before env_relocate is
-        * called.  One example is on systems that might use a L2 or L3 cache
-        * in SRAM mode and initialize that cache from SRAM mode back to being
-        * a cache in cpu_init_r.
+        * Relocate the early env_addr pointer unless we know it is not inside
+        * the binary. Some systems need this and for the rest, it doesn't hurt.
         */
-       gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
+       gd->env_addr += gd->reloc_off;
 #endif
 #ifdef CONFIG_OF_EMBED
        /*
-       * The fdt_blob needs to be moved to new relocation address
-       * incase of FDT blob is embedded with in image
-       */
+        * The fdt_blob needs to be moved to new relocation address
+        * incase of FDT blob is embedded with in image
+        */
        gd->fdt_blob += gd->reloc_off;
 #endif
 #ifdef CONFIG_EFI_LOADER
+       /*
+        * On the ARM architecture gd is mapped to a fixed register (r9 or x18).
+        * As this register may be overwritten by an EFI payload we save it here
+        * and restore it on every callback entered.
+        */
+       efi_save_gd();
+
        efi_runtime_relocate(gd->relocaddr, NULL);
 #endif
 
@@ -206,19 +198,6 @@ static int initr_addr_map(void)
 }
 #endif
 
-#ifdef CONFIG_LOGBUFFER
-unsigned long logbuffer_base(void)
-{
-       return gd->ram_top - LOGBUFF_LEN;
-}
-
-static int initr_logbuffer(void)
-{
-       logbuff_init_ptrs();
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_POST
 static int initr_post_backlog(void)
 {
@@ -259,7 +238,7 @@ static int initr_malloc(void)
 {
        ulong malloc_start;
 
-#ifdef CONFIG_SYS_MALLOC_F_LEN
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)
        debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
              gd->malloc_ptr / 1024);
 #endif
@@ -371,14 +350,16 @@ static int initr_flash(void)
        print_size(flash_size, "");
 #ifdef CONFIG_SYS_FLASH_CHECKSUM
        /*
-       * Compute and print flash CRC if flashchecksum is set to 'y'
-       *
-       * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
-       */
-       if (getenv_yesno("flashchecksum") == 1) {
+        * Compute and print flash CRC if flashchecksum is set to 'y'
+        *
+        * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
+        */
+       if (env_get_yesno("flashchecksum") == 1) {
+               const uchar *flash_base = (const uchar *)CONFIG_SYS_FLASH_BASE;
+
                printf("  CRC: %08X", crc32(0,
-                       (const unsigned char *) CONFIG_SYS_FLASH_BASE,
-                       flash_size));
+                                           flash_base,
+                                           flash_size));
        }
 #endif /* CONFIG_SYS_FLASH_CHECKSUM */
        putc('\n');
@@ -395,7 +376,6 @@ static int initr_flash(void)
        update_flash_size(flash_size);
 #endif
 
-
 #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
        /* flash mapped at end of memory map */
        bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
@@ -406,20 +386,6 @@ static int initr_flash(void)
 }
 #endif
 
-#if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
-static int initr_spi(void)
-{
-       /* PPC does this here */
-#ifdef CONFIG_SPI
-#if !defined(CONFIG_ENV_IS_IN_EEPROM)
-       spi_init_f();
-#endif
-       spi_init_r();
-#endif
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_CMD_NAND
 /* go init the NAND */
 static int initr_nand(void)
@@ -450,15 +416,6 @@ static int initr_mmc(void)
 }
 #endif
 
-#ifdef CONFIG_HAS_DATAFLASH
-static int initr_dataflash(void)
-{
-       AT91F_DataflashInit();
-       dataflash_print_info();
-       return 0;
-}
-#endif
-
 /*
  * Tell if it's OK to load the environment early in boot.
  *
@@ -487,13 +444,14 @@ static int initr_env(void)
        if (should_load_env())
                env_relocate();
        else
-               set_default_env(NULL);
+               set_default_env(NULL, 0);
 #ifdef CONFIG_OF_CONTROL
-       setenv_addr("fdtcontroladdr", gd->fdt_blob);
+       env_set_hex("fdtcontroladdr",
+                   (unsigned long)map_to_sysmem(gd->fdt_blob));
 #endif
 
        /* Initialize from environment */
-       load_addr = getenv_ulong("loadaddr", 16, load_addr);
+       load_addr = env_get_ulong("loadaddr", 16, load_addr);
 
        return 0;
 }
@@ -526,7 +484,7 @@ static int initr_api(void)
 #endif
 
 /* enable exceptions */
-#if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
+#ifdef CONFIG_ARM
 static int initr_enable_interrupts(void)
 {
        enable_interrupts();
@@ -540,21 +498,21 @@ static int initr_ethaddr(void)
        bd_t *bd = gd->bd;
 
        /* kept around for legacy kernels only ... ignore the next section */
-       eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
+       eth_env_get_enetaddr("ethaddr", bd->bi_enetaddr);
 #ifdef CONFIG_HAS_ETH1
-       eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
+       eth_env_get_enetaddr("eth1addr", bd->bi_enet1addr);
 #endif
 #ifdef CONFIG_HAS_ETH2
-       eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
+       eth_env_get_enetaddr("eth2addr", bd->bi_enet2addr);
 #endif
 #ifdef CONFIG_HAS_ETH3
-       eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
+       eth_env_get_enetaddr("eth3addr", bd->bi_enet3addr);
 #endif
 #ifdef CONFIG_HAS_ETH4
-       eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
+       eth_env_get_enetaddr("eth4addr", bd->bi_enet4addr);
 #endif
 #ifdef CONFIG_HAS_ETH5
-       eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
+       eth_env_get_enetaddr("eth5addr", bd->bi_enet5addr);
 #endif
        return 0;
 }
@@ -586,6 +544,7 @@ static int initr_scsi(void)
 {
        puts("SCSI:  ");
        scsi_init();
+       puts("\n");
 
        return 0;
 }
@@ -629,7 +588,7 @@ static int initr_pcmcia(void)
 }
 #endif
 
-#if defined(CONFIG_IDE)
+#if defined(CONFIG_IDE) && !defined(CONFIG_BLK)
 static int initr_ide(void)
 {
        puts("IDE:   ");
@@ -643,7 +602,7 @@ static int initr_ide(void)
 }
 #endif
 
-#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
+#if defined(CONFIG_PRAM)
 /*
  * Export available size of memory for Linux, taking into account the
  * protected RAM at top of memory
@@ -653,15 +612,9 @@ int initr_mem(void)
        ulong pram = 0;
        char memsz[32];
 
-# ifdef CONFIG_PRAM
-       pram = getenv_ulong("pram", 10, CONFIG_PRAM);
-# endif
-# if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
-       /* Also take the logbuffer into account (pram is in kB) */
-       pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
-# endif
-       sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
-       setenv("mem", memsz);
+       pram = env_get_ulong("pram", 10, CONFIG_PRAM);
+       sprintf(memsz, "%ldk", (long int)((gd->ram_size / 1024) - pram));
+       env_set("mem", memsz);
 
        return 0;
 }
@@ -676,15 +629,6 @@ static int initr_bedbug(void)
 }
 #endif
 
-#ifdef CONFIG_PS2KBD
-static int initr_kbd(void)
-{
-       puts("PS/2:  ");
-       kbd_init();
-       return 0;
-}
-#endif
-
 static int run_main_loop(void)
 {
 #ifdef CONFIG_SANDBOX
@@ -697,10 +641,7 @@ static int run_main_loop(void)
 }
 
 /*
- * Over time we hope to remove these functions with code fragments and
- * stub funtcions, and instead call the relevant function directly.
- *
- * We also hope to remove most of the driver-related init and do it if/when
+ * We hope to remove most of the driver-related init and do it if/when
  * the driver is later used.
  *
  * TODO: perhaps reset the watchdog in the initcall function after each call?
@@ -713,7 +654,7 @@ static init_fnc_t init_sequence_r[] = {
        initr_caches,
        /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
         *       A temporary mapping of IFC high region is since removed,
-        *       so environmental variables in NOR flash is not availble
+        *       so environmental variables in NOR flash is not available
         *       until board_init() is called below to remap IFC to high
         *       region.
         */
@@ -724,6 +665,7 @@ static init_fnc_t init_sequence_r[] = {
 #endif
        initr_barrier,
        initr_malloc,
+       log_init,
        initr_bootstage,        /* Needs malloc() but has its own timer */
        initr_console_record,
 #ifdef CONFIG_SYS_NONCACHED_MEMORY
@@ -736,7 +678,11 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_DM
        initr_dm,
 #endif
-#if defined(CONFIG_ARM) || defined(CONFIG_NDS32)
+#if defined(CONFIG_WDT)
+       initr_watchdog,
+#endif
+#if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV) || \
+       defined(CONFIG_SANDBOX)
        board_init,     /* Setup chipselects */
 #endif
        /*
@@ -768,9 +714,6 @@ static init_fnc_t init_sequence_r[] = {
        board_early_init_r,
 #endif
        INIT_FUNC_WATCHDOG_RESET
-#ifdef CONFIG_LOGBUFFER
-       initr_logbuffer,
-#endif
 #ifdef CONFIG_POST
        initr_post_backlog,
 #endif
@@ -778,7 +721,7 @@ static init_fnc_t init_sequence_r[] = {
 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
        /*
         * Do early PCI configuration _before_ the flash gets initialised,
-        * because PCU ressources are crucial for flash access on some boards.
+        * because PCU resources are crucial for flash access on some boards.
         */
        initr_pci,
 #endif
@@ -794,9 +737,6 @@ static init_fnc_t init_sequence_r[] = {
        /* initialize higher level parts of CPU like time base and timers */
        cpu_init_r,
 #endif
-#ifdef CONFIG_PPC
-       initr_spi,
-#endif
 #ifdef CONFIG_CMD_NAND
        initr_nand,
 #endif
@@ -805,9 +745,6 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #ifdef CONFIG_MMC
        initr_mmc,
-#endif
-#ifdef CONFIG_HAS_DATAFLASH
-       initr_dataflash,
 #endif
        initr_env,
 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
@@ -832,6 +769,7 @@ static init_fnc_t init_sequence_r[] = {
 #endif
        console_init_r,         /* fully init console as a device */
 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
+       console_announce_r,
        show_board_info,
 #endif
 #ifdef CONFIG_ARCH_MISC_INIT
@@ -845,10 +783,10 @@ static init_fnc_t init_sequence_r[] = {
        initr_kgdb,
 #endif
        interrupt_init,
-#if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
+#ifdef CONFIG_ARM
        initr_enable_interrupts,
 #endif
-#if defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || defined(CONFIG_M68K)
+#if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K)
        timer_init,             /* initialize timer */
 #endif
 #if defined(CONFIG_LED_STATUS)
@@ -878,7 +816,7 @@ static init_fnc_t init_sequence_r[] = {
 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE)
        initr_pcmcia,
 #endif
-#if defined(CONFIG_IDE)
+#if defined(CONFIG_IDE) && !defined(CONFIG_BLK)
        initr_ide,
 #endif
 #ifdef CONFIG_LAST_STAGE_INIT
@@ -894,11 +832,8 @@ static init_fnc_t init_sequence_r[] = {
        INIT_FUNC_WATCHDOG_RESET
        initr_bedbug,
 #endif
-#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
+#if defined(CONFIG_PRAM)
        initr_mem,
-#endif
-#ifdef CONFIG_PS2KBD
-       initr_kbd,
 #endif
        run_main_loop,
 };
@@ -919,13 +854,10 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
        int i;
 #endif
 
-#ifdef CONFIG_AVR32
-       mmu_init_r(dest_addr);
-#endif
-
 #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
        gd = new_gd;
 #endif
+       gd->flags &= ~GD_FLG_LOG_READY;
 
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
        for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)