From 7500370fb90ab82fc4737becce2fb5f08d584136 Mon Sep 17 00:00:00 2001 From: edef Date: Sun, 28 Jul 2024 04:41:14 +0000 Subject: [PATCH 1/6] flashrom: 1.3.0 -> 1.4.0 --- pkgs/by-name/fl/flashrom/package.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/fl/flashrom/package.nix b/pkgs/by-name/fl/flashrom/package.nix index 87209a371b02..7218a72d848d 100644 --- a/pkgs/by-name/fl/flashrom/package.nix +++ b/pkgs/by-name/fl/flashrom/package.nix @@ -13,11 +13,11 @@ stdenv.mkDerivation rec { pname = "flashrom"; - version = "1.3.0"; + version = "1.4.0"; src = fetchurl { - url = "https://download.flashrom.org/releases/flashrom-v${version}.tar.bz2"; - hash = "sha256-oFMjRFPM0BLnnzRDvcxhYlz5e3/Xy0zdi/v/vosUliM="; + url = "https://download.flashrom.org/releases/flashrom-${version}.tar.xz"; + hash = "sha256-rX7htJI5xvtPj1XjZwb81zFDXbGkvS+rPYDx9yUIzO4="; }; nativeBuildInputs = [ From a0e49b02711fbc4ee6c4aa780096a8517b4c3c7b Mon Sep 17 00:00:00 2001 From: edef Date: Sun, 28 Jul 2024 05:20:12 +0000 Subject: [PATCH 2/6] flashrom: build with meson Per the 1.4.0 release notes, Meson will be the only supported build system for future versions. --- pkgs/by-name/fl/flashrom/package.nix | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/pkgs/by-name/fl/flashrom/package.nix b/pkgs/by-name/fl/flashrom/package.nix index 7218a72d848d..287786e7ca8f 100644 --- a/pkgs/by-name/fl/flashrom/package.nix +++ b/pkgs/by-name/fl/flashrom/package.nix @@ -1,13 +1,17 @@ { fetchurl, stdenv, - installShellFiles, + bash-completion, + cmocka, lib, libftdi1, libjaylink, libusb1, + meson, + ninja, pciutils, pkg-config, + sphinx, jlinkSupport ? false, }: @@ -21,15 +25,19 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = [ + meson + ninja pkg-config - installShellFiles + sphinx + bash-completion ]; buildInputs = [ + cmocka libftdi1 libusb1 ] - ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ pciutils ] + ++ lib.optionals (!stdenv.isDarwin) [ pciutils ] ++ lib.optional jlinkSupport libjaylink; postPatch = '' @@ -37,20 +45,8 @@ stdenv.mkDerivation rec { --replace 'GROUP="plugdev"' 'TAG+="uaccess", TAG+="udev-acl"' ''; - makeFlags = - [ - "PREFIX=$(out)" - "libinstall" - ] - ++ lib.optional jlinkSupport "CONFIG_JLINK_SPI=yes" - ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [ - "CONFIG_INTERNAL_X86=no" - "CONFIG_INTERNAL_DMI=no" - "CONFIG_RAYER_SPI=no" - ]; - postInstall = '' - install -Dm644 util/flashrom_udev.rules $out/lib/udev/rules.d/flashrom.rules + install -Dm644 $NIX_BUILD_TOP/$sourceRoot/util/flashrom_udev.rules $out/lib/udev/rules.d/flashrom.rules ''; NIX_CFLAGS_COMPILE = lib.optionalString ( From 498430e280a63cb2b8e57e821066e289fd4d5564 Mon Sep 17 00:00:00 2001 From: edef Date: Mon, 29 Jul 2024 16:37:31 +0000 Subject: [PATCH 3/6] flashrom: remove (broken) Promontory support Release notes for 1.4.0 state that Promontory chipsets are unsupported, and that attempting to read flash on those systems may crash the system. The patch that removes this (broken) support only made it into the 1.3.0 release, seemingly by mistake, and the relevant code has been essentially untouched since. We'd rather not crash the systems of unsuspecting NixOS/nixpkgs users, so this change forward-ports the patch from 1.3.0, though amended to reference the relevant bug in the error message, rather than requesting the user email upstream. Link: https://ticket.coreboot.org/issues/370 Link: https://review.coreboot.org/c/flashrom/+/68824 --- ...1-sb600spi.c-Drop-Promontory-support.patch | 103 ++++++++++++++++++ pkgs/by-name/fl/flashrom/package.nix | 9 ++ 2 files changed, 112 insertions(+) create mode 100644 pkgs/by-name/fl/flashrom/0001-sb600spi.c-Drop-Promontory-support.patch diff --git a/pkgs/by-name/fl/flashrom/0001-sb600spi.c-Drop-Promontory-support.patch b/pkgs/by-name/fl/flashrom/0001-sb600spi.c-Drop-Promontory-support.patch new file mode 100644 index 000000000000..2fa422f8c1a1 --- /dev/null +++ b/pkgs/by-name/fl/flashrom/0001-sb600spi.c-Drop-Promontory-support.patch @@ -0,0 +1,103 @@ +From 38b2cb092e866dede6b6ffddd135ff54a9bda69e Mon Sep 17 00:00:00 2001 +From: Angel Pons +Date: Wed, 2 Nov 2022 22:45:52 +0100 +Subject: [PATCH] sb600spi.c: Drop "Promontory" support + +The "Promontory" code is riddled with issues, some of them can result in +soft bricks. Moreover, Promontory doesn't have a SPI controller. + +Drop support for "Promontory" in flashrom for now: it's holding back the +entire project and it's unlikely that it'll be fixed in a timely manner. + +Change-Id: I1457946dce68321b496d9ffa40a0c5ab46455f72 +Signed-off-by: Angel Pons +Reviewed-on: https://review.coreboot.org/c/flashrom/+/68824 +Tested-by: build bot (Jenkins) +Reviewed-by: Felix Singer +Reviewed-by: Swift Geek (Sebastian Grzywna) +Reviewed-by: Edward O'Callaghan +(cherry picked from commit 664c58f32af45b2acf7520c05bb40ef2c2f0891e) +--- + sb600spi.c | 31 ++----------------------------- + 1 file changed, 2 insertions(+), 29 deletions(-) + +diff --git a/sb600spi.c b/sb600spi.c +index cec7e0a5..e84bb8d6 100644 +--- a/sb600spi.c ++++ b/sb600spi.c +@@ -48,7 +48,6 @@ enum amd_chipset { + CHIPSET_HUDSON234, + CHIPSET_BOLTON, + CHIPSET_YANGTZE, +- CHIPSET_PROMONTORY, + }; + + #define FIFO_SIZE_OLD 8 +@@ -135,7 +134,8 @@ static enum amd_chipset determine_generation(struct pci_dev *dev) + */ + } else if (rev == 0x4b || rev == 0x51 || rev == 0x59 || rev == 0x61 || rev == 0x71) { + msg_pdbg("Promontory (rev 0x%02x) detected.\n", rev); +- return CHIPSET_PROMONTORY; ++ msg_perr("AMD \"Promontory\" chipsets are currently not supported (https://ticket.coreboot.org/issues/370)"); ++ return CHIPSET_AMD_UNKNOWN; + } else { + msg_pwarn("FCH device found but SMBus revision 0x%02x does not match known values.\n" + "Please report this to flashrom@flashrom.org and include this log and\n" +@@ -572,18 +572,6 @@ static int handle_imc(const struct programmer_cfg *cfg, struct pci_dev *dev, enu + return amd_imc_shutdown(dev); + } + +-static int promontory_read_memmapped(struct flashctx *flash, uint8_t *buf, +- unsigned int start, unsigned int len) +-{ +- struct sb600spi_data * data = (struct sb600spi_data *)flash->mst->spi.data; +- if (!data->flash) { +- map_flash(flash); +- data->flash = flash; /* keep a copy of flashctx for unmap() on tear-down. */ +- } +- mmio_readn((void *)(flash->virtual_memory + start), buf, len); +- return 0; +-} +- + static int sb600spi_shutdown(void *data) + { + struct sb600spi_data *sb600_data = data; +@@ -617,17 +605,6 @@ static const struct spi_master spi_master_yangtze = { + .shutdown = sb600spi_shutdown, + }; + +-static const struct spi_master spi_master_promontory = { +- .max_data_read = MAX_DATA_READ_UNLIMITED, +- .max_data_write = FIFO_SIZE_YANGTZE - 3, +- .command = spi100_spi_send_command, +- .map_flash_region = physmap, +- .unmap_flash_region = physunmap, +- .read = promontory_read_memmapped, +- .write_256 = default_spi_write_256, +- .shutdown = sb600spi_shutdown, +-}; +- + int sb600_probe_spi(const struct programmer_cfg *cfg, struct pci_dev *dev) + { + struct pci_dev *smbus_dev; +@@ -731,8 +708,6 @@ int sb600_probe_spi(const struct programmer_cfg *cfg, struct pci_dev *dev) + case CHIPSET_SB89XX: + case CHIPSET_HUDSON234: + case CHIPSET_YANGTZE: +- case CHIPSET_PROMONTORY: +- msg_pdbg(", SpiBusy=%"PRIi32"", (tmp >> 31) & 0x1); + default: break; + } + msg_pdbg("\n"); +@@ -808,8 +783,6 @@ int sb600_probe_spi(const struct programmer_cfg *cfg, struct pci_dev *dev) + register_spi_master(&spi_master_sb600, data); + else if (amd_gen == CHIPSET_YANGTZE) + register_spi_master(&spi_master_yangtze, data); +- else +- register_spi_master(&spi_master_promontory, data); + + return 0; + } +-- +2.45.2 + diff --git a/pkgs/by-name/fl/flashrom/package.nix b/pkgs/by-name/fl/flashrom/package.nix index 287786e7ca8f..f8cbd4f1354a 100644 --- a/pkgs/by-name/fl/flashrom/package.nix +++ b/pkgs/by-name/fl/flashrom/package.nix @@ -24,6 +24,15 @@ stdenv.mkDerivation rec { hash = "sha256-rX7htJI5xvtPj1XjZwb81zFDXbGkvS+rPYDx9yUIzO4="; }; + patches = [ + # Release notes for 1.4.0 state that Promontory chipsets are unsupported, and that attempting to read flash on those systems may crash the system. + # The patch that removes this (broken) support only made it into the 1.3.0 release, seemingly by mistake, and the relevant code has been essentially untouched since. + # We cherry-pick the upstream patch from 1.3.0, though amended to reference the relevant bug in the error message, rather than requesting the user email upstream. + # https://ticket.coreboot.org/issues/370 + # https://review.coreboot.org/c/flashrom/+/68824 + ./0001-sb600spi.c-Drop-Promontory-support.patch + ]; + nativeBuildInputs = [ meson ninja From 4251ec687095cb2e058e3eb4439bbd800fa6bb10 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 30 Jul 2024 03:21:39 +0000 Subject: [PATCH 4/6] flashrom: fix Darwin build memcpy is a macro on Darwin, and thus requires braced initializer lists to be parenthesized. --- ...rase-parenthesize-braced-initializer.patch | 50 +++++++++++++++++++ pkgs/by-name/fl/flashrom/package.nix | 19 ++++--- 2 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 pkgs/by-name/fl/flashrom/0002-tests-erase-parenthesize-braced-initializer.patch diff --git a/pkgs/by-name/fl/flashrom/0002-tests-erase-parenthesize-braced-initializer.patch b/pkgs/by-name/fl/flashrom/0002-tests-erase-parenthesize-braced-initializer.patch new file mode 100644 index 000000000000..fdad7832431b --- /dev/null +++ b/pkgs/by-name/fl/flashrom/0002-tests-erase-parenthesize-braced-initializer.patch @@ -0,0 +1,50 @@ +From ba84c4aba56420315973026288e7b336006336a9 Mon Sep 17 00:00:00 2001 +From: edef +Date: Tue, 30 Jul 2024 03:14:37 +0000 +Subject: [PATCH] tests/erase: parenthesize braced initializer + +memcpy is a macro on Darwin, and thus requires braced initializer lists +to be parenthesized. +--- + tests/erase_func_algo.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/tests/erase_func_algo.c b/tests/erase_func_algo.c +index 576923f8..b13ee70c 100644 +--- a/tests/erase_func_algo.c ++++ b/tests/erase_func_algo.c +@@ -1233,13 +1233,13 @@ static void erase_unwritable_regions_skipflag_on_test_success(void **state) + + // This test needs special block erase to emulate protected regions. + memcpy(g_test_erase_injector, +- (erasefunc_t *const[]){ ++ ((erasefunc_t *const[]){ + block_erase_chip_with_protected_region_1, + block_erase_chip_with_protected_region_2, + block_erase_chip_with_protected_region_3, + block_erase_chip_with_protected_region_4, + block_erase_chip_with_protected_region_5, +- }, ++ }), + sizeof(g_test_erase_injector) + ); + +@@ -1322,13 +1322,13 @@ static void write_unwritable_regions_skipflag_on_test_success(void **state) { + + // This test needs special block erase to emulate protected regions. + memcpy(g_test_erase_injector, +- (erasefunc_t *const[]){ ++ ((erasefunc_t *const[]){ + block_erase_chip_with_protected_region_1, + block_erase_chip_with_protected_region_2, + block_erase_chip_with_protected_region_3, + block_erase_chip_with_protected_region_4, + block_erase_chip_with_protected_region_5, +- }, ++ }), + sizeof(g_test_erase_injector) + ); + +-- +2.45.2 + diff --git a/pkgs/by-name/fl/flashrom/package.nix b/pkgs/by-name/fl/flashrom/package.nix index f8cbd4f1354a..75404ada546d 100644 --- a/pkgs/by-name/fl/flashrom/package.nix +++ b/pkgs/by-name/fl/flashrom/package.nix @@ -24,14 +24,17 @@ stdenv.mkDerivation rec { hash = "sha256-rX7htJI5xvtPj1XjZwb81zFDXbGkvS+rPYDx9yUIzO4="; }; - patches = [ - # Release notes for 1.4.0 state that Promontory chipsets are unsupported, and that attempting to read flash on those systems may crash the system. - # The patch that removes this (broken) support only made it into the 1.3.0 release, seemingly by mistake, and the relevant code has been essentially untouched since. - # We cherry-pick the upstream patch from 1.3.0, though amended to reference the relevant bug in the error message, rather than requesting the user email upstream. - # https://ticket.coreboot.org/issues/370 - # https://review.coreboot.org/c/flashrom/+/68824 - ./0001-sb600spi.c-Drop-Promontory-support.patch - ]; + patches = + [ + # Release notes for 1.4.0 state that Promontory chipsets are unsupported, and that attempting to read flash on those systems may crash the system. + # The patch that removes this (broken) support only made it into the 1.3.0 release, seemingly by mistake, and the relevant code has been essentially untouched since. + # We cherry-pick the upstream patch from 1.3.0, though amended to reference the relevant bug in the error message, rather than requesting the user email upstream. + # https://ticket.coreboot.org/issues/370 + # https://review.coreboot.org/c/flashrom/+/68824 + ./0001-sb600spi.c-Drop-Promontory-support.patch + ] + # Darwin's memcpy is a macro, and requires braced initializer lists to be parenthesized + ++ lib.optional stdenv.isDarwin ./0002-tests-erase-parenthesize-braced-initializer.patch; nativeBuildInputs = [ meson From 32ef95f442571ae12c31efc40925ce960f4109bc Mon Sep 17 00:00:00 2001 From: r-vdp Date: Sat, 15 Feb 2025 14:23:27 +0100 Subject: [PATCH 5/6] flashrom: 1.3.0 -> 1.5.1 I cherry-picked the commits from https://github.com/NixOS/nixpkgs/pull/330581 and then added the 1.5.1 update on top. We can drop the darwin patch since the affected code is only present in the tests and those don't work on darwin anyway, so we can better just don't compile them at all on that platform. On Linux we do compile and now also run the tests. --- ...rase-parenthesize-braced-initializer.patch | 50 ------------------- pkgs/by-name/fl/flashrom/package.nix | 37 ++++++++------ 2 files changed, 22 insertions(+), 65 deletions(-) delete mode 100644 pkgs/by-name/fl/flashrom/0002-tests-erase-parenthesize-braced-initializer.patch diff --git a/pkgs/by-name/fl/flashrom/0002-tests-erase-parenthesize-braced-initializer.patch b/pkgs/by-name/fl/flashrom/0002-tests-erase-parenthesize-braced-initializer.patch deleted file mode 100644 index fdad7832431b..000000000000 --- a/pkgs/by-name/fl/flashrom/0002-tests-erase-parenthesize-braced-initializer.patch +++ /dev/null @@ -1,50 +0,0 @@ -From ba84c4aba56420315973026288e7b336006336a9 Mon Sep 17 00:00:00 2001 -From: edef -Date: Tue, 30 Jul 2024 03:14:37 +0000 -Subject: [PATCH] tests/erase: parenthesize braced initializer - -memcpy is a macro on Darwin, and thus requires braced initializer lists -to be parenthesized. ---- - tests/erase_func_algo.c | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/tests/erase_func_algo.c b/tests/erase_func_algo.c -index 576923f8..b13ee70c 100644 ---- a/tests/erase_func_algo.c -+++ b/tests/erase_func_algo.c -@@ -1233,13 +1233,13 @@ static void erase_unwritable_regions_skipflag_on_test_success(void **state) - - // This test needs special block erase to emulate protected regions. - memcpy(g_test_erase_injector, -- (erasefunc_t *const[]){ -+ ((erasefunc_t *const[]){ - block_erase_chip_with_protected_region_1, - block_erase_chip_with_protected_region_2, - block_erase_chip_with_protected_region_3, - block_erase_chip_with_protected_region_4, - block_erase_chip_with_protected_region_5, -- }, -+ }), - sizeof(g_test_erase_injector) - ); - -@@ -1322,13 +1322,13 @@ static void write_unwritable_regions_skipflag_on_test_success(void **state) { - - // This test needs special block erase to emulate protected regions. - memcpy(g_test_erase_injector, -- (erasefunc_t *const[]){ -+ ((erasefunc_t *const[]){ - block_erase_chip_with_protected_region_1, - block_erase_chip_with_protected_region_2, - block_erase_chip_with_protected_region_3, - block_erase_chip_with_protected_region_4, - block_erase_chip_with_protected_region_5, -- }, -+ }), - sizeof(g_test_erase_injector) - ); - --- -2.45.2 - diff --git a/pkgs/by-name/fl/flashrom/package.nix b/pkgs/by-name/fl/flashrom/package.nix index 75404ada546d..100cd76fc6b9 100644 --- a/pkgs/by-name/fl/flashrom/package.nix +++ b/pkgs/by-name/fl/flashrom/package.nix @@ -7,6 +7,7 @@ libftdi1, libjaylink, libusb1, + openssl, meson, ninja, pciutils, @@ -17,24 +18,21 @@ stdenv.mkDerivation rec { pname = "flashrom"; - version = "1.4.0"; + version = "1.5.1"; src = fetchurl { - url = "https://download.flashrom.org/releases/flashrom-${version}.tar.xz"; - hash = "sha256-rX7htJI5xvtPj1XjZwb81zFDXbGkvS+rPYDx9yUIzO4="; + url = "https://download.flashrom.org/releases/flashrom-v${version}.tar.xz"; + hash = "sha256-H5NLB27UnqziA2Vewkn8eGGmuOh/5K73MuR7bkhbYpM="; }; - patches = - [ - # Release notes for 1.4.0 state that Promontory chipsets are unsupported, and that attempting to read flash on those systems may crash the system. - # The patch that removes this (broken) support only made it into the 1.3.0 release, seemingly by mistake, and the relevant code has been essentially untouched since. - # We cherry-pick the upstream patch from 1.3.0, though amended to reference the relevant bug in the error message, rather than requesting the user email upstream. - # https://ticket.coreboot.org/issues/370 - # https://review.coreboot.org/c/flashrom/+/68824 - ./0001-sb600spi.c-Drop-Promontory-support.patch - ] - # Darwin's memcpy is a macro, and requires braced initializer lists to be parenthesized - ++ lib.optional stdenv.isDarwin ./0002-tests-erase-parenthesize-braced-initializer.patch; + patches = [ + # Release notes for 1.4.0 state that Promontory chipsets are unsupported, and that attempting to read flash on those systems may crash the system. + # The patch that removes this (broken) support only made it into the 1.3.0 release, seemingly by mistake, and the relevant code has been essentially untouched since. + # We cherry-pick the upstream patch from 1.3.0, though amended to reference the relevant bug in the error message, rather than requesting the user email upstream. + # https://ticket.coreboot.org/issues/370 + # https://review.coreboot.org/c/flashrom/+/68824 + ./0001-sb600spi.c-Drop-Promontory-support.patch + ]; nativeBuildInputs = [ meson @@ -45,11 +43,12 @@ stdenv.mkDerivation rec { ]; buildInputs = [ + openssl cmocka libftdi1 libusb1 ] - ++ lib.optionals (!stdenv.isDarwin) [ pciutils ] + ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ pciutils ] ++ lib.optional jlinkSupport libjaylink; postPatch = '' @@ -57,6 +56,14 @@ stdenv.mkDerivation rec { --replace 'GROUP="plugdev"' 'TAG+="uaccess", TAG+="udev-acl"' ''; + mesonFlags = [ + (lib.mesonOption "programmer" "auto") + (lib.mesonEnable "man-pages" true) + (lib.mesonEnable "tests" (!stdenv.buildPlatform.isDarwin)) + ]; + + doCheck = !stdenv.hostPlatform.isDarwin; + postInstall = '' install -Dm644 $NIX_BUILD_TOP/$sourceRoot/util/flashrom_udev.rules $out/lib/udev/rules.d/flashrom.rules ''; From 2d4e8c8083c293b63d18d80841d5e973997988c7 Mon Sep 17 00:00:00 2001 From: r-vdp Date: Sat, 15 Feb 2025 14:49:40 +0100 Subject: [PATCH 6/6] flashrom: use finalAttrs --- pkgs/by-name/fl/flashrom/package.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/fl/flashrom/package.nix b/pkgs/by-name/fl/flashrom/package.nix index 100cd76fc6b9..77ea39d34128 100644 --- a/pkgs/by-name/fl/flashrom/package.nix +++ b/pkgs/by-name/fl/flashrom/package.nix @@ -16,12 +16,12 @@ jlinkSupport ? false, }: -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "flashrom"; version = "1.5.1"; src = fetchurl { - url = "https://download.flashrom.org/releases/flashrom-v${version}.tar.xz"; + url = "https://download.flashrom.org/releases/flashrom-v${finalAttrs.version}.tar.xz"; hash = "sha256-H5NLB27UnqziA2Vewkn8eGGmuOh/5K73MuR7bkhbYpM="; }; @@ -80,4 +80,4 @@ stdenv.mkDerivation rec { platforms = platforms.all; mainProgram = "flashrom"; }; -} +})