Skip to content

Commit 7e3757d

Browse files
committed
[rom_ext] Jump to immutable section first at startup
To minimize the divergence between SKUs that with and without immutable rom_ext feature enabled in ROM, we propose always linking the section to rom_ext, and call it first if it isn’t called by ROM. With this change, the boot flows will be always (almost) the same, while the OTP flag `IMMUTABLE_ROM_EXT_EN` basically only controls whether the immutability is enforced by ROM. SKUs without the immutability enforced enable should still link with the trunk/master imm_rom_ext section, but without the EN bit set in their OTP configuration. Signed-off-by: Yi-Hsuan Deng <[email protected]> (cherry picked from commit db977a5)
1 parent c53de62 commit 7e3757d

File tree

7 files changed

+77
-2
lines changed

7 files changed

+77
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
cc_library(
8+
name = "main_lib",
9+
srcs = ["imm_rom_ext.c"],
10+
hdrs = ["imm_rom_ext.h"],
11+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright lowRISC contributors (OpenTitan project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "sw/device/silicon_creator/imm_rom_ext/imm_rom_ext.h"
6+
7+
void imm_rom_ext_main(void) {
8+
// TODO(opentitan#24368): Implement this.
9+
return;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright lowRISC contributors (OpenTitan project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_IMM_ROM_EXT_IMM_ROM_EXT_H_
6+
#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_IMM_ROM_EXT_IMM_ROM_EXT_H_
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
void imm_rom_ext_main(void);
13+
14+
#ifdef __cplusplus
15+
} // extern "C"
16+
#endif
17+
18+
#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_IMM_ROM_EXT_IMM_ROM_EXT_H_

sw/device/silicon_creator/rom_ext/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ cc_test(
166166
"//sw/device/lib/base:memory",
167167
"//sw/device/lib/base:stdasm",
168168
"//sw/device/lib/runtime:hart",
169+
"//sw/device/silicon_creator/imm_rom_ext:main_lib",
169170
"//sw/device/silicon_creator/lib:boot_data",
170171
"//sw/device/silicon_creator/lib:boot_log",
171172
"//sw/device/silicon_creator/lib:dbg_print",

sw/device/silicon_creator/rom_ext/rom_ext.c

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "sw/device/lib/base/memory.h"
1111
#include "sw/device/lib/base/stdasm.h"
1212
#include "sw/device/lib/runtime/hart.h"
13+
#include "sw/device/silicon_creator/imm_rom_ext/imm_rom_ext.h"
1314
#include "sw/device/silicon_creator/lib/base/boot_measurements.h"
1415
#include "sw/device/silicon_creator/lib/base/chip.h"
1516
#include "sw/device/silicon_creator/lib/base/sec_mmio.h"
@@ -876,6 +877,11 @@ static rom_error_t rom_ext_start(boot_data_t *boot_data, boot_log_t *boot_log) {
876877
}
877878

878879
void rom_ext_main(void) {
880+
// TODO(opentitan#24368): Call immutable main in .rom_ext_immutable.
881+
// The immutable rom_ext startup code is not ready yet, so we call it here
882+
// to avoid breaking tests.
883+
imm_rom_ext_main();
884+
879885
rom_ext_check_rom_expectations();
880886
boot_data_t boot_data;
881887
boot_log_t *boot_log = &retention_sram_get()->creator.boot_log;
@@ -898,3 +904,9 @@ void rom_ext_exception_handler(void);
898904

899905
OT_ALIAS("rom_ext_interrupt_handler")
900906
void rom_ext_nmi_handler(void);
907+
908+
// A no-op immutable rom_ext fallback to avoid breaking tests before the
909+
// proper bazel target is ready.
910+
// TODO(opentitan#24368): Remove this nop fallback.
911+
OT_SECTION(".rom_ext_immutable.fallback")
912+
void imm_rom_ext_placeholder(void) {}

sw/device/silicon_creator/rom_ext/rom_ext_common.ld

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ SECTIONS {
7777
_text_start = .;
7878
_rom_ext_immutable_start = .;
7979
KEEP(*(.rom_ext_immutable))
80+
81+
/* TODO: Remove this fallback when rom_ext_immutable section is ready. */
82+
KEEP(*(.rom_ext_immutable.fallback))
83+
8084
/* Ensure section end is word-aligned. */
8185
. = ALIGN(256);
8286
_rom_ext_immutable_end = .;

sw/device/silicon_creator/rom_ext/rom_ext_start.S

+21-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#include "hw/top_earlgrey/sw/autogen/top_earlgrey_memory.h"
6+
#include "sw/device/lib/base/hardened_asm.h"
7+
#include "otp_ctrl_regs.h"
68

79
/**
810
* ROM_EXT Interrupt Vector
@@ -78,15 +80,32 @@ _rom_ext_interrupt_vector:
7880
.type _rom_ext_start_boot, @function
7981
_rom_ext_start_boot:
8082
/**
81-
* Set up the global pointer `gp`.
82-
*
8383
* Linker relaxations are disabled until the global pointer is setup below,
8484
* because otherwise some sequences may be turned into `gp`-relative
8585
* sequences, which is incorrect when `gp` is not initialized.
8686
*/
8787
.option push
8888
.option norelax
89+
90+
/**
91+
* Call the .rom_ext_immutable first if it's not called by ROM.
92+
*/
93+
li a0, (TOP_EARLGREY_OTP_CTRL_CORE_BASE_ADDR + \
94+
OTP_CTRL_SW_CFG_WINDOW_REG_OFFSET)
95+
lw t0, OTP_CTRL_PARAM_CREATOR_SW_CFG_IMMUTABLE_ROM_EXT_EN_OFFSET(a0)
96+
li t1, HARDENED_BOOL_TRUE
97+
beq t0, t1, .L_mutable_start_boot
98+
call _rom_ext_immutable_start
99+
100+
/**
101+
* Continue booting the mutable rom_ext.
102+
*/
103+
.L_mutable_start_boot:
104+
/**
105+
* Set up the global pointer `gp`.
106+
*/
89107
la gp, __global_pointer$
108+
90109
.option pop
91110

92111
/**

0 commit comments

Comments
 (0)