Skip to content

Commit

Permalink
[imm_rom_ext] Add linker scripts for slot A & B
Browse files Browse the repository at this point in the history
As now we always link IMM_ROM_EXT into ROM_EXT, the address of
IMM_ROM_EXT's linker for slot A/B ROM_EXT should be adjusted. Apply
similar solution from ROM_EXT's linker scripts on IMM_ROM_EXT ones.

Also cleaned up the hello-world ROM code as we do not need them anymore.

Signed-off-by: Chia-Wei Liu <[email protected]>
  • Loading branch information
lchiawei committed Jan 22, 2025
1 parent 5547e44 commit 3613069
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 111 deletions.
107 changes: 78 additions & 29 deletions sw/device/silicon_creator/imm_rom_ext/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package(default_visibility = ["//visibility:public"])
cc_library(
name = "main_lib",
srcs = [
"hello_world_start.S",
"imm_rom_ext.c",
"imm_rom_ext_start.S",
],
hdrs = ["imm_rom_ext.h"],
target_compatible_with = [OPENTITAN_CPU],
Expand Down Expand Up @@ -60,14 +60,51 @@ cc_library(
],
)

ld_library(
name = "ld_common",
includes = ["imm_rom_ext_common.ld"],
deps = [
"//hw/top_earlgrey/sw/autogen:top_earlgrey_memory",
"//sw/device:info_sections",
"//sw/device/silicon_creator/lib/base:static_critical_sections",
],
)

ld_library(
name = "ld_slot_a",
script = "imm_rom_ext_slot_a.ld",
deps = [
":ld_common",
"//hw/top_earlgrey/sw/autogen:top_earlgrey_memory",
],
)

ld_library(
name = "ld_slot_b",
script = "imm_rom_ext_slot_b.ld",
deps = [
":ld_common",
"//hw/top_earlgrey/sw/autogen:top_earlgrey_memory",
],
)

ld_library(
name = "ld_slot_virtual",
script = "imm_rom_ext_slot_virtual.ld",
deps = [
":ld_common",
"//hw/top_earlgrey/sw/autogen:top_earlgrey_memory",
],
)

