From fda7df678ddc0f8c99eb25649c40014fc316b45d Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Thu, 16 Aug 2018 14:10:21 +0800 Subject: [PATCH 1/2] uicode-tool: init at 2.3.1 --- .../linux/microcode/iucode-tool.nix | 25 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 pkgs/os-specific/linux/microcode/iucode-tool.nix diff --git a/pkgs/os-specific/linux/microcode/iucode-tool.nix b/pkgs/os-specific/linux/microcode/iucode-tool.nix new file mode 100644 index 000000000000..485272b1401b --- /dev/null +++ b/pkgs/os-specific/linux/microcode/iucode-tool.nix @@ -0,0 +1,25 @@ +{ stdenv, fetchFromGitLab, autoreconfHook }: + +stdenv.mkDerivation rec { + name = "iucode-tool-${version}"; + version = "2.3.1"; + + src = fetchFromGitLab { + owner = "iucode-tool"; + repo = "iucode-tool"; + rev = "v${version}"; + sha256 = "04dlisw87dd3q3hhmkqc5dd58cp22fzx3rzah7pvcyij135yjc3a"; + }; + + nativeBuildInputs = [ autoreconfHook ]; + + enableParallelBuilding = true; + + meta = with stdenv.lib; { + description = "Intel® 64 and IA-32 processor microcode tool"; + homepage = https://gitlab.com/iucode-tool/iucode-tool; + license = licenses.gpl2; + maintainers = with maintainers; [ peterhoeg ]; + platforms = [ "x86_64-linux" "i686-linux" ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ae8b67081225..a3cbf5208a42 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13474,6 +13474,8 @@ with pkgs; microcodeIntel = callPackage ../os-specific/linux/microcode/intel.nix { }; + iucode-tool = callPackage ../os-specific/linux/microcode/iucode-tool.nix { }; + inherit (callPackages ../os-specific/linux/apparmor { python = python3; }) libapparmor apparmor-utils apparmor-bin-utils apparmor-parser apparmor-pam apparmor-profiles apparmor-kernel-patches; From ff246c464dac740597423f972ff96b61b4e826fc Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Thu, 16 Aug 2018 14:11:50 +0800 Subject: [PATCH 2/2] microcodeIntel: 20180312 -> 20180807 --- .../linux/microcode/intel-microcode2ucode.c | 154 ------------------ pkgs/os-specific/linux/microcode/intel.nix | 21 ++- 2 files changed, 10 insertions(+), 165 deletions(-) delete mode 100644 pkgs/os-specific/linux/microcode/intel-microcode2ucode.c diff --git a/pkgs/os-specific/linux/microcode/intel-microcode2ucode.c b/pkgs/os-specific/linux/microcode/intel-microcode2ucode.c deleted file mode 100644 index c1660fae38a1..000000000000 --- a/pkgs/os-specific/linux/microcode/intel-microcode2ucode.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Convert Intel microcode.dat into a single binary microcode.bin file - * - * Based on code by Kay Sievers - * Changed to create a single file by Thomas Bächler - */ - - -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct microcode_header_intel { - unsigned int hdrver; - unsigned int rev; - unsigned int date; - unsigned int sig; - unsigned int cksum; - unsigned int ldrver; - unsigned int pf; - unsigned int datasize; - unsigned int totalsize; - unsigned int reserved[3]; -}; - -union mcbuf { - struct microcode_header_intel hdr; - unsigned int i[0]; - char c[0]; -}; - -int main(int argc, char *argv[]) -{ - const char *filename = "/lib/firmware/microcode.dat"; - FILE *f; - char line[LINE_MAX]; - char buf[4000000]; - union mcbuf *mc; - size_t bufsize, count, start; - int rc = EXIT_SUCCESS; - - if (argv[1] != NULL) - filename = argv[1]; - - count = 0; - mc = (union mcbuf *) buf; - f = fopen(filename, "re"); - if (f == NULL) { - printf("open %s: %m\n", filename); - rc = EXIT_FAILURE; - goto out; - } - - while (fgets(line, sizeof(line), f) != NULL) { - if (sscanf(line, "%x, %x, %x, %x", - &mc->i[count], - &mc->i[count + 1], - &mc->i[count + 2], - &mc->i[count + 3]) != 4) - continue; - count += 4; - } - fclose(f); - - bufsize = count * sizeof(int); - printf("%s: %lu(%luk) bytes, %zu integers\n", - filename, - bufsize, - bufsize / 1024, - count); - - if (bufsize < sizeof(struct microcode_header_intel)) - goto out; - - f = fopen("microcode.bin", "we"); - if (f == NULL) { - printf("open microcode.bin: %m\n"); - rc = EXIT_FAILURE; - goto out; - } - - start = 0; - for (;;) { - size_t size; - unsigned int family, model, stepping; - unsigned int year, month, day; - - mc = (union mcbuf *) &buf[start]; - - if (mc->hdr.totalsize) - size = mc->hdr.totalsize; - else - size = 2000 + sizeof(struct microcode_header_intel); - - if (mc->hdr.ldrver != 1 || mc->hdr.hdrver != 1) { - printf("unknown version/format:\n"); - rc = EXIT_FAILURE; - break; - } - - /* - * 0- 3 stepping - * 4- 7 model - * 8-11 family - * 12-13 type - * 16-19 extended model - * 20-27 extended family - */ - family = (mc->hdr.sig >> 8) & 0xf; - if (family == 0xf) - family += (mc->hdr.sig >> 20) & 0xff; - model = (mc->hdr.sig >> 4) & 0x0f; - if (family == 0x06) - model += ((mc->hdr.sig >> 16) & 0x0f) << 4; - stepping = mc->hdr.sig & 0x0f; - - year = mc->hdr.date & 0xffff; - month = mc->hdr.date >> 24; - day = (mc->hdr.date >> 16) & 0xff; - - printf("\n"); - printf("signature: 0x%02x\n", mc->hdr.sig); - printf("flags: 0x%02x\n", mc->hdr.pf); - printf("revision: 0x%02x\n", mc->hdr.rev); - printf("date: %04x-%02x-%02x\n", year, month, day); - printf("size: %zu\n", size); - - if (fwrite(mc, size, 1, f) != 1) { - printf("write microcode.bin: %m\n"); - rc = EXIT_FAILURE; - goto out; - } - - start += size; - if (start >= bufsize) - break; - } - fclose(f); - printf("\n"); -out: - return rc; -} diff --git a/pkgs/os-specific/linux/microcode/intel.nix b/pkgs/os-specific/linux/microcode/intel.nix index 857a3b580a8e..403824fb3a45 100644 --- a/pkgs/os-specific/linux/microcode/intel.nix +++ b/pkgs/os-specific/linux/microcode/intel.nix @@ -1,27 +1,26 @@ -{ stdenv, fetchurl, libarchive }: +{ stdenv, fetchurl, libarchive, iucode-tool }: stdenv.mkDerivation rec { name = "microcode-intel-${version}"; - version = "20180312"; + version = "20180807"; src = fetchurl { - url = "https://downloadmirror.intel.com/27591/eng/microcode-${version}.tgz"; - sha256 = "0yg7q5blcqgq8jyjxhn9n48rxws77ylqzyn4kn10l6yzwan1yf0b"; + url = "https://downloadmirror.intel.com/28039/eng/microcode-${version}.tgz"; + sha256 = "0h4ygwx5brnrjz8v47aikrwhf0q3jhizxmzcii4bdjg64zffiy99"; }; - buildInputs = [ libarchive ]; + nativeBuildInputs = [ iucode-tool libarchive ]; sourceRoot = "."; - buildPhase = '' - gcc -O2 -Wall -o intel-microcode2ucode ${./intel-microcode2ucode.c} - ./intel-microcode2ucode microcode.dat - ''; - installPhase = '' + runHook preInstall + mkdir -p $out kernel/x86/microcode - mv microcode.bin kernel/x86/microcode/GenuineIntel.bin + iucode_tool -w kernel/x86/microcode/GenuineIntel.bin intel-ucode/ echo kernel/x86/microcode/GenuineIntel.bin | bsdcpio -o -H newc -R 0:0 > $out/intel-ucode.img + + runHook postInstall ''; meta = with stdenv.lib; {