pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/sysutils/intel-microcode-netbsd/files If ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3f17b270e684
branches:  trunk
changeset: 307457:3f17b270e684
user:      msaitoh <msaitoh%pkgsrc.org@localhost>
date:      Mon May 07 04:27:43 2018 +0000
description:
If the microcode.dat file is not bundled in the archive file, extract from
binary files. I verified the output from both microcode-20180312.tgz's
microcode.dat and intel-ucode/??-??-?? are the same.

 This change is required for microcode-20180425.tgz.

diffstat:

 sysutils/intel-microcode-netbsd/files/extract.c |  152 +++++++++++++++++++++---
 1 files changed, 133 insertions(+), 19 deletions(-)

diffs (204 lines):

diff -r 992e09b6ecf6 -r 3f17b270e684 sysutils/intel-microcode-netbsd/files/extract.c
--- a/sysutils/intel-microcode-netbsd/files/extract.c   Sun May 06 22:21:45 2018 +0000
+++ b/sysutils/intel-microcode-netbsd/files/extract.c   Mon May 07 04:27:43 2018 +0000
@@ -1,5 +1,6 @@
-/* $NetBSD: extract.c,v 1.3 2014/02/19 19:31:08 drochner Exp $ */
+/* $NetBSD: extract.c,v 1.4 2018/05/07 04:27:43 msaitoh Exp $ */
 
+#include <sys/stat.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -81,12 +82,15 @@
        char name[18], alias[11];
        int fd, used, i, j;
        struct intel1_ucode_proc_signature *eps;
+       int rv;
 
        sprintf(name, "%08x.%08x", uh->uh_signature, uh->uh_rev);
        fd = open(name, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644);
        if (fd < 0)
                err(2, "open %s", name);
-       write(fd, uh, len);
+       rv = write(fd, uh, len);
+       if (rv == -1)
+               err(EXIT_FAILURE, "failed to write %s\n", name);
        close(fd);
 
        used = 0;
@@ -97,7 +101,7 @@
                used += link_unless_newer_exists(name, alias, uh->uh_rev);
        }
        if (eh) {
-               /* extension headers are unused in rev. 20140122 */
+               printf("%s: Check the extended header.\n", __func__);
                for (j = 0; j < eh->uet_count; j++) {
                        eps = &eh->uet_proc_sig[j];
                        for (i = 0; i < 8; i++) {
@@ -115,34 +119,40 @@
        printf("%s: %d links\n", name, used);
 }
 
+void
+update_size(struct intel1_ucode_header *uh,
+    uint32_t *datasize, uint32_t *totalsize)
+{
+               if (uh->uh_data_size)
+                       *datasize = uh->uh_data_size;
+               else
+                       *datasize = 2000;
+               if (uh->uh_total_size)
+                       *totalsize = uh->uh_total_size;
+               else
+                       *totalsize = *datasize + 48;
+}
+
+/* Extract .dat (or .inc) file. Usually for microcode.dat. */
 int
-main(int argc, char **argv)
+extract_dat(const char *fname)
 {
        struct intel1_ucode_header uh;
-       int datasize, totalsize;
+       uint32_t datasize, totalsize;
        void *theupdate;
        struct intel1_ucode_ext_table *eh;
 
-       if (argc < 2)
-               errx(1, "need filename");
-
-       in = fopen(argv[1], "r");
+       in = fopen(fname, "r");
        if (!in)
-               err(2, "could not open \"%s\"", argv[1]);
+               err(2, "could not open \"%s\"", fname);
 
        for (;;) {
                if (getbin(&uh, sizeof(uh)) < 0)
                        break;
                if (uh.uh_header_ver != 1)
                        errx(3, "wrong file format, last line %d", lc);
-               if (uh.uh_data_size)
-                       datasize = uh.uh_data_size;
-               else
-                       datasize = 2000;
-               if (uh.uh_total_size)
-                       totalsize = uh.uh_total_size;
-               else
-                       totalsize = datasize + 48;
+
+               update_size(&uh, &datasize, &totalsize);
 
                theupdate = malloc(totalsize);
                memcpy(theupdate, &uh, 48);
@@ -160,5 +170,109 @@
        }
 
        fclose(in);
-       exit(0);
+
+       return 0;
 }
+
+/* Extract binary files (UV-WX-YZ style filename) */
+int
+extract_bin(int argc, char **argv)
+{
+       struct intel1_ucode_header *uh;
+       uint32_t datasize, totalsize;
+       void *theupdate, *buf;
+       struct intel1_ucode_ext_table *eh;
+       struct stat sb;
+       size_t left;
+       int i, rv;
+
+       argv++; /* Skip argc[0] (command name). */
+       
+       for (i = 1; i < argc; i++, argv++) {
+               rv = stat(*argv, &sb);
+               if (rv != 0)
+                       err(EXIT_FAILURE, "failed to stat \"%s\"", *argv);
+
+               theupdate = buf = malloc(sb.st_size);
+               if (theupdate == NULL)
+                       err(EXIT_FAILURE,
+                           "failed to alloc buf for \"%s\" (size = %zu)",
+                           *argv, sb.st_size);
+
+               in = fopen(*argv, "r");
+               if (!in)
+                       err(EXIT_FAILURE, "could not open \"%s\"", *argv);
+
+               rv = fread(theupdate, sizeof(char), sb.st_size, in);
+               if (rv != sb.st_size)
+                       err(EXIT_FAILURE,
+                           "failed to read \"%s\" (size = %zu)",
+                           *argv, sb.st_size);
+               left = sb.st_size;
+next:
+               uh = (struct intel1_ucode_header *)theupdate;
+
+#if 0 /* Dump header */
+               for (int j = 0; j < sizeof(struct intel1_ucode_header) / 4;
+                    j++) {
+                       uint32_t *q = (uint32_t *)uh;
+
+                       if ((j % 4) == 0)
+                               printf("%08x:", j);
+                       printf(" %08x", q[j]);
+                       if ((j % 4) == 3)
+                               printf("\n");
+               }
+               printf("\n");
+#endif
+
+               if (uh->uh_header_ver != 1)
+                       errx(EXIT_FAILURE,
+                           "wrong file format, last line %d", lc);
+
+               update_size(uh, &datasize, &totalsize);
+
+               if (totalsize != datasize + 48)
+                       eh = (void *)((char *)theupdate + 48 + datasize);
+               else
+                       eh = NULL;
+
+               writeout(theupdate, totalsize, eh);
+
+               if ((eh == NULL) && (totalsize != left)) {
+                       printf("file = %s. size in headers (%u) != file size "
+                           "left (%zu). This file has multiple entries "
+                           "without the extended signature stucture.\n",
+                           *argv, totalsize, left);
+                       theupdate += totalsize;
+                       left -= totalsize;
+                       goto next;
+               }
+
+               free(buf);
+               fclose(in);
+       }
+
+       return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+       const char *p;
+       int rv;
+
+       if (argc < 2)
+               errx(1, "need filename");
+
+       p = strchr(argv[1], '.');
+       if ((p != NULL) && (strcmp(p + 1, "dat") == 0)) {
+               /* Extract microcode.dat file */
+               rv = extract_dat(argv[1]);
+       } else {
+               /* Extract UV-WX-YZ files */
+               rv = extract_bin(argc, argv);
+       }
+
+       return rv;
+}



Home | Main Index | Thread Index | Old Index