Blame SOURCES/microcode_ctl-revert-intel-microcode2ucode-removal.patch

ccd24f
Revert removal of intel_microcode2ucode [1].
ccd24f
ccd24f
Since it was shipped to end users, its removal may introduce unneeded
ccd24f
disruption.
ccd24f
ccd24f
[1] https://pagure.io/microcode_ctl/c/fde91236cc7b45ecffa5c48a7cd8b30ff75752cf.patch
ccd24f
Index: microcode_ctl-2.1-18/Makefile
ccd24f
===================================================================
ccd24f
--- microcode_ctl-2.1-18.orig/Makefile	2018-07-20 17:52:34.767187807 +0200
ccd24f
+++ microcode_ctl-2.1-18/Makefile	2018-07-20 19:13:37.948699082 +0200
ccd24f
@@ -7,6 +7,7 @@
ccd24f
 # as published by the Free Software Foundation; either version
ccd24f
 # 2 of the License, or (at your option) any later version.
ccd24f
 
ccd24f
+PROGRAM         = intel-microcode2ucode
ccd24f
 MICROCODE_INTEL = microcode-20180703.tgz
ccd24f
 
ccd24f
 INS             = install
ccd24f
@@ -16,23 +17,29 @@
ccd24f
 DESTDIR         =
ccd24f
 PREFIX          = /usr/local
ccd24f
 
ccd24f
+INSDIR          = $(PREFIX)/sbin
ccd24f
 DOCDIR          = $(PREFIX)/share/doc/microcode_ctl
ccd24f
 MICDIR          = /lib/firmware
ccd24f
 MICDIRINTEL     = $(MICDIR)/intel-ucode
ccd24f
 
ccd24f
-all:
ccd24f
+all: microcode_ctl
ccd24f
 	tar -xf $(MICROCODE_INTEL) ./intel-ucode
ccd24f
 
ccd24f
+microcode_ctl: intel-microcode2ucode.c
ccd24f
+	$(CC) $(CFLAGS) -o $(PROGRAM) intel-microcode2ucode.c
ccd24f
+
ccd24f
 clean:
ccd24f
-	rm -rf intel-ucode
ccd24f
+	rm -rf $(PROGRAM) intel-ucode
ccd24f
 
ccd24f
 install:
ccd24f
-	$(INS) -d $(DESTDIR)$(DOCDIR) \
ccd24f
+	$(INS) -d $(DESTDIR)$(INSDIR) $(DESTDIR)$(DOCDIR) \
ccd24f
 		$(DESTDIR)$(MICDIRINTEL)
ccd24f
+	$(INS) -m 755 $(PROGRAM) $(DESTDIR)$(INSDIR)
ccd24f
 	$(INS) -m 644 README $(DESTDIR)$(DOCDIR)
