2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-04-15 19:11:31 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2017 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2019-03-28 03:01:23 +00:00
|
|
|
#include <asm/arch-rockchip/bootrom.h>
|
|
|
|
#include <asm/arch-rockchip/boot_mode.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2017-10-11 07:00:49 +00:00
|
|
|
#include <asm/io.h>
|
2017-10-10 14:21:14 +00:00
|
|
|
#include <asm/setjmp.h>
|
|
|
|
#include <asm/system.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force the jmp_buf to the data-section, as .bss will not be valid
|
|
|
|
* when save_boot_params is invoked.
|
|
|
|
*/
|
|
|
|
static jmp_buf brom_ctx __section(".data");
|
2017-04-15 19:11:31 +00:00
|
|
|
|
2017-10-11 07:00:49 +00:00
|
|
|
static void _back_to_bootrom(enum rockchip_bootrom_cmd brom_cmd)
|
|
|
|
{
|
|
|
|
longjmp(brom_ctx, brom_cmd);
|
|
|
|
}
|
|
|
|
|
2017-10-10 14:21:16 +00:00
|
|
|
void back_to_bootrom(enum rockchip_bootrom_cmd brom_cmd)
|
2017-04-15 19:11:31 +00:00
|
|
|
{
|
2017-06-29 09:28:15 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
|
|
|
|
puts("Returning to boot ROM...\n");
|
2017-04-15 19:11:31 +00:00
|
|
|
#endif
|
2017-10-11 07:00:49 +00:00
|
|
|
_back_to_bootrom(brom_cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we back to bootrom download mode if get a
|
|
|
|
* BOOT_BROM_DOWNLOAD flag in boot mode register
|
|
|
|
*
|
|
|
|
* note: the boot mode register is configured by
|
|
|
|
* application(next stage bootloader, kernel, etc),
|
|
|
|
* and the bootrom never check this register, so we need
|
|
|
|
* to check it and back to bootrom at very early bootstage(before
|
|
|
|
* some basic configurations(such as interrupts) been
|
|
|
|
* changed by TPL/SPL, as the bootrom download operation
|
2019-11-14 02:18:03 +00:00
|
|
|
* relies on many default settings(such as interrupts) by
|
|
|
|
* itself.
|
2017-10-11 07:00:49 +00:00
|
|
|
*/
|
|
|
|
static bool check_back_to_brom_dnl_flag(void)
|
|
|
|
{
|
|
|
|
u32 boot_mode;
|
|
|
|
|
|
|
|
if (CONFIG_ROCKCHIP_BOOT_MODE_REG) {
|
|
|
|
boot_mode = readl(CONFIG_ROCKCHIP_BOOT_MODE_REG);
|
|
|
|
if (boot_mode == BOOT_BROM_DOWNLOAD) {
|
|
|
|
writel(0, CONFIG_ROCKCHIP_BOOT_MODE_REG);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2017-10-10 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All Rockchip BROM implementations enter with a valid stack-pointer,
|
|
|
|
* so this can safely be implemented in C (providing a single
|
|
|
|
* implementation both for ARMv7 and AArch64).
|
|
|
|
*/
|
|
|
|
int save_boot_params(void)
|
|
|
|
{
|
|
|
|
int ret = setjmp(brom_ctx);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 0:
|
2017-10-11 07:00:49 +00:00
|
|
|
if (check_back_to_brom_dnl_flag())
|
|
|
|
_back_to_bootrom(BROM_BOOT_ENTER_DNL);
|
2017-10-10 14:21:14 +00:00
|
|
|
/*
|
|
|
|
* This is the initial pass through this function
|
|
|
|
* (i.e. saving the context), setjmp just setup up the
|
|
|
|
* brom_ctx: transfer back into the startup-code at
|
|
|
|
* 'save_boot_params_ret' and let the compiler know
|
|
|
|
* that this will not return.
|
|
|
|
*/
|
|
|
|
save_boot_params_ret();
|
|
|
|
while (true)
|
|
|
|
/* does not return */;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BROM_BOOT_NEXTSTAGE:
|
|
|
|
/*
|
|
|
|
* To instruct the BROM to boot the next stage, we
|
|
|
|
* need to return 0 to it: i.e. we need to rewrite
|
|
|
|
* the return code once more.
|
|
|
|
*/
|
|
|
|
ret = 0;
|
|
|
|
break;
|
2017-10-11 07:00:49 +00:00
|
|
|
case BROM_BOOT_ENTER_DNL:
|
|
|
|
/*
|
|
|
|
* A non-zero return value will instruct the BROM enter
|
|
|
|
* download mode.
|
|
|
|
*/
|
|
|
|
ret = 1;
|
|
|
|
break;
|
2017-10-10 14:21:14 +00:00
|
|
|
default:
|
|
|
|
#if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
|
|
|
|
puts("FATAL: unexpected command to back_to_bootrom()\n");
|
|
|
|
#endif
|
|
|
|
hang();
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
2017-04-15 19:11:31 +00:00
|
|
|
}
|