blob: b04e8b7a666e888cd75f7c408857be50b30b9841 [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)
Konstantin Porotchkind8e39572018-11-14 17:15:08 +020038 marvell_console_boot_init();
Konstantin Porotchkin01851db2018-10-03 14:21:42 +030039
40 NOTICE("Starting binary extension\n");
41
Konstantin Porotchkind8e39572018-11-14 17:15:08 +020042 /* initialize time (for delay functionality) */
Konstantin Porotchkin01851db2018-10-03 14:21:42 +030043 plat_delay_timer_init();
44
45 ble_plat_setup(&skip);
46
47 /* if there's skip image request, bootrom will load from the image
48 * saved on the next address of the flash
49 */
50 if (skip)
51 return SKIP_IMAGE_CODE;
52
53 /*
54 * Check if the mailbox magic number is stored at index MBOX_IDX_MAGIC
55 * and the suspend to RAM magic number at index MBOX_IDX_SUSPEND_MAGIC.
56 * If the above is true, this is the recovery from suspend to RAM state.
57 * In such case the mailbox should remain intact, since it stores the
58 * warm boot jump address to be used by the TF-A in BL31.
59 * Othervise the mailbox should be cleaned from a garbage data.
60 */
61 if (mailbox[MBOX_IDX_MAGIC] != MVEBU_MAILBOX_MAGIC_NUM ||
62 mailbox[MBOX_IDX_SUSPEND_MAGIC] != MVEBU_MAILBOX_SUSPEND_STATE) {
63 NOTICE("Cold boot\n");
64 mailbox_clean();
65 } else {
66 void (*bootrom_exit)(void) =
67 (void (*)(void))mailbox[MBOX_IDX_ROM_EXIT_ADDR];
68
69 INFO("Recovery...\n");
70 /*
71 * If this is recovery from suspend, two things has to be done:
72 * 1. Define the DRAM region as executable memory for preparing
73 * jump to TF-A
74 * 2. Instead of returning control to the BootROM, invalidate
75 * and flush caches, and continue execution at address stored
76 * in the mailbox.
77 * This should be done until the BootROM have a native support
78 * for the system restore flow.
79 */
80 marvell_ble_prepare_exit();
81 bootrom_exit();
82 }
83
84 return 0;
85}
86
87/* NOTE: don't notify this function, all code must be added to exec_ble_main
88 * in order to keep the end of ble_main as a fixed address.
89 */
90int __attribute__ ((section(".entry"))) ble_main(int bootrom_flags)
91{
92 volatile int ret;
93
94 ret = exec_ble_main(bootrom_flags);
95 return ret;
96}