ccd24f
 	$(INS) -m 644 intel-ucode/* $(DESTDIR)$(MICDIRINTEL)
ccd24f
 
ccd24f
 uninstall:
ccd24f
-	rm -rf $(DESTDIR)$(MICDIRINTEL) \
ccd24f
+	rm -rf $(DESTDIR)$(INSDIR)/$(PROGRAM) \
ccd24f
+		$(DESTDIR)$(MICDIRINTEL) \
ccd24f
 		$(DESTDIR)$(DOCDIR)
ccd24f
 
ccd24f
Index: microcode_ctl-2.1-18/intel-microcode2ucode.c
ccd24f
===================================================================
ccd24f
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
ccd24f
+++ microcode_ctl-2.1-18/intel-microcode2ucode.c	2018-07-20 19:02:19.510433818 +0200
ccd24f
@@ -0,0 +1,169 @@
ccd24f
+/*
ccd24f
+ * Convert Intel microcode.dat into individual ucode files
ccd24f
+ * named: intel-ucode/$family-$model-$stepping
ccd24f
+ *
ccd24f
+ * The subdir intel-ucode/ is created in the current working
ccd24f
+ * directory. We get multiple ucodes in the same file, so they
ccd24f
+ * are appended to an existing file. Make sure the directory
ccd24f
+ * is empty before every run of the converter.
ccd24f
+ *
ccd24f
+ * Kay Sievers <kay.sievers@vrfy.org>
ccd24f
+ * Anton Arapov <anton@redhat.com>
ccd24f
+ */
ccd24f
+
ccd24f
+
ccd24f
+#ifndef _GNU_SOURCE
ccd24f
+# define _GNU_SOURCE 1
ccd24f
+#endif
ccd24f
+
ccd24f
+#include <stdio.h>
ccd24f
+#include <unistd.h>
ccd24f
+#include <stdlib.h>
ccd24f
+#include <string.h>
ccd24f
+#include <time.h>
ccd24f
+#include <limits.h>
ccd24f
+#include <stdbool.h>
ccd24f
+#include <inttypes.h>
ccd24f
+#include <fcntl.h>
ccd24f
+#include <errno.h>
ccd24f
+#include <sys/stat.h>
ccd24f
+
ccd24f
+struct microcode_header_intel {
ccd24f
+	unsigned int hdrver;
ccd24f
+	unsigned int rev;
ccd24f
+	unsigned int date;
ccd24f
+	unsigned int sig;
ccd24f
+	unsigned int cksum;
ccd24f
+	unsigned int ldrver;
ccd24f
+	unsigned int pf;
ccd24f
+	unsigned int datasize;
ccd24f
+	unsigned int totalsize;
ccd24f
+	unsigned int reserved[3];
ccd24f
+};
ccd24f
+
ccd24f
+union mcbuf {
ccd24f
+	struct microcode_header_intel hdr;
ccd24f
+	unsigned int i[0];
ccd24f
+	char c[0];
ccd24f
+};
ccd24f
+
ccd24f
+int main(int argc, char *argv[])
ccd24f
+{
ccd24f
+	char *filename = "/lib/firmware/microcode.dat";
ccd24f
+	FILE *input, *f;
ccd24f
+	char line[LINE_MAX];
ccd24f
+	char buf[4000000];
ccd24f
+	union mcbuf *mc;
ccd24f
+	size_t bufsize, count, start;
ccd24f
+	int rc = EXIT_SUCCESS;
ccd24f
+
ccd24f
+	if (argv[1] != NULL)
ccd24f
+		filename = argv[1];
ccd24f
+
ccd24f
+	if (!strcmp(filename, "-")) {
ccd24f
+		input = stdin;
ccd24f
+	} else {
ccd24f
+		input = fopen(filename, "re");
ccd24f
+		if (input == NULL) {
ccd24f
+			printf("open %s: %m\n", filename);
ccd24f
+			rc = EXIT_FAILURE;
ccd24f
+			goto out;
ccd24f
+		}
ccd24f
+	}
ccd24f
+
ccd24f
+	count = 0;
ccd24f
+	mc = (union mcbuf *) buf;
ccd24f
+	while (fgets(line, sizeof(line), input) != NULL) {
ccd24f
+		if (sscanf(line, "%x, %x, %x, %x",
ccd24f
+		    &mc->i[count],
ccd24f
+		    &mc->i[count + 1],
ccd24f
+		    &mc->i[count + 2],
ccd24f
+		    &mc->i[count + 3]) != 4)
ccd24f
+			continue;
ccd24f
+		count += 4;
ccd24f
+	}
ccd24f
+	fclose(input);
ccd24f
+
ccd24f
+	bufsize = count * sizeof(int);
ccd24f
+	printf("%s: %lu(%luk) bytes, %zu integers\n",
ccd24f
+	       filename,
ccd24f
+	       bufsize,
ccd24f
+	       bufsize / 1024,
ccd24f
+	       count);
ccd24f
+
ccd24f
+	if (bufsize < sizeof(struct microcode_header_intel))
ccd24f
+		goto out;
ccd24f
+
ccd24f
+	mkdir("intel-ucode", 0750);
ccd24f
+
ccd24f
+	start = 0;
ccd24f
+	for (;;) {
ccd24f
+		size_t size;
ccd24f
+		unsigned int family, model, stepping;
ccd24f
+		unsigned int year, month, day;
ccd24f
+
ccd24f
+		mc = (union mcbuf *) &buf[start];
ccd24f
+
ccd24f
+		if (mc->hdr.totalsize)
ccd24f
+			size = mc->hdr.totalsize;
ccd24f
+		else
ccd24f
+			size = 2000 + sizeof(struct microcode_header_intel);
ccd24f
+
ccd24f
+		if (mc->hdr.ldrver != 1 || mc->hdr.hdrver != 1) {
ccd24f
+			printf("unknown version/format:\n");
ccd24f
+			rc = EXIT_FAILURE;
ccd24f
+			break;
ccd24f
+		}
ccd24f
+
ccd24f
+		/*
ccd24f
+		 *  0- 3 stepping
ccd24f
+		 *  4- 7 model
ccd24f
+		 *  8-11 family
ccd24f
+		 * 12-13 type
ccd24f
+		 * 16-19 extended model
ccd24f
+		 * 20-27 extended family
ccd24f
+		 */
ccd24f
+		family = (mc->hdr.sig >> 8) & 0xf;
ccd24f
+		if (family == 0xf)
ccd24f
+			family += (mc->hdr.sig >> 20) & 0xff;
ccd24f
+		model = (mc->hdr.sig >> 4) & 0x0f;
ccd24f
+		if (family == 0x06)
ccd24f
+			model += ((mc->hdr.sig >> 16) & 0x0f) << 4;
ccd24f
+		stepping = mc->hdr.sig & 0x0f;
ccd24f
+
ccd24f
+		year = mc->hdr.date & 0xffff;
ccd24f
+		month = mc->hdr.date >> 24;
ccd24f
+		day = (mc->hdr.date >> 16) & 0xff;
ccd24f
+
ccd24f
+		asprintf(&filename, "intel-ucode/%02x-%02x-%02x", family, model, stepping);
ccd24f
+		printf("\n");
ccd24f
+		printf("%s\n", filename);
ccd24f
+		printf("signature: 0x%02x\n", mc->hdr.sig);
ccd24f
+		printf("flags:     0x%02x\n", mc->hdr.pf);
ccd24f
+		printf("revision:  0x%02x\n", mc->hdr.rev);
ccd24f
+		printf("date:      %04x-%02x-%02x\n", year, month, day);
ccd24f
+		printf("size:      %zu\n", size);
ccd24f
+
ccd24f
+		f = fopen(filename, "ae");
ccd24f
+		if (f == NULL) {
ccd24f
+			printf("open %s: %m\n", filename);
ccd24f
+			rc = EXIT_FAILURE;
ccd24f
+			goto out;
ccd24f
+		}
ccd24f
+		if (fwrite(mc, size, 1, f) != 1) {
ccd24f
+			printf("write %s: %m\n", filename);
ccd24f
+			rc = EXIT_FAILURE;
ccd24f
+			goto out;
ccd24f
+		}
ccd24f
+		fclose(f);
ccd24f
+		free(filename);
ccd24f
+
ccd24f
+		start += size;
ccd24f
+		if (start >= bufsize)
ccd24f
+			break;
ccd24f
+	}
ccd24f
+	printf("\n");
ccd24f
+
ccd24f
+ out:
ccd24f
+	return rc;
ccd24f
+}