diff options
Diffstat (limited to 'non-free/intel-ucode/intel-microcode2ucode.c')
-rw-r--r-- | non-free/intel-ucode/intel-microcode2ucode.c | 47 |
1 files changed, 20 insertions, 27 deletions
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 <kay.sievers@vrfy.org> + * Based on code by Kay Sievers <kay.sievers@vrfy.org> + * Changed to create a single file by Thomas Bächler <thomas@archlinux.org> */ @@ -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; |