opentitan_binary(
name = "main_binaries",
name = "main_binaries_slot_a",
exec_env = DEFAULT_EXEC_ENV,
extra_bazel_features = [
"minsize",
"use_lld",
],
linker_script = ":ld_hello_world",
linker_script = ":ld_slot_a",
manifest = "//hw/top_earlgrey:none_manifest",
deps = [
":main_lib",
Expand All @@ -77,45 +114,57 @@ opentitan_binary(

[
create_imm_rom_ext_targets(
src = ":main_binaries",
base_name = "main_section",
src = ":main_binaries_slot_a",
base_name = "main_section_slot_a",
exec_env = env,
)
for env in DEFAULT_EXEC_ENV
]

ld_library(
name = "ld_hello_world",
script = "hello_world.ld",
deps = [
"//hw/top_earlgrey/sw/autogen:top_earlgrey_memory",
"//sw/device:info_sections",
"//sw/device/silicon_creator/lib/base:static_critical_sections",
],
)

cc_library(
name = "hello_world",
srcs = [
"hello_world.c",
"hello_world_start.S",
opentitan_binary(
name = "main_binaries_slot_b",
exec_env = DEFAULT_EXEC_ENV,
extra_bazel_features = [
"minsize",
"use_lld",
],
hdrs = ["hello_world.h"],
target_compatible_with = [OPENTITAN_CPU],
linker_script = ":ld_slot_b",
manifest = "//hw/top_earlgrey:none_manifest",
deps = [
"//sw/device/silicon_creator/lib/base:static_critical",
"//sw/device/silicon_creator/lib/drivers:uart",
":main_lib",
"//sw/device/lib/crt",
],
)

[
create_imm_rom_ext_targets(
src = ":main_binaries_slot_b",
base_name = "main_section_slot_b",
exec_env = env,
)
for env in DEFAULT_EXEC_ENV
]

opentitan_binary(
name = "hello_world_binaries",
exec_env = [
"//hw/top_earlgrey:fpga_cw340",
name = "main_binaries_slot_virtual",
exec_env = DEFAULT_EXEC_ENV,
extra_bazel_features = [
"minsize",
"use_lld",
],
linker_script = ":ld_hello_world",
linker_script = ":ld_slot_virtual",
manifest = "//hw/top_earlgrey:none_manifest",
deps = [
":hello_world",
":main_lib",
"//sw/device/lib/crt",
],
)

[
create_imm_rom_ext_targets(
src = ":main_binaries_slot_virtual",
base_name = "main_section_slot_virtual",
exec_env = env,
)
for env in DEFAULT_EXEC_ENV
]
32 changes: 26 additions & 6 deletions sw/device/silicon_creator/imm_rom_ext/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,32 @@ DEFAULT_EXEC_ENV = [
]

# The target list should contian prebuilt artifacts and run-time build targets.
IMM_ROM_EXT_SECTIONS = {
SLOT_A_IMM_ROM_EXT_SECTIONS = {
"main": [
"//sw/device/silicon_creator/imm_rom_ext:main_section_fpga_cw310",
"//sw/device/silicon_creator/imm_rom_ext:main_section_fpga_cw340",
"//sw/device/silicon_creator/imm_rom_ext:main_section_sim_dv_base",
"//sw/device/silicon_creator/imm_rom_ext:main_section_sim_verilator_base",
"//sw/device/silicon_creator/imm_rom_ext:main_section_silicon_creator",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_a_fpga_cw310",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_a_fpga_cw340",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_a_sim_dv_base",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_a_sim_verilator_base",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_a_silicon_creator",
],
}

SLOT_B_IMM_ROM_EXT_SECTIONS = {
"main": [
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_b_fpga_cw310",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_b_fpga_cw340",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_b_sim_dv_base",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_b_sim_verilator_base",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_b_silicon_creator",
],
}

SLOT_VIRTUAL_IMM_ROM_EXT_SECTIONS = {
"main": [
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_virtual_fpga_cw310",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_virtual_fpga_cw340",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_virtual_sim_dv_base",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_virtual_sim_verilator_base",
"//sw/device/silicon_creator/imm_rom_ext:main_section_slot_virtual_silicon_creator",
],
}
37 changes: 0 additions & 37 deletions sw/device/silicon_creator/imm_rom_ext/hello_world.c

This file was deleted.

18 changes: 0 additions & 18 deletions sw/device/silicon_creator/imm_rom_ext/hello_world.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
* script only works for hello-world IMM_ROM_EXT.
*/

INCLUDE hw/top_earlgrey/sw/autogen/top_earlgrey_memory.ld

/**
* Symbols to be used in the setup of the address translation for IMM_ROM_EXT.
*/

MEMORY {
imm_rom_ext_virtual(rx) : ORIGIN = ORIGIN(rom_ext_virtual) + 0x400, LENGTH = 0x80000 - 0x400
}

REGION_ALIAS("rom_ext_flash", imm_rom_ext_virtual);

OUTPUT_ARCH(riscv)

/**
Expand Down
27 changes: 27 additions & 0 deletions sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_a.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright lowRISC contributors (OpenTitan project). */
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
/* SPDX-License-Identifier: Apache-2.0 */

/**
* Linker script for an OpenTitan IMM_ROM_EXT.
*
* Portions of this file are Ibex-specific.
*
* The IMM_ROM_EXT is kept in the .rom_ext_immutable section in ROM, after the
* .manifest section. This linker script targets to use slot A address, and
* the addresses are similar to the linker script rom_ext_slot_a.ld that ROM_EXT
* is using.
*/

INCLUDE hw/top_earlgrey/sw/autogen/top_earlgrey_memory.ld

/**
* Symbols to be used in the setup of the address translation for IMM_ROM_EXT.
*/

MEMORY {
imm_rom_ext_slot_a(rx) : ORIGIN = ORIGIN(eflash) + 0x400, LENGTH = LENGTH(eflash) / 2 - 0x400
}
REGION_ALIAS("rom_ext_flash", imm_rom_ext_slot_a);

INCLUDE sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_common.ld
28 changes: 28 additions & 0 deletions sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_b.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright lowRISC contributors (OpenTitan project). */
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
/* SPDX-License-Identifier: Apache-2.0 */

/**
* Linker script for an OpenTitan IMM_ROM_EXT.
*
* Portions of this file are Ibex-specific.
*
* The IMM_ROM_EXT is kept in the .rom_ext_immutable section in ROM, after the
* .manifest section. This linker script targets to use slot B address, and
* the addresses are similar to the linker script rom_ext_slot_b.ld that ROM_EXT
* is using.
*/

INCLUDE hw/top_earlgrey/sw/autogen/top_earlgrey_memory.ld

/**
* Symbols to be used in the setup of the address translation for IMM_ROM_EXT.
*/

/* Slot B starts at the half-size mark of the eFlash. */
MEMORY {
imm_rom_ext_slot_b(rx) : ORIGIN = ORIGIN(eflash) + LENGTH(eflash) / 2 + 0x400, LENGTH = LENGTH(eflash) / 2 - 0x400
}
REGION_ALIAS("rom_ext_flash", imm_rom_ext_slot_b);

INCLUDE sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_common.ld
27 changes: 27 additions & 0 deletions sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_virtual.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright lowRISC contributors (OpenTitan project). */
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
/* SPDX-License-Identifier: Apache-2.0 */

/**
* Linker script for an OpenTitan IMM_ROM_EXT.
*
* Portions of this file are Ibex-specific.
*
* The IMM_ROM_EXT is kept in the .rom_ext_immutable section in ROM, after the
* .manifest section. This linker script targets to use virtual address, and
* the addresses are similar to the linker script rom_ext_slot_virtual.ld that
* ROM_EXT is using.
*/

INCLUDE hw/top_earlgrey/sw/autogen/top_earlgrey_memory.ld

/**
* Symbols to be used in the setup of the address translation for IMM_ROM_EXT.
*/

MEMORY {
imm_rom_ext_virtual(rx) : ORIGIN = ORIGIN(rom_ext_virtual) + 0x400, LENGTH = 0x80000 - 0x400
}
REGION_ALIAS("rom_ext_flash", imm_rom_ext_virtual);

INCLUDE sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_common.ld
12 changes: 7 additions & 5 deletions sw/device/silicon_creator/rom_ext/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ load(
)
load(
"//sw/device/silicon_creator/imm_rom_ext:defs.bzl",
"IMM_ROM_EXT_SECTIONS",
"SLOT_A_IMM_ROM_EXT_SECTIONS",
"SLOT_B_IMM_ROM_EXT_SECTIONS",
"SLOT_VIRTUAL_IMM_ROM_EXT_SECTIONS",
)

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -290,7 +292,7 @@ opentitan_binary(
"minsize",
"use_lld",
],
immutable_rom_ext_sections = IMM_ROM_EXT_SECTIONS["main"],
immutable_rom_ext_sections = SLOT_A_IMM_ROM_EXT_SECTIONS["main"],
linker_script = ":ld_slot_a",
manifest = ":manifest",
spx_key = {"//sw/device/silicon_creator/rom/keys/fake/spx:prod_key_0_spx": "prod_key_0"},
Expand Down Expand Up @@ -319,7 +321,7 @@ opentitan_binary(
"minsize",
"use_lld",
],
immutable_rom_ext_sections = IMM_ROM_EXT_SECTIONS["main"],
immutable_rom_ext_sections = SLOT_B_IMM_ROM_EXT_SECTIONS["main"],
linker_script = ":ld_slot_b",
manifest = ":manifest",
spx_key = {"//sw/device/silicon_creator/rom/keys/fake/spx:prod_key_0_spx": "prod_key_0"},
Expand Down Expand Up @@ -348,7 +350,7 @@ opentitan_binary(
"minsize",
"use_lld",
],
immutable_rom_ext_sections = IMM_ROM_EXT_SECTIONS["main"],
immutable_rom_ext_sections = SLOT_VIRTUAL_IMM_ROM_EXT_SECTIONS["main"],
linker_script = ":ld_slot_virtual",
manifest = ":manifest",
deps = [
Expand Down Expand Up @@ -387,7 +389,7 @@ opentitan_binary(
"//sw/device/silicon_creator/lib/ownership/keys/fake",
],
)
for name, imm_rom_ext_sections in IMM_ROM_EXT_SECTIONS.items()
for name, imm_rom_ext_sections in SLOT_VIRTUAL_IMM_ROM_EXT_SECTIONS.items()
]

manifest(d = {
Expand Down
Loading

0 comments on commit 3613069

Please sign in to comment.