File microcode-select.diff of Package microcode_ctl
diff -uNrp microcode_ctl-1.11.orig/microcode_ctl.c microcode_ctl-1.11/microcode_ctl.c
--- microcode_ctl-1.11.orig/microcode_ctl.c 2004-10-30 01:25:03.000000000 +0200
+++ microcode_ctl-1.11/microcode_ctl.c 2005-02-21 13:52:31.901882546 +0100
@@ -2,7 +2,7 @@
* microcode_ctl - Manipulate /dev/cpu/microcode under Linux
*
* Copyright 2000 (c) Simon Trimmer, Tigran Aivazian.
- *
+ * Minor changes added by Jesus Molina, 2001
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
@@ -23,7 +23,7 @@ int print_error_messages=1;
#define BUFFER_SIZE 4096
#define MAX_MICROCODE 2000000
-
+#define MICROCODE_SIZE 512
#define MICROCODE_DEVICE_DEFAULT "/dev/cpu/microcode"
#define MICROCODE_FILE_DEFAULT "/etc/microcode.dat"
@@ -32,12 +32,13 @@ static void usage(void)
fprintf(stderr, "\nThis program is for updating the microcode on Intel processors\n"
"belonging to the IA32 family - PentiumPro upwards (x86_64 included).\n"
"It depends on the Linux kernel microcode driver.\n\n"
- "Usage: %s [-h] [-u] [-q] [-Q] [-f microcode]\n\n"
+ "Usage: %s [-h] [-u] [-q] [-Q] [-s microcode number] [-f microcode]\n\n"
" -h this usage message\n"
" -q run silently when successful\n"
" -Q run silently even on failure\n"
" -u upload microcode (default filename:\"%s\"\n"
- " -f upload microcode from named Intel formatted file\n\n",
+ " -f upload microcode from named Intel formatted file\n\n"
+ " -s select a specific microcode \n",
progname, MICROCODE_FILE_DEFAULT);
exit(1);
}
@@ -48,7 +49,7 @@ static void usage(void)
* for the processor.
* b) send the microcode to the driver which applies the update
*/
-static int do_update(char *device, char *filename)
+static int do_update(char *device, char *filename, int number)
{
FILE *fp;
char line_buffer[BUFFER_SIZE];
@@ -56,6 +57,7 @@ static int do_update(char *device, char
int *pos;
int outfd;
int wrote, length;
+ int *micro;
if( (fp=fopen(filename, "r")) == NULL){
@@ -91,6 +93,19 @@ static int do_update(char *device, char
fclose(fp);
length = sizeof(int) * (pos - microcode);
+
+ if (number) {
+ length = 2048;
+ number = number-1;
+ }
+ micro = microcode+512*(number); /* Select a especific microcode */
+
+ if (micro >= pos) {
+ if (print_error_messages)
+ fprintf(stderr, "%s: No such microcode in the file provided: Exiting \n", progname);
+ return 1;
+ }
+
if(print_normal_messages)
fprintf(stderr, "%s: writing microcode (length: %d)\n", progname, length);
@@ -100,8 +115,8 @@ static int do_update(char *device, char
progname, device, errno, strerror(errno));
return errno;
}
-
- if( (wrote = write(outfd, µcode, length)) < 0){
+
+ if ( (wrote = write(outfd, micro, length)) < 0) {
if(print_error_messages)
fprintf(stderr, "%s: error writing to '%s' errno=%d (%s)\n"
"%s: there may be messages from the driver in your system log.\n",
@@ -124,7 +139,7 @@ int main(int argc, char *argv[])
int c;
static char device[2048];
static char filename[2048];
- int upload=0;
+ int upload = 0, number = 0;
int return_code;
progname = argv[0];
@@ -132,7 +147,7 @@ int main(int argc, char *argv[])
strcpy(device, MICROCODE_DEVICE_DEFAULT);
strcpy(filename, MICROCODE_FILE_DEFAULT);
- while (EOF != (c = getopt(argc, argv, "hqQud:f:"))) {
+ while (EOF != (c = getopt(argc, argv, "hqQud:f:s:"))) {
switch(c) {
case 'h':
usage();
@@ -158,6 +173,10 @@ int main(int argc, char *argv[])
upload++;
strcpy(filename, optarg);
break;
+ case 's': /* select an especific microcode and upload */
+ upload++;
+ number = atoi(optarg);
+ break;
case '?':
usage();
@@ -165,7 +184,7 @@ int main(int argc, char *argv[])
}
if (upload) {
- if((return_code = do_update(device, filename)))
+ if ((return_code = do_update(device, filename, number)))
exit(return_code);
} else
usage();