blob: e52c738d3295a0606b28aa260561988846889436 [file] [log] [blame]
Konstantin Porotchkin01851db2018-10-03 14:21:42 +03001/*
2 * Copyright (C) 2018 Marvell International Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 * https://spdx.org/licenses
6 */
7
8#include <arch_helpers.h>
9#include <debug.h>
10#include <console.h>
11#include <marvell_plat_priv.h>
12#include <marvell_pm.h>
13#include <platform_def.h>
14#include <plat_marvell.h>
15#include <string.h>
16
17#define BR_FLAG_SILENT 0x1
18#define SKIP_IMAGE_CODE 0xDEADB002
19
20void mailbox_clean(void)
21{
22 uintptr_t *mailbox = (void *)PLAT_MARVELL_MAILBOX_BASE;
23
24 memset(mailbox, 0, PLAT_MARVELL_MAILBOX_SIZE);
25}
26
27int exec_ble_main(int bootrom_flags)
28{
29 int skip = 0;
30 uintptr_t *mailbox = (void *)PLAT_MARVELL_MAILBOX_BASE;
31
32 /*
33 * In some situations, like boot from UART, bootrom will
34 * request to avoid printing to console. in that case don't
35 * initialize the console and prints will be ignored
36 */
37 if ((bootrom_flags & BR_FLAG_SILENT) == 0)
38 console_init(PLAT_MARVELL_BOOT_UART_BASE,
39 PLAT_MARVELL_BOOT_UART_CLK_IN_HZ,
40 MARVELL_CONSOLE_BAUDRATE);
41
42 NOTICE("Starting binary extension\n");
43
44 /* initiliaze time (for delay functionality) */
45 plat_delay_timer_init();
46
47 ble_plat_setup(&skip);
48
49 /* if there's skip image request, bootrom will load from the image
50 * saved on the next address of the flash
51 */
52 if (skip)
53 return SKIP_IMAGE_CODE;
54
55 /*
56 * Check if the mailbox magic number is stored at index MBOX_IDX_MAGIC
57 * and the suspend to RAM magic number at index MBOX_IDX_SUSPEND_MAGIC.
58 * If the above is true, this is the recovery from suspend to RAM state.
59 * In such case the mailbox should remain intact, since it stores the
60 * warm boot jump address to be used by the TF-A in BL31.
61 * Othervise the mailbox should be cleaned from a garbage data.
62 */
63 if (mailbox[MBOX_IDX_MAGIC] != MVEBU_MAILBOX_MAGIC_NUM ||
64 mailbox[MBOX_IDX_SUSPEND_MAGIC] != MVEBU_MAILBOX_SUSPEND_STATE) {
65 NOTICE("Cold boot\n");
66 mailbox_clean();
67 } else {
68 void (*bootrom_exit)(void) =
69 (void (*)(void))mailbox[MBOX_IDX_ROM_EXIT_ADDR];
70
71 INFO("Recovery...\n");
72 /*
73 * If this is recovery from suspend, two things has to be done:
74 * 1. Define the DRAM region as executable memory for preparing
75 * jump to TF-A
76 * 2. Instead of returning control to the BootROM, invalidate
77 * and flush caches, and continue execution at address stored
78 * in the mailbox.
79 * This should be done until the BootROM have a native support
80 * for the system restore flow.
81 */
82 marvell_ble_prepare_exit();
83 bootrom_exit();
84 }
85
86 return 0;
87}
88
89/* NOTE: don't notify this function, all code must be added to exec_ble_main
90 * in order to keep the end of ble_main as a fixed address.
91 */
92int __attribute__ ((section(".entry"))) ble_main(int bootrom_flags)
93{
94 volatile int ret;
95
96 ret = exec_ble_main(bootrom_flags);
97 return ret;
98}