Skip to content

Commit

Permalink
Add automated test case for NXP T1024 FDT.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Jan 5, 2024
1 parent 3812c30 commit a3d289b
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 23 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/test-parse-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test parsing tools (elf and fdt)

on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]

jobs:

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Install cross compilers
run: |
sudo apt-get install -y gcc-arm-none-eabi gcc-powerpc-linux-gnu
- name: make distclean
run: |
make distclean
- name: Select config
run: |
cp config/examples/nxp-t1024.config .config
- name: Build wolfBoot
run: |
make
- name: Build tools
run: |
make elf-parser
make fdt-parser
- name: Run elf-parser test
run: |
./tools/elf-parser/elf-parser
- name: Run fdt-parser test (nxp_t1024.dtb)
run: |
./tools/fdt-parser/fdt-parser ./tools/fdt-parser/nxp_t1024.dtb -t
21 changes: 13 additions & 8 deletions hal/nxp_t1024.c
Original file line number Diff line number Diff line change
Expand Up @@ -1984,9 +1984,12 @@ int hal_dts_fixup(void* dts_addr)
uint64_t core_spin_table;

reg = (uint32_t*)fdt_getprop(fdt, off, "reg", NULL);
if (reg == NULL || *reg >= CPU_NUMCORES)
if (reg == NULL)
break;
core = *reg;
core = (int)fdt32_to_cpu(*reg);
if (core >= CPU_NUMCORES) {
break; /* invalid core index */
}

