cbfs: Replace more instances of cbfs_boot_locate() with newer APIs
In pursuit of the eventual goal of removing cbfs_boot_locate() (and
direct rdev access) from CBFS APIs, this patch replaces all remaining
"simple" uses of the function call that can easily be replaced by the
newer APIs (like cbfs_load() or cbfs_map()). Some cases of
cbfs_boot_locate() remain that will be more complicated to solve.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Icd0f21e2fa49c7cc834523578b7b45b5482cb1a8
Reviewed-on: https://review.coreboot.org/c/coreboot/+/50348
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
diff --git a/src/cpu/x86/pae/pgtbl.c b/src/cpu/x86/pae/pgtbl.c
index 145a31b..814dbf5 100644
--- a/src/cpu/x86/pae/pgtbl.c
+++ b/src/cpu/x86/pae/pgtbl.c
@@ -321,42 +321,17 @@
paging_set_pat(pat);
}
-static int read_from_cbfs(const char *name, void *buf, size_t size)
-{
- struct cbfsf fh;
- struct region_device rdev;
- size_t rdev_sz;
-
- if (cbfs_boot_locate(&fh, name, NULL))
- return -1;
-
- cbfs_file_data(&rdev, &fh);
-
- rdev_sz = region_device_sz(&rdev);
-
- if (size < rdev_sz) {
- printk(BIOS_ERR, "%s region too small to load: %zx < %zx\n",
- name, size, rdev_sz);
- return -1;
- }
-
- if (rdev_readat(&rdev, buf, 0, rdev_sz) != rdev_sz)
- return -1;
-
- return 0;
-}
-
int paging_enable_for_car(const char *pdpt_name, const char *pt_name)
{
if (!preram_symbols_available())
return -1;
- if (read_from_cbfs(pdpt_name, _pdpt, REGION_SIZE(pdpt))) {
+ if (!cbfs_load(pdpt_name, _pdpt, REGION_SIZE(pdpt))) {
printk(BIOS_ERR, "Couldn't load pdpt\n");
return -1;
}
- if (read_from_cbfs(pt_name, _pagetables, REGION_SIZE(pagetables))) {
+ if (!cbfs_load(pt_name, _pagetables, REGION_SIZE(pagetables))) {
printk(BIOS_ERR, "Couldn't load page tables\n");
return -1;
}
diff --git a/src/drivers/generic/cbfs-serial/cbfs-serial.c b/src/drivers/generic/cbfs-serial/cbfs-serial.c
index 9f8aaa8..6ff010c 100644
--- a/src/drivers/generic/cbfs-serial/cbfs-serial.c
+++ b/src/drivers/generic/cbfs-serial/cbfs-serial.c
@@ -10,25 +10,14 @@
const char *smbios_mainboard_serial_number(void)
{
static char serial_number[MAX_SERIAL_LENGTH + 1] = {0};
- struct cbfsf file;
if (serial_number[0] != 0)
return serial_number;
- if (cbfs_boot_locate(&file, "serial_number", NULL) == 0) {
- struct region_device cbfs_region;
- size_t serial_len;
-
- cbfs_file_data(&cbfs_region, &file);
-
- serial_len = region_device_sz(&cbfs_region);
- if (serial_len <= MAX_SERIAL_LENGTH) {
- if (rdev_readat(&cbfs_region, serial_number, 0,
- serial_len) == serial_len) {
- serial_number[serial_len] = 0;
- return serial_number;
- }
- }
+ size_t serial_len = cbfs_load("serial_number", serial_number, MAX_SERIAL_LENGTH);
+ if (serial_len) {
+ serial_number[serial_len] = '\0';
+ return serial_number;
}
strncpy(serial_number, CONFIG_MAINBOARD_SERIAL_NUMBER,
diff --git a/src/drivers/net/atl1e.c b/src/drivers/net/atl1e.c
index b533537..9b1b2ab 100644
--- a/src/drivers/net/atl1e.c
+++ b/src/drivers/net/atl1e.c
@@ -41,18 +41,11 @@
static enum cb_err fetch_mac_string_cbfs(u8 *macstrbuf)
{
- struct cbfsf fh;
- uint32_t matchraw = CBFS_TYPE_RAW;
-
- if (!cbfs_boot_locate(&fh, "atl1e-macaddress", &matchraw)) {
- /* check the cbfs for the mac address */
- if (rdev_readat(&fh.data, macstrbuf, 0, MACLEN) != MACLEN) {
- printk(BIOS_ERR, "atl1e: Error reading MAC from CBFS\n");
- return CB_ERR;
- }
- return CB_SUCCESS;
+ if (!cbfs_load("atl1e-macaddress", macstrbuf, MACLEN)) {
+ printk(BIOS_ERR, "atl1e: Error reading MAC from CBFS\n");
+ return CB_ERR;
}
- return CB_ERR;
+ return CB_SUCCESS;
}
static void get_mac_address(u8 *macaddr, const u8 *strbuf)
diff --git a/src/drivers/net/r8168.c b/src/drivers/net/r8168.c
index af7c387..398b15d 100644
--- a/src/drivers/net/r8168.c
+++ b/src/drivers/net/r8168.c
@@ -166,18 +166,11 @@
static enum cb_err fetch_mac_string_cbfs(u8 *macstrbuf)
{
- struct cbfsf fh;
- uint32_t matchraw = CBFS_TYPE_RAW;
-
- if (!cbfs_boot_locate(&fh, "rt8168-macaddress", &matchraw)) {
- /* check the cbfs for the mac address */
- if (rdev_readat(&fh.data, macstrbuf, 0, MACLEN) != MACLEN) {
- printk(BIOS_ERR, "r8168: Error reading MAC from CBFS\n");
- return CB_ERR;
- }
- return CB_SUCCESS;
+ if (!cbfs_load("rt8168-macaddress", macstrbuf, MACLEN)) {
+ printk(BIOS_ERR, "r8168: Error reading MAC from CBFS\n");
+ return CB_ERR;
}
- return CB_ERR;
+ return CB_SUCCESS;
}
static void get_mac_address(u8 *macaddr, const u8 *strbuf)
diff --git a/src/lib/nhlt.c b/src/lib/nhlt.c
index 80b3f2e..90a6cd9 100644
--- a/src/lib/nhlt.c
+++ b/src/lib/nhlt.c
@@ -149,9 +149,8 @@
for (i = 0; i < num_formats; i++) {
struct nhlt_format *fmt;
- struct cbfsf file;
- struct region_device settings;
void *settings_data;
+ size_t size;
const struct nhlt_format_config *cfg = &formats[i];
fmt = nhlt_add_format(endp, cfg->num_channels,
@@ -167,23 +166,16 @@
continue;
/* Find the settings file in CBFS and place it in format. */
- if (cbfs_boot_locate(&file, cfg->settings_file, NULL))
+ settings_data = cbfs_map(cfg->settings_file, &size);
+ if (!settings_data)
return -1;
- cbfs_file_data(&settings, &file);
-
- settings_data = rdev_mmap_full(&settings);
-
- if (settings_data == NULL)
- return -1;
-
- if (nhlt_format_append_config(fmt, settings_data,
- region_device_sz(&settings))) {
- rdev_munmap(&settings, settings_data);
+ if (nhlt_format_append_config(fmt, settings_data, size)) {
+ cbfs_unmap(settings_data);
return -1;
}
- rdev_munmap(&settings, settings_data);
+ cbfs_unmap(settings_data);
}
return 0;
diff --git a/src/mainboard/razer/blade_stealth_kbl/Kconfig b/src/mainboard/razer/blade_stealth_kbl/Kconfig
index 31c29cd..3e9f462 100644
--- a/src/mainboard/razer/blade_stealth_kbl/Kconfig
+++ b/src/mainboard/razer/blade_stealth_kbl/Kconfig
@@ -14,6 +14,7 @@
select DRIVERS_I2C_HID
select HAVE_ACPI_RESUME
select HAVE_ACPI_TABLES
+ select DRIVERS_GENERIC_CBFS_SERIAL
# For now no way to choose the correct the available RAM
config BOARD_RAZER_BLADE_STEALTH_KBL_16GB
diff --git a/src/mainboard/razer/blade_stealth_kbl/Makefile.inc b/src/mainboard/razer/blade_stealth_kbl/Makefile.inc
index 3d8d4fc..0d4380a6 100644
--- a/src/mainboard/razer/blade_stealth_kbl/Makefile.inc
+++ b/src/mainboard/razer/blade_stealth_kbl/Makefile.inc
@@ -2,7 +2,6 @@
subdirs-y += spd
-ramstage-y += mainboard.c
ramstage-y += ramstage.c
ramstage-y += hda_verb.c
diff --git a/src/mainboard/razer/blade_stealth_kbl/mainboard.c b/src/mainboard/razer/blade_stealth_kbl/mainboard.c
deleted file mode 100644
index eecfa3b..0000000
--- a/src/mainboard/razer/blade_stealth_kbl/mainboard.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#include <smbios.h>
-#include <string.h>
-#include <cbfs.h>
-
-#define MAX_SERIAL_LENGTH 0x100
-
-const char *smbios_mainboard_serial_number(void)
-{
- static char serial_number[MAX_SERIAL_LENGTH + 1] = {0};
- struct cbfsf file;
-
- if (serial_number[0] != 0)
- return serial_number;
-
- if (cbfs_boot_locate(&file, "serial_number", NULL) == 0) {
- struct region_device cbfs_region;
- size_t ser_len;
-
- cbfs_file_data(&cbfs_region, &file);
-
- ser_len = region_device_sz(&cbfs_region);
- if (ser_len <= MAX_SERIAL_LENGTH) {
- if (rdev_readat(&cbfs_region, serial_number, 0, ser_len) == ser_len) {
- serial_number[ser_len] = 0;
- return serial_number;
- }
- }
- }
-
- strncpy(serial_number, CONFIG_MAINBOARD_SERIAL_NUMBER, MAX_SERIAL_LENGTH);
-
- return serial_number;
-}
diff --git a/src/security/intel/txt/common.c b/src/security/intel/txt/common.c
index 4dd4ad3..437c55e 100644
--- a/src/security/intel/txt/common.c
+++ b/src/security/intel/txt/common.c
@@ -215,25 +215,17 @@
*/
static void *intel_txt_prepare_bios_acm(struct region_device *acm, size_t *acm_len)
{
- struct cbfsf file;
void *acm_data = NULL;
if (!acm || !acm_len)
return NULL;
- if (cbfs_boot_locate(&file, CONFIG_INTEL_TXT_CBFS_BIOS_ACM, NULL)) {
+ acm_data = cbfs_map(CONFIG_INTEL_TXT_CBFS_BIOS_ACM, acm_len);
+ if (!acm_data) {
printk(BIOS_ERR, "TEE-TXT: Couldn't locate BIOS ACM in CBFS.\n");
return NULL;
}
- cbfs_file_data(acm, &file);
- acm_data = rdev_mmap_full(acm);
- *acm_len = region_device_sz(acm);
- if (!acm_data || *acm_len == 0) {
- printk(BIOS_ERR, "TEE-TXT: Couldn't map BIOS ACM from CBFS.\n");
- return NULL;
- }
-
/*
* CPU enforces only 4KiB alignment.
* Chapter A.1.1
@@ -241,7 +233,7 @@
*/
if (!IS_ALIGNED((uintptr_t)acm_data, 4096)) {
printk(BIOS_ERR, "TEE-TXT: BIOS ACM isn't mapped at page boundary.\n");
- rdev_munmap(acm, acm_data);
+ cbfs_unmap(acm_data);
return NULL;
}
@@ -252,7 +244,7 @@
*/
if (!IS_ALIGNED(*acm_len, 64)) {
printk(BIOS_ERR, "TEE-TXT: BIOS ACM size isn't multiple of 64.\n");
- rdev_munmap(acm, acm_data);
+ cbfs_unmap(acm_data);
return NULL;
}
@@ -262,7 +254,7 @@
*/
if (!IS_ALIGNED((uintptr_t)acm_data, (1UL << log2_ceil(*acm_len)))) {
printk(BIOS_ERR, "TEE-TXT: BIOS ACM isn't aligned to its size.\n");
- rdev_munmap(acm, acm_data);
+ cbfs_unmap(acm_data);
return NULL;
}
@@ -273,7 +265,7 @@
*/
if (popcnt(ALIGN_UP(*acm_len, 4096)) > get_var_mtrr_count()) {
printk(BIOS_ERR, "TEE-TXT: Not enough MTRRs to cache this BIOS ACM's size.\n");
- rdev_munmap(acm, acm_data);
+ cbfs_unmap(acm_data);
return NULL;
}
@@ -283,7 +275,7 @@
const int ret = validate_acm(acm_data);
if (ret < 0) {
printk(BIOS_ERR, "TEE-TXT: Validation of ACM failed with: %d\n", ret);
- rdev_munmap(acm, acm_data);
+ cbfs_unmap(acm_data);
return NULL;
}
diff --git a/src/security/intel/txt/ramstage.c b/src/security/intel/txt/ramstage.c
index 3401aef..c830f97 100644
--- a/src/security/intel/txt/ramstage.c
+++ b/src/security/intel/txt/ramstage.c
@@ -233,23 +233,14 @@
memset(sinit_base, 0, read64((void *)TXT_SINIT_SIZE));
}
- struct cbfsf file;
/* The following have been removed from BIOS Data Table in version 6 */
- if (!cbfs_boot_locate(&file, CONFIG_INTEL_TXT_CBFS_BIOS_POLICY, NULL)) {
- struct region_device policy;
-
- cbfs_file_data(&policy, &file);
- void *policy_data = rdev_mmap_full(&policy);
- size_t policy_len = region_device_sz(&policy);
-
- if (policy_data && policy_len) {
- /* Point to FIT Type 9 entry in flash */
- data.bdr.lcp_pd_base = (uintptr_t)policy_data;
- data.bdr.lcp_pd_size = (uint64_t)policy_len;
- rdev_munmap(&policy, policy_data);
- } else {
- printk(BIOS_ERR, "TEE-TXT: Couldn't map LCP PD Policy from CBFS.\n");
- }
+ size_t policy_len;
+ void *policy_data = cbfs_map(CONFIG_INTEL_TXT_CBFS_BIOS_POLICY, &policy_len);
+ if (policy_data) {
+ /* Point to FIT Type 9 entry in flash */
+ data.bdr.lcp_pd_base = (uintptr_t)policy_data;
+ data.bdr.lcp_pd_size = (uint64_t)policy_len;
+ cbfs_unmap(policy_data);
} else {
printk(BIOS_ERR, "TEE-TXT: Couldn't locate LCP PD Policy in CBFS.\n");
}
diff --git a/src/soc/amd/common/block/psp/psp_gen1.c b/src/soc/amd/common/block/psp/psp_gen1.c
index 5096dd3..076d354 100644
--- a/src/soc/amd/common/block/psp/psp_gen1.c
+++ b/src/soc/amd/common/block/psp/psp_gen1.c
@@ -101,8 +101,6 @@
int cmd_status;
u32 command;
void *blob;
- struct cbfsf cbfs_file;
- struct region_device rdev;
switch (type) {
case BLOB_SMU_FW:
@@ -122,13 +120,7 @@
return -PSPSTS_UNSUPPORTED;
}
- if (cbfs_boot_locate(&cbfs_file, name, NULL)) {
- printk(BIOS_ERR, "BUG: Cannot locate blob for PSP loading\n");
- return -PSPSTS_INVALID_NAME;
- }
-
- cbfs_file_data(&rdev, &cbfs_file);
- blob = rdev_mmap_full(&rdev);
+ blob = cbfs_map(name, NULL);
if (!blob) {
printk(BIOS_ERR, "BUG: Cannot map blob for PSP loading\n");
return -PSPSTS_INVALID_NAME;
@@ -140,6 +132,6 @@
cmd_status = send_psp_command(command, blob);
psp_print_cmd_status(cmd_status, NULL);
- rdev_munmap(&rdev, blob);
+ cbfs_unmap(blob);
return cmd_status;
}
diff --git a/src/soc/nvidia/tegra210/mtc.c b/src/soc/nvidia/tegra210/mtc.c
index b0bba9c..47cbd92 100644
--- a/src/soc/nvidia/tegra210/mtc.c
+++ b/src/soc/nvidia/tegra210/mtc.c
@@ -15,30 +15,17 @@
int tegra210_run_mtc(void)
{
- ssize_t nread;
- struct region_device fh;
- struct cbfsf mtc_file;
-
+ size_t nread;
void *const mtc = (void *)(uintptr_t)CONFIG_MTC_ADDRESS;
void *dvfs_table;
size_t (*mtc_fw)(void **dvfs_table) = (void *)mtc;
- if (cbfs_boot_locate(&mtc_file, "tegra_mtc.bin", NULL)) {
+ nread = cbfs_load("tegra_mtc.bin", mtc, 1*GiB);
+ if (!nread) {
printk(BIOS_ERR, "MTC file not found: tegra_mtc.bin\n");
return -1;
}
- cbfs_file_data(&fh, &mtc_file);
-
- /* Read MTC file into predefined region. */
- nread = rdev_readat(&fh, mtc, 0, region_device_sz(&fh));
-
- if (nread != region_device_sz(&fh)) {
- printk(BIOS_ERR, "MTC bytes read (%zu) != file length(%zu)!\n",
- nread, region_device_sz(&fh));
- return -1;
- }
-
printk(BIOS_INFO, "MTC: %zu bytes loaded @ %p\n", nread, mtc);
mtc_table_size = (*mtc_fw)(&dvfs_table);