From 7a1e9f38f2e4c2b4d5a7e36eb08c39c530d2aaf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arkadiusz=20Mi=C5=9Bkiewicz?= Date: Fri, 25 May 2018 09:13:04 +0200 Subject: [PATCH] - up to 20180425 --- intel-microcode2ucode-single.c | 156 ------------------------------- intel-microcode2ucode.c | 163 --------------------------------- microcode-data-intel.spec | 21 ++--- 3 files changed, 6 insertions(+), 334 deletions(-) delete mode 100644 intel-microcode2ucode-single.c delete mode 100644 intel-microcode2ucode.c diff --git a/intel-microcode2ucode-single.c b/intel-microcode2ucode-single.c deleted file mode 100644 index fe410ac..0000000 --- a/intel-microcode2ucode-single.c +++ /dev/null @@ -1,156 +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, type; - 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 - */ - stepping = mc->hdr.sig & 0x0f; - model = (mc->hdr.sig >> 4) & 0x0f; - family = (mc->hdr.sig >> 8) & 0x0f; - type = (mc->hdr.sig >> 12) & 0x0f; - if (family == 0x06) - model += ((mc->hdr.sig >> 16) & 0x0f) << 4; - if (family == 0x0f) - family += (mc->hdr.sig >> 20) & 0xff; - - year = mc->hdr.date & 0xffff; - month = mc->hdr.date >> 24; - day = (mc->hdr.date >> 16) & 0xff; - - printf("\n"); - printf("signature: 0x%02x (stepping %d, model %d, family %d, type %d)\n", - mc->hdr.sig, stepping, model, family, type); - 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/intel-microcode2ucode.c b/intel-microcode2ucode.c deleted file mode 100644 index caad032..0000000 --- a/intel-microcode2ucode.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Convert Intel microcode.dat into individual ucode files - * named: intel-ucode/$family-$model-$stepping - * - * The subdir intel-ucode/ is created in the current working - * directory. We get multiple ucodes in the same file, so they - * are appended to an existing file. Make sure the directory - * is empty before every run of the converter. - * - * Kay Sievers - */ - - -#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[]) -{ - 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; - - mkdir("intel-ucode", 0750); - - 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; - - asprintf(&filename, "intel-ucode/%02x-%02x-%02x", family, model, stepping); - printf("\n"); - printf("%s\n", filename); - 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); - - f = fopen(filename, "ae"); - if (f == NULL) { - printf("open %s: %m\n", filename); - rc = EXIT_FAILURE; - goto out; - } - if (fwrite(mc, size, 1, f) != 1) { - printf("write %s: %m\n", filename); - rc = EXIT_FAILURE; - goto out; - } - fclose(f); - free(filename); - - start += size; - if (start >= bufsize) - break; - } - printf("\n"); -out: - return rc; -} diff --git a/microcode-data-intel.spec b/microcode-data-intel.spec index bd755dd..cebce57 100644 --- a/microcode-data-intel.spec +++ b/microcode-data-intel.spec @@ -1,18 +1,15 @@ Summary: Microcode definitions for Intel processors Summary(pl.UTF-8): Definicje mikrokodu dla procesorów Intela Name: microcode-data-intel -Version: 20180312 +Version: 20180425 Release: 1 License: INTEL SOFTWARE LICENSE AGREEMENT Group: Base # http://downloadcenter.intel.com/, enter "processor microcode data file" to the search Source0: https://downloadmirror.intel.com/27591/eng/microcode-%{version}.tgz -# Source0-md5: be315cd99a7ca392a2f917ceacbe14f2 -# Tool for splitting Intel's microcode file. From Fedora -Source1: intel-microcode2ucode.c -# Produces single file for use by boot loader (like grub) -Source2: intel-microcode2ucode-single.c +# Source0-md5: 99c80f9229554953a868127cda44e7e3 Provides: microcode-data +BuildRequires: iucode-tool BuildArch: noarch BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n) @@ -39,16 +36,8 @@ Mikrokod dla procesorów Intel dla initrd. %setup -qc %build -if ! grep -q 0x00000000 microcode.dat; then - echo >&2 "microcode.dat contains giberrish" - exit 1 -fi -%{__cc} %{rpmcflags} %{rpmcppflags} %{rpmldflags} -Wall -o intel-microcode2ucode %{SOURCE1} -%{__cc} %{rpmcflags} %{rpmcppflags} %{rpmldflags} -Wall -o intel-microcode2ucode-single %{SOURCE2} - -./intel-microcode2ucode microcode.dat -./intel-microcode2ucode-single microcode.dat +%{_sbindir}/iucode_tool intel-ucode*/*-* --write-to=microcode.bin install -d kernel/x86/microcode ln microcode.bin kernel/x86/microcode/GenuineIntel.bin @@ -66,8 +55,10 @@ rm -rf $RPM_BUILD_ROOT %files %defattr(644,root,root,755) +%doc releasenote /lib/firmware/intel-ucode %files initrd +%doc releasenote %defattr(644,root,root,755) /boot/intel-ucode.img -- 2.44.0