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