Split up microcode files for the kernel to autoload (using util from Fedora).
authorMike Frysinger <vapier@gentoo.org>
Mon, 12 Dec 2011 21:34:38 +0000 (21:34 +0000)
committerMike Frysinger <vapier@gentoo.org>
Mon, 12 Dec 2011 21:34:38 +0000 (21:34 +0000)
Package-Manager: portage-2.2.0_alpha79/cvs/Linux x86_64

sys-apps/microcode-data/ChangeLog
sys-apps/microcode-data/Manifest
sys-apps/microcode-data/files/intel-microcode2ucode.c [new file with mode: 0644]
sys-apps/microcode-data/microcode-data-20110915-r1.ebuild [new file with mode: 0644]

index e55107af1e9ab0fba1d44ebd4777ff51447b0770..14186bec96c9153237ed34d17c4fd95b25028155 100644 (file)
@@ -1,6 +1,12 @@
 # ChangeLog for sys-apps/microcode-data
 # Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/sys-apps/microcode-data/ChangeLog,v 1.15 2011/09/22 20:26:48 flameeyes Exp $
+# $Header: /var/cvsroot/gentoo-x86/sys-apps/microcode-data/ChangeLog,v 1.16 2011/12/12 21:34:38 vapier Exp $
+
+*microcode-data-20110915-r1 (12 Dec 2011)
+
+  12 Dec 2011; Mike Frysinger <vapier@gentoo.org>
+  +files/intel-microcode2ucode.c, +microcode-data-20110915-r1.ebuild:
+  Split up microcode files for the kernel to autoload (using util from Fedora).
 
 *microcode-data-20110915 (22 Sep 2011)
 
index 25591638ff75d34191673a15d1ab01a5d69a7bf8..fa5ee20e1c7936afb8e3484fabc3c757e4331e1a 100644 (file)
@@ -1,6 +1,7 @@
 -----BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
+Hash: SHA256
 
+AUX intel-microcode2ucode.c 3484 RMD160 775416e811c24847c8c553aad18b9e6bbc34edb3 SHA1 97fa0cdb05c9eeecace080821e5f73947d6cf7c2 SHA256 c51b1b1d8b4b28e7d5d007917c1e444af1a2ff04a9408aa9067c0e57d70164de
 DIST microcode-20100209.tgz 563138 RMD160 432a02247fd92ebdfef26a6567a81792ec45fd00 SHA1 10efd9ad6cf94de8fdb7da6136a699f3e271d9a8 SHA256 48f249ff6789406eaff298a3de5843e72b59a016c46c6065a2b1a4a41e025393
 DIST microcode-20101123.tgz 509090 RMD160 af570f5ae0e290dff56a04c607feb7fc2fdb0d31 SHA1 d089db615464fa39cfa4d4ef23f63aa8e950c5c1 SHA256 d6fdce48483e38af4891206c5ebeb12f8881c1d5eb57214b1d8bab219e9f84f9
 DIST microcode-20110428.tgz 512731 RMD160 40a080ccc3503b4f5db1418d99643c6247d13c15 SHA1 169cf15e92461d2ee616071e14a844a4d70cd63c SHA256 90b8a28a122afcfbcc53404f13037cb10701ea4b834419b1883acbefc1c79c29
@@ -8,13 +9,14 @@ DIST microcode-20110915.tgz 555123 RMD160 03edb878cb8fde21b55a520a2b4273f6fa6005
 EBUILD microcode-data-20100209.ebuild 853 RMD160 28985ace7c10b438ee194388550dd993fafe67a5 SHA1 b18322c8914f699ec6b633b16cb8f260a553f089 SHA256 2a003a5505fd19d449f97c8e43cf8033d1047a5acd4bd16edaae09ef17f2cdc6
 EBUILD microcode-data-20101123.ebuild 852 RMD160 fce4001d6e6f49a9a20f42dd962cbb7d2222f6ef SHA1 cc6a167b1fa316e1905694fc7600390ca2e60b4a SHA256 eb7b5056825fa6fcc7114b460b06460e96b9c7127b55bac7962a2e9619acce3b
 EBUILD microcode-data-20110428.ebuild 834 RMD160 b317f87d071e0248b0282547f71d3c841bb3e9dc SHA1 7da23ea3a10320034680aa7c3fa7a13ccbd89b2d SHA256 63b3805292c1db5f8612accb004d5e0a26ca3ee7da6ec4a8e00f64e99ac4c050
