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

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