Software APIs
flash_regions.c
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 "sw/device/lib/base/status.h"
9 
11 
12 OTTF_DEFINE_TEST_CONFIG();
13 
14 dif_flash_ctrl_state_t flash_state;
15 
16 const char *mubi_prop(multi_bit_bool_t val, const char *name) {
17  switch (val) {
18  case kMultiBitBool4True:
19  return name;
20  case kMultiBitBool4False:
21  return "xx";
22  default:
23  return "uu";
24  }
25 }
26 
27 void flash_data_region_print(size_t index,
29  bool locked) {
30  LOG_INFO("data region n=%u st=%u sz=%u %s-%s-%s-%s-%s-%s %s", index, p->base,
31  p->size, mubi_prop(p->properties.rd_en, "RD"),
32  mubi_prop(p->properties.prog_en, "WR"),
33  mubi_prop(p->properties.erase_en, "ER"),
34  mubi_prop(p->properties.scramble_en, "SC"),
35  mubi_prop(p->properties.ecc_en, "EC"),
36  mubi_prop(p->properties.high_endurance_en, "HE"),
37  locked ? "LK" : "UN");
38 }
39 
40 void flash_info_region_print(dif_flash_ctrl_info_region_t region,
42  bool locked) {
43  LOG_INFO("info region bank=%u part=%u page=%u %s-%s-%s-%s-%s-%s %s",
44  region.bank, region.partition_id, region.page,
45  mubi_prop(p->rd_en, "RD"), mubi_prop(p->prog_en, "WR"),
46  mubi_prop(p->erase_en, "ER"), mubi_prop(p->scramble_en, "SC"),
47  mubi_prop(p->ecc_en, "EC"), mubi_prop(p->high_endurance_en, "HE"),
48  locked ? "LK" : "UN");
49 }
50 
51 status_t flash_regions_print(dif_flash_ctrl_state_t *f) {
52  for (uint32_t i = 0; i < 8; ++i) {
54  bool locked;
56  TRY(dif_flash_ctrl_data_region_is_locked(f, i, &locked));
57  flash_data_region_print(i, &p, locked);
58  }
59  for (uint32_t bank = 0; bank < 2; ++bank) {
60  for (uint32_t page = 0; page < 10; ++page) {
62  .bank = bank,
63  .partition_id = 0,
64  .page = page,
65  };
66  bool locked;
69  TRY(dif_flash_ctrl_info_region_is_locked(f, region, &locked));
70  flash_info_region_print(region, &p, locked);
71  }
72  }
73  return OK_STATUS();
74 }
75 
76 bool test_main(void) {
77  CHECK_DIF_OK(dif_flash_ctrl_init_state(
78  &flash_state,
80  status_t sts = flash_regions_print(&flash_state);
81 
82  if (status_err(sts)) {
83  LOG_ERROR("flash_regions_print: %r", sts);
84  }
85  return status_ok(sts);
86 }