Skip to content

Commit

Permalink
[test_rom] Make test_rom buildable for english breakfast.
Browse files Browse the repository at this point in the history
This commit converts just the necessary files to DT to be able
to build the test_rom for english breakfast.

Signed-off-by: Amaury Pouly <[email protected]>
  • Loading branch information
pamaury committed Sep 30, 2024
1 parent a3e658c commit 4f03305
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 131 deletions.
16 changes: 14 additions & 2 deletions sw/device/lib/dif/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ cc_test(
":test_base",
"@googletest//:gtest_main",
],
# This test is not compatible with english_breakfast
target_compatible_with = select({
"//sw/device:is_english_breakfast": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)

cc_library(
Expand Down Expand Up @@ -820,7 +825,10 @@ cc_library(
name = "rstmgr_intf",
srcs = ["autogen/dif_rstmgr_autogen.h"],
hdrs = ["dif_rstmgr.h"],
deps = [":base"],
deps = [
":base",
"//hw/top:rstmgr_dt",
],
)

cc_library(
Expand All @@ -833,7 +841,6 @@ cc_library(
":base",
":rstmgr_intf",
"//hw/top:rstmgr_c_regs",
"//hw/top:rstmgr_dt",
"//sw/device/lib/base:bitfield",
"//sw/device/lib/base:macros",
"//sw/device/lib/base:memory",
Expand Down Expand Up @@ -953,6 +960,11 @@ cc_test(
":test_base",
"@googletest//:gtest_main",
],
# This test is not compatible with english_breakfast
target_compatible_with = select({
"//sw/device:is_english_breakfast": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)

cc_library(
Expand Down
6 changes: 3 additions & 3 deletions sw/device/lib/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ cc_library(
hdrs = ["flash_ctrl_testutils.h"],
target_compatible_with = [OPENTITAN_CPU],
deps = [
"//hw/top_earlgrey/ip_autogen/flash_ctrl:flash_ctrl_c_regs",
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//hw/top:flash_ctrl_c_regs",
"//hw/top:devicetables",
"//sw/device/lib/base:abs_mmio",
"//sw/device/lib/base:mmio",
"//sw/device/lib/dif:flash_ctrl",
Expand Down Expand Up @@ -318,7 +318,7 @@ cc_library(
hdrs = ["pinmux_testutils.h"],
target_compatible_with = [OPENTITAN_CPU],
deps = [
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//hw/top:devicetables",
"//sw/device/lib/arch:device",
"//sw/device/lib/dif:base",
"//sw/device/lib/dif:gpio",
Expand Down
12 changes: 7 additions & 5 deletions sw/device/lib/testing/flash_ctrl_testutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
#include <stdbool.h>
#include <stdint.h>

#include "devicetables.h" // Generated
#include "sw/device/lib/base/abs_mmio.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_flash_ctrl.h"
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/runtime/ibex.h"
#include "sw/device/lib/testing/test_framework/check.h"

#include "flash_ctrl_regs.h"
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
#include "flash_ctrl_regs.h" // Generated

static const dt_flash_ctrl_t *kFlashCtrlDt = &kDtFlashCtrl[0];

#define MODULE_ID MAKE_MODULE_ID('f', 'c', 't')

Expand Down Expand Up @@ -298,9 +300,9 @@ status_t flash_ctrl_testutils_bank_erase(dif_flash_ctrl_state_t *flash_state,

status_t flash_ctrl_testutils_backdoor_init(
dif_flash_ctrl_state_t *flash_state) {
TRY(dif_flash_ctrl_init_state(
flash_state,
mmio_region_from_addr(TOP_EARLGREY_FLASH_CTRL_CORE_BASE_ADDR)));
TRY(dif_flash_ctrl_init_state(flash_state,
mmio_region_from_addr(dt_flash_ctrl_reg_block(
kFlashCtrlDt, kDtFlashCtrlRegBlockCore))));

return flash_ctrl_testutils_default_region_access(flash_state,
/*rd_en*/ true,
Expand Down
67 changes: 34 additions & 33 deletions sw/device/lib/testing/pinmux_testutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "sw/device/lib/testing/pinmux_testutils.h"

#include "devicetables.h"
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/status.h"
Expand All @@ -13,29 +14,27 @@
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/testing/test_framework/check.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
static const dt_gpio_t *kGpioDt = &kDtGpio[0];
static const dt_uart_t *kUart0Dt = &kDtUart[0];
static const dt_uart_t *kUart1Dt = &kDtUart[1];

void pinmux_testutils_init(dif_pinmux_t *pinmux) {
// Set up SW straps on IOC0-IOC2, for GPIOs 22-24
CHECK_DIF_OK(dif_pinmux_input_select(pinmux,
kTopEarlgreyPinmuxPeripheralInGpioGpio22,
kTopEarlgreyPinmuxInselIoc0));
CHECK_DIF_OK(dif_pinmux_input_select(pinmux,
kTopEarlgreyPinmuxPeripheralInGpioGpio23,
kTopEarlgreyPinmuxInselIoc1));
CHECK_DIF_OK(dif_pinmux_input_select(pinmux,
kTopEarlgreyPinmuxPeripheralInGpioGpio24,
kTopEarlgreyPinmuxInselIoc2));
CHECK_DIF_OK(dif_pinmux_mio_select_input(
pinmux, dt_gpio_pin(kGpioDt, kDtGpioPinGpio22), kDtPad[kDtPadIoc0]));
CHECK_DIF_OK(dif_pinmux_mio_select_input(
pinmux, dt_gpio_pin(kGpioDt, kDtGpioPinGpio23), kDtPad[kDtPadIoc1]));
CHECK_DIF_OK(dif_pinmux_mio_select_input(
pinmux, dt_gpio_pin(kGpioDt, kDtGpioPinGpio24), kDtPad[kDtPadIoc2]));

// Configure UART0 RX input to connect to MIO pad IOC3
CHECK_DIF_OK(dif_pinmux_input_select(pinmux,
kTopEarlgreyPinmuxPeripheralInUart0Rx,
kTopEarlgreyPinmuxInselIoc3));
CHECK_DIF_OK(dif_pinmux_output_select(pinmux, kTopEarlgreyPinmuxMioOutIoc3,
kTopEarlgreyPinmuxOutselConstantHighZ));
CHECK_DIF_OK(dif_pinmux_mio_select_input(
pinmux, dt_uart_pin(kUart0Dt, kDtUartPinRx), kDtPad[kDtPadIoc3]));
CHECK_DIF_OK(dif_pinmux_mio_select_output(pinmux, kDtPad[kDtPadIoc3],
kDtPinConstantHighZ));
// Configure UART0 TX output to connect to MIO pad IOC4
CHECK_DIF_OK(dif_pinmux_output_select(pinmux, kTopEarlgreyPinmuxMioOutIoc4,
kTopEarlgreyPinmuxOutselUart0Tx));
CHECK_DIF_OK(dif_pinmux_mio_select_output(
pinmux, kDtPad[kDtPadIoc4], dt_uart_pin(kUart0Dt, kDtUartPinTx)));

// Enable pull-ups on UART0 RX
// Pull-ups are available only on certain platforms.
Expand All @@ -47,20 +46,19 @@ void pinmux_testutils_init(dif_pinmux_t *pinmux) {
.flags = kDifPinmuxPadAttrPullResistorEnable |
kDifPinmuxPadAttrPullResistorUp};

CHECK_DIF_OK(dif_pinmux_pad_write_attrs(pinmux, kTopEarlgreyMuxedPadsIoc3,
kDifPinmuxPadKindMio, in_attr,
&out_attr));
CHECK_DIF_OK(
dif_pinmux_pad_write_attrs(pinmux, dt_pad_mio_pad(kDtPad[kDtPadIoc3]),
kDifPinmuxPadKindMio, in_attr, &out_attr));
};

// Configure UART1 RX input to connect to MIO pad IOB4
CHECK_DIF_OK(dif_pinmux_input_select(pinmux,
kTopEarlgreyPinmuxPeripheralInUart1Rx,
kTopEarlgreyPinmuxInselIob4));
CHECK_DIF_OK(dif_pinmux_output_select(pinmux, kTopEarlgreyPinmuxMioOutIob4,
kTopEarlgreyPinmuxOutselConstantHighZ));
CHECK_DIF_OK(dif_pinmux_mio_select_input(
pinmux, dt_uart_pin(kUart1Dt, kDtUartPinRx), kDtPad[kDtPadIob4]));
CHECK_DIF_OK(dif_pinmux_mio_select_output(pinmux, kDtPad[kDtPadIob4],
kDtPinConstantHighZ));
// Configure UART1 TX output to connect to MIO pad IOB5
CHECK_DIF_OK(dif_pinmux_output_select(pinmux, kTopEarlgreyPinmuxMioOutIob5,
kTopEarlgreyPinmuxOutselUart1Tx));
CHECK_DIF_OK(dif_pinmux_mio_select_output(
pinmux, kDtPad[kDtPadIob5], dt_uart_pin(kUart1Dt, kDtUartPinTx)));

#if !OT_IS_ENGLISH_BREAKFAST
// Configure a higher drive strength for the USB_P and USB_N pads because we
Expand Down Expand Up @@ -89,10 +87,12 @@ void pinmux_testutils_init(dif_pinmux_t *pinmux) {
#endif

// Configure USBDEV SENSE outputs to be high-Z (IOC7)
CHECK_DIF_OK(dif_pinmux_output_select(pinmux, kTopEarlgreyPinmuxMioOutIoc7,
kTopEarlgreyPinmuxOutselConstantHighZ));
CHECK_DIF_OK(dif_pinmux_mio_select_output(pinmux, kDtPad[kDtPadIoc7],
kDtPinConstantHighZ));
}

// FIXME convert to DT
#ifndef OT_IS_ENGLISH_BREAKFAST
// Mapping of Chip IOs to the GPIO peripheral.
//
// Depending on the simulation platform, there may be a limitation to how chip
Expand Down Expand Up @@ -138,6 +138,7 @@ const dif_pinmux_index_t kPinmuxTestutilsGpioMioOutPins[kDifGpioNumPins] = {
kTopEarlgreyPinmuxMioOutIor6, kTopEarlgreyPinmuxMioOutIor7,
kTopEarlgreyPinmuxMioOutIor10, kTopEarlgreyPinmuxMioOutIor11,
kTopEarlgreyPinmuxMioOutIor12, kTopEarlgreyPinmuxMioOutIor13};
#endif

uint32_t pinmux_testutils_get_testable_gpios_mask(void) {
switch (kDeviceType) {
Expand All @@ -159,7 +160,7 @@ uint32_t pinmux_testutils_get_testable_gpios_mask(void) {

uint32_t pinmux_testutils_read_strap_pin(dif_pinmux_t *pinmux, dif_gpio_t *gpio,
dif_gpio_pin_t io,
top_earlgrey_muxed_pads_t pad) {
dt_pinmux_muxed_pad_t pad) {
// Turn off the pull enable on the pad and read the IO.
dif_pinmux_pad_attr_t attr = {.flags = 0};
dif_pinmux_pad_attr_t attr_out;
Expand Down Expand Up @@ -193,12 +194,12 @@ uint32_t pinmux_testutils_read_strap_pin(dif_pinmux_t *pinmux, dif_gpio_t *gpio,
uint32_t pinmux_testutils_read_straps(dif_pinmux_t *pinmux, dif_gpio_t *gpio) {
uint32_t strap = 0;
strap |= pinmux_testutils_read_strap_pin(pinmux, gpio, 22,
kTopEarlgreyMuxedPadsIoc0);
dt_pad_mio_pad(kDtPad[kDtPadIoc0]));
strap |= pinmux_testutils_read_strap_pin(pinmux, gpio, 23,
kTopEarlgreyMuxedPadsIoc1)
dt_pad_mio_pad(kDtPad[kDtPadIoc1]))
<< 2;
strap |= pinmux_testutils_read_strap_pin(pinmux, gpio, 24,
kTopEarlgreyMuxedPadsIoc2)
dt_pad_mio_pad(kDtPad[kDtPadIoc2]))
<< 4;
return strap;
}
Expand Down
13 changes: 6 additions & 7 deletions sw/device/lib/testing/pinmux_testutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@

#include <stdint.h>

#include "devicetables.h"
#include "sw/device/lib/base/status.h"
#include "sw/device/lib/dif/dif_gpio.h"
#include "sw/device/lib/dif/dif_pinmux.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"

/**
* Define a pinmux configuration for a peripheral input and output .
*/
typedef struct pinmux_testutils_peripheral_pin {
top_earlgrey_pinmux_peripheral_in_t peripheral_in;
top_earlgrey_pinmux_outsel_t outsel;
dt_pinmux_peripheral_in_t peripheral_in;
dt_pinmux_outsel_t outsel;
} pinmux_testutils_peripheral_pin_t;

/**
* Define a pinmux configuration for a mio input and output.
*/
typedef struct pinmux_testutils_mio_pin {
top_earlgrey_pinmux_mio_out_t mio_out;
top_earlgrey_pinmux_insel_t insel;
dt_pinmux_mio_out_t mio_out;
dt_pinmux_insel_t insel;
} pinmux_testutils_mio_pin_t;

/**
Expand Down Expand Up @@ -74,7 +73,7 @@ uint32_t pinmux_testutils_get_testable_gpios_mask(void);
*/
uint32_t pinmux_testutils_read_strap_pin(dif_pinmux_t *pinmux, dif_gpio_t *gpio,
dif_gpio_pin_t io,
top_earlgrey_muxed_pads_t pad);
dt_pinmux_muxed_pad_t pad);

/**
* Reads the OpenTitan sw strap pins for the strap configuration value.
Expand Down
25 changes: 14 additions & 11 deletions sw/device/lib/testing/test_rom/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ opentitan_binary(
"//hw/top_earlgrey:fpga_cw305",
"//hw/top_earlgrey:fpga_cw340",
"//hw/top_earlgrey:sim_dv_base",
"//hw/top_earlgrey:sim_verilator_base",
],
] +
select({
"//sw/device:is_english_breakfast": ["//hw/top_englishbreakfast:sim_verilator_base"],
"//conditions:default": ["//hw/top_earlgrey:sim_verilator_base"],
}),
kind = "rom",
linker_script = ":linker_script",
deps = [
Expand Down Expand Up @@ -80,8 +83,8 @@ cc_library(
"//hw/ip/gpio/data:gpio_c_regs",
"//hw/ip/otp_ctrl/data:otp_ctrl_c_regs",
"//hw/ip/spi_device/data:spi_device_c_regs",
"//hw/top_englishbreakfast:flash_ctrl_c_regs",
"//hw/top_englishbreakfast:top_lib",
"//hw/top_englishbreakfast/ip_autogen/flash_ctrl:flash_ctrl_c_regs",
"//hw/top_englishbreakfast/sw/autogen:top_englishbreakfast",
"//sw/device/lib/base:abs_mmio",
"//sw/device/lib/base:multibits",
"//sw/device/lib/dif:rstmgr_intf",
Expand Down Expand Up @@ -123,8 +126,8 @@ cc_library(
deps = [
"//hw/ip/otp_ctrl/data:otp_ctrl_c_regs",
"//hw/ip/spi_device/data:spi_device_c_regs",
"//hw/top_englishbreakfast:flash_ctrl_c_regs",
"//hw/top_englishbreakfast:top_lib",
"//hw/top_englishbreakfast/ip_autogen/flash_ctrl:flash_ctrl_c_regs",
"//hw/top_englishbreakfast/sw/autogen:top_englishbreakfast",
"//sw/device/lib/base:abs_mmio",
"//sw/device/lib/base:macros",
"//sw/device/lib/base:multibits",
Expand Down Expand Up @@ -162,11 +165,11 @@ cc_library(
"//hw/ip/entropy_src/data:entropy_src_c_regs",
"//hw/ip/otp_ctrl/data:otp_ctrl_c_regs",
"//hw/ip/sram_ctrl/data:sram_ctrl_c_regs",
"//hw/top_earlgrey/ip/ast/data:ast_c_regs",
"//hw/top_earlgrey/ip/sensor_ctrl/data:sensor_ctrl_c_regs",
"//hw/top_earlgrey/ip_autogen/clkmgr:clkmgr_c_regs",
"//hw/top_earlgrey/ip_autogen/flash_ctrl:flash_ctrl_c_regs",
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//hw/top:ast_c_regs",
"//hw/top:sensor_ctrl_c_regs",
"//hw/top:clkmgr_c_regs",
"//hw/top:flash_ctrl_c_regs",
"//hw/top:top_lib",
"//sw/device/lib/arch:device",
"//sw/device/lib/base:abs_mmio",
"//sw/device/lib/base:bitfield",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ dif_result_t dif_rstmgr_init(mmio_region_t base_addr, dif_rstmgr_t *rstmgr) {
return kDifOk;
}

dif_result_t dif_rstmgr_init_from_dt(const dt_rstmgr_t *dt,
dif_rstmgr_t *rstmgr) {
return kDifOk;
}

dif_result_t dif_rstmgr_reset_info_get(const dif_rstmgr_t *handle,
dif_rstmgr_reset_info_bitfield_t *info) {
*info = 1 << kRstmgrReasonPowerOn;
Expand Down
Loading

0 comments on commit 4f03305

Please sign in to comment.