summaryrefslogtreecommitdiff
path: root/arch/arm/mach-rockchip/bootrom.c
blob: 7b9b307a89c403d662264d99ff1fdce1b6ee0c90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
 * Copyright (c) 2017 Google, Inc
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <asm/arch/bootrom.h>
#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");

void back_to_bootrom(void)
{
#if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
	puts("Returning to boot ROM...\n");
#endif
	longjmp(brom_ctx, BROM_BOOT_NEXTSTAGE);
}

/*
 * 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:
		/*
		 * 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;

	default:
#if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
		puts("FATAL: unexpected command to back_to_bootrom()\n");
#endif
		hang();
	};

	return ret;
}