From: Simon Glass <sjg@chromium.org> Currently qfw_locate_file() always prints error messages when it can't find a file. This causes unwanted error output in qemu_get_bootcmd() when the optional "opt/u-boot/bootcmd" file doesn't exist. Adjust qfw_locate_file() to be silent, with a new qfw_locate_file_msg() that shows messages. This allows callers to choose whether missing files should generate error messages. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <sjg@chromium.org> --- drivers/qfw/qfw.c | 26 ++++++++++++++++++-------- include/qfw.h | 20 +++++++++++++++++++- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/drivers/qfw/qfw.c b/drivers/qfw/qfw.c index 2e260d60449..51f25b9ff0b 100644 --- a/drivers/qfw/qfw.c +++ b/drivers/qfw/qfw.c @@ -220,16 +220,12 @@ int qfw_locate_file(struct udevice *dev, const char *fname, /* make sure fw_list is loaded */ ret = qfw_read_firmware_list(dev); - if (ret) { - printf("error: can't read firmware file list\n"); + if (ret) return -EINVAL; - } file = qfw_find_file(dev, fname); - if (!file) { - printf("error: can't find %s\n", fname); + if (!file) return -ENOENT; - } *selectp = be16_to_cpu(file->cfg.select); *sizep = be32_to_cpu(file->cfg.size); @@ -237,13 +233,27 @@ int qfw_locate_file(struct udevice *dev, const char *fname, return 0; } +int qfw_locate_file_msg(struct udevice *dev, const char *fname, + enum fw_cfg_selector *selectp, ulong *sizep) +{ + int ret; + + ret = qfw_locate_file(dev, fname, selectp, sizep); + if (ret == -EINVAL) + printf("error: can't read firmware file list\n"); + else if (ret == -ENOENT) + printf("error: can't find %s\n", fname); + + return ret; +} + int qfw_load_file(struct udevice *dev, const char *fname, ulong addr) { enum fw_cfg_selector select; ulong size; int ret; - ret = qfw_locate_file(dev, fname, &select, &size); + ret = qfw_locate_file_msg(dev, fname, &select, &size); if (ret) return ret; @@ -258,7 +268,7 @@ int qfw_get_file(struct udevice *dev, const char *fname, struct abuf *loader) ulong size; int ret; - ret = qfw_locate_file(dev, fname, &select, &size); + ret = qfw_locate_file_msg(dev, fname, &select, &size); if (ret) return ret; diff --git a/include/qfw.h b/include/qfw.h index 75aada09206..1a634d7ed5d 100644 --- a/include/qfw.h +++ b/include/qfw.h @@ -467,15 +467,33 @@ int qfw_get_file(struct udevice *dev, const char *fname, struct abuf *loader); /** * qfw_locate_file() - Locate a file in the QEMU firmware config * + * This is the silent version that doesn't print error messages + * * @dev: UCLASS_QFW device * @fname: Filename to locate * @selectp: Returns the selector for the file * @sizep: Returns the size of the file - * Return: 0 on success, -EINVAL if firmware list cannot be read or file not found + * Return: 0 on success, -EINVAL if firmware list cannot be read, -ENOENT if + * file not found */ int qfw_locate_file(struct udevice *dev, const char *fname, enum fw_cfg_selector *selectp, ulong *sizep); +/** + * qfw_locate_file_msg() - Locate a file in the QEMU firmware config + * + * This version prints error messages on failure + * + * @dev: UCLASS_QFW device + * @fname: Filename to locate + * @selectp: Returns the selector for the file + * @sizep: Returns the size of the file + * Return: 0 on success, -EINVAL if firmware list cannot be read, -ENOENT if + * file not found + */ +int qfw_locate_file_msg(struct udevice *dev, const char *fname, + enum fw_cfg_selector *selectp, ulong *sizep); + /** * cmd_qfw_e820() - Execute the 'qfw e820' command for x86 * -- 2.43.0