added non-committed changes for intel ucode

This commit is contained in:
Fabian Kosmale 2015-09-08 12:08:13 +00:00
parent 00bdf9711a
commit a685a60585

View File

@ -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,7 +84,12 @@ 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 (;;) {
@ -130,33 +130,24 @@ int main(int argc, char *argv[])
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("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;