From 41a4a3085591b8e837f6eec27821218b0be31036 Mon Sep 17 00:00:00 2001 From: Thomas Perrot Date: Fri, 2 Jul 2021 11:32:37 +0200 Subject: doc: fix typo in signature.txt Fix value fields in signature nodes. Signed-off-by: Thomas Perrot Reviewed-by: Heinrich Schuchardt --- doc/uImage.FIT/signature.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt index d9a9121..7cb1c15 100644 --- a/doc/uImage.FIT/signature.txt +++ b/doc/uImage.FIT/signature.txt @@ -266,14 +266,14 @@ As an example, consider this FIT: data = ; signature-1 { algo = "sha1,rsa2048"; - vaue = <...fdt signature 1...> + value = <...fdt signature 1...> }; }; fdt-2 { data = ; signature-1 { algo = "sha1,rsa2048"; - vaue = <...fdt signature 2...> + value = <...fdt signature 2...> }; }; }; -- cgit v1.1 From 13c11c665320beff22ea94674da42719b6281501 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 May 2021 22:06:16 +0200 Subject: fs: fat: add file attributes to struct fs_dirent When reading a directory in the UEFI file system we have to return file attributes and timestamps. Copy this data to the directory entry structure. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat.c | 32 +++++++++++++++++++++++++++++++- include/fs.h | 22 ++++++++++++++++++---- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index c561d82..7021138 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -1187,6 +1187,28 @@ out: return ret == 0; } +/** + * fat2rtc() - convert FAT time stamp to RTC file stamp + * + * @date: FAT date + * @time: FAT time + * @tm: RTC time stamp + */ +static void __maybe_unused fat2rtc(u16 date, u16 time, struct rtc_time *tm) +{ + tm->tm_mday = date & 0x1f; + tm->tm_mon = (date & 0x1e0) >> 4; + tm->tm_year = (date >> 9) + 1980; + + tm->tm_sec = (time & 0x1f) << 1; + tm->tm_min = (time & 0x7e0) >> 5; + tm->tm_hour = time >> 11; + + rtc_calc_weekday(tm); + tm->tm_yday = 0; + tm->tm_isdst = 0; +} + int fat_size(const char *filename, loff_t *size) { fsdata fsdata; @@ -1325,7 +1347,15 @@ int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp) memset(dent, 0, sizeof(*dent)); strcpy(dent->name, dir->itr.name); - + if (CONFIG_IS_ENABLED(EFI_LOADER)) { + dent->attr = dir->itr.dent->attr; + fat2rtc(le16_to_cpu(dir->itr.dent->cdate), + le16_to_cpu(dir->itr.dent->ctime), &dent->create_time); + fat2rtc(le16_to_cpu(dir->itr.dent->date), + le16_to_cpu(dir->itr.dent->time), &dent->change_time); + fat2rtc(le16_to_cpu(dir->itr.dent->adate), + 0, &dent->access_time); + } if (fat_itr_isdir(&dir->itr)) { dent->type = FS_DT_DIR; } else { diff --git a/include/fs.h b/include/fs.h index 0794b50..1c79e29 100644 --- a/include/fs.h +++ b/include/fs.h @@ -6,6 +6,7 @@ #define _FS_H #include +#include struct cmd_tbl; @@ -160,13 +161,26 @@ int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, #define FS_DT_REG 8 /* regular file */ #define FS_DT_LNK 10 /* symbolic link */ -/* - * A directory entry, returned by fs_readdir(). Returns information +/** + * struct fs_dirent - directory entry + * + * A directory entry, returned by fs_readdir(). Returns information * about the file/directory at the current directory entry position. */ struct fs_dirent { - unsigned type; /* one of FS_DT_x (not a mask) */ - loff_t size; /* size in bytes */ + /** @type: one of FS_DT_x (not a mask) */ + unsigned int type; + /** @size: file size */ + loff_t size; + /** @flags: attribute flags (FS_ATTR_*) */ + u32 attr; + /** create_time: time of creation */ + struct rtc_time create_time; + /** access_time: time of last access */ + struct rtc_time access_time; + /** change_time: time of last modification */ + struct rtc_time change_time; + /** name: file name */ char name[256]; }; -- cgit v1.1 From cbe3ab986bdd5301dd4cbfd50e316a063d17d7b8 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 14 Jun 2021 18:47:09 +0200 Subject: lib: remove superfluous #ifdefs from date.c We should avoid #ifdef in C modules. Unused functions are eliminated by the linker. Signed-off-by: Heinrich Schuchardt --- lib/date.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/date.c b/lib/date.c index 0456de7..c589d9e 100644 --- a/lib/date.c +++ b/lib/date.c @@ -10,8 +10,6 @@ #include #include -#if defined(CONFIG_LIB_DATE) || defined(CONFIG_TIMESTAMP) - #define FEBRUARY 2 #define STARTOFTIME 1970 #define SECDAY 86400L @@ -97,9 +95,6 @@ unsigned long rtc_mktime(const struct rtc_time *tm) return (hours * 60 + tm->tm_min) * 60 + tm->tm_sec; } -#endif /* CONFIG_LIB_DATE || CONFIG_TIMESTAMP */ - -#ifdef CONFIG_LIB_DATE /* for compatibility with linux code */ time64_t mktime64(const unsigned int year, const unsigned int mon, const unsigned int day, const unsigned int hour, @@ -116,4 +111,3 @@ time64_t mktime64(const unsigned int year, const unsigned int mon, return (time64_t)rtc_mktime((const struct rtc_time *)&time); } -#endif -- cgit v1.1 From 79a61ccb236547a69db53ee52751e62b6a4361c3 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 May 2021 22:41:26 +0200 Subject: efi_loader: provide file attributes in EFI_FILE_PROTOCOL.Read() When reading a directory using EFI_FILE_PROTOCOL.Read() provide file attributes and timestamps. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_file.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 6b3f596..6299fcb 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -480,6 +480,17 @@ static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size, return EFI_SUCCESS; } +static void rtc2efi(struct efi_time *time, struct rtc_time *tm) +{ + memset(time, 0, sizeof(struct efi_time)); + time->year = tm->tm_year; + time->month = tm->tm_mon; + time->day = tm->tm_mday; + time->hour = tm->tm_hour; + time->minute = tm->tm_min; + time->second = tm->tm_sec; +} + static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size, void *buffer) { @@ -535,6 +546,10 @@ static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size, info->size = required_size; info->file_size = dent->size; info->physical_size = dent->size; + info->attribute = dent->attr; + rtc2efi(&info->create_time, &dent->create_time); + rtc2efi(&info->modification_time, &dent->change_time); + rtc2efi(&info->last_access_time, &dent->access_time); if (dent->type == FS_DT_DIR) info->attribute |= EFI_FILE_DIRECTORY; -- cgit v1.1 From 3e49119efbcd2c73d4d5065ce8327e90a941ea02 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 10 Jul 2021 11:03:27 +0200 Subject: efi_loader: rework messages for capsule updates * Use log category LOGC_EFI. This allows to remove 'EFI:' prefixes in messages. * Rephrase some of the messages. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_capsule.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 50bed32..843a3e3 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -6,6 +6,8 @@ * Author: AKASHI Takahiro */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include @@ -101,7 +103,7 @@ void set_capsule_result(int index, struct efi_capsule_header *capsule, EFI_VARIABLE_RUNTIME_ACCESS, sizeof(result), &result); if (ret) - log_err("EFI: creating %ls failed\n", variable_name16); + log_err("Setting %ls failed\n", variable_name16); } #ifdef CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT @@ -361,7 +363,7 @@ static efi_status_t efi_capsule_update_firmware( /* sanity check */ if ((capsule->item_offset_list[item] + sizeof(*image) >= capsule_size)) { - log_err("EFI: A capsule has not enough data\n"); + log_err("Capsule does not have enough data\n"); ret = EFI_INVALID_PARAMETER; goto out; } @@ -379,7 +381,7 @@ static efi_status_t efi_capsule_update_firmware( image->update_hardware_instance, handles, no_handles); if (!fmp) { - log_err("EFI Capsule: driver not found for firmware type: %pUl, hardware instance: %lld\n", + log_err("FMP driver not found for firmware type %pUl, hardware instance %lld\n", &image->update_image_type_id, image->update_hardware_instance); ret = EFI_UNSUPPORTED; @@ -397,7 +399,7 @@ static efi_status_t efi_capsule_update_firmware( vendor_code, NULL, &abort_reason)); if (ret != EFI_SUCCESS) { - log_err("EFI Capsule: firmware update failed: %ls\n", + log_err("Firmware update failed: %ls\n", abort_reason); efi_free_pool(abort_reason); goto out; @@ -453,7 +455,7 @@ efi_status_t EFIAPI efi_update_capsule( /* sanity check */ if (capsule->header_size < sizeof(*capsule) || capsule->capsule_image_size < sizeof(*capsule)) { - log_err("EFI: A capsule has not enough data\n"); + log_err("Capsule does not have enough data\n"); continue; } @@ -463,7 +465,7 @@ efi_status_t EFIAPI efi_update_capsule( &efi_guid_firmware_management_capsule_id)) { ret = efi_capsule_update_firmware(capsule); } else { - log_err("EFI: not support capsule type: %pUl\n", + log_err("Unsupported capsule type: %pUl\n", &capsule->capsule_guid); ret = EFI_UNSUPPORTED; } @@ -476,7 +478,7 @@ efi_status_t EFIAPI efi_update_capsule( /* Rebuild the ESRT to reflect any updated FW images. */ ret = efi_esrt_populate(); if (ret != EFI_SUCCESS) - log_warning("EFI Capsule: failed to update ESRT\n"); + log_warning("ESRT update failed\n"); } out: @@ -679,7 +681,7 @@ skip: u16 *path_str; path_str = efi_dp_str(boot_dev); - log_debug("EFI Capsule: bootdev is %ls\n", path_str); + log_debug("Boot device %ls\n", path_str); efi_free_pool(path_str); volume = efi_fs_from_path(boot_dev); @@ -720,7 +722,7 @@ static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num) ret = find_boot_device(); if (ret == EFI_NOT_FOUND) { - log_debug("EFI Capsule: bootdev is not set\n"); + log_debug("Boot device is not set\n"); *num = 0; return EFI_SUCCESS; } else if (ret != EFI_SUCCESS) { @@ -1011,19 +1013,19 @@ efi_status_t efi_launch_capsules(void) /* Launch capsules */ for (i = 0, ++index; i < nfiles; i++, index++) { - log_debug("capsule from %ls ...\n", files[i]); + log_debug("Applying %ls\n", files[i]); if (index > 0xffff) index = 0; ret = efi_capsule_read_file(files[i], &capsule); if (ret == EFI_SUCCESS) { ret = EFI_CALL(efi_update_capsule(&capsule, 1, 0)); if (ret != EFI_SUCCESS) - log_err("EFI Capsule update failed at %ls\n", + log_err("Applying capsule %ls failed\n", files[i]); free(capsule); } else { - log_err("EFI: reading capsule failed: %ls\n", files[i]); + log_err("Reading capsule %ls failed\n", files[i]); } /* create CapsuleXXXX */ set_capsule_result(index, capsule, ret); @@ -1031,7 +1033,7 @@ efi_status_t efi_launch_capsules(void) /* delete a capsule either in case of success or failure */ ret = efi_capsule_delete_file(files[i]); if (ret != EFI_SUCCESS) - log_err("EFI: deleting a capsule file failed: %ls\n", + log_err("Deleting capsule %ls failed\n", files[i]); } efi_capsule_scan_done(); -- cgit v1.1 From d7eedd9d50334388766a69f99cca7484e04684d6 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 10 Jul 2021 11:10:26 +0200 Subject: efi_loader: missing EFI_CALL() in set_capsule_result efi_set_variable() should be called with EFI_CALL(). Use efi_set_variable_int() instead. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_capsule.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 843a3e3..7831a27 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -97,11 +97,11 @@ void set_capsule_result(int index, struct efi_capsule_header *capsule, else memset(&result.capsule_processed, 0, sizeof(time)); result.capsule_status = return_status; - ret = efi_set_variable(variable_name16, &efi_guid_capsule_report, - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - sizeof(result), &result); + ret = efi_set_variable_int(variable_name16, &efi_guid_capsule_report, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(result), &result, false); if (ret) log_err("Setting %ls failed\n", variable_name16); } -- cgit v1.1 From 70bad5462ca77dcd62efb6fdff03b26460df5f14 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 10 Jul 2021 11:14:13 +0200 Subject: efi_loader: set CapsuleLast after each capsule If multiple capsules are applied, the FMP drivers for the individual capsules can expect the value of CapsuleLast to be accurate. Hence CapsuleLast must be updated after each capsule. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_capsule.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 7831a27..bef9d61 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -102,8 +102,20 @@ void set_capsule_result(int index, struct efi_capsule_header *capsule, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, sizeof(result), &result, false); - if (ret) + if (ret != EFI_SUCCESS) { log_err("Setting %ls failed\n", variable_name16); + return; + } + + /* Variable CapsuleLast must not include terminating 0x0000 */ + ret = efi_set_variable_int(L"CapsuleLast", &efi_guid_capsule_report, + EFI_VARIABLE_READ_ONLY | + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + 22, variable_name16, false); + if (ret != EFI_SUCCESS) + log_err("Setting %ls failed\n", L"CapsuleLast"); } #ifdef CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT @@ -990,7 +1002,6 @@ efi_status_t efi_launch_capsules(void) struct efi_capsule_header *capsule = NULL; u16 **files; unsigned int nfiles, index, i; - u16 variable_name16[12]; efi_status_t ret; if (!check_run_capsules()) @@ -1042,16 +1053,6 @@ efi_status_t efi_launch_capsules(void) free(files[i]); free(files); - /* CapsuleLast */ - efi_create_indexed_name(variable_name16, sizeof(variable_name16), - "Capsule", index - 1); - efi_set_variable_int(L"CapsuleLast", &efi_guid_capsule_report, - EFI_VARIABLE_READ_ONLY | - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - 22, variable_name16, false); - return ret; } #endif /* CONFIG_EFI_CAPSULE_ON_DISK */ -- cgit v1.1 From b0b1449b3be9b93ecc57d91b0cb18ed81fc8a1ee Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Mon, 12 Jul 2021 18:05:17 +0900 Subject: efi_loader: Fix to set bootdev_root correctly if bootdev found Fix find_boot_device() to set bootdev_root if it finds the bootdev from BootNext. Currently it sets the bootdev_root only when it finds bootdev from BootOrder. Fixes: c74cd8bd08d1 ("efi_loader: capsule: add capsule_on_disk support") Signed-off-by: Masami Hiramatsu Accked-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_capsule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index bef9d61..b878e71 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -646,7 +646,7 @@ static efi_status_t find_boot_device(void) ret = get_dp_device(boot_var16, &boot_dev); if (ret == EFI_SUCCESS) { if (device_is_present_and_system_part(boot_dev)) { - goto out; + goto found; } else { efi_free_pool(boot_dev); boot_dev = NULL; @@ -689,6 +689,7 @@ skip: efi_free_pool(boot_dev); boot_dev = NULL; } +found: if (boot_dev) { u16 *path_str; -- cgit v1.1