Skip to content

allwinner-v83x: boot from the SD card first, and say so in boot_media - #204

Merged
dimerr merged 1 commit into
OpenIPC:masterfrom
dimerr:allwinner-sd-boot
Oct 25, 2026
Merged

dimerr merged 1 commit into
OpenIPC:masterfrom
dimerr:allwinner-sd-boot

Conversation

@dimerr

@dimerr dimerr commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

The V831/V833 mask ROM tries the SD card before the SPI NOR: an eGON.BT0 at sector 16 of the card wins. The stub ROM only looked at the flash, so OpenIPC's SD card U-Boot images (u-boot-v831-mmc.bin / u-boot-v833-mmc.bin, mainline SPL with SPL_MMC, OpenIPC/u-boot openipc-allwinner) could not be booted.

  • With -drive if=sd holding an eGON.BT0 at 8 KiB, that is loaded instead of the flash's.
  • The medium goes into the eGON header's boot_media word (0x28: 0 SD card, 3 SPI NOR), as the ROM writes it: mainline's sunxi SPL decides from it where to load U-Boot. boot0 does not read it.

Checked:

  • The YI camera dump still boots to its kernel, also with a card attached that holds no SPL (qemu-boot/test-v831-boot.sh's card).
  • u-boot-v831-mmc.bin / u-boot-v833-mmc.bin on a card with an erased flash reach the U-Boot prompt; a card with the image and u-boot-v831-nor.bin, uImage.v831, rootfs.squashfs.v831 on FAT unbricks an erased flash (run ub, run fwupd, then the NOR boots the kernel to its root).
  • The NOR images (-nor.bin) boot as before.

Needed by the -mmc smoke legs of OpenIPC/u-boot's build-allwinner.yml.

The mask ROM tries the card before the SPI NOR: an eGON.BT0 at sector 16
of the SD card wins. The stub ROM did not look there, so OpenIPC's SD
card U-Boot images (u-boot-v83x-mmc.bin, mainline SPL) could not be
tested. It also writes the medium into the eGON header's boot_media word
(0x28; 0 card, 3 NOR) as the ROM does: mainline's sunxi SPL decides from
it where to load U-Boot.

The YI camera dump still boots to its kernel (boot0 does not read the
word), and so does a flash with a card holding no SPL.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Boot Allwinner V83x from SD before SPI NOR

✨ Enhancement 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Try a valid SD-card eGON.BT0 before SPI NOR, enabling MMC U-Boot images to boot.
• Write the selected medium into boot_media so mainline SPL loads U-Boot from the right device.
• Document SD priority and preserve SPI NOR fallback when the card has no valid boot image.
Diagram

graph TD
  SD["SD card"] --> Check{"Valid eGON?"} -->|yes| Boot["Selected boot0"] --> Header["Set boot_media"] --> SRAM["SRAM boot0"] --> Next["SPL or boot0"]
  Check -->|no| NOR["SPI NOR"] --> Boot
  subgraph Legend
    direction LR
    _source["Boot source"] ~~~ _decision{"Validation"}
  end
Loading
High-Level Assessment

Extend the existing stub-ROM boot path: it already validates and loads NOR boot0, so adding SD priority there keeps the behavior localized. A full mask-ROM emulation would be disproportionate to the boot-selection requirement.

Files changed (2) +45 / -7

Enhancement (1) +41 / -7
allwinner-v83x.cSelect SD boot0 before NOR and record its source +41/-7

Select SD boot0 before NOR and record its source

• Checks the SD drive for a valid eGON.BT0 at 8 KiB before falling back to the flash image. Sets boot_media to MMC0 or SPI NOR in the selected image before loading it, and permits booting from SD without a flash image.

qemu/hw/arm/allwinner-v83x.c

Documentation (1) +4 / -0
allwinner-v83x.mdDocument SD-first boot and boot_media values +4/-0

Document SD-first boot and boot_media values

• Explains that an eGON.BT0 at SD sector 16 takes precedence over flash. Documents the medium values written into boot_media and notes that mainline SPL reads the field while boot0 ignores it.

docs/allwinner-v83x.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. A damaged card can block flash boot 🐞 Bug ≡ Correctness
Description
aw_boot0_ok() accepts an SD image with the eGON magic and a plausible length without checking the
header checksum. When such an image is present at sector 16, the new SD-first branch selects it and
skips a valid SPI NOR boot image.
Code

qemu/hw/arm/allwinner-v83x.c[R557-559]

+                aw_boot0_ok(sdimg, AW_BOOT0_MAX, &plen)) {
+                boot0 = sdimg;
+                media = AW_BOOT_MEDIA_MMC0;
Evidence
The header identifies a checksum, but the validator checks only magic and length. The new selection
assigns the SD buffer to boot0 when that validator succeeds, and the NOR branch runs only while
boot0 is null.

qemu/hw/arm/allwinner-v83x.c[224-236]
qemu/hw/arm/allwinner-v83x.c[553-576]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A checksum-corrupt SD boot image can take priority over a valid SPI NOR image because the SD selection uses a magic-and-length-only check.
## Fix Focus Areas
- qemu/hw/arm/allwinner-v83x.c[224-236]
- qemu/hw/arm/allwinner-v83x.c[553-563]
## Recommended Fix
Validate the complete eGON image, including its checksum, before selecting the SD card. On validation failure, continue to the SPI NOR fallback.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Boot media can retain the wrong value 🐞 Bug ≡ Correctness
Description
boot0[AW_EGON_BOOT_MEDIA] = media replaces only one byte of the header’s 32-bit boot-media word.
If the source image has nonzero bytes in the rest of that word, the loaded image contains neither
documented media value when the SPL reads it.
Code

qemu/hw/arm/allwinner-v83x.c[573]

+            boot0[AW_EGON_BOOT_MEDIA] = media;
Evidence
The documentation identifies offset 0x28 as a word with values 0 and 3. Both selection paths
preserve the source header until the single-byte assignment, so its other three bytes remain
unchanged.

docs/allwinner-v83x.md[67-71]
qemu/hw/arm/allwinner-v83x.c[553-576]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The ROM stub changes only the low byte of the boot-media word, leaving the value dependent on the image’s original upper bytes.
## Fix Focus Areas
- qemu/hw/arm/allwinner-v83x.c[572-576]
## Recommended Fix
Store the selected media value as a little-endian 32-bit word at the boot-media offset in the loaded image copy.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +557 to +559
aw_boot0_ok(sdimg, AW_BOOT0_MAX, &plen)) {
boot0 = sdimg;
media = AW_BOOT_MEDIA_MMC0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. A damaged card can block flash boot 🐞 Bug ≡ Correctness

aw_boot0_ok() accepts an SD image with the eGON magic and a plausible length without checking the
header checksum. When such an image is present at sector 16, the new SD-first branch selects it and
skips a valid SPI NOR boot image.
Agent Prompt
## Issue description
A checksum-corrupt SD boot image can take priority over a valid SPI NOR image because the SD selection uses a magic-and-length-only check.

## Fix Focus Areas
- qemu/hw/arm/allwinner-v83x.c[224-236]
- qemu/hw/arm/allwinner-v83x.c[553-563]

## Recommended Fix
Validate the complete eGON image, including its checksum, before selecting the SD card. On validation failure, continue to the SPI NOR fallback.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

sdimg = boot0;
}
if (boot0) {
boot0[AW_EGON_BOOT_MEDIA] = media;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

2. Boot media can retain the wrong value 🐞 Bug ≡ Correctness

boot0[AW_EGON_BOOT_MEDIA] = media replaces only one byte of the header’s 32-bit boot-media word.
If the source image has nonzero bytes in the rest of that word, the loaded image contains neither
documented media value when the SPL reads it.
Agent Prompt
## Issue description
The ROM stub changes only the low byte of the boot-media word, leaving the value dependent on the image’s original upper bytes.

## Fix Focus Areas
- qemu/hw/arm/allwinner-v83x.c[572-576]

## Recommended Fix
Store the selected media value as a little-endian 32-bit word at the boot-media offset in the loaded image copy.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@dimerr
dimerr merged commit 8020673 into OpenIPC:master Oct 25, 2026
23 checks passed
@dimerr
dimerr deleted the allwinner-sd-boot branch October 25, 2026 06:04
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.

1 participant