dm: refine the detection of "iasl" utility

At run time (on the *target* machine), acrn-dm depends on "iasl" to build
the ACPI tables for post-launched VMs.

This patch does:
- remove the dependency on ASL_COMPILER, which would only be used at build time
- add a new acrn-dm parameter "--iasl <iasl_compiler_path>"
  If "--iasl <iasl_compiler_path>" is specified as the acrn-dm parameter,
  acrn-dm uses <iasl_compiler_path> as the path to the "iasl" compiler;
  otherwise, "which iasl" is used to detect the "iasl" compiler.

  If "iasl" is not found at run time, refuse to launch the post-launched VM
  and exit directly.

v2 -> v3:
 - use "strlen" rather than "strncmp" to check whether asl_compiler
   has been set or not

v1 -> v2:
 - remove "iasl_param" and "with_iasl_param" to simplify the logic

Tracked-On: #7880

Signed-off-by: Victor Sun <victor.sun@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
Shiqing Gao 2022-07-04 10:40:13 +08:00 committed by acrnsi-robot
parent 7cffac359b
commit cc309bd973
5 changed files with 77 additions and 12 deletions

View File

@ -132,7 +132,7 @@ hvapplydiffconfig:
@$(MAKE) applydiffconfig $(HV_MAKEOPTS) PATCH=$(abspath $(PATCH))
devicemodel: tools
$(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) DM_ASL_COMPILER=$(ASL_COMPILER) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE)
$(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE)
tools:
mkdir -p $(TOOLS_OUT)

View File

@ -45,10 +45,6 @@ CFLAGS += -I$(SYSROOT)/usr/include/SDL2
CFLAGS += -I$(SYSROOT)/usr/include/EGL
CFLAGS += -I$(SYSROOT)/usr/include/GLES2
ifneq (, $(DM_ASL_COMPILER))
CFLAGS += -DASL_COMPILER=\"$(DM_ASL_COMPILER)\"
endif
GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)

View File

@ -146,6 +146,7 @@ usage(int code)
" %*s [-k kernel_image_path]\n"
" %*s [-l lpc] [-m mem] [-r ramdisk_image_path]\n"
" %*s [-s pci] [--ovmf ovmf_file_path]\n"
" %*s [--iasl iasl_compiler_path]\n"
" %*s [--enable_trusty] [--intr_monitor param_setting]\n"
" %*s [--acpidev_pt HID] [--mmiodev_pt MMIO_Regions]\n"
" %*s [--vtpm2 sock_path] [--virtio_poll interval]\n"
@ -162,6 +163,7 @@ usage(int code)
" -s: <slot,driver,configinfo> PCI slot config\n"
" -v: version\n"
" --ovmf: ovmf file path\n"
" --iasl: iasl compiler path\n"
" --ssram: Congfiure Software SRAM parameters\n"
" --cpu_affinity: list of Service VM vCPUs assigned to this User VM, the vCPUs are"
" identified by their local APIC IDs.\n"
@ -185,7 +187,7 @@ usage(int code)
(int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "",
(int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "",
(int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "",
(int)strnlen(progname, PATH_MAX), "");
(int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "");
exit(code);
}
@ -762,6 +764,7 @@ sig_handler_term(int signo)
enum {
CMD_OPT_VSBL = 1000,
CMD_OPT_OVMF,
CMD_OPT_IASL,
CMD_OPT_CPU_AFFINITY,
CMD_OPT_PART_INFO,
CMD_OPT_TRUSTY_ENABLE,
@ -806,6 +809,7 @@ static struct option long_options[] = {
#endif
{"vsbl", required_argument, 0, CMD_OPT_VSBL},
{"ovmf", required_argument, 0, CMD_OPT_OVMF},
{"iasl", required_argument, 0, CMD_OPT_IASL},
{"cpu_affinity", required_argument, 0, CMD_OPT_CPU_AFFINITY},
{"part_info", required_argument, 0, CMD_OPT_PART_INFO},
{"enable_trusty", no_argument, 0,
@ -926,6 +930,10 @@ main(int argc, char *argv[])
errx(EX_USAGE, "invalid ovmf param %s", optarg);
skip_pci_mem64bar_workaround = true;
break;
case CMD_OPT_IASL:
if (acrn_parse_iasl(optarg) != 0)
errx(EX_USAGE, "invalid iasl param %s", optarg);
break;
case CMD_OPT_CPU_AFFINITY:
if (acrn_parse_cpu_affinity(optarg) != 0)
errx(EX_USAGE, "invalid pcpu param %s", optarg);
@ -1020,6 +1028,12 @@ main(int argc, char *argv[])
usage(1);
}
}
if (get_iasl_compiler() != 0) {
pr_err("Cannot find Intel ACPI ASL compiler tool \"iasl\".\n");
exit(1);
}
argc -= optind;
argv += optind;

View File

@ -95,9 +95,8 @@
#define ASL_TEMPLATE "dm.XXXXXXX"
#define ASL_SUFFIX ".aml"
#ifndef ASL_COMPILER
#define ASL_COMPILER "/usr/sbin/iasl"
#endif
static char asl_compiler[MAXPATHLEN] = {0};
uint64_t audio_nhlt_len = 0;
@ -972,7 +971,7 @@ basl_compile(struct vmctx *ctx,
uint64_t offset)
{
struct basl_fio io[2];
static char iaslbuf[3*MAXPATHLEN + 10];
static char iaslbuf[4*MAXPATHLEN + 10];
int err;
err = basl_start(&io[0], &io[1]);
@ -990,12 +989,12 @@ basl_compile(struct vmctx *ctx,
if (basl_verbose_iasl)
snprintf(iaslbuf, sizeof(iaslbuf),
"%s -p %s %s",
ASL_COMPILER,
asl_compiler,
io[1].f_name, io[0].f_name);
else
snprintf(iaslbuf, sizeof(iaslbuf),
"/bin/sh -c \"%s -p %s %s\" 1> /dev/null",
ASL_COMPILER,
asl_compiler,
io[1].f_name, io[0].f_name);
err = system(iaslbuf);
@ -1110,6 +1109,59 @@ get_acpi_table_length(void)
return ACPI_LENGTH;
}
int
get_default_iasl_compiler(void)
{
int ret = -1;
char c;
int i = 0;
FILE *fd_iasl = popen("which iasl", "r");
if (fd_iasl != NULL)
{
while (i < (MAXPATHLEN - 1)) {
c = fgetc(fd_iasl);
if ((c == EOF) || (c == '\n') || (c == '\r') || (c == 0)) {
break;
}
asl_compiler[i++] = c;
}
if (strlen(asl_compiler) > 0) {
pr_info("Found default iasl path: %s\n", asl_compiler);
ret = 0;
}
pclose(fd_iasl);
}
return ret;
}
int
acrn_parse_iasl(char *arg)
{
size_t len = strnlen(arg, MAXPATHLEN);
if (len < MAXPATHLEN) {
strncpy(asl_compiler, arg, len + 1);
pr_info("iasl path is given by --iasl at run time: %s\n", asl_compiler);
return 0;
} else
return -1;
}
int
get_iasl_compiler(void)
{
int ret = 0;
if(strlen(asl_compiler) == 0) {
ret = get_default_iasl_compiler();
}
return ret;
}
int
acpi_build(struct vmctx *ctx, int ncpu)
{

View File

@ -121,4 +121,7 @@ int lapicid_from_pcpuid(int pcpu_id);
int lapic_to_pcpu(int lapic);
int parse_madt(void);
int acrn_parse_iasl(char *arg);
int get_iasl_compiler(void);
#endif /* _ACPI_H_ */