summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2011-12-12 21:34:38 +0000
committerMike Frysinger <vapier@gentoo.org>2011-12-12 21:34:38 +0000
commit946454bfa264d6e2b3fc956d936d471f599933ef (patch)
treea8fcfdfef21c0af4c20836d4386cd74b1c23028a /sys-apps/microcode-data
parentUse correct LICENSE. (diff)
downloadgentoo-2-946454bfa264d6e2b3fc956d936d471f599933ef.tar.gz
gentoo-2-946454bfa264d6e2b3fc956d936d471f599933ef.tar.bz2
gentoo-2-946454bfa264d6e2b3fc956d936d471f599933ef.zip
Split up microcode files for the kernel to autoload (using util from Fedora).
(Portage version: 2.2.0_alpha79/cvs/Linux x86_64)
Diffstat (limited to 'sys-apps/microcode-data')
-rw-r--r--sys-apps/microcode-data/ChangeLog8
-rw-r--r--sys-apps/microcode-data/files/intel-microcode2ucode.c163
-rw-r--r--sys-apps/microcode-data/microcode-data-20110915-r1.ebuild42
3 files changed, 212 insertions, 1 deletions
diff --git a/sys-apps/microcode-data/ChangeLog b/sys-apps/microcode-data/ChangeLog
index e55107af1e9a..14186bec96c9 100644
--- a/sys-apps/microcode-data/ChangeLog
+++ b/sys-apps/microcode-data/ChangeLog
@@ -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)
diff --git a/sys-apps/microcode-data/files/intel-microcode2ucode.c b/sys-apps/microcode-data/files/intel-microcode2ucode.c
new file mode 100644
index 000000000000..caad0323e805
--- /dev/null
+++ b/sys-apps/microcode-data/files/intel-microcode2ucode.c
@@ -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
index 000000000000..ddab8d4ac863
--- /dev/null
+++ b/sys-apps/microcode-data/microcode-data-20110915-r1.ebuild
@@ -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"
+}