Skip to content

Commit

Permalink
sfdp: Implemented a function for determining the correct length for a…
Browse files Browse the repository at this point in the history
… table based on its version number
  • Loading branch information
dragonmux committed Dec 7, 2023
1 parent 9082209 commit 2895d64
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/include/sfdpInternal.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ namespace bmpflash::sfdp

struct parameterTableHeader_t
{
private:
[[nodiscard]] size_t lengthForVersion() const noexcept;

public:
uint8_t jedecParameterIDLow{};
uint8_t versionMinor{};
uint8_t versionMajor{};
Expand Down
37 changes: 37 additions & 0 deletions src/sfdp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,41 @@ namespace bmpflash::sfdp
}
return std::nullopt;
}

size_t parameterTableHeader_t::lengthForVersion() const noexcept
{
if (versionMajor < 1U)
{
console.warn("SFDP basic parameters table header version incorrect, got v"sv, versionMajor, '.',
versionMinor, " which is less than minimum allowable version of v1.0"sv);
// If the version number is impossible, just return the table length - there's nothing else we can do.
return tableLength();
}
// Turn the version number into a uint16_t with the upper byte being the major and the lower being the minor
const auto version{static_cast<uint16_t>((versionMajor << 8U) | versionMinor)};
// Now switch on the valid ones we know about
switch (version)
{
// v1.0 through v1.4 from the original JESD216
case 0x0100U:
case 0x0101U:
case 0x0102U:
case 0x0103U:
case 0x0104U:
return 36U; // 9 uint32_t's
// v1.5 (JESD216A), v1.6 (JESD216B)
case 0x0105U:
case 0x0106U:
return 64U; // 16 uint32_t's
// v1.7 (JESD216C, JESD216D, JESD216E)
case 0x0107U:
return 84U; // 21 uint32_t's
// v1.8 (JESD216F)
case 0x0108U:
return 96U; // 24 uint32_t's
default:
console.warn("Unknown SFDP version v"sv, versionMajor, '.', versionMinor, ", assuming valid size"sv);
return tableLength();
}
}
} // namespace bmpflash::sfdp

0 comments on commit 2895d64

Please sign in to comment.