1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2017 Google, Inc
8 #include <asm/arch-rockchip/bootrom.h>
9 #include <asm/arch-rockchip/boot_mode.h>
10 #include <asm/cache.h>
12 #include <asm/setjmp.h>
13 #include <asm/system.h>
16 * Force the jmp_buf to the data-section, as .bss will not be valid
17 * when save_boot_params is invoked.
19 static jmp_buf brom_ctx __section(".data");
21 static void _back_to_bootrom(enum rockchip_bootrom_cmd brom_cmd)
23 longjmp(brom_ctx, brom_cmd);
26 void back_to_bootrom(enum rockchip_bootrom_cmd brom_cmd)
28 #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
29 puts("Returning to boot ROM...\n");
31 _back_to_bootrom(brom_cmd);
35 * we back to bootrom download mode if get a
36 * BOOT_BROM_DOWNLOAD flag in boot mode register
38 * note: the boot mode register is configured by
39 * application(next stage bootloader, kernel, etc),
40 * and the bootrom never check this register, so we need
41 * to check it and back to bootrom at very early bootstage(before
42 * some basic configurations(such as interrupts) been
43 * changed by TPL/SPL, as the bootrom download operation
44 * relies on many default settings(such as interrupts) by
47 static bool check_back_to_brom_dnl_flag(void)
51 if (CONFIG_ROCKCHIP_BOOT_MODE_REG) {
52 boot_mode = readl(CONFIG_ROCKCHIP_BOOT_MODE_REG);
53 if (boot_mode == BOOT_BROM_DOWNLOAD) {
54 writel(0, CONFIG_ROCKCHIP_BOOT_MODE_REG);
63 * All Rockchip BROM implementations enter with a valid stack-pointer,
64 * so this can safely be implemented in C (providing a single
65 * implementation both for ARMv7 and AArch64).
67 int save_boot_params(void)
69 int ret = setjmp(brom_ctx);
73 if (check_back_to_brom_dnl_flag())
74 _back_to_bootrom(BROM_BOOT_ENTER_DNL);
76 * This is the initial pass through this function
77 * (i.e. saving the context), setjmp just setup up the
78 * brom_ctx: transfer back into the startup-code at
79 * 'save_boot_params_ret' and let the compiler know
80 * that this will not return.
82 save_boot_params_ret();
84 /* does not return */;
87 case BROM_BOOT_NEXTSTAGE:
89 * To instruct the BROM to boot the next stage, we
90 * need to return 0 to it: i.e. we need to rewrite
91 * the return code once more.
95 case BROM_BOOT_ENTER_DNL:
97 * A non-zero return value will instruct the BROM enter
103 #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
104 puts("FATAL: unexpected command to back_to_bootrom()\n");