
From: Simon Glass <sjg@chromium.org> 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> --- boot/bootm.c | 25 ++++++++++++++++-- boot/bootmeth_qfw.c | 8 +++--- boot/vbe_abrec_os.c | 5 ++-- include/bootm.h | 62 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 10 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index 46320363270..32232654b12 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -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)); diff --git a/boot/bootmeth_qfw.c b/boot/bootmeth_qfw.c index 3997dfa6b6f..43db8da5e24 100644 --- a/boot/bootmeth_qfw.c +++ b/boot/bootmeth_qfw.c @@ -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; diff --git a/boot/vbe_abrec_os.c b/boot/vbe_abrec_os.c index ea23c61f69c..3bf2727a6e9 100644 --- a/boot/vbe_abrec_os.c +++ b/boot/vbe_abrec_os.c @@ -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 | diff --git a/include/bootm.h b/include/bootm.h index 9ddf9fd364d..7420c657293 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -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 -- 2.43.0