Merge changes from topic "xlnx_fitimage_check" into integration

* changes:
  fix(xilinx): update correct return types
  fix(xilinx): add FIT image check in DT console
  fix(xilinx): add FIT image check in prepare_dtb
This commit is contained in:
Manish Pandey 2023-11-28 22:48:16 +01:00 committed by TrustedFirmware Code Review
commit e7486343d4
3 changed files with 118 additions and 75 deletions

View file

@ -9,4 +9,8 @@
void prepare_dtb(void);
#if defined(XILINX_OF_BOARD_DTB_ADDR)
int32_t is_valid_dtb(void *fdt);
#endif
#endif /* PLAT_FDT_H */

View file

@ -18,6 +18,7 @@
#include <drivers/console.h>
#include <libfdt.h>
#include <plat_console.h>
#include <plat_fdt.h>
#include <platform_def.h>
#include <plat_private.h>
@ -108,7 +109,7 @@ static uint32_t fdt_add_uart_info(dt_uart_info_t *info, int node, void *dtb)
{
uintptr_t base_addr;
const char *com;
uint32_t ret = 0;
int32_t ret = 0;
com = fdt_getprop(dtb, node, "compatible", NULL);
if (com != NULL) {
@ -143,16 +144,10 @@ error:
*/
static int fdt_get_uart_info(dt_uart_info_t *info)
{
int node, ret = 0;
int node = 0, ret = 0;
void *dtb = (void *)XILINX_OF_BOARD_DTB_ADDR;
if (fdt_check_header(dtb) != 0) {
ERROR("Can't read DT at %p\n", dtb);
ret = -FDT_ERR_NOTFOUND;
goto error;
}
ret = fdt_open_into(dtb, dtb, XILINX_OF_BOARD_DTB_MAX_SIZE);
ret = is_valid_dtb(dtb);
if (ret < 0) {
ERROR("Invalid Device Tree at %p: error %d\n", dtb, ret);
ret = -FDT_ERR_NOTFOUND;
@ -183,9 +178,9 @@ error:
*
* Return: On success, it returns 0; on failure, it returns an error+reason.
*/
static int check_fdt_uart_info(dt_uart_info_t *info)
static int32_t check_fdt_uart_info(dt_uart_info_t *info)
{
uint32_t ret = 0;
int32_t ret = 0;
if (info->status == 0) {
ret = -ENODEV;
@ -224,7 +219,7 @@ static void console_boot_end(console_t *boot_console)
static void setup_runtime_console(uint32_t clock, dt_uart_info_t *info)
{
static console_t bl31_runtime_console;
uint32_t rc;
int32_t rc;
#if defined(PLAT_zynqmp)
rc = console_cdns_register(info->base,
@ -265,6 +260,7 @@ static int32_t runtime_console_init(dt_uart_info_t *uart_info,
rc = fdt_get_uart_info(uart_info);
if (rc < 0) {
rc = -FDT_ERR_NOTFOUND;
goto error;
}
if (strncmp(uart_info->compatible, DT_UART_COMPAT,
@ -288,13 +284,14 @@ static int32_t runtime_console_init(dt_uart_info_t *uart_info,
WARN("BL31: No console device found in DT.\n");
}
error:
return rc;
}
#endif
void setup_console(void)
{
uint32_t rc;
int32_t rc;
uint32_t uart_clk = get_uart_clk();
#if defined(PLAT_zynqmp)

View file

@ -13,6 +13,79 @@
#include <plat_fdt.h>
#include <platform_def.h>
#if defined(XILINX_OF_BOARD_DTB_ADDR)
#define FIT_CONFS_PATH "/configurations"
static uint8_t is_fit_image(void *dtb)
{
int64_t confs_noffset;
uint8_t status = 0;
confs_noffset = fdt_path_offset(dtb, FIT_CONFS_PATH);
/*confs_noffset is only present on FIT image */
if (confs_noffset < 0) {
status = 0;
} else {
status = 1;
}
return status;
}
int32_t is_valid_dtb(void *fdt)
{
int32_t ret = 0;
if (fdt_check_header(fdt) != 0) {
ERROR("Can't read DT at %p\n", fdt);
ret = -FDT_ERR_NOTFOUND;
goto error;
}
ret = fdt_open_into(fdt, fdt, XILINX_OF_BOARD_DTB_MAX_SIZE);
if (ret < 0) {
ERROR("Invalid Device Tree at %p: error %d\n", fdt, ret);
ret = -FDT_ERR_NOTFOUND;
goto error;
}
if (is_fit_image(fdt) != 0U) {
WARN("FIT image detected, TF-A will not update DTB for DDR address space\n");
ret = -FDT_ERR_NOTFOUND;
}
error:
return ret;
}
static int add_mmap_dynamic_region(unsigned long long base_pa, uintptr_t base_va,
size_t size, unsigned int attr)
{
int ret = 0;
#if defined(PLAT_XLAT_TABLES_DYNAMIC)
ret = mmap_add_dynamic_region(base_pa, base_va, size, attr);
if (ret != 0) {
WARN("Failed to add dynamic region for dtb: error %d\n",
ret);
}
#endif
return ret;
}
static int remove_mmap_dynamic_region(uintptr_t base_va, size_t size)
{
int ret = 0;
#if defined(PLAT_XLAT_TABLES_DYNAMIC)
ret = mmap_remove_dynamic_region(base_va, size);
if (ret != 0) {
WARN("Failed to remove dynamic region for dtb:error %d\n",
ret);
}
#endif
return ret;
}
#endif
void prepare_dtb(void)
{
#if defined(XILINX_OF_BOARD_DTB_ADDR)
@ -24,75 +97,44 @@ void prepare_dtb(void)
if (!IS_TFA_IN_OCM(BL31_BASE)) {
#if defined(PLAT_XLAT_TABLES_DYNAMIC)
map_ret = mmap_add_dynamic_region((unsigned long long)dtb,
(uintptr_t)dtb,
XILINX_OF_BOARD_DTB_MAX_SIZE,
MT_MEMORY | MT_RW | MT_NS);
if (map_ret != 0) {
WARN("Failed to add dynamic region for dtb: error %d\n",
map_ret);
}
#endif
if (!map_ret) {
map_ret = add_mmap_dynamic_region((unsigned long long)dtb,
(uintptr_t)dtb,
XILINX_OF_BOARD_DTB_MAX_SIZE,
MT_MEMORY | MT_RW | MT_NS);
if (map_ret == 0) {
/* Return if no device tree is detected */
if (fdt_check_header(dtb) != 0) {
NOTICE("Can't read DT at %p\n", dtb);
} else {
ret = fdt_open_into(dtb, dtb, XILINX_OF_BOARD_DTB_MAX_SIZE);
if (ret < 0) {
ERROR("Invalid Device Tree at %p: error %d\n",
dtb, ret);
} else {
if (dt_add_psci_node(dtb)) {
WARN("Failed to add PSCI Device Tree node\n");
}
if (dt_add_psci_cpu_enable_methods(dtb)) {
WARN("Failed to add PSCI cpu enable methods in DT\n");
}
/* Reserve memory used by Trusted Firmware. */
ret = fdt_add_reserved_memory(dtb,
"tf-a",
BL31_BASE,
BL31_LIMIT
-
BL31_BASE);
if (ret < 0) {
WARN("Failed to add reserved memory nodes for BL31 to DT.\n");
}
ret = fdt_pack(dtb);
if (ret < 0) {
WARN("Failed to pack dtb at %p: error %d\n",
dtb, ret);
}
flush_dcache_range((uintptr_t)dtb,
fdt_blob_size(dtb));
INFO("Changed device tree to advertise PSCI and reserved memories.\n");
if (is_valid_dtb(dtb) == 0) {
if (dt_add_psci_node(dtb)) {
WARN("Failed to add PSCI Device Tree node\n");
}
if (dt_add_psci_cpu_enable_methods(dtb)) {
WARN("Failed to add PSCI cpu enable methods in DT\n");
}
/* Reserve memory used by Trusted Firmware. */
ret = fdt_add_reserved_memory(dtb, "tf-a",
BL31_BASE,
BL31_LIMIT - BL31_BASE);
if (ret < 0) {
WARN("Failed to add reserved memory nodes for BL31 to DT.\n");
}
ret = fdt_pack(dtb);
if (ret < 0) {
WARN("Failed to pack dtb at %p: error %d\n", dtb, ret);
}
flush_dcache_range((uintptr_t)dtb, fdt_blob_size(dtb));
INFO("Changed device tree to advertise PSCI and reserved memories.\n");
}
}
#if defined(PLAT_XLAT_TABLES_DYNAMIC)
if (!map_ret) {
ret = mmap_remove_dynamic_region((uintptr_t)dtb,
XILINX_OF_BOARD_DTB_MAX_SIZE);
ret = remove_mmap_dynamic_region((uintptr_t)dtb,
XILINX_OF_BOARD_DTB_MAX_SIZE);
if (ret != 0) {
WARN("Failed to remove dynamic region for dtb:error %d\n",
ret);
WARN("Failed to remove mmap dynamic regions.\n");
}
}
#endif
}
#endif
}