+EBUILD microcode-data-20110915-r1.ebuild 1062 RMD160 1c0e4683ea21522861e4e7e2c8a1dc4cc522a28f SHA1 0783e56f99a033c1e674f1ef91a5397c28e46156 SHA256 0c7d618c13cf1f4e7700fc7dd70fbf4031f68e0089dadeb13ad76d71d71a54ec
 EBUILD microcode-data-20110915.ebuild 832 RMD160 7544936d93d413eb6346eba3c42baaf9ecc3163f SHA1 6715c9eb0c0f1cccfb478d61ae79b7407f00dd19 SHA256 e85e9a17bad3c8fdd88d6631fc4b6bad0ffb875a7aab0a73bd35f2f954f09d47
-MISC ChangeLog 2890 RMD160 571346b1628a72b4ae1564ce9fcf66a81f5211db SHA1 d1c636f49d50ff3753c7516f2c04e56a5150a1a3 SHA256 cf0d51a9a225fdbdcb05c3890256125827237bf6049a794f28a94c94edcd91be
+MISC ChangeLog 3131 RMD160 55d347b3beb57dbb6490e2aa0a04ec903ebc0f92 SHA1 db0988e643371f0c4205e2f75f8a8ab400dc67cb SHA256 4fdf54d8d9f16d86063dfa3a99f6311c4bdd26dbeb9e2f78e368f8c20e0ad459
 MISC metadata.xml 164 RMD160 f43cbec30b7074319087c9acffdb9354b17b0db3 SHA1 9c213f5803676c56439df3716be07d6692588856 SHA256 f5f2891f2a4791cd31350bb2bb572131ad7235cd0eeb124c9912c187ac10ce92
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.18 (GNU/Linux)
 
-iEYEARECAAYFAk57mgsACgkQAiZjviIA2XjhkACeNK2nn4mJdnn3OGaoqob4LKA0
-JBQAn2Bh/JgkHmvNYEAvg8lOO8gEqABd
-=UNYu
+iF4EAREIAAYFAk7mc3cACgkQaC/OocHi7JaLwgD7Bpq0V3GJXEn/pe78TDsMBNrS
++YTD8c1nMS18eq7qAdQBAIuSm7WPxtmAmH1h4Xal0VQkJ2vwa0zkpswoAPtaArRg
+=h2uo
 -----END PGP SIGNATURE-----
diff --git a/sys-apps/microcode-data/files/intel-microcode2ucode.c b/sys-apps/microcode-data/files/intel-microcode2ucode.c
new file mode 100644 (file)
index 0000000..caad032
--- /dev/null
@@ -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@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;
+}
diff --git a/sys-apps/microcode-data/microcode-data-20110915-r1.ebuild b/sys-apps/microcode-data/microcode-data-20110915-r1.ebuild
new file mode 100644 (file)
index 0000000..ddab8d4
--- /dev/null
@@ -0,0 +1,42 @@
+# Copyright 1999-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/sys-apps/microcode-data/microcode-data-20110915-r1.ebuild,v 1.1 2011/12/12 21:34:38 vapier Exp $
+
+EAPI=4
+
+inherit toolchain-funcs
+
+NUM="20429"
+DESCRIPTION="Intel IA32 microcode update data"
+HOMEPAGE="http://urbanmyth.org/microcode/"
+SRC_URI="http://downloadmirror.intel.com/${NUM}/eng/microcode-${PV}.tgz"
+
+LICENSE="intel-ucode"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE=""
+
+RDEPEND="!<sys-apps/microcode-ctl-1.17-r2" #268586
+
+S=${WORKDIR}
+
+src_unpack() {
+       unpack ${A}
+       cp "${FILESDIR}"/intel-microcode2ucode.c ./ || die
+}
+
+src_compile() {
+       tc-env_build emake intel-microcode2ucode
+       ./intel-microcode2ucode microcode.dat || die
+}
+
+src_install() {
+       insinto /lib/firmware
+       doins -r microcode.dat intel-ucode
+}
+
+pkg_postinst() {
+       elog "The microcode available for Intel CPUs has been updated.  You'll need"
+       elog "to reload the code into your processor.  If you're using the init.d:"
+       elog "/etc/init.d/microcode_ctl restart"
+}