packages: microcode-data-intel/microcode-data-intel.spec, microcode-data-in...

arekm arekm at pld-linux.org
Sun May 27 09:24:42 CEST 2012


Author: arekm                        Date: Sun May 27 07:24:42 2012 GMT
Module: packages                      Tag: HEAD
---- Log message:
- rel 2; use ucode format which is directly accessed by kernel module (no need for microcode_ctl)

---- Files affected:
packages/microcode-data-intel:
   microcode-data-intel.spec (1.10 -> 1.11) , intel-microcode2ucode.c (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: packages/microcode-data-intel/microcode-data-intel.spec
diff -u packages/microcode-data-intel/microcode-data-intel.spec:1.10 packages/microcode-data-intel/microcode-data-intel.spec:1.11
--- packages/microcode-data-intel/microcode-data-intel.spec:1.10	Sun May 27 09:11:19 2012
+++ packages/microcode-data-intel/microcode-data-intel.spec	Sun May 27 09:24:36 2012
@@ -2,19 +2,18 @@
 Summary:	Microcode definitions for Intel processors
 Name:		microcode-data-intel
 Version:	20111110
-Release:	1
+Release:	2
 License:	INTEL SOFTWARE LICENSE AGREEMENT
 Group:		Base
 # http://downloadcenter.intel.com/, enter "processor microcode data file" to the search
 Source0:	http://downloadmirror.intel.com/20728/eng/microcode-%{version}.tgz
 # Source0-md5:	ba288eb9490986513e59c5a035c93a65
+# Tool for splitting Intel's microcode file. From Fedora
+Source1:	intel-microcode2ucode.c
 Provides:	microcode-data
 ExclusiveArch:	i686 pentium2 pentium3 pentium4 %{x8664}
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
-# nothing to put there
-%define		_enable_debug_packages	0
-
 %description
 The microcode data file for Linux contains the latest microcode
 definitions for all Intel processors.
@@ -28,17 +27,23 @@
 	exit 1
 fi
 
+%{__cc} %{rpmcflags} %{rpmcppflags} %{rpmldflags} -Wall -o intel-microcode2ucode %{SOURCE1}
+./intel-microcode2ucode microcode.dat > /dev/null || exit 1
+
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT/lib/firmware
-cp -a microcode.dat $RPM_BUILD_ROOT/lib/firmware/microcode.dat
+install -d $RPM_BUILD_ROOT{%{_sbindir},/lib/firmware}
+
+install intel-microcode2ucode $RPM_BUILD_ROOT%{_sbindir}
+mv intel-ucode $RPM_BUILD_ROOT/lib/firmware
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
 %files
 %defattr(644,root,root,755)
-%attr(640,root,root) /lib/firmware/microcode.dat
+%attr(755,root,root) %{_sbindir}/intel-microcode2ucode
+/lib/firmware/intel-ucode
 
 %define date	%(echo `LC_ALL="C" date +"%a %b %d %Y"`)
 %changelog
@@ -46,6 +51,9 @@
 All persons listed below can be reached at <cvs_login>@pld-linux.org
 
 $Log$
+Revision 1.11  2012/05/27 07:24:36  arekm
+- rel 2; use ucode format which is directly accessed by kernel module (no need for microcode_ctl)
+
 Revision 1.10  2012/05/27 07:11:19  arekm
 - easier search
 

================================================================
Index: packages/microcode-data-intel/intel-microcode2ucode.c
diff -u /dev/null packages/microcode-data-intel/intel-microcode2ucode.c:1.1
--- /dev/null	Sun May 27 09:24:42 2012
+++ packages/microcode-data-intel/intel-microcode2ucode.c	Sun May 27 09:24:36 2012
@@ -0,0 +1,163 @@
+/*
+ * 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 <kay.sievers at vrfy.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[])
+{
+	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;
+}
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/packages/microcode-data-intel/microcode-data-intel.spec?r1=1.10&r2=1.11



More information about the pld-cvs-commit mailing list