diff --git a/sw/device/silicon_creator/imm_rom_ext/BUILD b/sw/device/silicon_creator/imm_rom_ext/BUILD index 094d5c8601b4b..a55fefff49c26 100644 --- a/sw/device/silicon_creator/imm_rom_ext/BUILD +++ b/sw/device/silicon_creator/imm_rom_ext/BUILD @@ -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], @@ -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", @@ -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 +] diff --git a/sw/device/silicon_creator/imm_rom_ext/defs.bzl b/sw/device/silicon_creator/imm_rom_ext/defs.bzl index d161d36148a80..01d2937c42a5b 100644 --- a/sw/device/silicon_creator/imm_rom_ext/defs.bzl +++ b/sw/device/silicon_creator/imm_rom_ext/defs.bzl @@ -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", ], } diff --git a/sw/device/silicon_creator/imm_rom_ext/hello_world.c b/sw/device/silicon_creator/imm_rom_ext/hello_world.c deleted file mode 100644 index 00644725ca268..0000000000000 --- a/sw/device/silicon_creator/imm_rom_ext/hello_world.c +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright lowRISC contributors (OpenTitan project). -// Licensed under the Apache License, Version 2.0, see LICENSE for details. -// SPDX-License-Identifier: Apache-2.0 - -#include "sw/device/silicon_creator/imm_rom_ext/hello_world.h" - -#include "sw/device/silicon_creator/lib/drivers/uart.h" - -// These arrays are used to "HelloWorld!" to the UART console. -// o l l e H -uint64_t kArray1[8] = {0x6f6c6c6548}; -// The value will be updated in the main function. -uint64_t kArray2[8]; - -void imm_rom_ext_main(void) { - // Print "Immutable" to the UART console. - // l b a t u m m I - const uint64_t kStr1 = 0x6c626174756d6d49; - // : e - const uint32_t kStr2 = 0x3a65; - const uint32_t kSpace = 0x20; - const uint32_t kNewline = 0x0a0d; - uart_write_imm(kStr1); - uart_write_imm(kStr2); - uart_write_imm(kSpace); - // ! d l r o W - kArray2[0] += 0x21646c726f57; - uart_write_imm(kArray1[0]); // To test the .data section. - uart_write_imm(kArray2[0]); // To test the .bss section. - uart_write_imm(kNewline); - - // Wait until the UART is done transmitting. - while (!uart_tx_idle()) { - } - - return; -} diff --git a/sw/device/silicon_creator/imm_rom_ext/hello_world.h b/sw/device/silicon_creator/imm_rom_ext/hello_world.h deleted file mode 100644 index 2932989cb8e76..0000000000000 --- a/sw/device/silicon_creator/imm_rom_ext/hello_world.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright lowRISC contributors (OpenTitan project). -// Licensed under the Apache License, Version 2.0, see LICENSE for details. -// SPDX-License-Identifier: Apache-2.0 - -#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_IMM_ROM_EXT_HELLO_WORLD_H_ -#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_IMM_ROM_EXT_HELLO_WORLD_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -void imm_rom_ext_main(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_IMM_ROM_EXT_HELLO_WORLD_H_ diff --git a/sw/device/silicon_creator/imm_rom_ext/hello_world.ld b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_common.ld similarity index 92% rename from sw/device/silicon_creator/imm_rom_ext/hello_world.ld rename to sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_common.ld index 6c45899b02531..03731afd856fd 100644 --- a/sw/device/silicon_creator/imm_rom_ext/hello_world.ld +++ b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_common.ld @@ -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) /** diff --git a/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_a.ld b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_a.ld new file mode 100644 index 0000000000000..e7751d59bf4fc --- /dev/null +++ b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_a.ld @@ -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 diff --git a/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_b.ld b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_b.ld new file mode 100644 index 0000000000000..35540731a9888 --- /dev/null +++ b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_b.ld @@ -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 diff --git a/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_virtual.ld b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_virtual.ld new file mode 100644 index 0000000000000..47d3dcd372bfd --- /dev/null +++ b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_slot_virtual.ld @@ -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 diff --git a/sw/device/silicon_creator/imm_rom_ext/hello_world_start.S b/sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_start.S similarity index 100% rename from sw/device/silicon_creator/imm_rom_ext/hello_world_start.S rename to sw/device/silicon_creator/imm_rom_ext/imm_rom_ext_start.S diff --git a/sw/device/silicon_creator/rom_ext/BUILD b/sw/device/silicon_creator/rom_ext/BUILD index 292cb74d2ed52..1e145f06a9279 100644 --- a/sw/device/silicon_creator/rom_ext/BUILD +++ b/sw/device/silicon_creator/rom_ext/BUILD @@ -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"]) @@ -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"}, @@ -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"}, @@ -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 = [ @@ -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 = { diff --git a/sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD b/sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD index ab5070bd28a82..bb69b14a06d69 100644 --- a/sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD +++ b/sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD @@ -23,7 +23,7 @@ load( ) load( "//sw/device/silicon_creator/imm_rom_ext:defs.bzl", - "IMM_ROM_EXT_SECTIONS", + "SLOT_VIRTUAL_IMM_ROM_EXT_SECTIONS", ) package(default_visibility = ["//visibility:public"]) @@ -48,7 +48,7 @@ filegroup( rom_ext = "//sw/device/silicon_creator/rom_ext:rom_ext_with_{}_imm_slot_virtual".format(name), visibility = ["//visibility:private"], ) - for name in IMM_ROM_EXT_SECTIONS + for name in SLOT_VIRTUAL_IMM_ROM_EXT_SECTIONS ] [ @@ -62,7 +62,7 @@ filegroup( ], visibility = ["//visibility:private"], ) - for name in IMM_ROM_EXT_SECTIONS + for name in SLOT_VIRTUAL_IMM_ROM_EXT_SECTIONS ] _POSITIONS = { @@ -139,7 +139,7 @@ _POSITIONS = { "success": "rom_ext_slot = AA__\r\n", "otp_img": ":otp_img_with_{}_imm_romext_enabled".format(name), } - for name in IMM_ROM_EXT_SECTIONS + for name in SLOT_VIRTUAL_IMM_ROM_EXT_SECTIONS } [ diff --git a/sw/device/silicon_creator/rom_ext/sival/BUILD b/sw/device/silicon_creator/rom_ext/sival/BUILD index 7db34c0cd79df..ac2a597615e20 100644 --- a/sw/device/silicon_creator/rom_ext/sival/BUILD +++ b/sw/device/silicon_creator/rom_ext/sival/BUILD @@ -11,6 +11,11 @@ load( "ROM_EXT_VERSION", ) load("@rules_pkg//pkg:tar.bzl", "pkg_tar") +load( + "//sw/device/silicon_creator/imm_rom_ext:defs.bzl", + "SLOT_A_IMM_ROM_EXT_SECTIONS", + "SLOT_B_IMM_ROM_EXT_SECTIONS", +) package(default_visibility = ["//visibility:public"]) @@ -49,6 +54,7 @@ opentitan_binary( "minsize", "use_lld", ], + immutable_rom_ext_sections = SLOT_A_IMM_ROM_EXT_SECTIONS["main"], linker_script = "//sw/device/silicon_creator/rom_ext:ld_slot_a", linkopts = LINK_ORDER, manifest = ":manifest_sival", @@ -75,6 +81,7 @@ opentitan_binary( "minsize", "use_lld", ], + immutable_rom_ext_sections = SLOT_B_IMM_ROM_EXT_SECTIONS["main"], linker_script = "//sw/device/silicon_creator/rom_ext:ld_slot_b", linkopts = LINK_ORDER, manifest = ":manifest_sival", @@ -97,6 +104,7 @@ opentitan_binary( "minsize", "use_lld", ], + immutable_rom_ext_sections = SLOT_A_IMM_ROM_EXT_SECTIONS["main"], linker_script = "//sw/device/silicon_creator/rom_ext:ld_slot_a", linkopts = LINK_ORDER, deps = [ @@ -117,6 +125,7 @@ opentitan_binary( "minsize", "use_lld", ], + immutable_rom_ext_sections = SLOT_B_IMM_ROM_EXT_SECTIONS["main"], linker_script = "//sw/device/silicon_creator/rom_ext:ld_slot_b", linkopts = LINK_ORDER, deps = [