Commit 6a8d7fbf authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'acpi-5.17-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Pull more ACPI updates from Rafael Wysocki:
 "The most significant item here is the Platform Firmware Runtime Update
  and Telemetry (PFRUT) support designed to allow certain pieces of the
  platform firmware to be updated on the fly, among other things.

  Also important is the e820 handling change on x86 that should work
  around PCI BAR allocation issues on some systems shipping since 2019.

  The rest is just a handful of assorted fixes and cleanups on top of
  the ACPI material merged previously.

  Specifics:

   - Add support for the the Platform Firmware Runtime Update and
     Telemetry (PFRUT) interface based on ACPI to allow certain pieces
     of the platform firmware to be updated without restarting the
     system and to provide a mechanism for collecting platform firmware
     telemetry data (Chen Yu, Dan Carpenter, Yang Yingliang).

   - Ignore E820 reservations covering PCI host bridge windows on
     sufficiently recent x86 systems to avoid issues with allocating PCI
     BARs on systems where the E820 reservations cover the entire PCI
     host bridge memory window returned by the _CRS object in the
     system's ACPI tables (Hans de Goede).

   - Fix and clean up acpi_scan_init() (Rafael Wysocki).

   - Add more sanity checking to ACPI SPCR tables parsing (Mark
     Langsdorf).

   - Fix up ACPI APD (AMD Soc) driver initialization (Jiasheng Jiang).

   - Drop unnecessary "static" from the ACPI PCC address space handling
     driver added recently (kernel test robot)"

* tag 'acpi-5.17-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm:
  ACPI: PCC: pcc_ctx can be static
  ACPI: scan: Rename label in acpi_scan_init()
  ACPI: scan: Simplify initialization of power and sleep buttons
  ACPI: scan: Change acpi_scan_init() return value type to void
  ACPI: SPCR: check if table->serial_port.access_width is too wide
  ACPI: APD: Check for NULL pointer after calling devm_ioremap()
  x86/PCI: Ignore E820 reservations for bridge windows on newer systems
  ACPI: pfr_telemetry: Fix info leak in pfrt_log_ioctl()
  ACPI: pfr_update: Fix return value check in pfru_write()
  ACPI: tools: Introduce utility for firmware updates/telemetry
  ACPI: Introduce Platform Firmware Runtime Telemetry driver
  ACPI: Introduce Platform Firmware Runtime Update device driver
  efi: Introduce EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER and corresponding structures
