Subject: [alpine-aports] [PATCH] non-free/intel-ucode: Update to 20170511

From: Marian Buschsieweke <[email-masked]>
Date: Mon, 26 Jun 2017 15:13:27 +0200

In the context of the recent Skylake/Kaby Lake hyper-threading bug [1], an
update of the intel microcode seems to be quite relevant. The resulting
package will contain "/boot/intel-ucode.img", which needs to be added as
first initial ram drive. This is achieved in extlinux by chaining the line

  INITRD=linux-$tag

to

  INITRD=intel-ucode.img,linux-$tag

See [2] for more details. If this packet is accepted, changing
/sbin/update-extlinux to check for "/boot/init-ucode.img" and adding it
as first INITRD on detection seems to be a good idea.

All credit goes to Thomas Bächler [3], from whom I shamelessly stole the build
recipe.

[1] https://lists.debian.org/debian-devel/2017/06/msg00308.html
[2] https://wiki.archlinux.org/index.php/Microcode#Syslinux
[3] https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/intel-ucode
---
 non-free/intel-ucode/APKBUILD                | 30 +++++++++---------
 non-free/intel-ucode/intel-microcode2ucode.c | 47 ++++++++++++----------------
 2 files changed, 35 insertions(+), 42 deletions(-)

diff --git a/non-free/intel-ucode/APKBUILD b/non-free/intel-ucode/APKBUILD
index 82ec5d1204..5652fa6590 100644
--- a/non-free/intel-ucode/APKBUILD
+++ b/non-free/intel-ucode/APKBUILD
@@ -1,34 +1,34 @@
+# Maintainer: Marian Buschsieweke <[email-masked]>
 pkgname=intel-ucode
-pkgver=20130222
+pkgver=20170511
 pkgrel=0
 pkgdesc="Microcode update files for Intel CPUs"
 arch=noarch
 url="http://downloadcenter.intel.com/SearchResult.aspx?lang=eng&keyword=%22microcode%22"
 license='custom'
-source="http://downloadmirror.intel.com/22508/eng/microcode-${pkgver}.tgz
+source="http://downloadmirror.intel.com/26798/eng/microcode-${pkgver}.tgz
         LICENSE
         intel-microcode2ucode.c"
+options="!check"
 
 build() {
   cd "$srcdir"
-  gcc -Wall ${CFLAGS} -o intel-microcode2ucode \
-    intel-microcode2ucode.c || return 1
-  ./intel-microcode2ucode ./microcode.dat || return 1
+  gcc -Wall ${CFLAGS} -o intel-microcode2ucode intel-microcode2ucode.c
+  ./intel-microcode2ucode ./microcode.dat
 }
 
 package() {
   cd "$srcdir"
-  install -d -m755 "${pkgdir}"/usr/lib/firmware/intel-ucode/ || return 1
-  cp intel-ucode/* "${pkgdir}"/usr/lib/firmware/intel-ucode/ || return 1
+  
+  install -d -m755 "${pkgdir}"/boot
+
+  mkdir -p kernel/x86/microcode
+  mv microcode.bin kernel/x86/microcode/GenuineIntel.bin
+  echo kernel/x86/microcode/GenuineIntel.bin | cpio -o -H newc -R 0:0 > "${pkgdir}"/boot/intel-ucode.img
+  
   install -D -m644 LICENSE \
     "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE || return 1
 }
-md5sums="e2dd0f73dc9882aa26aaade76139aee1  microcode-20130222.tgz
-b0f489ae4b3e36dc8827dc53a76047aa  LICENSE
-0efc5f6c74a4d7e61ca22683c93c98cf  intel-microcode2ucode.c"
-sha256sums="fd25bd9777fc3c3b11f01e9090a2d24f7650023c9ec74bbf9f43bffe1d9d01cc  microcode-20130222.tgz
-6983e83ec10c6467fb9101ea496e0443f0574c805907155118e2c9f0bbea97b6  LICENSE
-c51b1b1d8b4b28e7d5d007917c1e444af1a2ff04a9408aa9067c0e57d70164de  intel-microcode2ucode.c"
-sha512sums="7ba41a8e0f79beeb046750e30b6a9a181ed53a524f80db78cb9fe3e09bb9fdce664bf5a99882aa139d12e3a98aa5ecae316c950003bab3c69d890a5f223308f0  microcode-20130222.tgz
+sha512sums="4e2066096d56430c2df73631f15cf16f2317c1d8ff745d7b7cdd784ebccc2b797565eb52703cce9b4238774dbfdcaecacd892d729b7869fdfd7644008ce74a60  microcode-20170511.tgz
 d80ce9087e2ffd0168600a34de195d6514d3a496bc233294cd838498e1ce668b9ad4463bbbe7958feec0421b5aed3ade1633432ce086241e03ed06bbd53b83a5  LICENSE
-0e29f995dee47707026cfb6224580c2166d000e91af7b1afe12f00158be8606093d07cdbc0d583a0af79370cf1d9c16b5f35a306bae7f545a5c774ea253509b7  intel-microcode2ucode.c"
+ee60f968acab4067f5660449eabae533b5d3996cd59fd4b69d0e23e0b264da216ab6e6ccd554222cf355fc14dbd348562a2d36a87a60f1f54433603e04998cd1  intel-microcode2ucode.c"
diff --git a/non-free/intel-ucode/intel-microcode2ucode.c b/non-free/intel-ucode/intel-microcode2ucode.c
index caad0323e8..fe410ac86e 100644
--- a/non-free/intel-ucode/intel-microcode2ucode.c
+++ b/non-free/intel-ucode/intel-microcode2ucode.c
@@ -1,13 +1,8 @@
 /*
- * Convert Intel microcode.dat into individual ucode files
- * named: intel-ucode/$family-$model-$stepping
+ * Convert Intel microcode.dat into a single binary microcode.bin file
  *
- * 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 <[email-masked]>
+ * Based on code by Kay Sievers <[email-masked]>
+ * Changed to create a single file by Thomas Bächler <[email-masked]>
  */

@@ -48,7 +43,7 @@ union mcbuf {
 
 int main(int argc, char *argv[])
 {
-	char *filename = "/lib/firmware/microcode.dat";
+	const char *filename = "/lib/firmware/microcode.dat";
 	FILE *f;
 	char line[LINE_MAX];
 	char buf[4000000];
@@ -89,12 +84,17 @@ int main(int argc, char *argv[])
 	if (bufsize < sizeof(struct microcode_header_intel))
 		goto out;
 
-	mkdir("intel-ucode", 0750);
+	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;
+		unsigned int family, model, stepping, type;
 		unsigned int year, month, day;
 
 		mc = (union mcbuf *) &buf[start];
@@ -118,45 +118,38 @@ int main(int argc, char *argv[])
 		 * 16-19 extended model
 		 * 20-27 extended family
 		 */
-		family = (mc->hdr.sig >> 8) & 0xf;
-		if (family == 0xf)
-			family += (mc->hdr.sig >> 20) & 0xff;
+		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;
-		stepping = mc->hdr.sig & 0x0f;
+		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;
 
-		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("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);
 
-		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);
+			printf("write microcode.bin: %m\n");
 			rc = EXIT_FAILURE;
 			goto out;
 		}
-		fclose(f);
-		free(filename);
 
 		start += size;
 		if (start >= bufsize)
 			break;
 	}
+	fclose(f);
 	printf("\n");
 out:
 	return rc;
-- 
2.13.1

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---