Skip to content

Commit 036c46d

Browse files
committed
Fix MP15x boot detect
1 parent 8ba3a8e commit 036c46d

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

linkscript-mp15x.ld

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ ENTRY(_Reset);
99

1010
__STACK_START = 0x30000000;
1111
__HEAP_SIZE = 0x0;
12-
boot_mode_table_addr = 0x30000004;
1312

1413
SECTIONS {
1514
.text : {

src/boot_detect.hh

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#pragma once
2+
#include "boot_mode_table.hh"
23
#include "print.hh"
34
#include <cstdint>
45
#include <string_view>
56

6-
extern uint32_t boot_mode_table_addr[];
7-
87
namespace BootDetect
98
{
109

@@ -55,7 +54,6 @@ constexpr std::string_view bootmethod_string(BootMethod method)
5554
// - boot instance = bit 31:16
5655
// - boot device = bit 15:0
5756
//
58-
static constexpr uint32_t BOOTROM_PARAM_ADDR = 0x2FFC0078;
5957
static constexpr uint32_t BOOTROM_MODE_MASK = 0x0000FFFF;
6058
static constexpr uint32_t BOOTROM_MODE_SHIFT = 0;
6159
static constexpr uint32_t BOOTROM_INSTANCE_MASK = 0xFFFF0000;
@@ -65,28 +63,6 @@ static constexpr uint32_t BOOT_TYPE_SHIFT = 4;
6563
static constexpr uint32_t BOOT_INSTANCE_MASK = 0x0F;
6664
static constexpr uint32_t BOOT_INSTANCE_SHIFT = 0;
6765

68-
inline uint32_t read_raw_bootrom_itf()
69-
{
70-
print("&boot_mode_table_addr = 0x", Hex{(uint32_t)boot_mode_table_addr}, "\n");
71-
72-
if ((uint32_t)boot_mode_table_addr == 0) {
73-
print("Boot mode table address not defined in linker script. Presuming SD Card boot\n");
74-
return BOOT_SDCARD << BOOTROM_MODE_SHIFT;
75-
}
76-
77-
auto table_addr = boot_mode_table_addr[0];
78-
print("boot_mode_table_addr = 0x", Hex{table_addr}, "\n");
79-
80-
if (table_addr == 0) {
81-
print("Boot mode table was not set by startup.s. Presuming SD Card boot\n");
82-
return BOOT_SDCARD << BOOTROM_MODE_SHIFT;
83-
}
84-
85-
auto val = *reinterpret_cast<uint32_t *>(table_addr);
86-
print("boot_mode value = 0x", Hex{val}, "\n");
87-
return val;
88-
}
89-
9066
inline BootMethod read_boot_method()
9167
{
9268
uint32_t bootrom_itf = read_raw_bootrom_itf();

src/mp13x/boot_mode_table.hh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "print.hh"
2+
#include <cstdint>
3+
4+
inline uint32_t read_raw_bootrom_itf()
5+
{
6+
// Allocated by the linker, and value is written to the address by the startup script
7+
extern uint32_t boot_mode_table_addr[];
8+
9+
print("&boot_mode_table_addr = 0x", Hex{(uint32_t)boot_mode_table_addr}, "\n");
10+
11+
if ((uint32_t)boot_mode_table_addr == 0) {
12+
print("Boot mode table address not defined in linker script. Presuming SD Card boot\n");
13+
return 1;
14+
}
15+
16+
auto table_addr = boot_mode_table_addr[0];
17+
print("boot_mode_table_addr = 0x", Hex{table_addr}, "\n");
18+
19+
if (table_addr == 0) {
20+
print("Boot mode table was not set by startup.s. Presuming SD Card boot\n");
21+
return 1;
22+
}
23+
24+
auto val = *reinterpret_cast<uint32_t *>(table_addr);
25+
print("boot_mode value = 0x", Hex{val}, "\n");
26+
return val;
27+
}

src/mp15x/boot_mode_table.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <cstdint>
2+
3+
inline uint32_t read_raw_bootrom_itf()
4+
{
5+
static constexpr uint32_t BOOTROM_PARAM_ADDR = 0x2FFC0078;
6+
auto val = *reinterpret_cast<uint32_t *>(BOOTROM_PARAM_ADDR);
7+
return val;
8+
}

src/mp15x/startup.s

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ _Reset:
2525
Reset_Handler:
2626
cpsid if // Mask Interrupts
2727

28-
ldr r4, =boot_mode_table_addr // Store boot info from BOOTROM
29-
str r0, [r4] // into designated address in SRAM
30-
3128
mrc p15, 0, r0, c1, c0, 0 // Read System Control register (SCTLR)
3229
bic r0, r0, #(0x1 << 12) // Clear I bit 12 to disable I Cache
3330
bic r0, r0, #(0x1 << 2) // Clear C bit 2 to disable D Cache

0 commit comments

Comments
 (0)