[sw/silicon_creator] Remove rom_ext_manifest_parser
Signed-off-by: Alphan Ulusoy <alphan@google.com>
diff --git a/sw/device/silicon_creator/mask_rom/meson.build b/sw/device/silicon_creator/mask_rom/meson.build
index fd267fe..b36dd8a 100644
--- a/sw/device/silicon_creator/mask_rom/meson.build
+++ b/sw/device/silicon_creator/mask_rom/meson.build
@@ -55,7 +55,6 @@
sw_silicon_creator_lib_fake_deps,
sw_silicon_creator_lib_manifest,
sw_silicon_creator_mask_rom_sigverify,
- rom_ext_manifest_parser,
sw_silicon_creator_mask_rom_romextimage,
sw_lib_crt,
sw_lib_pinmux,
@@ -64,7 +63,6 @@
link_with: static_library(
'mask_rom_lib',
sources: [
- rom_exts_manifest_offsets_header,
'mask_rom.c'
],
link_depends: [rom_linkfile],
diff --git a/sw/device/silicon_creator/rom_exts/meson.build b/sw/device/silicon_creator/rom_exts/meson.build
index 2892a27..0918377 100644
--- a/sw/device/silicon_creator/rom_exts/meson.build
+++ b/sw/device/silicon_creator/rom_exts/meson.build
@@ -62,60 +62,6 @@
}
endforeach
-# ROM_EXT manifest generator.
-rom_exts_manifest_offsets_header = custom_target(
- 'rom_exts_manifest_h',
- output: 'manifest.h',
- depend_files: [
- 'manifest.h.tpl',
- 'manifest.hjson',
- meson.source_root() / 'util/rom-ext-manifest-generator.py',
- ],
- command: [
- prog_python,
- meson.source_root() / 'util/rom-ext-manifest-generator.py',
- '--input-dir', meson.current_source_dir(),
- '--output-dir', meson.current_build_dir(),
- '--output-files', 'c',
- ],
-)
-
-# ROM_EXT manifest parser.
-rom_ext_manifest_parser = declare_dependency(
- link_with: static_library(
- 'rom_ext_manifest_parser',
- sources: [
- 'rom_ext_manifest_parser.c',
- rom_exts_manifest_offsets_header,
- ],
- dependencies: [
- sw_lib_mmio,
- ],
- ),
- sources: [
- rom_exts_manifest_offsets_header,
- ],
-)
-
-test('sw_silicon_creator_rom_exts_rom_ext_parser_unittest', executable(
- 'sw_silicon_creator_rom_exts_rom_ext_parser_unittest',
- sources: [
- 'rom_ext_parser_unittest.cc',
- 'rom_ext_manifest_parser.c',
- rom_exts_manifest_offsets_header,
- ],
- dependencies: [
- sw_vendor_gtest,
- sw_lib_base_testing_mock_mmio,
- sw_lib_testing_bitfield,
- ],
- native: true,
- c_args: ['-DMOCK_MMIO'],
- cpp_args: ['-DMOCK_MMIO'],
- ),
- suite: 'mask_rom',
-)
-
foreach device_name, device_lib : sw_lib_arch_core_devices
foreach slot, slot_lib : rom_ext_slot_libs
rom_ext_elf = executable(
diff --git a/sw/device/silicon_creator/rom_exts/rom_ext_manifest_parser.c b/sw/device/silicon_creator/rom_exts/rom_ext_manifest_parser.c
deleted file mode 100644
index f0277d1..0000000
--- a/sw/device/silicon_creator/rom_exts/rom_ext_manifest_parser.c
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright lowRISC contributors.
-// Licensed under the Apache License, Version 2.0, see LICENSE for details.
-// SPDX-License-Identifier: Apache-2.0
-
-#include "sw/device/silicon_creator/rom_exts/rom_ext_manifest_parser.h"
-
-#include <assert.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "sw/device/lib/base/bitfield.h"
-#include "sw/device/lib/base/mmio.h"
-#include "sw/device/silicon_creator/rom_exts/manifest.h"
-
-#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
-
-const rom_ext_manifest_slot_t kRomExtManifestSlotA =
- TOP_EARLGREY_EFLASH_BASE_ADDR;
-const rom_ext_manifest_slot_t kRomExtManifestSlotB =
- TOP_EARLGREY_EFLASH_BASE_ADDR + (TOP_EARLGREY_EFLASH_SIZE_BYTES / 2);
-
-static_assert((TOP_EARLGREY_EFLASH_SIZE_BYTES % 2) == 0,
- "Flash size is not divisible by 2");
-
-rom_ext_manifest_t rom_ext_get_parameters(rom_ext_manifest_slot_t slot) {
- if (kRomExtManifestSlotA) {
- return (rom_ext_manifest_t){
- .base_addr = mmio_region_from_addr(kRomExtManifestSlotA),
- .slot = kRomExtManifestSlotA,
- };
- } else {
- return (rom_ext_manifest_t){
- .base_addr = mmio_region_from_addr(kRomExtManifestSlotB),
- .slot = kRomExtManifestSlotB,
- };
- }
-}
-
-uint32_t rom_ext_get_identifier(rom_ext_manifest_t params) {
- return mmio_region_read32(params.base_addr,
- ROM_EXT_MANIFEST_IDENTIFIER_OFFSET);
-}
-
-bool rom_ext_get_signature(rom_ext_manifest_t params,
- rom_ext_signature_t *dst) {
- if (dst == NULL) {
- return false;
- }
-
- mmio_region_memcpy_from_mmio32(params.base_addr,
- ROM_EXT_IMAGE_SIGNATURE_OFFSET, &dst->data[0],
- ROM_EXT_IMAGE_SIGNATURE_SIZE_BYTES);
-
- return true;
-}
-
-rom_ext_ranges_t rom_ext_get_ranges(rom_ext_manifest_t params) {
- uintptr_t image_length =
- mmio_region_read32(params.base_addr, ROM_EXT_IMAGE_LENGTH_OFFSET);
-
- rom_ext_ranges_t ranges = {
- .image_start = params.slot,
- .signed_area_start = params.slot + ROM_EXT_SIGNED_AREA_START_OFFSET,
- .image_end = params.slot + image_length,
- };
-
- return ranges;
-}
-
-uint32_t rom_ext_get_version(rom_ext_manifest_t params) {
- return mmio_region_read32(params.base_addr, ROM_EXT_IMAGE_VERSION_OFFSET);
-}
-
-uint64_t rom_ext_get_timestamp(rom_ext_manifest_t params) {
- uint32_t timestamp_low =
- mmio_region_read32(params.base_addr, ROM_EXT_IMAGE_TIMESTAMP_OFFSET);
-
- ptrdiff_t offset_high = ROM_EXT_IMAGE_TIMESTAMP_OFFSET + sizeof(uint32_t);
- uint32_t timestamp_high = mmio_region_read32(params.base_addr, offset_high);
-
- return ((uint64_t)timestamp_high << 32) | timestamp_low;
-}
-
-uint32_t rom_ext_get_signature_key_public_exponent(rom_ext_manifest_t params) {
- return mmio_region_read32(params.base_addr,
- ROM_EXT_SIGNATURE_KEY_PUBLIC_EXPONENT_OFFSET);
-}
-
-uint32_t rom_ext_get_usage_constraints(rom_ext_manifest_t params) {
- return mmio_region_read32(params.base_addr, ROM_EXT_USAGE_CONSTRAINTS_OFFSET);
-}
-
-bool rom_ext_get_peripheral_lockdown_info(rom_ext_manifest_t params,
- rom_ext_lockdown_info_t *dst) {
- if (dst == NULL) {
- return false;
- }
-
- mmio_region_memcpy_from_mmio32(
- params.base_addr, ROM_EXT_PERIPHERAL_LOCKDOWN_INFO_OFFSET, &dst->data[0],
- ROM_EXT_PERIPHERAL_LOCKDOWN_INFO_SIZE_BYTES);
-
- return true;
-}
-
-bool rom_ext_get_signature_key_modulus(rom_ext_manifest_t params,
- rom_ext_signature_key_modulus_t *dst) {
- if (dst == NULL) {
- return false;
- }
-
- mmio_region_memcpy_from_mmio32(
- params.base_addr, ROM_EXT_SIGNATURE_KEY_MODULUS_OFFSET, &dst->data[0],
- ROM_EXT_SIGNATURE_KEY_MODULUS_SIZE_BYTES);
-
- return true;
-}
-
-bool rom_ext_get_extension(rom_ext_manifest_t params, rom_ext_extension_id_t id,
- rom_ext_extension_t *extension) {
- if (extension == NULL) {
- return false;
- }
-
- uint32_t offset = 0;
- uint32_t checksum = 0;
- switch (id) {
- case kRomExtExtensionId0:
- offset = ROM_EXT_EXTENSION0_OFFSET_OFFSET;
- checksum = ROM_EXT_EXTENSION0_CHECKSUM_OFFSET;
- break;
- case kRomExtExtensionId1:
- offset = ROM_EXT_EXTENSION1_OFFSET_OFFSET;
- checksum = ROM_EXT_EXTENSION1_CHECKSUM_OFFSET;
- break;
- case kRomExtExtensionId2:
- offset = ROM_EXT_EXTENSION2_OFFSET_OFFSET;
- checksum = ROM_EXT_EXTENSION2_CHECKSUM_OFFSET;
- break;
- case kRomExtExtensionId3:
- offset = ROM_EXT_EXTENSION3_OFFSET_OFFSET;
- checksum = ROM_EXT_EXTENSION3_CHECKSUM_OFFSET;
- break;
- default:
- return false;
- }
-
- uint32_t extension_offset = mmio_region_read32(params.base_addr, offset);
-
- extension->address = (void *)(extension_offset + params.slot);
- extension->checksum = mmio_region_read32(params.base_addr, checksum);
-
- return true;
-}
-
-uintptr_t rom_ext_get_interrupt_vector(rom_ext_manifest_t params) {
- uintptr_t vector_addr = params.slot + ROM_EXT_INTERRUPT_VECTOR_OFFSET;
-
- // A valid value for `mtvec` contains:
- //
- // - The most-significant 30 bits of the value are the most-significant 30
- // bits of the interrupt vector address.
- // - The least-significant 2 bits of the value must be `0b01` to encode
- // vectored interrupts, which we want.
- //
- // One additional restriction is that Ibex wants the address to be 256-byte
- // aligned. We enforce that in the definition of
- // ROM_EXT_INTERRUPT_VECTOR_OFFSET;
-
- return (vector_addr & ~0x3) | 0x1;
-}
-
-uintptr_t rom_ext_get_entry(rom_ext_manifest_t params) {
- return params.slot + ROM_EXT_ENTRY_POINT_OFFSET;
-}
diff --git a/sw/device/silicon_creator/rom_exts/rom_ext_manifest_parser.h b/sw/device/silicon_creator/rom_exts/rom_ext_manifest_parser.h
deleted file mode 100644
index 36fedd2..0000000
--- a/sw/device/silicon_creator/rom_exts/rom_ext_manifest_parser.h
+++ /dev/null
@@ -1,298 +0,0 @@
-// Copyright lowRISC contributors.
-// Licensed under the Apache License, Version 2.0, see LICENSE for details.
-// SPDX-License-Identifier: Apache-2.0
-
-#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_EXTS_ROM_EXT_MANIFEST_PARSER_H_
-#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_EXTS_ROM_EXT_MANIFEST_PARSER_H_
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "sw/device/lib/base/mmio.h"
-#include "sw/device/silicon_creator/rom_exts/manifest.h"
-
-/**
- * @file
- * @brief Parser for the ROM_EXT Image Format
- *
- * This parser is intended to parse in-memory ROM_EXT images, from either Slot A
- * or Slot B. The fields it is parsing are defined in
- * `sw/device/silicon_creator/rom_exts/manifest.md` and
- * `sw/device_rom_exts/manifest.hjson`.
- *
- * This parser does minimal validity checking of the returned values, which must
- * always be checked by the caller to ensure do not contain incorrect or
- * insecure values.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-/**
- * ROM Extension manifest slot type.
- */
-typedef uintptr_t rom_ext_manifest_slot_t;
-
-/**
- * ROM Extension manifest slots base addresses.
- *
- * These are intended to be used as an input parameter to
- * `rom_ext_parameters_get`.
- */
-extern const rom_ext_manifest_slot_t kRomExtManifestSlotA;
-extern const rom_ext_manifest_slot_t kRomExtManifestSlotB;
-
-/**
- * ROM Extension parameters required for the manifest parsing.
- */
-typedef struct rom_ext_manifest {
- /**
- * Base address of the manifest in memory.
- */
- mmio_region_t base_addr;
- rom_ext_manifest_slot_t slot;
-} rom_ext_manifest_t;
-
-/**
- * ROM Extension Memory Extents.
- *
- * This information is needed for calculating the signature of the entire
- * ROM_EXT.
- */
-typedef struct rom_ext_ranges {
- /**
- * Image Start Address
- */
- uintptr_t image_start;
- /**
- * Signed Area Start Address
- *
- * Not all of a ROM_EXT is signed. This is the address of the first signed
- * byte of the ROM_EXT, in memory.
- */
- uintptr_t signed_area_start;
- /**
- * Image End Address
- *
- * This is also the Signed Area End Address.
- *
- * This is parsed from user-provided data, and must be checked to ensure it
- * the value is within the expected range, and has not overflowed.
- */
- uintptr_t image_end;
-} rom_ext_ranges_t;
-
-/**
- * ROM Extension image signature.
- */
-typedef struct rom_ext_signature {
- uint32_t data[ROM_EXT_IMAGE_SIGNATURE_SIZE_WORDS];
-} rom_ext_signature_t;
-
-/**
- * ROM Extension lockdown information.
- *
- * TODO - probably would eventually become an internal type, and there will
- * be another public type with more finely parsed information.
- */
-typedef struct rom_ext_lockdown_info {
- uint32_t data[ROM_EXT_PERIPHERAL_LOCKDOWN_INFO_SIZE_WORDS];
-} rom_ext_lockdown_info_t;
-
-/**
- * ROM Extension Signature Key Modulus.
- */
-typedef struct rom_ext_signature_key_modulus {
- uint32_t data[ROM_EXT_SIGNATURE_KEY_MODULUS_SIZE_WORDS];
-} rom_ext_signature_key_modulus_t;
-
-/**
- * ROM Extension image extension IDs.
- */
-typedef enum rom_ext_extension_id {
- /**
- * Image extension 0.
- */
- kRomExtExtensionId0 = 0,
- /**
- * Image extension 1.
- */
- kRomExtExtensionId1,
- /**
- * Image extension 2.
- */
- kRomExtExtensionId2,
- /**
- * Image extension 3.
- */
- kRomExtExtensionId3,
-} rom_ext_extension_id_t;
-
-/**
- * ROM Extension image extension.
- */
-typedef struct rom_ext_extension {
- /**
- * Image extension address in memory.
- */
- void *address;
- /**
- * Image extension checksum.
- */
- uint32_t checksum;
-} rom_ext_extension_t;
-
-/**
- * Creates the ROM extension manifest parameters.
- *
- * Required for all ROM Extension manifest parser API.
- *
- * @param slot ROM Extension manifest slot base address.
- * @return `rom_ext_manifest_t`.
- */
-rom_ext_manifest_t rom_ext_get_parameters(rom_ext_manifest_slot_t slot);
-
-/**
- * Retrieves the ROM_EXT identifier.
- *
- * The memory address where ROM_EXT identifier field resides, is relative.
- *
- * @param params Parameters required for manifest parsing.
- * @return ROM_EXT identifier.
- */
-uint32_t rom_ext_get_identifier(rom_ext_manifest_t params);
-
-/**
- * Retrieves the ROM_EXT signature.
- *
- * The memory address where ROM_EXT identifier field resides, is relative.
- *
- * @param params Parameters required for manifest parsing.
- * @param dst The destination address where the signature is copied to.
- * @return `true` on success, `false` on failure.
- */
-bool rom_ext_get_signature(rom_ext_manifest_t params, rom_ext_signature_t *dst);
-
-/**
- * Retrieves the ROM_EXT image address ranges.
- *
- * This uses the ROM_EXT image length field, and the offset of the signed area.
- *
- * The results provided are absolute addresses, not relative.
- *
- * This assumes that the slot identified by `params` is a valid ROM_EXT, and
- * does not check the ROM_EXT image identifier.
- *
- * @param params Parameters required to identify the ROM_EXT.
- * @return The address ranges of the specific ROM_EXT.
- */
-rom_ext_ranges_t rom_ext_get_ranges(rom_ext_manifest_t params);
-
-/**
- * Retrieves the ROM_EXT image version.
- *
- * The memory address where ROM_EXT image version field resides, is relative.
- *
- * @param params Parameters required for manifest parsing.
- * @return ROM_EXT image version.
- */
-uint32_t rom_ext_get_version(rom_ext_manifest_t params);
-
-/**
- * Retrieves the ROM_EXT image timestamp.
- *
- * The memory address where ROM_EXT image timestamp field resides, is relative.
- *
- * @param params Parameters required for manifest parsing.
- * @return ROM_EXT image timestamp.
- */
-uint64_t rom_ext_get_timestamp(rom_ext_manifest_t params);
-
-/**
- * Retrieves the ROM_EXT Signature Key Public Exponent.
- *
- * The memory address where ROM_EXT exponent field resides, is relative.
- *
- * @param params Parameters required for manifest parsing.
- * @return ROM_EXT Signature Key Public Exponent.
- */
-uint32_t rom_ext_get_signature_key_public_exponent(rom_ext_manifest_t params);
-
-/**
- * Retrieves the ROM_EXT usage constraints.
- *
- * The memory address where ROM_EXT usage constraints field resides, is
- * relative.
- *
- * @param params Parameters required for manifest parsing.
- * @return ROM_EXT usage constraints.
- */
-uint32_t rom_ext_get_usage_constraints(rom_ext_manifest_t params);
-
-/**
- * Retrieves the ROM_EXT lockdown info.
- *
- * The memory address where ROM_EXT lockdown info field resides, is relative.
- *
- * @param params Parameters required for manifest parsing.
- * @param dst The destination address where the lockdown info is copied to.
- * @return `true` on success, `false` on failure.
- */
-bool rom_ext_get_peripheral_lockdown_info(rom_ext_manifest_t params,
- rom_ext_lockdown_info_t *dst);
-
-/**
- * Retrieves the ROM_EXT Signature Key Modulus.
- *
- * The memory address where ROM_EXT key modulus field resides, is relative.
- *
- * @param params Parameters required for manifest parsing.
- * @param dst The destination address where the key modulus is copied to.
- * @return `true` on success, `false` on failure.
- */
-bool rom_ext_get_signature_key_modulus(rom_ext_manifest_t params,
- rom_ext_signature_key_modulus_t *dst);
-
-/**
- * Retrieves the ROM_EXT image extension specified in `id`.
- *
- * The memory address where ROM_EXT image extension information fields reside,
- * is relative.
- *
- * @param params Parameters required for manifest parsing.
- * @param id Extension identifier.
- * @param extension Parsed `rom_ext_extension_t` output.
- * @return `true` on success, `false` on failure.
- */
-bool rom_ext_get_extension(rom_ext_manifest_t params, rom_ext_extension_id_t id,
- rom_ext_extension_t *extension);
-
-/**
- * Calculates the ROM_EXT interrupt vector value.
- *
- * This value is based upon the absolute address of the ROM_EXT interrupt
- * vector, for this particular ROM_EXT.
- *
- * The value returned does not need extra processing to be used for vectored
- * interrupts in Ibex - the least significant two bits will have the correct
- * value.
- *
- * @param params Parameters required for manifest parsing.
- * @return The value to write to the `mtvec` RISC-V CSR.
- */
-uintptr_t rom_ext_get_interrupt_vector(rom_ext_manifest_t params);
-
-/**
- * Calculates the ROM_EXT image code entry point.
- *
- * @param params Parameters required for manifest parsing.
- * @return The absolute address to jump to to begin execution of the ROM_EXT.
- */
-uintptr_t rom_ext_get_entry(rom_ext_manifest_t params);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif // __cplusplus
-
-#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_EXTS_ROM_EXT_MANIFEST_PARSER_H_
diff --git a/sw/device/silicon_creator/rom_exts/rom_ext_parser_unittest.cc b/sw/device/silicon_creator/rom_exts/rom_ext_parser_unittest.cc
deleted file mode 100644
index 2410cef..0000000
--- a/sw/device/silicon_creator/rom_exts/rom_ext_parser_unittest.cc
+++ /dev/null
@@ -1,275 +0,0 @@
-// Copyright lowRISC contributors.
-// Licensed under the Apache License, Version 2.0, see LICENSE for details.
-// SPDX-License-Identifier: Apache-2.0
-
-#include "gtest/gtest.h"
-#include "sw/device/lib/base/bitfield.h"
-#include "sw/device/lib/base/mmio.h"
-#include "sw/device/lib/base/testing/mock_mmio.h"
-#include "sw/device/silicon_creator/rom_exts/manifest.h"
-#include "sw/device/silicon_creator/rom_exts/rom_ext_manifest_parser.h"
-
-namespace rom_ext_parser_unittest {
-namespace {
-using mock_mmio::MmioTest;
-using mock_mmio::MockDevice;
-using testing::Each;
-using testing::ElementsAreArray;
-using testing::Eq;
-using testing::Test;
-
-class ParserTest : public Test, public MmioTest {
- protected:
- rom_ext_manifest_t params_ = {
- .base_addr =
- (mmio_region_t){
- .mock = dev().region(),
- },
- .slot = kRomExtManifestSlotA,
- };
-};
-
-class IdentifierGetTest : public ParserTest {};
-
-TEST_F(IdentifierGetTest, Success) {
- EXPECT_READ32(ROM_EXT_MANIFEST_IDENTIFIER_OFFSET, 0xa5a5a5a5);
- EXPECT_EQ(rom_ext_get_identifier(params_), 0xa5a5a5a5);
-}
-
-class SignatureGetTest : public ParserTest {
- protected:
- SignatureGetTest() {
- for (uint32_t i = 0; i < kSizeInWords_; ++i) {
- src_.data[i] = dev().GarbageMemory<uint32_t>();
- }
- }
-
- const uint32_t kSizeInWords_ = ROM_EXT_IMAGE_SIGNATURE_SIZE_WORDS;
- rom_ext_signature_t src_;
-};
-
-TEST_F(SignatureGetTest, NullArgs) {
- EXPECT_FALSE(rom_ext_get_signature(params_, nullptr));
-}
-
-TEST_F(SignatureGetTest, Success) {
- rom_ext_signature_t dst;
-
- auto offset_word_0 = ROM_EXT_IMAGE_SIGNATURE_OFFSET;
- for (size_t i = 0; i < kSizeInWords_; ++i) {
- auto offset = offset_word_0 + (i * sizeof(uint32_t));
- EXPECT_READ32(offset, src_.data[i]);
- }
-
- EXPECT_TRUE(rom_ext_get_signature(params_, &dst));
- EXPECT_THAT(src_.data, ElementsAreArray(dst.data));
-}
-
-class RangesGetTest : public ParserTest {
- protected:
- testing::Matcher<rom_ext_ranges_t> EqualsRanges(const rom_ext_ranges_t &rhs) {
- return testing::AllOf(
- testing::Field("image_start", &rom_ext_ranges_t::image_start,
- rhs.image_start),
- testing::Field("signed_area_start",
- &rom_ext_ranges_t::signed_area_start,
- rhs.signed_area_start),
- testing::Field("image_end", &rom_ext_ranges_t::image_end,
- rhs.image_end));
- }
-};
-
-TEST_F(RangesGetTest, Success) {
- EXPECT_READ32(ROM_EXT_IMAGE_LENGTH_OFFSET, 0xa5a5a5a5);
-
- rom_ext_ranges_t expected = {
- .image_start = kRomExtManifestSlotA,
- .signed_area_start =
- kRomExtManifestSlotA + ROM_EXT_SIGNED_AREA_START_OFFSET,
- .image_end = kRomExtManifestSlotA + 0xa5a5a5a5,
- };
-
- EXPECT_THAT(rom_ext_get_ranges(params_), EqualsRanges(expected));
-}
-
-class ImageVersionGetTest : public ParserTest {};
-
-TEST_F(ImageVersionGetTest, Success) {
- EXPECT_READ32(ROM_EXT_IMAGE_VERSION_OFFSET, 0xa5a5a5a5);
- EXPECT_EQ(rom_ext_get_version(params_), 0xa5a5a5a5);
-}
-
-class ImageTimestampGetTest : public ParserTest {};
-
-TEST_F(ImageTimestampGetTest, Success) {
- EXPECT_READ32(ROM_EXT_IMAGE_TIMESTAMP_OFFSET, 0xcdcdcdcd);
- EXPECT_READ32(ROM_EXT_IMAGE_TIMESTAMP_OFFSET + sizeof(uint32_t), 0xabababab);
-
- EXPECT_EQ(rom_ext_get_timestamp(params_), 0xababababcdcdcdcd);
-}
-
-class SignatureKeyPublicExponentGetTest : public ParserTest {};
-
-TEST_F(SignatureKeyPublicExponentGetTest, Success) {
- EXPECT_READ32(ROM_EXT_SIGNATURE_KEY_PUBLIC_EXPONENT_OFFSET, 0xa5a5a5a5);
- EXPECT_EQ(rom_ext_get_signature_key_public_exponent(params_), 0xa5a5a5a5);
-}
-
-class UsageConstraintsGetTest : public ParserTest {};
-
-TEST_F(UsageConstraintsGetTest, Success) {
- EXPECT_READ32(ROM_EXT_USAGE_CONSTRAINTS_OFFSET, 0xa5a5a5a5);
- EXPECT_EQ(rom_ext_get_usage_constraints(params_), 0xa5a5a5a5);
-}
-
-class PeripheralLockdownInfoGetTest : public ParserTest {
- protected:
- PeripheralLockdownInfoGetTest() {
- for (uint32_t i = 0; i < kSizeInWords_; ++i) {
- src_.data[i] = dev().GarbageMemory<uint32_t>();
- }
- }
-
- const uint32_t kSizeInWords_ = ROM_EXT_PERIPHERAL_LOCKDOWN_INFO_SIZE_WORDS;
- rom_ext_lockdown_info_t src_;
-};
-
-TEST_F(PeripheralLockdownInfoGetTest, NullArgs) {
- EXPECT_FALSE(rom_ext_get_peripheral_lockdown_info(params_, nullptr));
-}
-
-TEST_F(PeripheralLockdownInfoGetTest, Success) {
- rom_ext_lockdown_info_t dst;
-
- auto offset_word_0 = ROM_EXT_PERIPHERAL_LOCKDOWN_INFO_OFFSET;
- for (size_t i = 0; i < kSizeInWords_; ++i) {
- auto offset = offset_word_0 + (i * sizeof(uint32_t));
- EXPECT_READ32(offset, src_.data[i]);
- }
-
- EXPECT_TRUE(rom_ext_get_peripheral_lockdown_info(params_, &dst));
- EXPECT_THAT(src_.data, ElementsAreArray(dst.data));
-}
-
-class SignatureKeyModulusGetTest : public ParserTest {
- protected:
- SignatureKeyModulusGetTest() {
- for (uint32_t i = 0; i < kSizeInWords_; ++i) {
- src_.data[i] = dev().GarbageMemory<uint32_t>();
- }
- }
-
- const uint32_t kSizeInWords_ = ROM_EXT_SIGNATURE_KEY_MODULUS_SIZE_WORDS;
- rom_ext_signature_key_modulus_t src_;
-};
-
-TEST_F(SignatureKeyModulusGetTest, NullArgs) {
- EXPECT_FALSE(rom_ext_get_signature_key_modulus(params_, nullptr));
-}
-
-TEST_F(SignatureKeyModulusGetTest, Success) {
- rom_ext_signature_key_modulus_t dst;
-
- auto offset_word_0 = ROM_EXT_SIGNATURE_KEY_MODULUS_OFFSET;
- for (size_t i = 0; i < kSizeInWords_; ++i) {
- auto offset = offset_word_0 + (i * sizeof(uint32_t));
- EXPECT_READ32(offset, src_.data[i]);
- }
-
- EXPECT_TRUE(rom_ext_get_signature_key_modulus(params_, &dst));
- EXPECT_THAT(src_.data, ElementsAreArray(dst.data));
-}
-
-class ExtensionGetTest : public ParserTest {
- protected:
- testing::Matcher<rom_ext_extension_t> Eq(const rom_ext_extension_t &rhs) {
- return testing::AllOf(
- testing::Field("checksum", &rom_ext_extension_t::checksum,
- rhs.checksum),
- testing::Field("address", &rom_ext_extension_t::address, rhs.address));
- }
-};
-
-TEST_F(ExtensionGetTest, NullArgs) {
- EXPECT_FALSE(rom_ext_get_extension(params_, kRomExtExtensionId0, nullptr));
- EXPECT_FALSE(rom_ext_get_extension(params_, kRomExtExtensionId1, nullptr));
- EXPECT_FALSE(rom_ext_get_extension(params_, kRomExtExtensionId2, nullptr));
- EXPECT_FALSE(rom_ext_get_extension(params_, kRomExtExtensionId3, nullptr));
-}
-
-TEST_F(ExtensionGetTest, Success) {
- EXPECT_READ32(ROM_EXT_EXTENSION0_OFFSET_OFFSET, 0x10);
- EXPECT_READ32(ROM_EXT_EXTENSION0_CHECKSUM_OFFSET, 0xbbbbbbbb);
-
- rom_ext_extension_t ext0;
- rom_ext_extension_t ext0_expected = {
- .address = (void *)(kRomExtManifestSlotA + 0x10),
- .checksum = 0xbbbbbbbb,
- };
- EXPECT_TRUE(rom_ext_get_extension(params_, kRomExtExtensionId0, &ext0));
- EXPECT_THAT(ext0, Eq(ext0_expected));
-
- EXPECT_READ32(ROM_EXT_EXTENSION1_OFFSET_OFFSET, 0x20);
- EXPECT_READ32(ROM_EXT_EXTENSION1_CHECKSUM_OFFSET, 0xdddddddd);
-
- rom_ext_extension_t ext1;
- rom_ext_extension_t ext1_expected = {
- .address = (void *)(kRomExtManifestSlotA + 0x20),
- .checksum = 0xdddddddd,
- };
- EXPECT_TRUE(rom_ext_get_extension(params_, kRomExtExtensionId1, &ext1));
- EXPECT_THAT(ext1, Eq(ext1_expected));
-
- EXPECT_READ32(ROM_EXT_EXTENSION2_OFFSET_OFFSET, 0x30);
- EXPECT_READ32(ROM_EXT_EXTENSION2_CHECKSUM_OFFSET, 0xffffffff);
-
- rom_ext_extension_t ext2;
- rom_ext_extension_t ext2_expected = {
- .address = (void *)(kRomExtManifestSlotA + 0x30),
- .checksum = 0xffffffff,
- };
- EXPECT_TRUE(rom_ext_get_extension(params_, kRomExtExtensionId2, &ext2));
- EXPECT_THAT(ext2, Eq(ext2_expected));
-
- EXPECT_READ32(ROM_EXT_EXTENSION3_OFFSET_OFFSET, 0x40);
- EXPECT_READ32(ROM_EXT_EXTENSION3_CHECKSUM_OFFSET, 0x66666666);
-
- rom_ext_extension_t ext3;
- rom_ext_extension_t ext3_expected = {
- .address = (void *)(kRomExtManifestSlotA + 0x40),
- .checksum = 0x66666666,
- };
- EXPECT_TRUE(rom_ext_get_extension(params_, kRomExtExtensionId3, &ext3));
- EXPECT_THAT(ext3, Eq(ext3_expected));
-}
-
-class EntryGetTest : public ParserTest {};
-
-TEST_F(EntryGetTest, Success) {
- EXPECT_EQ(rom_ext_get_entry(params_),
- kRomExtManifestSlotA + ROM_EXT_ENTRY_POINT_OFFSET);
-}
-
-class InterruptVectorGetTest : public ParserTest {};
-
-TEST_F(InterruptVectorGetTest, Success) {
- uintptr_t mtvec_val = rom_ext_get_interrupt_vector(params_);
- uintptr_t vec_addr = kRomExtManifestSlotA + ROM_EXT_INTERRUPT_VECTOR_OFFSET;
-
- const bitfield_field32_t most_significant_30_bits = {
- .mask = 0x3fffffff,
- .index = 2,
- };
-
- const bitfield_field32_t least_significant_2_bits = {
- .mask = 0x3,
- .index = 0,
- };
-
- EXPECT_EQ(bitfield_field32_read(mtvec_val, most_significant_30_bits),
- bitfield_field32_read(vec_addr, most_significant_30_bits));
- EXPECT_EQ(bitfield_field32_read(mtvec_val, least_significant_2_bits), 0x1);
-}
-
-} // namespace
-} // namespace rom_ext_parser_unittest