From a6cd353a3e1cc32042b8a370dcb2a2960d19b5a7 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 18 Oct 2022 15:59:05 -0700 Subject: [PATCH] src/flashrom: allow nested regions --- .../0002-layout.c-allow-nested-regions.patch | 45 +++++++++++++++++++ src/flashrom/default.nix | 1 + 2 files changed, 46 insertions(+) create mode 100644 src/flashrom/0002-layout.c-allow-nested-regions.patch diff --git a/src/flashrom/0002-layout.c-allow-nested-regions.patch b/src/flashrom/0002-layout.c-allow-nested-regions.patch new file mode 100644 index 0000000..82f38fd --- /dev/null +++ b/src/flashrom/0002-layout.c-allow-nested-regions.patch @@ -0,0 +1,45 @@ +From 5af5c5418f5335ab1c843f8ab6eb148d413d32a6 Mon Sep 17 00:00:00 2001 +From: Adam Joseph +Date: Tue, 18 Oct 2022 15:47:41 -0700 +Subject: [PATCH 2/2] layout.c: allow nested regions + +Many BIOSes have nested regions. For example, AGESA for KGPE-D16 +expects a BIOS region covering essentially the whole chip, which is +used by SMM to protect the critical parts of the flash chip. This +means that `flashrom --fmap` won't work with those images. + +Let's adjust the overlapping-regions check to allow nested regions, +where one region completely contains another region. +--- + layout.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/layout.c b/layout.c +index e688f79..072ab5f 100644 +--- a/layout.c ++++ b/layout.c +@@ -245,7 +245,7 @@ int process_include_args(struct flashrom_layout *l, const struct layout_include_ + return 0; + } + +-/* returns boolean 1 if any regions overlap, 0 otherwise */ ++/* returns boolean 1 if any regions overlap and neither fully contains the other, 0 otherwise */ + int included_regions_overlap(const struct flashrom_layout *const l) + { + const struct romentry *lhs = NULL; +@@ -266,6 +266,12 @@ int included_regions_overlap(const struct flashrom_layout *const l) + if (lhs->end < rhs->start) + continue; + ++ if (lhs->start <= rhs->start && lhs->end >= rhs->end) ++ continue; ++ ++ if (rhs->start <= lhs->start && rhs->end >= lhs->end) ++ continue; ++ + msg_gdbg("Regions %s [0x%08x-0x%08x] and %s [0x%08x-0x%08x] overlap\n", + lhs->name, lhs->start, lhs->end, rhs->name, rhs->start, rhs->end); + overlap_detected = 1; +-- +2.37.2 + diff --git a/src/flashrom/default.nix b/src/flashrom/default.nix index 4cd9748..71ce23c 100644 --- a/src/flashrom/default.nix +++ b/src/flashrom/default.nix @@ -25,6 +25,7 @@ stdenv.mkDerivation { patches = [ ./0001-implement-wp-enable-disable-for-gigadevice-flash-chi.patch + ./0002-layout.c-allow-nested-regions.patch ]; makeFlags = [ "PREFIX=$(out)" "libinstall" ];