Files
xen/tools/misc/xen-ucode.c
T
Chao Gao 05f13382aa tools/xen-ucode: Upload a microcode blob to the hypervisor
This patch provides a tool for late microcode update.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Chao Gao <chao.gao@intel.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
[Use consistent style.  Add to gitignore.]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
2019-08-01 18:45:13 +01:00

79 lines
1.7 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]);
return 0;
}
filename = argv[1];
fd = open(filename, O_RDONLY);
if ( fd < 0 )
{
fprintf(stderr, "Could not open %s. (err: %s)\n",
filename, strerror(errno));
return errno;
}
if ( fstat(fd, &st) != 0 )
{
fprintf(stderr, "Could not get the size of %s. (err: %s)\n",
filename, strerror(errno));
return errno;
}
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));
return errno;
}
xch = xc_interface_open(NULL, NULL, 0);
if ( xch == NULL )
{
fprintf(stderr, "Error opening xc interface. (err: %s)\n",
strerror(errno));
return errno;
}
ret = xc_microcode_update(xch, buf, len);
if ( ret )
fprintf(stderr, "Failed to update microcode. (err: %s)\n",
strerror(errno));
xc_interface_close(xch);
if ( munmap(buf, len) )
{
printf("Could not unmap: %d(%s)\n", errno, strerror(errno));
return errno;
}
close(fd);
return 0;
}