qfw: Silence the message when opt/u-boot/bootcmd is not found

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>
This commit is contained in:
Simon Glass
2025-10-25 08:10:55 +01:00
parent 9c3919f31e
commit eb2dc2bac8
2 changed files with 37 additions and 9 deletions

View File

@@ -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;

View File

@@ -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
*