mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-08-14 19:26:58 +02:00
The set_dfu_alt_info() function calls the ALLOC_CACHE_ALIGN_BUFFER()
macro to declare a `buf' variable pointer into an array allocated on the
stack. It then calls the memset() function to clear the useable portion
of the array using the idiomatic expression `sizeof(buf)'.
While this would indeed work fine for an array, in the present case we
end up clearing only the size of a pointer.
Fix this by specifying the explicit size `DFU_ALT_BUF_LEN' instead.
Fixes: 6b403ca4dc
("fwu: DeveloperBox: add support for FWU")
Signed-off-by: Vincent Stehlé <vincent.stehle@arm.com>
Cc: Masahisa Kojima <kojima.masahisa@socionext.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Jassi Brar <jaswinder.singh@linaro.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
Link: https://lore.kernel.org/r/20250407170529.893307-2-vincent.stehle@arm.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
69 lines
1.4 KiB
C
69 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Copyright (c) 2023, Linaro Limited
|
|
*/
|
|
|
|
#include <efi_loader.h>
|
|
#include <fwu.h>
|
|
#include <fwu_mdata.h>
|
|
#include <memalign.h>
|
|
#include <mtd.h>
|
|
|
|
#define DFU_ALT_BUF_LEN 256
|
|
|
|
/* Generate dfu_alt_info from partitions */
|
|
void set_dfu_alt_info(char *interface, char *devstr)
|
|
{
|
|
ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
|
|
struct mtd_info *mtd;
|
|
int ret;
|
|
|
|
memset(buf, 0, DFU_ALT_BUF_LEN);
|
|
|
|
mtd_probe_devices();
|
|
|
|
mtd = get_mtd_device_nm("nor1");
|
|
if (IS_ERR_OR_NULL(mtd))
|
|
return;
|
|
|
|
ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd);
|
|
if (ret < 0) {
|
|
log_err("Error: Failed to generate dfu_alt_info. (%d)\n", ret);
|
|
return;
|
|
}
|
|
log_debug("Make dfu_alt_info: '%s'\n", buf);
|
|
|
|
env_set("dfu_alt_info", buf);
|
|
}
|
|
|
|
/**
|
|
* fwu_plat_get_bootidx() - Get the value of the boot index
|
|
* @boot_idx: Boot index value
|
|
*
|
|
* Get the value of the bank(partition) from which the platform
|
|
* has booted. This value is passed to U-Boot from the earlier
|
|
* stage bootloader which loads and boots all the relevant
|
|
* firmware images
|
|
*/
|
|
void fwu_plat_get_bootidx(uint *boot_idx)
|
|
{
|
|
int ret;
|
|
u32 buf;
|
|
size_t readlen;
|
|
struct mtd_info *mtd;
|
|
|
|
*boot_idx = 0;
|
|
|
|
mtd_probe_devices();
|
|
mtd = get_mtd_device_nm("nor1");
|
|
if (IS_ERR_OR_NULL(mtd))
|
|
return;
|
|
|
|
ret = mtd_read(mtd, SCB_PLAT_METADATA_OFFSET, sizeof(buf),
|
|
&readlen, (u_char *)&buf);
|
|
if (ret < 0)
|
|
return;
|
|
|
|
*boot_idx = buf;
|
|
}
|