-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[imm_rom_ext] Add hello world IM_EXT
* Add minimized C code, startup asm and linker script for a standalone IM_EXT build target. * Add a bazel rule `imm_rom_ext_section`, which will transform binaries into object files and turn it to a target that can be directly used as deps of ROM_EXT's bazel targets. * Add a map for all IM_EXT target that can be used and make the ROM_EXT targets iterate the map to generate multiple targets. * Update the ROM_EXT to use in e2e verified boot test. Test: String `Immutable` appears in the UART output of the test target `verified_boot:position_romext_virtual_a_with_hello_world_imm_romext_enabled_fpga_cw340_rom_ext`: ``` OpenTitan:4001-0002-01 ROM:0a7a997f bootstrap:1 OpenTitan:4001-0002-01 ROM:0a7a997f Immutable Starting ROM_EXT 0.1 ``` Signed-off-by: Chia-Wei Liu <[email protected]>
- Loading branch information
Showing
9 changed files
with
289 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# The target list should contian prebuilt artifacts and run-time build targets. | ||
IMM_ROM_EXT_TARGETS = { | ||
"nop": "//sw/device/silicon_creator/imm_rom_ext/prebuilts:nop_imm_rom_ext", | ||
"hello_world": "//sw/device/silicon_creator/imm_rom_ext:hello_world_section", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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" | ||
|
||
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 = 0x65; | ||
const uint32_t kNewline = 0x0a0d; | ||
uart_write_imm(kStr1); | ||
uart_write_imm(kStr2); | ||
uart_write_imm(kNewline); | ||
|
||
// Wait until the UART is done transmitting. | ||
while (!uart_tx_idle()) { | ||
} | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* Copyright lowRISC contributors (OpenTitan project). */ | ||
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
/** | ||
* TODO(#24368): Adapt the linker script for real IMM_ROM_EXT. This linker | ||
* script only works for hello-world IMM_ROM_EXT. | ||
*/ | ||
OUTPUT_ARCH(riscv) | ||
|
||
/** | ||
* Indicate that there are no dynamic libraries, whatsoever. | ||
*/ | ||
__DYNAMIC = 0; | ||
|
||
/* DV Log offset (has to be different to other boot stages). */ | ||
_dv_log_offset = 0x10000; | ||
|
||
ENTRY(_imm_rom_ext_start_boot) | ||
|
||
SECTIONS { | ||
.rom_ext_immutable : ALIGN(4) { | ||
/* Ibex */ | ||
*(.vectors) | ||
. = ALIGN(256); | ||
/* CRT */ | ||
*(.crt) | ||
. = ALIGN(4); | ||
/* Text */ | ||
*(.text) | ||
*(.text.*) | ||
. = ALIGN(4); | ||
/* Read-only Data */ | ||
*(.srodata) | ||
*(.srodata.*) | ||
*(.rodata) | ||
*(.rodata.*) | ||
. = ALIGN(4); | ||
*(.data) | ||
. = ALIGN(4); | ||
*(.bss) | ||
. = ALIGN(4); | ||
} | ||
|
||
INCLUDE sw/device/info_sections.ld | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// TODO(#24368): Adapt the startup assembly for real IMM_ROM_EXT. This startup | ||
// assembly only works for hello-world IMM_ROM_EXT. | ||
#include "hw/top_earlgrey/sw/autogen/top_earlgrey_memory.h" | ||
|
||
.balign 4 | ||
.global _imm_rom_ext_start_boot | ||
.type _imm_rom_ext_start_boot, @function | ||
_imm_rom_ext_start_boot: | ||
tail imm_rom_ext_main | ||
.size _imm_rom_ext_start_boot, .-_imm_rom_ext_start_boot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain") | ||
load("@lowrisc_opentitan//rules:rv.bzl", "rv_rule") | ||
|
||
def _bin_to_imm_rom_ext_object_impl(ctx): | ||
cc_toolchain = find_cc_toolchain(ctx) | ||
outputs = [] | ||
for src in ctx.files.srcs: | ||
if src.extension != "bin": | ||
continue | ||
object = ctx.actions.declare_file( | ||
"{}.{}".format( | ||
src.basename.replace("." + src.extension, ""), | ||
"o", | ||
), | ||
) | ||
ctx.actions.run( | ||
outputs = [object], | ||
inputs = [src] + cc_toolchain.all_files.to_list(), | ||
arguments = [ | ||
"-I", | ||
"binary", | ||
"-O", | ||
"elf32-littleriscv", | ||
"--rename-section", | ||
".data=.rom_ext_immutable,alloc,load,readonly,data,contents", | ||
src.path, | ||
object.path, | ||
], | ||
executable = cc_toolchain.objcopy_executable, | ||
) | ||
outputs.append(object) | ||
return [DefaultInfo(files = depset(outputs), runfiles = ctx.runfiles(files = outputs))] | ||
|
||
bin_to_imm_rom_ext_object = rv_rule( | ||
implementation = _bin_to_imm_rom_ext_object_impl, | ||
attrs = { | ||
"srcs": attr.label_list(allow_files = True), | ||
"_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), | ||
}, | ||
toolchains = ["@rules_cc//cc:toolchain_type"], | ||
) | ||
|
||
def imm_rom_ext_section(name, srcs): | ||
object_target_name = name + "_object" | ||
bin_to_imm_rom_ext_object(name = object_target_name, srcs = srcs) | ||
native.cc_import( | ||
name = name, | ||
objects = [object_target_name], | ||
data = [object_target_name], | ||
alwayslink = 1, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.