boot: Provide functions to set the bootm string-fields

Provide some helper functions which can set the string value of a field
in struct bootm_info from an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-08-07 05:27:28 -06:00
parent ceef5b5949
commit 3f94b241cd
4 changed files with 90 additions and 10 deletions

View File

@@ -1273,7 +1273,7 @@ int booti_run(struct bootm_info *bmi)
int bootm_boot_start(ulong addr, const char *cmdline)
{
char addr_str[30];
char addr_str[BOOTM_STRLEN];
struct bootm_info bmi;
int states;
int ret;
@@ -1296,13 +1296,34 @@ int bootm_boot_start(ulong addr, const char *cmdline)
return ret;
}
bootm_init(&bmi);
bmi.addr_img = addr_str;
bootm_set_addr_img(&bmi, addr, addr_str);
bmi.cmd_name = "bootm";
ret = bootm_run_states(&bmi, states);
return ret;
}
void bootm_set_addr_img_(struct bootm_info *bmi, ulong addr,
char str[BOOTM_STRLEN])
{
strlcpy(str, simple_xtoa(addr), BOOTM_STRLEN);
bmi->addr_img = str;
}
void bootm_set_conf_ramdisk_(struct bootm_info *bmi, ulong addr,
char str[BOOTM_STRLEN])
{
strlcpy(str, simple_xtoa(addr), BOOTM_STRLEN);
bmi->conf_ramdisk = str;
}
void bootm_set_conf_fdt_(struct bootm_info *bmi, ulong addr,
char str[BOOTM_STRLEN])
{
strlcpy(str, simple_xtoa(addr), BOOTM_STRLEN);
bmi->conf_fdt = str;
}
void bootm_init(struct bootm_info *bmi)
{
memset(bmi, '\0', sizeof(struct bootm_info));

View File

@@ -142,7 +142,7 @@ static int qfw_read_all(struct udevice *dev, struct bootflow *bflow)
static int qfw_boot(struct udevice *dev, struct bootflow *bflow)
{
const struct bootflow_img *simg, *kimg, *rimg;
char conf_fdt[20], conf_ramdisk[40], addr_img_str[20];
char conf_fdt[BOOTM_STRLEN], addr_img[BOOTM_STRLEN], conf_ramdisk[40];
struct bootm_info bmi;
int ret;
@@ -153,10 +153,8 @@ static int qfw_boot(struct udevice *dev, struct bootflow *bflow)
ret = booti_run(&bmi);
bootm_init(&bmi);
snprintf(conf_fdt, sizeof(conf_fdt), "%lx",
(ulong)map_to_sysmem(gd->fdt_blob));
snprintf(addr_img_str, sizeof(addr_img_str), "%lx", kimg->addr);
bmi.addr_img = addr_img_str;
bootm_set_conf_fdt(&bmi, map_to_sysmem(gd->fdt_blob), conf_fdt);
bootm_set_addr_img(&bmi, kimg->addr, addr_img);
snprintf(conf_ramdisk, sizeof(conf_ramdisk), "%lx:%lx", rimg->addr,
rimg->size);
bmi.conf_ramdisk = conf_ramdisk;

View File

@@ -211,13 +211,12 @@ static int vbe_abrec_boot(struct udevice *dev, struct bootflow *bflow)
img = bootflow_img_find(bflow, BFI_VBE_OEM_FIT);
if (img) {
struct bootm_info bmi;
char addr_str[30];
char addr_str[BOOTM_STRLEN];
int states;
printf("Loading OEM devicetree from FIT\n");
bootm_init(&bmi);
snprintf(addr_str, sizeof(addr_str), "%lx", img->addr);
bmi.addr_img = addr_str;
bootm_set_addr_img(&bmi, img->addr, addr_str);
bmi.cmd_name = "vbe_os";
states = BOOTM_STATE_START | BOOTM_STATE_FINDOS |
BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER |

View File

@@ -104,6 +104,68 @@ struct bootm_info {
#define bootm_x86_set(_bmi, _field, _val)
#endif
/* length of strings needed to hold an address within struct bootm_info */
enum {
BOOTM_STRLEN = 2 * sizeof(long) + 1,
};
/**
* bootm_set_addr_img() - Set the address of an image
*
* This only supports setting a single address, with no FIT configuration, etc.
*
* @bmi: Bootm information
* @addr: Address to set
* @str: String to hold the address (must be maintained by the caller)
*/
void bootm_set_addr_img_(struct bootm_info *bmi, ulong addr,
char str[BOOTM_STRLEN]);
#define bootm_set_addr_img(bmi, addr, str) \
({ \
_Static_assert(sizeof(str) >= BOOTM_STRLEN, \
"string buffer too small"); \
bootm_set_addr_img_(bmi, addr, str); \
})
/**
* bootm_set_conf_ramdisk() - Set the address of a ramdisk
*
* This only supports setting a single address, with no FIT configuration, etc.
*
* @bmi: Bootm information
* @addr: Address to set
* @str: String to hold the address (must be maintained by the caller)
*/
void bootm_set_conf_ramdisk_(struct bootm_info *bmi, ulong addr,
char str[BOOTM_STRLEN]);
#define bootm_set_conf_ramdisk(bmi, addr, str) \
({ \
_Static_assert(sizeof(str) >= BOOTM_STRLEN, \
"string buffer too small"); \
bootm_set_conf_ramdisk_(bmi, addr, str); \
})
/**
* bootm_set_conf_fdt() - Set the address of the FDT
*
* This only supports setting a single address, with no FIT configuration, etc.
*
* @bmi: Bootm information
* @addr: Address to set
* @str: String to hold the address (must be maintained by the caller)
*/
void bootm_set_conf_fdt_(struct bootm_info *bmi, ulong addr,
char str[BOOTM_STRLEN]);
#define bootm_set_conf_fdt(bmi, addr, str) \
({ \
_Static_assert(sizeof(str) >= BOOTM_STRLEN, \
"string buffer too small"); \
bootm_set_conf_fdt_(bmi, addr, str); \
})
static inline ulong bootm_len(void)
{
#ifdef CONFIG_SYS_BOOTM_LEN