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 8d6ab46
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 8 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
4 changes: 1 addition & 3 deletions hal/nxp_t1024.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ int hal_dts_fixup(void* dts_addr)
uint32_t liodns[2];
if (!ci)
break;
i = *ci;
i = fdt32_to_cpu(*ci);

liodns[0] = qp_info[i].dliodn;
liodns[1] = qp_info[i].fliodn;
Expand All @@ -2055,8 +2055,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
3 changes: 2 additions & 1 deletion src/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,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
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.
205 changes: 204 additions & 1 deletion tools/fdt-parser/fdt-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <stdio.h>
#include <stdlib.h>

static int gEnableUnitTest = 0;
#define UNIT_TEST_GROW_SIZE 1024

void print_bin(const uint8_t* buffer, uint32_t length)
{
uint32_t i, notprintable = 0;
Expand Down Expand Up @@ -113,6 +116,194 @@ int dts_parse(void* dts_addr)
}
}

if (gEnableUnitTest) {
int off, i;
uint32_t *reg;

/* Test case for "nxp_t1024.dtb" */
#define DDR_ADDRESS 0
#define DDR_SIZE (2048ULL * 1024ULL * 1024ULL)
#define CPU_NUMCORES 0
#define SPIN_TABLE_ADDR 0x7FF01900
#define ENTRY_SIZE 64
#define SYS_CLK (100000000) /* 100MHz */
#define PLAT_CLK (SYS_CLK * 4)
#define BUS_CLK (PLAT_CLK / 2)
#define TIMEBASE_HZ (PLAT_CLK / 16)

#define CCSRBAR (0xFE000000)
#define DCFG_BASE (CCSRBAR + 0xE0000)
#define DCFG_USB1LIODNR ((volatile uint32_t*)(DCFG_BASE + 0x520))
#define DCFG_USB2LIODNR ((volatile uint32_t*)(DCFG_BASE + 0x524))
#define DCFG_SDMMCLIODNR ((volatile uint32_t*)(DCFG_BASE + 0x530))
#define DCFG_SATALIODNR ((volatile uint32_t*)(DCFG_BASE + 0x550))
#define DCFG_DIULIODNR ((volatile uint32_t*)(DCFG_BASE + 0x570))
#define DCFG_TDMDMALIODNR ((volatile uint32_t*)(DCFG_BASE + 0x574))
#define DCFG_QELIODNR ((volatile uint32_t*)(DCFG_BASE + 0x578))
#define DCFG_DMA1LIODNR ((volatile uint32_t*)(DCFG_BASE + 0x580))
#define DCFG_DMA2LIODNR ((volatile uint32_t*)(DCFG_BASE + 0x584))

#define QMAN_CCSR_BASE (CCSRBAR + 0x318000)
#define QMAN_LIODNR ((volatile uint32_t*)(QMAN_CCSR_BASE + 0xD08))

#define BMAN_CCSR_BASE (CCSRBAR + 0x31A000)
#define BMAN_LIODNR ((volatile uint32_t*)(BMAN_CCSR_BASE + 0xD08))

#define PCI_BASE(n) (0x240000 + ((n) * 0x10000))
#define PCIE_LIODN(n) ((volatile uint32_t*)(PCI_BASE(n) + 0x40))

struct qportal_info {
uint16_t dliodn; /* DQRR LIODN */
uint16_t fliodn; /* frame data LIODN */
uint16_t liodn_offset;
uint8_t sdest;
};

#define SET_QP_INFO(dqrr, fdata, off, dest) \
{ .dliodn = dqrr, .fliodn = fdata, .liodn_offset = off, .sdest = dest }

#define QMAN_NUM_PORTALS 10
static const struct qportal_info qp_info[QMAN_NUM_PORTALS] = {
/* dqrr liodn, frame data liodn, liodn off, sdest */
SET_QP_INFO(1, 27, 1, 0),
SET_QP_INFO(2, 28, 1, 0),
SET_QP_INFO(3, 29, 1, 1),
SET_QP_INFO(4, 30, 1, 1),
SET_QP_INFO(5, 31, 1, 2),
SET_QP_INFO(6, 32, 1, 2),
SET_QP_INFO(7, 33, 1, 3),
SET_QP_INFO(8, 34, 1, 3),
SET_QP_INFO(9, 35, 1, 0),
SET_QP_INFO(10, 36, 1, 0)
};

struct liodn_id_table {
const char* compat;
uint32_t id;
void* reg_offset;
};
#define SET_LIODN(fdtcomp, liodn, reg) \
{.compat = fdtcomp, .id = liodn, .reg_offset = (void*)reg}

static const struct liodn_id_table liodn_tbl[] = {
SET_LIODN("fsl-usb2-mph", 553, DCFG_USB1LIODNR),
SET_LIODN("fsl-usb2-dr", 554, DCFG_USB2LIODNR),
SET_LIODN("fsl,esdhc", 552, DCFG_SDMMCLIODNR),
SET_LIODN("fsl,pq-sata-v2", 555, DCFG_SATALIODNR),
SET_LIODN("fsl,tdm1.0", 560, DCFG_TDMDMALIODNR),
SET_LIODN("fsl,qe", 559, DCFG_QELIODNR),
SET_LIODN("fsl,elo3-dma", 147, DCFG_DMA1LIODNR),
SET_LIODN("fsl,elo3-dma", 227, DCFG_DMA2LIODNR),

SET_LIODN("fsl,qman", 62, QMAN_LIODNR),
SET_LIODN("fsl,bman", 63, BMAN_LIODNR),
SET_LIODN("fsl,qoriq-pcie-v2.4", 148, PCIE_LIODN(1)),
SET_LIODN("fsl,qoriq-pcie-v2.4", 228, PCIE_LIODN(2)),
SET_LIODN("fsl,qoriq-pcie-v2.4", 308, PCIE_LIODN(3)),
};

/* expand total size */
fdt_set_totalsize(fdt, fdt_totalsize(fdt) + UNIT_TEST_GROW_SIZE);

/* expand total size */
fdt->totalsize += 1024; /* expand by 1KB */
wolfBoot_printf("FDT: Expanded (1KB) to %d bytes\n",
fdt_totalsize(fdt));

/* fixup the memory region - single bank */
off = fdt_find_devtype(fdt, -1, "memory");
if (off != -FDT_ERR_NOTFOUND) {
/* build addr/size as 64-bit */
uint8_t ranges[sizeof(uint64_t) * 2], *p = ranges;
*(uint64_t*)p = cpu_to_fdt64(DDR_ADDRESS);
p += sizeof(uint64_t);
*(uint64_t*)p = cpu_to_fdt64(DDR_SIZE);
p += sizeof(uint64_t);
fdt_setprop(fdt, off, "reg", ranges, (int)(p - ranges));
wolfBoot_printf("FDT: Set memory, start=0x%x, size=0x%x\n",
DDR_ADDRESS, (uint32_t)DDR_SIZE);
}

/* fixup CPU status and, release address and enable method */
off = fdt_find_devtype(fdt, -1, "cpu");
while (off != -FDT_ERR_NOTFOUND) {
int core;
uint64_t core_spin_table_addr;

reg = (uint32_t*)fdt_getprop(fdt, off, "reg", NULL);
if (reg == NULL || *reg >= CPU_NUMCORES)
break;
core = *reg;

/* calculate location of spin table for core */
core_spin_table_addr = (uint64_t)((uintptr_t)(
(uint8_t*)SPIN_TABLE_ADDR + (core * ENTRY_SIZE)));

fdt_fixup_str(fdt, off, "cpu", "status", (core == 0) ? "okay" : "disabled");
fdt_fixup_val64(fdt, off, "cpu", "cpu-release-addr", core_spin_table_addr);
fdt_fixup_str(fdt, off, "cpu", "enable-method", "spin-table");
fdt_fixup_val(fdt, off, "cpu", "timebase-frequency", TIMEBASE_HZ);
fdt_fixup_val(fdt, off, "cpu", "clock-frequency", PLAT_CLK);
fdt_fixup_val(fdt, off, "cpu", "bus-frequency", PLAT_CLK);

off = fdt_find_devtype(fdt, off, "cpu");
}

/* fixup the soc clock */
off = fdt_find_devtype(fdt, -1, "soc");
if (off != -FDT_ERR_NOTFOUND) {
fdt_fixup_val(fdt, off, "soc", "bus-frequency", PLAT_CLK);
}

/* fixup the serial clocks */
off = fdt_find_devtype(fdt, -1, "serial");
while (off != -FDT_ERR_NOTFOUND) {
fdt_fixup_val(fdt, off, "serial", "clock-frequency", BUS_CLK);
off = fdt_find_devtype(fdt, off, "serial");
}

/* fixup the QE bridge and bus blocks */
off = fdt_find_devtype(fdt, -1, "qe");
if (off != -FDT_ERR_NOTFOUND) {
fdt_fixup_val(fdt, off, "qe", "clock-frequency", BUS_CLK);
fdt_fixup_val(fdt, off, "qe", "bus-frequency", BUS_CLK);
fdt_fixup_val(fdt, off, "qe", "brg-frequency", BUS_CLK/2);
}

/* fixup the LIODN */
for (i=0; i<(int)(sizeof(liodn_tbl)/sizeof(struct liodn_id_table)); i++) {
off = fdt_node_offset_by_compatible(fdt, -1, liodn_tbl[i].compat);
if (off >= 0) {
fdt_fixup_val(fdt, off, liodn_tbl[i].compat, "fsl,liodn",
liodn_tbl[i].id);
}
}

/* 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 = fdt32_to_cpu(*ci);

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));

off = fdt_node_offset_by_compatible(fdt, off, "fsl,qman-portal");
}

/* mpic clock */
off = fdt_find_devtype(fdt, -1, "open-pic");
if (off != -FDT_ERR_NOTFOUND) {
fdt_fixup_val(fdt, off, "open-pic", "clock-frequency", BUS_CLK);
}
}

return 0;
}

Expand All @@ -127,6 +318,12 @@ int main(int argc, char *argv[])
if (argc >= 2) {
filename = argv[1];
}
while (argc > 2) {
if (strcmp(argv[argc-1], "-t") == 0) {
gEnableUnitTest = 1;
}
argc--;
}

printf("FDT Parser (%s):\n", filename);
if (filename == NULL) {
Expand All @@ -144,7 +341,13 @@ int main(int argc, char *argv[])
fseek(f, 0, SEEK_END);
imageSz = ftell(f);
fseek(f, 0, SEEK_SET);
image = malloc(imageSz);
if (gEnableUnitTest) {
/* add extra 1KB for testing expansion room */
image = malloc(imageSz + UNIT_TEST_GROW_SIZE);
}
else {
image = malloc(imageSz);
}
if (image == NULL) {
printf("Allocate %lu failed!\n", imageSz);
ret = -1;
Expand Down
Binary file added tools/fdt-parser/nxp_t1024.dtb
Binary file not shown.

0 comments on commit 8d6ab46

Please sign in to comment.