parents e3a8b6a1 e3daa260
......@@ -367,6 +367,7 @@ Code Seq# Include File Comments
<mailto:aherrman@de.ibm.com>
0xE5 00-3F linux/fuse.h
0xEC 00-01 drivers/platform/chrome/cros_ec_dev.h ChromeOS EC driver
0xEE 00-09 uapi/linux/pfrut.h Platform Firmware Runtime Update and Telemetry
0xF3 00-3F drivers/usb/misc/sisusbvga/sisusb.h sisfb (in development)
<mailto:thomas@winischhofer.net>
0xF6 all LTTng Linux Trace Toolkit Next Generation
......
// SPDX-License-Identifier: GPL-2.0
#include <linux/dmi.h>
#include <linux/ioport.h>
#include <asm/e820/api.h>
......@@ -23,11 +24,31 @@ static void resource_clip(struct resource *res, resource_size_t start,
res->start = end + 1;
}
/*
* Some BIOS-es contain a bug where they add addresses which map to
* system RAM in the PCI host bridge window returned by the ACPI _CRS
* method, see commit 4dc2287c1805 ("x86: avoid E820 regions when
* allocating address space"). To avoid this Linux by default excludes
* E820 reservations when allocating addresses since 2010.
* In 2019 some systems have shown-up with E820 reservations which cover
* the entire _CRS returned PCI host bridge window, causing all attempts
* to assign memory to PCI BARs to fail if Linux uses E820 reservations.
*
* Ideally Linux would fully stop using E820 reservations, but then
* the old systems this was added for will regress.
* Instead keep the old behavior for old systems, while ignoring the
* E820 reservations for any systems from now on.
*/
static void remove_e820_regions(struct resource *avail)
{
int i;
int i, year = dmi_get_bios_year();
struct e820_entry *entry;
if (year >= 2018)
return;
pr_info_once("PCI: Removing E820 reservations from host bridge windows\n");
for (i = 0; i < e820_table->nr_entries; i++) {
entry = &e820_table->entries[i];
......
......@@ -520,6 +520,28 @@ config ACPI_CONFIGFS
userspace. The configurable ACPI groups will be visible under
/config/acpi, assuming configfs is mounted under /config.
config ACPI_PFRUT
tristate "ACPI Platform Firmware Runtime Update and Telemetry"
depends on 64BIT
help
This mechanism allows certain pieces of the platform firmware
to be updated on the fly while the system is running (runtime)
without the need to restart it, which is key in the cases when
the system needs to be available 100% of the time and it cannot
afford the downtime related to restarting it, or when the work
carried out by the system is particularly important, so it cannot
be interrupted, and it is not practical to wait until it is complete.
The existing firmware code can be modified (driver update) or
extended by adding new code to the firmware (code injection).
Besides, the telemetry driver allows user space to fetch telemetry
data from the firmware with the help of the Platform Firmware Runtime
Telemetry interface.
To compile the drivers as modules, choose M here:
the modules will be called pfr_update and pfr_telemetry.
if ARM64
source "drivers/acpi/arm64/Kconfig"
......
......@@ -103,6 +103,7 @@ obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o
obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o
obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o
obj-$(CONFIG_ACPI_PPTT) += pptt.o
obj-$(CONFIG_ACPI_PFRUT) += pfr_update.o pfr_telemetry.o
# processor has its own "processor." module_param namespace
processor-y := processor_driver.o
......
......@@ -102,6 +102,8 @@ static int fch_misc_setup(struct apd_private_data *pdata)
resource_size(rentry->res));
break;
}
if (!clk_data->base)
return -ENOMEM;
acpi_dev_free_resource_list(&resource_list);
......
......@@ -31,7 +31,7 @@ struct pcc_data {
struct acpi_pcc_info ctx;
};
struct acpi_pcc_info pcc_ctx;
static struct acpi_pcc_info pcc_ctx;
static void pcc_rx_callback(struct mbox_client *cl, void *m)
{
......
......@@ -14,7 +14,7 @@
int early_acpi_osi_init(void);
int acpi_osi_init(void);
acpi_status acpi_os_initialize1(void);
int acpi_scan_init(void);
void acpi_scan_init(void);
#ifdef CONFIG_PCI
void acpi_pci_root_init(void);
void acpi_pci_link_init(void);
......
This diff is collapsed.
This diff is collapsed.
......@@ -2502,42 +2502,33 @@ int acpi_bus_register_early_device(int type)
}
EXPORT_SYMBOL_GPL(acpi_bus_register_early_device);
static int acpi_bus_scan_fixed(void)
static void acpi_bus_scan_fixed(void)
{
int result = 0;
/*
* Enumerate all fixed-feature devices.
*/
if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) {
struct acpi_device *device = NULL;
result = acpi_add_single_object(&device, NULL,
ACPI_BUS_TYPE_POWER_BUTTON, false);
if (result)
return result;
device->flags.match_driver = true;
result = device_attach(&device->dev);
if (result < 0)
return result;
device_init_wakeup(&device->dev, true);
struct acpi_device *adev = NULL;
acpi_add_single_object(&adev, NULL, ACPI_BUS_TYPE_POWER_BUTTON,
false);
if (adev) {
adev->flags.match_driver = true;
if (device_attach(&adev->dev) >= 0)
device_init_wakeup(&adev->dev, true);
else
dev_dbg(&adev->dev, "No driver\n");
}
}
if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) {
struct acpi_device *device = NULL;
result = acpi_add_single_object(&device, NULL,
ACPI_BUS_TYPE_SLEEP_BUTTON, false);
if (result)
return result;
device->flags.match_driver = true;
result = device_attach(&device->dev);
struct acpi_device *adev = NULL;
acpi_add_single_object(&adev, NULL, ACPI_BUS_TYPE_SLEEP_BUTTON,
false);
if (adev) {
adev->flags.match_driver = true;
if (device_attach(&adev->dev) < 0)
dev_dbg(&adev->dev, "No driver\n");
}
}
return result < 0 ? result : 0;
}
static void __init acpi_get_spcr_uart_addr(void)
......@@ -2558,9 +2549,8 @@ static void __init acpi_get_spcr_uart_addr(void)
static bool acpi_scan_initialized;
int __init acpi_scan_init(void)
void __init acpi_scan_init(void)
{
int result;
acpi_status status;
struct acpi_table_stao *stao_ptr;
......@@ -2610,33 +2600,23 @@ int __init acpi_scan_init(void)
/*
* Enumerate devices in the ACPI namespace.
*/
result = acpi_bus_scan(ACPI_ROOT_OBJECT);
if (result)
goto out;
if (acpi_bus_scan(ACPI_ROOT_OBJECT))
goto unlock;
acpi_root = acpi_fetch_acpi_dev(ACPI_ROOT_OBJECT);
if (!acpi_root)
goto out;
goto unlock;
/* Fixed feature devices do not exist on HW-reduced platform */
if (!acpi_gbl_reduced_hardware) {
result = acpi_bus_scan_fixed();
if (result) {
acpi_detach_data(acpi_root->handle,
acpi_scan_drop_device);
acpi_device_del(acpi_root);
acpi_bus_put_acpi_device(acpi_root);
goto out;
}
}
if (!acpi_gbl_reduced_hardware)
acpi_bus_scan_fixed();
acpi_turn_off_unused_power_resources();
acpi_scan_initialized = true;
out:
unlock:
mutex_unlock(&acpi_scan_lock);
return result;
}
static struct acpi_probe_entry *ape;
......
......@@ -107,8 +107,13 @@ int __init acpi_parse_spcr(bool enable_earlycon, bool enable_console)
pr_info("SPCR table version %d\n", table->header.revision);
if (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
switch (ACPI_ACCESS_BIT_WIDTH((
table->serial_port.access_width))) {
u32 bit_width = table->serial_port.access_width;
if (bit_width > ACPI_ACCESS_BIT_MAX) {
pr_err("Unacceptable wide SPCR Access Width. Defaulting to byte size\n");
bit_width = ACPI_ACCESS_BIT_DEFAULT;
}
switch (ACPI_ACCESS_BIT_WIDTH((bit_width))) {
default:
pr_err("Unexpected SPCR Access Width. Defaulting to byte size\n");
fallthrough;
......
......@@ -148,6 +148,52 @@ typedef struct {
u32 imagesize;
} efi_capsule_header_t;
/* EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER */
struct efi_manage_capsule_header {
u32 ver;
u16 emb_drv_cnt;
u16 payload_cnt;
/*
* Variable-size array of the size given by the sum of
* emb_drv_cnt and payload_cnt.
*/
u64 offset_list[];
} __packed;
/* EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER */
struct efi_manage_capsule_image_header {
u32 ver;
efi_guid_t image_type_id;
u8 image_index;
u8 reserved_bytes[3];
u32 image_size;
u32 vendor_code_size;
/* hw_ins was introduced in version 2 */
u64 hw_ins;
/* capsule_support was introduced in version 3 */
u64 capsule_support;
} __packed;
/* WIN_CERTIFICATE */
struct win_cert {
u32 len;
u16 rev;
u16 cert_type;
};
/* WIN_CERTIFICATE_UEFI_GUID */
struct win_cert_uefi_guid {
struct win_cert hdr;
efi_guid_t cert_type;
u8 cert_data[];
};
/* EFI_FIRMWARE_IMAGE_AUTHENTICATION */
struct efi_image_auth {
u64 mon_count;
struct win_cert_uefi_guid auth_info;
};
/*
* EFI capsule flags
*/
......
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* Platform Firmware Runtime Update header
*
* Copyright(c) 2021 Intel Corporation. All rights reserved.
*/
#ifndef __PFRUT_H__
#define __PFRUT_H__
#include <linux/ioctl.h>
#include <linux/types.h>
#define PFRUT_IOCTL_MAGIC 0xEE
/**
* PFRU_IOC_SET_REV - _IOW(PFRUT_IOCTL_MAGIC, 0x01, unsigned int)
*
* Return:
* * 0 - success
* * -EFAULT - fail to read the revision id
* * -EINVAL - user provides an invalid revision id
*
* Set the Revision ID for Platform Firmware Runtime Update.
*/
#define PFRU_IOC_SET_REV _IOW(PFRUT_IOCTL_MAGIC, 0x01, unsigned int)
/**
* PFRU_IOC_STAGE - _IOW(PFRUT_IOCTL_MAGIC, 0x02, unsigned int)
*
* Return:
* * 0 - success
* * -EINVAL - stage phase returns invalid result
*
* Stage a capsule image from communication buffer and perform authentication.
*/
#define PFRU_IOC_STAGE _IOW(PFRUT_IOCTL_MAGIC, 0x02, unsigned int)
/**
* PFRU_IOC_ACTIVATE - _IOW(PFRUT_IOCTL_MAGIC, 0x03, unsigned int)
*
* Return:
* * 0 - success
* * -EINVAL - activate phase returns invalid result
*
* Activate a previously staged capsule image.
*/
#define PFRU_IOC_ACTIVATE _IOW(PFRUT_IOCTL_MAGIC, 0x03, unsigned int)
/**
* PFRU_IOC_STAGE_ACTIVATE - _IOW(PFRUT_IOCTL_MAGIC, 0x04, unsigned int)
*
* Return:
* * 0 - success
* * -EINVAL - stage/activate phase returns invalid result.
*
* Perform both stage and activation action.
*/
#define PFRU_IOC_STAGE_ACTIVATE _IOW(PFRUT_IOCTL_MAGIC, 0x04, unsigned int)
/**
* PFRU_IOC_QUERY_CAP - _IOR(PFRUT_IOCTL_MAGIC, 0x05,
* struct pfru_update_cap_info)
*
* Return:
* * 0 - success
* * -EINVAL - query phase returns invalid result
* * -EFAULT - the result fails to be copied to userspace
*
* Retrieve information on the Platform Firmware Runtime Update capability.
* The information is a struct pfru_update_cap_info.
*/
#define PFRU_IOC_QUERY_CAP _IOR(PFRUT_IOCTL_MAGIC, 0x05, struct pfru_update_cap_info)
/**
* struct pfru_payload_hdr - Capsule file payload header.
*
* @sig: Signature of this capsule file.
* @hdr_version: Revision of this header structure.
* @hdr_size: Size of this header, including the OemHeader bytes.
* @hw_ver: The supported firmware version.
* @rt_ver: Version of the code injection image.
* @platform_id: A platform specific GUID to specify the platform what
* this capsule image support.
*/
struct pfru_payload_hdr {
__u32 sig;
__u32 hdr_version;
__u32 hdr_size;
__u32 hw_ver;
__u32 rt_ver;
__u8 platform_id[16];
};
enum pfru_dsm_status {
DSM_SUCCEED = 0,
DSM_FUNC_NOT_SUPPORT = 1,
DSM_INVAL_INPUT = 2,
DSM_HARDWARE_ERR = 3,
DSM_RETRY_SUGGESTED = 4,
DSM_UNKNOWN = 5,
DSM_FUNC_SPEC_ERR = 6,
};
/**
* struct pfru_update_cap_info - Runtime update capability information.
*
* @status: Indicator of whether this query succeed.
* @update_cap: Bitmap to indicate whether the feature is supported.
* @code_type: A buffer containing an image type GUID.
* @fw_version: Platform firmware version.
* @code_rt_version: Code injection runtime version for anti-rollback.
* @drv_type: A buffer containing an image type GUID.
* @drv_rt_version: The version of the driver update runtime code.
* @drv_svn: The secure version number(SVN) of the driver update runtime code.
* @platform_id: A buffer containing a platform ID GUID.
* @oem_id: A buffer containing an OEM ID GUID.
* @oem_info_len: Length of the buffer containing the vendor specific information.
*/
struct pfru_update_cap_info {
__u32 status;
__u32 update_cap;
__u8 code_type[16];
__u32 fw_version;
__u32 code_rt_version;
__u8 drv_type[16];
__u32 drv_rt_version;
__u32 drv_svn;
__u8 platform_id[16];
__u8 oem_id[16];
__u32 oem_info_len;
};
/**
* struct pfru_com_buf_info - Communication buffer information.
*
* @status: Indicator of whether this query succeed.
* @ext_status: Implementation specific query result.
* @addr_lo: Low 32bit physical address of the communication buffer to hold
* a runtime update package.
* @addr_hi: High 32bit physical address of the communication buffer to hold
* a runtime update package.
* @buf_size: Maximum size in bytes of the communication buffer.
*/
struct pfru_com_buf_info {
__u32 status;
__u32 ext_status;
__u64 addr_lo;
__u64 addr_hi;
__u32 buf_size;
};
/**
* struct pfru_updated_result - Platform firmware runtime update result information.
* @status: Indicator of whether this update succeed.
* @ext_status: Implementation specific update result.
* @low_auth_time: Low 32bit value of image authentication time in nanosecond.
* @high_auth_time: High 32bit value of image authentication time in nanosecond.
* @low_exec_time: Low 32bit value of image execution time in nanosecond.
* @high_exec_time: High 32bit value of image execution time in nanosecond.
*/
struct pfru_updated_result {
__u32 status;
__u32 ext_status;
__u64 low_auth_time;
__u64 high_auth_time;
__u64 low_exec_time;
__u64 high_exec_time;
};
/**
* struct pfrt_log_data_info - Log Data from telemetry service.
* @status: Indicator of whether this update succeed.
* @ext_status: Implementation specific update result.
* @chunk1_addr_lo: Low 32bit physical address of the telemetry data chunk1
* starting address.
* @chunk1_addr_hi: High 32bit physical address of the telemetry data chunk1
* starting address.
* @chunk2_addr_lo: Low 32bit physical address of the telemetry data chunk2
* starting address.
* @chunk2_addr_hi: High 32bit physical address of the telemetry data chunk2
* starting address.
* @max_data_size: Maximum supported size of data of all data chunks combined.
* @chunk1_size: Data size in bytes of the telemetry data chunk1 buffer.
* @chunk2_size: Data size in bytes of the telemetry data chunk2 buffer.
* @rollover_cnt: Number of times telemetry data buffer is overwritten
* since telemetry buffer reset.
* @reset_cnt: Number of times telemetry services resets that results in
* rollover count and data chunk buffers are reset.
*/
struct pfrt_log_data_info {
__u32 status;
__u32 ext_status;
__u64 chunk1_addr_lo;
__u64 chunk1_addr_hi;
__u64 chunk2_addr_lo;
__u64 chunk2_addr_hi;
__u32 max_data_size;
__u32 chunk1_size;
__u32 chunk2_size;
__u32 rollover_cnt;
__u32 reset_cnt;
};
/**
* struct pfrt_log_info - Telemetry log information.
* @log_level: The telemetry log level.
* @log_type: The telemetry log type(history and execution).
* @log_revid: The telemetry log revision id.
*/
struct pfrt_log_info {
__u32 log_level;
__u32 log_type;
__u32 log_revid;
};
/**
* PFRT_LOG_IOC_SET_INFO - _IOW(PFRUT_IOCTL_MAGIC, 0x06,
* struct pfrt_log_info)
*
* Return:
* * 0 - success
* * -EFAULT - fail to get the setting parameter
* * -EINVAL - fail to set the log level
*
* Set the PFRT log level and log type. The input information is
* a struct pfrt_log_info.
*/
#define PFRT_LOG_IOC_SET_INFO _IOW(PFRUT_IOCTL_MAGIC, 0x06, struct pfrt_log_info)
/**
* PFRT_LOG_IOC_GET_INFO - _IOR(PFRUT_IOCTL_MAGIC, 0x07,
* struct pfrt_log_info)
*
* Return:
* * 0 - success
* * -EINVAL - fail to get the log level
* * -EFAULT - fail to copy the result back to userspace
*
* Retrieve log level and log type of the telemetry. The information is
* a struct pfrt_log_info.
*/
#define PFRT_LOG_IOC_GET_INFO _IOR(PFRUT_IOCTL_MAGIC, 0x07, struct pfrt_log_info)
/**
* PFRT_LOG_IOC_GET_DATA_INFO - _IOR(PFRUT_IOCTL_MAGIC, 0x08,
* struct pfrt_log_data_info)
*
* Return:
* * 0 - success
* * -EINVAL - fail to get the log buffer information
* * -EFAULT - fail to copy the log buffer information to userspace
*
* Retrieve data information about the telemetry. The information
* is a struct pfrt_log_data_info.
*/
#define PFRT_LOG_IOC_GET_DATA_INFO _IOR(PFRUT_IOCTL_MAGIC, 0x08, struct pfrt_log_data_info)
#endif /* __PFRUT_H__ */
......@@ -2,4 +2,5 @@
/acpidbg
/acpidump
/ec
/pfrut
/include/
......@@ -9,18 +9,18 @@ include ../../scripts/Makefile.include
.NOTPARALLEL:
all: acpidbg acpidump ec
clean: acpidbg_clean acpidump_clean ec_clean
install: acpidbg_install acpidump_install ec_install
uninstall: acpidbg_uninstall acpidump_uninstall ec_uninstall
all: acpidbg acpidump ec pfrut
clean: acpidbg_clean acpidump_clean ec_clean pfrut_clean
install: acpidbg_install acpidump_install ec_install pfrut_install
uninstall: acpidbg_uninstall acpidump_uninstall ec_uninstall pfrut_uninstall
acpidbg acpidump ec: FORCE
acpidbg acpidump ec pfrut: FORCE
$(call descend,tools/$@,all)
acpidbg_clean acpidump_clean ec_clean:
acpidbg_clean acpidump_clean ec_clean pfrut_clean:
$(call descend,tools/$(@:_clean=),clean)
acpidbg_install acpidump_install ec_install:
acpidbg_install acpidump_install ec_install pfrut_install:
$(call descend,tools/$(@:_install=),install)
acpidbg_uninstall acpidump_uninstall ec_uninstall:
acpidbg_uninstall acpidump_uninstall ec_uninstall pfrut_uninstall:
$(call descend,tools/$(@:_uninstall=),uninstall)
.PHONY: FORCE
......@@ -9,7 +9,7 @@ objdir := $(OUTPUT)tools/$(TOOL)/
toolobjs := $(addprefix $(objdir),$(TOOL_OBJS))
$(OUTPUT)$(TOOL): $(toolobjs) FORCE
$(ECHO) " LD " $(subst $(OUTPUT),,$@)
$(QUIET) $(LD) $(CFLAGS) $(LDFLAGS) $(toolobjs) -L$(OUTPUT) -o $@
$(QUIET) $(LD) $(CFLAGS) $(toolobjs) $(LDFLAGS) -L$(OUTPUT) -o $@
$(ECHO) " STRIP " $(subst $(OUTPUT),,$@)
$(QUIET) $(STRIPCMD) $@
......
.TH "PFRUT" "8" "October 2021" "pfrut 1.0" ""
.hy
.SH Name
.PP
pfrut \- Platform Firmware Runtime Update and Telemetry tool
.SH SYNOPSIS
.PP
\f[B]pfrut\f[R] [\f[I]Options\f[R]]
.SH DESCRIPTION
.PP
The PFRUT(Platform Firmware Runtime Update and Telemetry) kernel interface is designed
to
.PD 0
.P
.PD
interact with the platform firmware interface defined in the
.PD 0
.P
.PD
Management Mode Firmware Runtime
Update (https://uefi.org/sites/default/files/resources/Intel_MM_OS_Interface_Spec_Rev100.pdf)
.PD 0
.P
.PD
\f[B]pfrut\f[R] is the tool to interact with the kernel interface.
.PD 0
.P
.PD
.SH OPTIONS
.TP
.B \f[B]\-h\f[R], \f[B]\-\-help\f[R]
Display helper information.
.TP
.B \f[B]\-l\f[R], \f[B]\-\-load\f[R]
Load the capsule file into the system.
To be more specific, the capsule file will be copied to the
communication buffer.
.TP
.B \f[B]\-s\f[R], \f[B]\-\-stage\f[R]
Stage the capsule image from communication buffer into Management Mode
and perform authentication.
.TP
.B \f[B]\-a\f[R], \f[B]\-\-activate\f[R]
Activate a previous staged capsule image.
.TP
.B \f[B]\-u\f[R], \f[B]\-\-update\f[R]
Perform both stage and activation actions.
.TP
.B \f[B]\-q\f[R], \f[B]\-\-query\f[R]
Query the update capability.
.TP
.B \f[B]\-d\f[R], \f[B]\-\-setrev\f[R]
Set the revision ID of code injection/driver update.
.TP
.B \f[B]\-D\f[R], \f[B]\-\-setrevlog\f[R]
Set the revision ID of telemetry.
.TP
.B \f[B]\-G\f[R], \f[B]\-\-getloginfo\f[R]
Get telemetry log information and print it out.
.TP
.B \f[B]\-T\f[R], \f[B]\-\-type\f[R]
Set the telemetry log data type.
.TP
.B \f[B]\-L\f[R], \f[B]\-\-level\f[R]
Set the telemetry log level.
.TP
.B \f[B]\-R\f[R], \f[B]\-\-read\f[R]
Read all the telemetry data and print it out.
.SH EXAMPLES
.PP
\f[B]pfrut \-G\f[R]
.PP
log_level:4
.PD 0
.P
.PD
log_type:0
.PD 0
.P
.PD
log_revid:2
.PD 0
.P
.PD
max_data_size:65536
.PD 0
.P
.PD
chunk1_size:0
.PD 0
.P
.PD
chunk2_size:1401
.PD 0
.P
.PD
rollover_cnt:0
.PD 0
.P
.PD
reset_cnt:4
.PP
\f[B]pfru \-q\f[R]
.PP
code injection image type:794bf8b2\-6e7b\-454e\-885f\-3fb9bb185402
.PD 0
.P
.PD
fw_version:0
.PD 0
.P
.PD
code_rt_version:1
.PD 0
.P
.PD
driver update image type:0e5f0b14\-f849\-7945\-ad81\-bc7b6d2bb245
.PD 0
.P
.PD
drv_rt_version:0
.PD 0
.P
.PD
drv_svn:0
.PD 0
.P
.PD
platform id:39214663\-b1a8\-4eaa\-9024\-f2bb53ea4723
.PD 0
.P
.PD
oem id:a36db54f\-ea2a\-e14e\-b7c4\-b5780e51ba3d
.PP
\f[B]pfrut \-l yours.cap \-u \-T 1 \-L 4\f[R]
.SH AUTHORS
Chen Yu.
# SPDX-License-Identifier: GPL-2.0+
include ../../Makefile.config
TOOL = pfrut
EXTRA_INSTALL = install-man
EXTRA_UNINSTALL = uninstall-man
CFLAGS += -Wall -O2
CFLAGS += -DPFRUT_HEADER='"../../../../../include/uapi/linux/pfrut.h"'
LDFLAGS += -luuid
TOOL_OBJS = \
pfrut.o
include ../../Makefile.rules
install-man: $(srctree)/man/pfrut.8
$(ECHO) " INST " pfrut.8
$(QUIET) $(INSTALL_DATA) -D $< $(DESTDIR)$(mandir)/man8/pfrut.8
uninstall-man:
$(ECHO) " UNINST " pfrut.8
$(QUIET) rm -f $(DESTDIR)$(mandir)/man8/pfrut.8
// SPDX-License-Identifier: GPL-2.0
/*
* Platform Firmware Runtime Update tool to do Management
* Mode code injection/driver update and telemetry retrieval.
*
* This tool uses the interfaces provided by pfr_update and
* pfr_telemetry drivers. These interfaces are exposed via
* /dev/pfr_update and /dev/pfr_telemetry. Write operation
* on the /dev/pfr_update is to load the EFI capsule into
* kernel space. Mmap/read operations on /dev/pfr_telemetry
* could be used to read the telemetry data to user space.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <uuid/uuid.h>
#include PFRUT_HEADER
char *capsule_name;
int action, query_cap, log_type, log_level, log_read, log_getinfo,
revid, log_revid;
int set_log_level, set_log_type,
set_revid, set_log_revid;
char *progname;
#define LOG_ERR 0
#define LOG_WARN 1
#define LOG_INFO 2
#define LOG_VERB 4
#define LOG_EXEC_IDX 0
#define LOG_HISTORY_IDX 1
#define REVID_1 1
#define REVID_2 2
static int valid_log_level(int level)
{
return level == LOG_ERR || level == LOG_WARN ||
level == LOG_INFO || level == LOG_VERB;
}
static int valid_log_type(int type)
{
return type == LOG_EXEC_IDX || type == LOG_HISTORY_IDX;
}
static inline int valid_log_revid(int id)
{
return id == REVID_1 || id == REVID_2;
}
static void help(void)
{
fprintf(stderr,
"usage: %s [OPTIONS]\n"
" code injection:\n"
" -l, --load\n"
" -s, --stage\n"
" -a, --activate\n"
" -u, --update [stage and activate]\n"
" -q, --query\n"
" -d, --revid update\n"
" telemetry:\n"
" -G, --getloginfo\n"
" -T, --type(0:execution, 1:history)\n"
" -L, --level(0, 1, 2, 4)\n"
" -R, --read\n"
" -D, --revid log\n",
progname);
}
char *option_string = "l:sauqd:GT:L:RD:h";
static struct option long_options[] = {
{"load", required_argument, 0, 'l'},
{"stage", no_argument, 0, 's'},
{"activate", no_argument, 0, 'a'},
{"update", no_argument, 0, 'u'},
{"query", no_argument, 0, 'q'},
{"getloginfo", no_argument, 0, 'G'},
{"type", required_argument, 0, 'T'},
{"level", required_argument, 0, 'L'},
{"read", no_argument, 0, 'R'},
{"setrev", required_argument, 0, 'd'},
{"setrevlog", required_argument, 0, 'D'},
{"help", no_argument, 0, 'h'},
{}
};
static void parse_options(int argc, char **argv)
{
int option_index = 0;
char *pathname;
int opt;
pathname = strdup(argv[0]);
progname = basename(pathname);
while ((opt = getopt_long_only(argc, argv, option_string,
long_options, &option_index)) != -1) {
switch (opt) {
case 'l':
capsule_name = optarg;
break;
case 's':
action = 1;
break;
case 'a':
action = 2;
break;
case 'u':
action = 3;
break;
case 'q':
query_cap = 1;
break;
case 'G':
log_getinfo = 1;
break;
case 'T':
log_type = atoi(optarg);
set_log_type = 1;
break;
case 'L':
log_level = atoi(optarg);
set_log_level = 1;
break;
case 'R':
log_read = 1;
break;
case 'd':
revid = atoi(optarg);
set_revid = 1;
break;
case 'D':
log_revid = atoi(optarg);
set_log_revid = 1;
break;
case 'h':
help();
exit(0);
default:
break;
}
}
}
void print_cap(struct pfru_update_cap_info *cap)
{
char *uuid;
uuid = malloc(37);
if (!uuid) {
perror("Can not allocate uuid buffer\n");
exit(1);
}
uuid_unparse(cap->code_type, uuid);
printf("code injection image type:%s\n", uuid);
printf("fw_version:%d\n", cap->fw_version);
printf("code_rt_version:%d\n", cap->code_rt_version);
uuid_unparse(cap->drv_type, uuid);
printf("driver update image type:%s\n", uuid);
printf("drv_rt_version:%d\n", cap->drv_rt_version);
printf("drv_svn:%d\n", cap->drv_svn);
uuid_unparse(cap->platform_id, uuid);
printf("platform id:%s\n", uuid);
uuid_unparse(cap->oem_id, uuid);
printf("oem id:%s\n", uuid);
printf("oem information length:%d\n", cap->oem_info_len);
free(uuid);
}
int main(int argc, char *argv[])
{
int fd_update, fd_update_log, fd_capsule;
struct pfrt_log_data_info data_info;
struct pfrt_log_info info;
struct pfru_update_cap_info cap;
void *addr_map_capsule;
struct stat st;
char *log_buf;
int ret = 0;
if (getuid() != 0) {
printf("Please run the tool as root - Exiting.\n");
return 1;
}
parse_options(argc, argv);
fd_update = open("/dev/acpi_pfr_update0", O_RDWR);
if (fd_update < 0) {
printf("PFRU device not supported - Quit...\n");
return 1;
}
fd_update_log = open("/dev/acpi_pfr_telemetry0", O_RDWR);
if (fd_update_log < 0) {
printf("PFRT device not supported - Quit...\n");
return 1;
}
if (query_cap) {
ret = ioctl(fd_update, PFRU_IOC_QUERY_CAP, &cap);
if (ret)
perror("Query Update Capability info failed.");
else
print_cap(&cap);
close(fd_update);
close(fd_update_log);
return ret;
}
if (log_getinfo) {
ret = ioctl(fd_update_log, PFRT_LOG_IOC_GET_DATA_INFO, &data_info);
if (ret) {
perror("Get telemetry data info failed.");
close(fd_update);
close(fd_update_log);
return 1;
}
ret = ioctl(fd_update_log, PFRT_LOG_IOC_GET_INFO, &info);
if (ret) {
perror("Get telemetry info failed.");
close(fd_update);
close(fd_update_log);
return 1;
}
printf("log_level:%d\n", info.log_level);
printf("log_type:%d\n", info.log_type);
printf("log_revid:%d\n", info.log_revid);
printf("max_data_size:%d\n", data_info.max_data_size);
printf("chunk1_size:%d\n", data_info.chunk1_size);
printf("chunk2_size:%d\n", data_info.chunk2_size);
printf("rollover_cnt:%d\n", data_info.rollover_cnt);
printf("reset_cnt:%d\n", data_info.reset_cnt);
return 0;
}
info.log_level = -1;
info.log_type = -1;
info.log_revid = -1;
if (set_log_level) {
if (!valid_log_level(log_level)) {
printf("Invalid log level %d\n",
log_level);
} else {
info.log_level = log_level;
}
}
if (set_log_type) {
if (!valid_log_type(log_type)) {
printf("Invalid log type %d\n",
log_type);
} else {
info.log_type = log_type;
}
}
if (set_log_revid) {
if (!valid_log_revid(log_revid)) {
printf("Invalid log revid %d, unchanged.\n",
log_revid);
} else {
info.log_revid = log_revid;
}
}
ret = ioctl(fd_update_log, PFRT_LOG_IOC_SET_INFO, &info);
if (ret) {
perror("Log information set failed.(log_level, log_type, log_revid)");
close(fd_update);
close(fd_update_log);
return 1;
}
if (set_revid) {
ret = ioctl(fd_update, PFRU_IOC_SET_REV, &revid);
if (ret) {
perror("pfru update revid set failed");
close(fd_update);
close(fd_update_log);
return 1;
}
printf("pfru update revid set to %d\n", revid);
}
if (capsule_name) {
fd_capsule = open(capsule_name, O_RDONLY);
if (fd_capsule < 0) {
perror("Can not open capsule file...");
close(fd_update);
close(fd_update_log);
return 1;
}
if (fstat(fd_capsule, &st) < 0) {
perror("Can not fstat capsule file...");
close(fd_capsule);
close(fd_update);
close(fd_update_log);
return 1;
}
addr_map_capsule = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED,
fd_capsule, 0);
if (addr_map_capsule == MAP_FAILED) {
perror("Failed to mmap capsule file.");
close(fd_capsule);
close(fd_update);
close(fd_update_log);
return 1;
}
ret = write(fd_update, (char *)addr_map_capsule, st.st_size);
printf("Load %d bytes of capsule file into the system\n",
ret);
if (ret == -1) {
perror("Failed to load capsule file");
close(fd_capsule);
close(fd_update);
close(fd_update_log);
return 1;
}
munmap(addr_map_capsule, st.st_size);
close(fd_capsule);
printf("Load done.\n");
}
if (action) {
if (action == 1) {
ret = ioctl(fd_update, PFRU_IOC_STAGE, NULL);
} else if (action == 2) {
ret = ioctl(fd_update, PFRU_IOC_ACTIVATE, NULL);
} else if (action == 3) {
ret = ioctl(fd_update, PFRU_IOC_STAGE_ACTIVATE, NULL);
} else {
close(fd_update);
close(fd_update_log);
return 1;
}
printf("Update finished, return %d\n", ret);
}
close(fd_update);
if (log_read) {
void *p_mmap;
int max_data_sz;
ret = ioctl(fd_update_log, PFRT_LOG_IOC_GET_DATA_INFO, &data_info);
if (ret) {
perror("Get telemetry data info failed.");
close(fd_update_log);
return 1;
}
max_data_sz = data_info.max_data_size;
if (!max_data_sz) {
printf("No telemetry data available.\n");
close(fd_update_log);
return 1;
}
log_buf = malloc(max_data_sz + 1);
if (!log_buf) {
perror("log_buf allocate failed.");
close(fd_update_log);
return 1;
}
p_mmap = mmap(NULL, max_data_sz, PROT_READ, MAP_SHARED, fd_update_log, 0);
if (p_mmap == MAP_FAILED) {
perror("mmap error.");
close(fd_update_log);
return 1;
}
memcpy(log_buf, p_mmap, max_data_sz);
log_buf[max_data_sz] = '\0';
printf("%s\n", log_buf);
free(log_buf);
munmap(p_mmap, max_data_sz);
}
close(fd_update_log);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment