Skip to content

Commit

Permalink
sfdp: Pass the parameter table header into displayBasicParameterTable…
Browse files Browse the repository at this point in the history
…() and handle table versioning for the page size properly
  • Loading branch information
dragonmux authored and esden committed Sep 28, 2023
1 parent c900d9d commit f87ad30
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/sfdp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,21 @@ namespace bmpflash::sfdp
console.info("-> table SFDP address: "sv, uint32_t{header.tableAddress});
}

[[nodiscard]] bool displayBasicParameterTable(const bmp_t &probe, const uint32_t address, const size_t length)
[[nodiscard]] bool displayBasicParameterTable(const bmp_t &probe, const parameterTableHeader_t &header)
{
basicParameterTable_t parameterTable{};
if (!sfdpRead(probe, address, &parameterTable, std::min(sizeof(basicParameterTable_t), length)))
if (!sfdpRead(probe, header.tableAddress, &parameterTable,
std::min(sizeof(basicParameterTable_t), header.tableLength())))
return false;

console.info("Basic parameter table:");
const auto [capacityValue, capacityUnits] =
humanReadableSize(static_cast<size_t>(parameterTable.flashMemoryDensity.capacity()));
console.info("-> capacity "sv, capacityValue, capacityUnits);
console.info("-> program page size: "sv, parameterTable.programmingAndChipEraseTiming.pageSize());
if (header.versionMajor > 1U || (header.versionMajor == 1U && header.versionMinor >= 5U))
console.info("-> program page size: "sv, parameterTable.programmingAndChipEraseTiming.pageSize());
else
console.info("-> program page size: default (256)"sv);
console.info("-> sector erase opcode: "sv, asHex_t<2, '0'>(parameterTable.sectorEraseOpcode));
console.info("-> supported erase types:"sv);
for (const auto &[idx, eraseType] : indexedIterator_t{parameterTable.eraseTypes})
Expand Down Expand Up @@ -107,7 +111,7 @@ namespace bmpflash::sfdp
displayTableHeader(tableHeader, idx + 1U);
if (tableHeader.jedecParameterID() == basicSPIParameterTable)
{
if (!displayBasicParameterTable(probe, tableHeader.tableAddress, tableHeader.tableLength()))
if (!displayBasicParameterTable(probe, tableHeader))
return false;
}
}
Expand Down

0 comments on commit f87ad30

Please sign in to comment.