/* calculate location of spin table for core */
core_spin_table = (uint64_t)((uintptr_t)(
Expand Down Expand Up @@ -2035,14 +2038,18 @@ int hal_dts_fixup(void* dts_addr)
/* fixup the QMAN portals */
off = fdt_node_offset_by_compatible(fdt, -1, "fsl,qman-portal");
while (off != -FDT_ERR_NOTFOUND) {
const int *ci = fdt_getprop(fdt, off, "cell-index", NULL);
uint32_t liodns[2];
if (!ci)
break;
i = *ci;

reg = (uint32_t*)fdt_getprop(fdt, off, "cell-index", NULL);
if (reg == NULL)
break;
i = (int)fdt32_to_cpu(*reg);
if (i >= QMAN_NUM_PORTALS) {
break; /* invalid index */
}
liodns[0] = qp_info[i].dliodn;
liodns[1] = qp_info[i].fliodn;

wolfBoot_printf("FDT: Set %s@%d (%d), %s=%d,%d\n",
"qman-portal", i, off, "fsl,liodn", liodns[0], liodns[1]);
fdt_setprop(fdt, off, "fsl,liodn", liodns, sizeof(liodns));
Expand All @@ -2055,8 +2062,6 @@ int hal_dts_fixup(void* dts_addr)
if (off != -FDT_ERR_NOTFOUND) {
fdt_fixup_val(fdt, off, "open-pic", "clock-frequency", hal_get_bus_clk());
}


#endif /* !BUILD_LOADER_STAGE1 */
return 0;
}
Expand Down
6 changes: 4 additions & 2 deletions include/fdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset);
int fdt_next_property_offset(const void *fdt, int offset);
const struct fdt_property *fdt_get_property_by_offset(const void *fdt, int offset, int *lenp);

const char *fdt_get_name(const void *fdt, int nodeoffset, int *len);
const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
const char* fdt_get_name(const void *fdt, int nodeoffset, int *len);
const char* fdt_get_string(const void *fdt, int stroffset, int *lenp);

const void *fdt_getprop(const void *fdt, int nodeoffset, const char *name, int *lenp);
int fdt_setprop(void *fdt, int nodeoffset, const char *name, const void *val, int len);
Expand All @@ -145,6 +145,8 @@ int fdt_fixup_str(void* fdt, int off, const char* node, const char* name, const
int fdt_fixup_val(void* fdt, int off, const char* node, const char* name, uint32_t val);
int fdt_fixup_val64(void* fdt, int off, const char* node, const char* name, uint64_t val);

int fdt_shrink(void* fdt);

#ifdef __cplusplus
}
#endif
Expand Down
22 changes: 17 additions & 5 deletions src/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "hal.h"
#include "printf.h"
#include "string.h"
#include <stdint.h>

uint32_t cpu_to_fdt32(uint32_t x)
{
Expand Down Expand Up @@ -293,7 +294,7 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
return prop;
}

const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
const char* fdt_get_name(const void *fdt, int nodeoffset, int *len)
{
int err;
const struct fdt_node_header *nh = fdt_offset_ptr_(fdt, nodeoffset);
Expand All @@ -315,7 +316,7 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
return name;
}

const char *fdt_get_string(const void *fdt, int stroffset, int *lenp)
const char* fdt_get_string(const void *fdt, int stroffset, int *lenp)
{
const char *s = (const char*)fdt + fdt_off_dt_strings(fdt) + stroffset;
if (lenp) {
Expand Down Expand Up @@ -370,7 +371,7 @@ const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
return fdt_get_property_namelen(fdt, nodeoffset, name, strlen(name), lenp);
}

struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
const char *name, int *lenp)
{
return (struct fdt_property*)(uintptr_t)
Expand Down Expand Up @@ -443,7 +444,7 @@ static int fdt_splice_string_(void *fdt, int newlen)
return 0;
}

const char *fdt_find_string_(const char *strtab, int tabsize, const char *s)
const char* fdt_find_string_(const char *strtab, int tabsize, const char *s)
{
int len = strlen(s) + 1;
const char *last = strtab + tabsize - len;
Expand Down Expand Up @@ -584,7 +585,8 @@ int fdt_fixup_val(void* fdt, int off, const char* node, const char* name,
int fdt_fixup_val64(void* fdt, int off, const char* node, const char* name,
uint64_t val)
{
wolfBoot_printf("FDT: Set %s (%d), %s=%lu\n", node, off, name, val);
wolfBoot_printf("FDT: Set %s (%d), %s=%llu\n",
node, off, name, (unsigned long long)val);
val = cpu_to_fdt64(val);
fdt_setprop(fdt, off, name, &val, sizeof(val));
return off;
Expand Down Expand Up @@ -657,4 +659,14 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
return offset;
}

int fdt_shrink(void* fdt)
{
uint32_t total_size;
/* the last part of the FDT is the DT string, so use that offset to
* determine total size */
total_size = fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);

return fdt_set_totalsize(fdt, total_size);
}

#endif /* MMU && !BUILD_LOADER_STAGE1 */
9 changes: 7 additions & 2 deletions test-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ endif

ifeq ($(TARGET),sim)
APP_OBJS=app_$(TARGET).o ../test-app/libwolfboot.o ../hal/$(TARGET).o
# Override linker flags
LDFLAGS=-Wl,-Map=image.map
# LD on MacOS does not support "-Map="
LDMAPSUPPORTED=$(shell $(CC) -Wl,-Map=image.map 2>&1 | grep 'unknown option')
LDFLAGS=
ifeq ($(LDMAPSUPPORTED),)
# Override linker flags
LDFLAGS+=-Wl,-Map=image.map
endif
endif

ifeq ($(EXT_FLASH),1)
Expand Down
2 changes: 1 addition & 1 deletion tools/elf-parser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

CC=gcc
CFLAGS=-Wall -g -ggdb
CFLAGS+=-I../../include -DWOLFBOOT_ELF -DELF_PARSER -DPRINTF_ENABLED
CFLAGS+=-I../../include -DWOLFBOOT_ELF -DELF_PARSER -DDEBUG_ELF -DPRINTF_ENABLED
EXE=elf-parser

LIBS=
Expand Down
Binary file added tools/fdt-parser/bcm2710-rpi-3-b.dtb
Binary file not shown.
Loading

0 comments on commit a3d289b

Please sign in to comment.