mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
Right now, Xen returns -ENOENT for both "the provided blob isn't correct for
this CPU", and "the blob isn't newer than what's loaded".
This in turn causes xen-ucode to exit with an error, when "nothing to do" is
more commonly a success condition.
Handle EEXIST specially and exit cleanly.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
master commit: 648db37a15
master date: 2024-05-09 18:19:49 +0100
85 lines
1.8 KiB
C
85 lines
1.8 KiB
C
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/mman.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <inttypes.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <xenctrl.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int fd, ret;
|
|
char *filename, *buf;
|
|
size_t len;
|
|
struct stat st;
|
|
xc_interface *xch;
|
|
|
|
if ( argc < 2 )
|
|
{
|
|
fprintf(stderr,
|
|
"xen-ucode: Xen microcode updating tool\n"
|
|
"Usage: %s <microcode blob>\n", argv[0]);
|
|
exit(2);
|
|
}
|
|
|
|
filename = argv[1];
|
|
fd = open(filename, O_RDONLY);
|
|
if ( fd < 0 )
|
|
{
|
|
fprintf(stderr, "Could not open %s. (err: %s)\n",
|
|
filename, strerror(errno));
|
|
exit(1);
|
|
}
|
|
|
|
if ( fstat(fd, &st) != 0 )
|
|
{
|
|
fprintf(stderr, "Could not get the size of %s. (err: %s)\n",
|
|
filename, strerror(errno));
|
|
exit(1);
|
|
}
|
|
|
|
len = st.st_size;
|
|
buf = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
if ( buf == MAP_FAILED )
|
|
{
|
|
fprintf(stderr, "mmap failed. (error: %s)\n", strerror(errno));
|
|
exit(1);
|
|
}
|
|
|
|
xch = xc_interface_open(NULL, NULL, 0);
|
|
if ( xch == NULL )
|
|
{
|
|
fprintf(stderr, "Error opening xc interface. (err: %s)\n",
|
|
strerror(errno));
|
|
exit(1);
|
|
}
|
|
|
|
errno = 0;
|
|
ret = xc_microcode_update(xch, buf, len);
|
|
if ( ret == -1 && errno == EEXIST )
|
|
printf("Microcode already up to date\n");
|
|
else if ( ret )
|
|
{
|
|
fprintf(stderr, "Failed to update microcode. (err: %s)\n",
|
|
strerror(errno));
|
|
exit(1);
|
|
}
|
|
|
|
xc_interface_close(xch);
|
|
|
|
if ( munmap(buf, len) )
|
|
{
|
|
printf("Could not unmap: %d(%s)\n", errno, strerror(errno));
|
|
exit(1);
|
|
}
|
|
close(fd);
|
|
|
|
return 0;
|
|
}
|