uboot/arch/sandbox/cpu/spl.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright (c) 2016 Google, Inc
   4 */
   5
   6#include <common.h>
   7#include <dm.h>
   8#include <hang.h>
   9#include <init.h>
  10#include <log.h>
  11#include <os.h>
  12#include <spl.h>
  13#include <asm/global_data.h>
  14#include <asm/spl.h>
  15#include <asm/state.h>
  16#include <test/ut.h>
  17
  18DECLARE_GLOBAL_DATA_PTR;
  19
  20/* SPL / TPL init function */
  21void board_init_f(ulong flag)
  22{
  23        struct sandbox_state *state = state_get_current();
  24
  25        gd->arch.ram_buf = state->ram_buf;
  26        gd->ram_size = state->ram_size;
  27}
  28
  29u32 spl_boot_device(void)
  30{
  31        return BOOT_DEVICE_BOARD;
  32}
  33
  34static int spl_board_load_image(struct spl_image_info *spl_image,
  35                                struct spl_boot_device *bootdev)
  36{
  37        char fname[256];
  38        int ret;
  39
  40        ret = os_find_u_boot(fname, sizeof(fname), false);
  41        if (ret) {
  42                printf("(%s not found, error %d)\n", fname, ret);
  43                return ret;
  44        }
  45
  46        /*
  47         * Set up spl_image to boot from jump_to_image_no_args(). Allocate this
  48         * outsdide the RAM buffer (i.e. don't use strdup()).
  49         */
  50        spl_image->arg = os_malloc(strlen(fname) + 1);
  51        if (!spl_image->arg)
  52                return log_msg_ret("exec", -ENOMEM);
  53        strcpy(spl_image->arg, fname);
  54
  55        return 0;
  56}
  57SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
  58
  59void spl_board_init(void)
  60{
  61        struct sandbox_state *state = state_get_current();
  62
  63        preloader_console_init();
  64
  65        if (state->run_unittests) {
  66                struct unit_test *tests = UNIT_TEST_ALL_START();
  67                const int count = UNIT_TEST_ALL_COUNT();
  68                int ret;
  69
  70                ret = ut_run_list("spl", NULL, tests, count,
  71                                  state->select_unittests);
  72                /* continue execution into U-Boot */
  73        }
  74}
  75
  76void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  77{
  78        const char *fname = spl_image->arg;
  79
  80        if (fname) {
  81                os_fd_restore();
  82                os_spl_to_uboot(fname);
  83        } else {
  84                printf("No filename provided for U-Boot\n");
  85        }
  86        hang();
  87}
  88
  89int handoff_arch_save(struct spl_handoff *ho)
  90{
  91        ho->arch.magic = TEST_HANDOFF_MAGIC;
  92
  93        return 0;
  94}
  95