Skip to content

Add SD card disk boot support for NXP T1040 (eSDHC) - #877

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:t1040_esdhc
Open

Add SD card disk boot support for NXP T1040 (eSDHC)#877
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:t1040_esdhc

Conversation

@dgarske

@dgarske dgarske commented Aug 27, 2026

Copy link
Copy Markdown
Member

This PR adds SD card disk boot to the NXP QorIQ T1040 (PPC e5500) using the on-chip Freescale eSDHC controller, making it the first big-endian target to use the src/update_disk.c boot path: wolfBoot reads the signed image from GPT/MBR A/B partitions on the card, picks the higher version, verifies it and boots it from RAM.

@dgarske dgarske self-assigned this Aug 27, 2026
Copilot AI lite review requested due to automatic review settings August 27, 2026 21:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds SD-card disk boot support for NXP QorIQ T1040 (big-endian PPC) via the on-chip eSDHC controller, and updates GPT/MBR parsing to be endian-correct across hosts/targets.

Changes:

  • Implement new eSDHC-based disk_* backend for PPC and wire disk boot (update_disk) into the nxp_t10xx build.
  • Refactor GPT/MBR parsing to read on-disk fields byte-wise (LE) instead of via packed structs; expand unit tests accordingly.
  • Update linker scripts and documentation/config to support SD disk boot on T1040.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/unit-tests/unit-disk.c Makes the GPT/MBR fixtures endian-robust and adds offset/CRC regression tests.
src/gpt.c Switches GPT/MBR parsing to explicit little-endian loads and avoids packed-struct aliasing.
src/disk.c Makes MBR partition parsing endian-correct by reading fields via LE helpers.
include/gpt.h Adds shared gpt_le16/32/64 helpers and MBR field offsets.
hal/nxp_esdhc.c Adds a new eSDHC SD-card PIO block driver implementing disk_* API for PPC.
hal/nxp_t10xx.c Includes the eSDHC driver into the HAL translation unit for access to static clock helpers.
arch.mk Selects disk-boot update path and links src/disk.o for nxp_t10xx when SD/eMMC is enabled.
options.mk Avoids linking Cadence SDHCI driver on PPC to prevent symbol collisions with eSDHC backend.
hal/nxp_t1040.ld / hal/nxp_t1040_stage1.ld Adjusts DRAM LENGTH constants around the 2GB boundary.
hal/nxp_t1024.ld / hal/nxp_t1024_stage1.ld Same DRAM LENGTH adjustment for T1024.
config/examples/nxp-t1040-sdcard.config Adds a sample config enabling SD disk boot and related limits/defines.
docs/Targets.md Documents T1040 SD-card boot workflow and example partitioning.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 246 to 247
boot_sig = (uint16_t *)(fake_disk + GPT_MBR_BOOTSIG_OFFSET);
*boot_sig = GPT_MBR_BOOTSIG_VALUE;
Comment on lines +128 to +134
static void finalize_gpt_header_crc(uint8_t *hdr)
{
uint32_t hdr_size = 92;

hdr->part_crc = test_crc32(array, array_len);
d_put32(hdr + D_HDR_CRC32, 0);
d_put32(hdr + D_HDR_CRC32, test_crc32(hdr, hdr_size));
}
Comment on lines +142 to 150
static void finalize_gpt_part_array_crc(uint8_t *hdr)
{
uint32_t start_array = d_get32(hdr + D_HDR_START_ARRAY);
uint32_t n_part = d_get32(hdr + D_HDR_N_PART);
uint32_t array_sz = d_get32(hdr + D_HDR_ARRAY_SZ);
uint8_t *array = fake_disk + (start_array * GPT_SECTOR_SIZE);

d_put32(hdr + D_HDR_PART_CRC, test_crc32(array, n_part * array_sz));
}
Comment thread hal/nxp_esdhc.c
Comment on lines +552 to +590
int ret;

if ((count == 0U) || (buf == NULL)) {
return -1;
}

/* Standard-capacity cards are addressed in bytes, high-capacity in
* blocks. Getting this backwards reads from a wildly wrong offset. */
arg = (g_esdhc_hc != 0) ? (uint32_t)lba
: (uint32_t)(lba * SD_BLOCK_SIZE);

/* Read watermark in words. */
*ESDHC_REG(ESDHC_WML) = (SD_BLOCK_SIZE / 4U);
*ESDHC_REG(ESDHC_BLKATTR) = ESDHC_BLKATTR_CNT(count) |
ESDHC_BLKATTR_SIZE(SD_BLOCK_SIZE);

xfertyp = ESDHC_XFERTYP_DPSEL | ESDHC_XFERTYP_DTDSEL |
ESDHC_XFERTYP_RSPTYP_48 | ESDHC_XFERTYP_CICEN | ESDHC_XFERTYP_CCCEN;
if (count > 1U) {
xfertyp |= ESDHC_XFERTYP_MSBSEL | ESDHC_XFERTYP_BCEN |
ESDHC_XFERTYP_AC12EN;
ret = esdhc_send_cmd(SD_CMD_READ_MULTI, arg, xfertyp, NULL);
}
else {
ret = esdhc_send_cmd(SD_CMD_READ_SINGLE, arg, xfertyp, NULL);
}
if (ret != 0) {
ESDHC_DBG("esdhc: read cmd failed at lba %u\r\n", (uint32_t)lba);
return ret;
}

for (i = 0; i < count; i++) {
ret = esdhc_read_block(buf + ((size_t)i * SD_BLOCK_SIZE));
if (ret != 0) {
return ret;
}
}

return esdhc_wait_irq(ESDHC_IRQSTAT_TC, ESDHC_IRQSTAT_DAT_ERR, 5000000U);
Comment thread hal/nxp_t10xx.c
Comment on lines +1180 to +1185
/* eSDHC SD card driver for the disk boot path. Included here (not built
* standalone) because it uses hal_get_bus_clk(), which is static in
* nxp_ppc.c. Kept out of the size-constrained stage1 loader. */
#if defined(DISK_SDCARD) && !defined(BUILD_LOADER_STAGE1)
#include "nxp_esdhc.c"
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants