[packages/microcode-data-intel] - rel 2; produce single file that can be used by grub

arekm arekm at pld-linux.org
Mon Sep 4 09:14:45 CEST 2017


commit ca91a51dba2b1d6abb2a81b073d7d54210e81c9d
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Mon Sep 4 09:14:37 2017 +0200

    - rel 2; produce single file that can be used by grub

 intel-microcode2ucode-single.c | 156 +++++++++++++++++++++++++++++++++++++++++
 microcode-data-intel.spec      |  32 ++++++++-
 2 files changed, 185 insertions(+), 3 deletions(-)
---
diff --git a/microcode-data-intel.spec b/microcode-data-intel.spec
index c665dab..cec10eb 100644
--- a/microcode-data-intel.spec
+++ b/microcode-data-intel.spec
@@ -4,7 +4,7 @@ Summary:	Microcode definitions for Intel processors
 Summary(pl.UTF-8):	Definicje mikrokodu dla procesorów Intela
 Name:		microcode-data-intel
 Version:	20170707
-Release:	1
+Release:	2
 License:	INTEL SOFTWARE LICENSE AGREEMENT
 Group:		Base
 # http://downloadcenter.intel.com/, enter "processor microcode data file" to the search
@@ -12,6 +12,9 @@ Source0:	http://downloadmirror.intel.com/26925/eng/microcode-%{version}.tgz
 # Source0-md5:	fe4bcb12e4600629a81fb65208c34248
 # 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
+BuildRequires:	cpio
 Provides:	microcode-data
 ExclusiveArch:	i686 pentium2 pentium3 pentium4 %{x8664} x32
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
@@ -24,6 +27,17 @@ definitions for all Intel processors.
 Te pliki danych mikrokodu dla Linuksa zawierają najnowsze definicje
 mikrokodu dla procesorów Intela.
 
+%package initrd
+Summary:	Microcode for initrd
+Summary(pl.UTF-8):	Mikrokod dla initrd
+Group:		Base
+
+%description initrd
+Intel microcode for initrd.
+
+%description initrd -l pl.UTF-8
+Mikrokod dla procesorów Intel dla initrd.
+
 %prep
 %setup -q -c
 
@@ -34,15 +48,22 @@ if ! grep -q 0x00000000 microcode.dat; then
 fi
 
 %{__cc} %{rpmcflags} %{rpmcppflags} %{rpmldflags} -Wall -o intel-microcode2ucode %{SOURCE1}
+%{__cc} %{rpmcflags} %{rpmcppflags} %{rpmldflags} -Wall -o intel-microcode2ucode-single %{SOURCE2}
 ./intel-microcode2ucode microcode.dat > /dev/null || exit 1
+./intel-microcode2ucode-single microcode.dat > /dev/null || exit 1
 
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT{%{_sbindir},/lib/firmware}
+install -d $RPM_BUILD_ROOT{%{_sbindir},/lib/firmware,/boot}
 
-install intel-microcode2ucode $RPM_BUILD_ROOT%{_sbindir}
+cp -p intel-microcode2ucode $RPM_BUILD_ROOT%{_sbindir}
 mv intel-ucode $RPM_BUILD_ROOT/lib/firmware
 
+cp -p intel-microcode2ucode-single $RPM_BUILD_ROOT%{_sbindir}
+install -d kernel/x86/microcode
+mv microcode.bin kernel/x86/microcode/GenuineIntel.bin
+echo kernel/x86/microcode/GenuineIntel.bin | cpio -o -H newc -R 0:0 > $RPM_BUILD_ROOT/boot/intel-ucode.img
+
 %clean
 rm -rf $RPM_BUILD_ROOT
 
@@ -50,3 +71,8 @@ rm -rf $RPM_BUILD_ROOT
 %defattr(644,root,root,755)
 %attr(755,root,root) %{_sbindir}/intel-microcode2ucode
 /lib/firmware/intel-ucode
+
+%files initrd
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_sbindir}/intel-microcode2ucode-single
+/boot/intel-ucode.img
diff --git a/intel-microcode2ucode-single.c b/intel-microcode2ucode-single.c
new file mode 100644
index 0000000..fe410ac
--- /dev/null
+++ b/intel-microcode2ucode-single.c
@@ -0,0 +1,156 @@
+/*
+ * Convert Intel microcode.dat into a single binary microcode.bin file
+ *
+ * Based on code by Kay Sievers <kay.sievers at vrfy.org>
+ * Changed to create a single file by Thomas Bächler <thomas at archlinux.org>
+ */
+
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+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;
+}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/microcode-data-intel.git/commitdiff/ca91a51dba2b1d6abb2a81b073d7d54210e81c9d



More information about the pld-cvs-commit mailing list