Software APIs
bootstrap_fuzz_test.cc
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include <stddef.h>
6 #include <utility>
7 
8 #include "absl/types/span.h"
9 #include "sw/device/lib/base/mock_abs_mmio.h"
11 #include "sw/device/silicon_creator/lib/bootstrap_fuzzer_util.h"
12 #include "sw/device/silicon_creator/rom/bootstrap.h"
13 
14 #include "gpio_regs.h"
16 #include "otp_ctrl_regs.h"
17 
18 namespace {
21 
23  public:
24  RomMockGroup(StreamParser stream, bool verbose)
25  : AbstractBootstrapMockGroup(std::move(stream), verbose) {}
26 
27  void ConfigureMocks() override {
28  AbstractBootstrapMockGroup::ConfigureMocks();
29 
30  ON_CALL(otp_, read32(OTP_CTRL_PARAM_OWNER_SW_CFG_ROM_BOOTSTRAP_DIS_OFFSET))
31  .WillByDefault(::testing::Return(stream_.ParseIntOr<hardened_bool_t>(
32  "bootstrap_enabled", kHardenedBoolFalse)));
33 
34  ON_CALL(mmio_,
35  Read32(TOP_EARLGREY_GPIO_BASE_ADDR + GPIO_DATA_IN_REG_OFFSET))
36  .WillByDefault(
37  ::testing::Return(stream_.ParseIntOr<uint32_t>("strapping", 0)));
38  }
39 
40  private:
41  ::rom_test::NiceMockAbsMmio mmio_;
42 };
43 } // namespace
44 
45 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
46  static bootstrap_fuzzer::StaticFuzzerEnvironment static_fuzzer_env;
47 
48  constexpr bool kVerbose = false;
49  StreamParser stream(absl::MakeConstSpan(data, size), kVerbose);
50  RomMockGroup mock_group(std::move(stream), kVerbose);
51  mock_group.ConfigureMocks();
52 
53  (void)bootstrap();
54 
55  return 0; // Values other than 0 and -1 are reserved for future use.
56 }