8000 Update boot-mvebu.cmd by djurny · Pull Request #8166 · armbian/build · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update boot-mvebu.cmd #8166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 10, 2025
Merged

Update boot-mvebu.cmd #8166

merged 4 commits into from
May 10, 2025

Conversation

djurny
Copy link
Contributor
@djurny djurny commented May 7, 2025

Fix for #8165

Determine the load address for kernel and initial ramdisk based on DT and kernel image size.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

  • Minor changes to DT handling:
    • Added ${fdt_extrasize} variable to fdt resize ${fdt_extrasize} at every point a fdt resize is done.
    • Removed the fdt apply and fdt resize from the SPI -SATA workaround as fdt already applied and resized.
    • Added fdt resize ${fdt_extrasize} at fallback to original DT in case any overlay fails to apply.
  • Based on the current U-Boot load addresses for DT, kernel and initrd, reordered the loads.
  • Determine the totalsize of the DT with a fallback to calculating it based on DT filesize + size increases due to fdt resize.
  • Align all calculated load addresses to 4k boundary, but can be overridden with a different ${addr_align}.
  • Added some feedback to the user as to where the files are loaded to.

GitHub issue reference: 8165
Jira reference number AR-2676

Documentation summary for feature / change

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.

  • Test A
    Helios4 with U-Boot 2018.11 and linux-image-current-mvebu 25.5.0-trunk.435.
    As fdt header get <var> totalsize is not working on this version of U-Boot, the fallback correctly determines the DT size.
    Box boots without issue.
  • Test B
    Orangepi zero with U-Boot 2021.04-armbian (linux-u-boot-orangepizero-current 25.5.0-trunk.496) and linux-image-current-sunxi 25.5.0-trunk.496.
    This was a test of the concept itself, to see if the calculation methods would work. On this U-Boot the fdt header get <var> totalsize is working.
    SBC boots without issue.

Checklist:

Please delete options that are not relevant.

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

Fix for armbian#8165

Determine the load address for kernel and initial ramdisk based on DT and kernel image size.
@djurny djurny requested a review from igorpecovnik as a code owner May 7, 2025 20:35
Copy link
8000
Contributor
coderabbitai bot commented May 7, 2025

"""

Walkthrough

The boot script in config/bootscripts/boot-mvebu.cmd was updated to explicitly define and align load addresses for the device tree (DT), kernel, and ramdisk, replacing a single generic load address. A new environment variable fdt_extrasize was introduced to specify additional space for dynamic DT resizing. The script aligns addresses to 4KB boundaries and prints progress messages during loading steps. DT overlays are applied with improved error handling by reloading and resizing the DT if overlay application fails. Kernel and ramdisk loading occur after DT processing at calculated aligned addresses, followed by booting with bootz.

Suggested labels

ready to merge

Suggested reviewers

  • igorpecovnik
    """

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1107021 and 17329c1.

📒 Files selected for processing (1)
  • config/bootscripts/boot-mvebu.cmd (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
config/bootscripts/boot-mvebu.cmd (1)
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.938Z
Learning: The 4KB (0x1000) boundary used for device tree size calculations in U-Boot scripts is specific to how the `fdt resize` command works internally and should remain hardcoded rather than being tied to adjustable alignment variables.
🔇 Additional comments (11)
config/bootscripts/boot-mvebu.cmd (11)

6-9: Improved memory layout with documented purposes and max sizes

The script now defines specific load addresses for each boot component with clear comments about their maximum sizes, making the memory layout more predictable and maintainable. This prevents potential memory overlaps during boot.


22-24: Well-structured memory management configuration

The addition of fdt_extrasize, align_to, and the alignment function improves DT handling and memory management:

  • fdt_extrasize reserves additional space for device tree modifications
  • align_to defines a standard 4KB alignment boundary
  • align_addr_next ensures proper memory alignment between loaded components

This structured approach prevents memory address collision during the boot process.


28-31: Improved logging of environment loading

The added echo statement improves debugging visibility by explicitly showing where the environment is being loaded from and to which memory address.


35-37: Enhanced DT loading feedback

The updated echo statement provides clearer feedback about the DT loading process and destination address, improving traceability during boot.


38-40: Device tree initialization with extra size

The script now resizes the device tree using the fdt_extrasize variable immediately after loading, ensuring sufficient space for subsequent overlay operations.


41-45: Robust command availability detection

Good implementation of a self-test for the setexpr command availability. This ensures compatibility with older U-Boot versions that might not support this command, falling back to the pre-configured addresses when necessary.


47-64: Comprehensive device tree size calculation

The implementation intelligently handles device tree size determination:

  1. First attempts to get the total size from the DT header
  2. If not supported, calculates size based on file size, properly aligned to 4KB boundary
  3. Adds the extra size for overlays and fixups
  4. Calculates and aligns the next address for the kernel

The hardcoded 0x1000 (4KB) value is correctly used for DT boundary calculations as it matches the internal fdt resize implementation, per the provided learning context.


80-86: Improved error recovery for overlay failures

When overlay application fails, the script now properly:

  1. Reloads the original device tree
  2. Re-initializes it with fdt addr
  3. Resizes it with the extra space allocation

This ensures a clean recovery from overlay errors without memory corruption.


115-117: Clear kernel loading process

The added echo statement and reorganized loading sequence (after all DT operations) improves clarity and ensures that kernel loading happens at the properly calculated address.


118-122: Dynamic ramdisk address calculation

The script calculates the ramdisk load address based on the kernel size, with proper alignment. This eliminates the risk of memory overlap between the kernel and ramdisk, especially with varying kernel sizes.


124-128: Enhanced ramdisk loading and boot feedback

The added echo statements for ramdisk loading and kernel booting improve visibility into the boot process, making debugging easier when issues occur.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added 05 Milestone: Second quarter release size/small PR with less then 50 lines Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... labels May 7, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label May 7, 2025
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
config/bootscripts/boot-mvebu.cmd (5)

18-20: Make alignment & extra-size parameters self-consistent and documented
Great to see fdt_extrasize and addr_align promoted to variables – this makes the script far more portable.
Two small improvements would tighten things up:

  1. Document in a short comment that both values must be hexadecimal (or decimal) and that addr_align must be a power-of-two.
  2. Re-use ${addr_align} wherever 0x1000 is hard-coded later (lines 42-44) so that a single variable truly controls alignment.

20-20: Local scratch variable modulo can leak into the persistent U-Boot environment
setexpr modulo … stores the result in the global environment.
If the board re-boots without power-cycling, the previous value stays around and could pollute other scripts.
Prepend local. to the variable name (U-Boot 2020.04+) or setexpr _mod … to minimise the risk:

-setexpr modulo ${addr_next} % ${addr_align}
-if itest $modulo -gt 0 ; then
+setexpr _mod ${addr_next} % ${addr_align}
+if itest $_mod -gt 0 ; then

47-49: Comment does not match implementation
The note “add 'extrasize' before aligning” is misleading – you actually add it after the first alignment and before the final addr_next alignment.
Either update the comment or move the addition above the alignment step.


104-113: Guard against missing kernel / ramdisk and propagate their sizes
load ${devtype} … ${prefix}zImage and …uInitrd can fail silently (e.g., wrong partition).
Consider surrounding each load with if and aborting on failure, otherwise bootz will jump into undefined memory.
Second, after loading the ramdisk you may want to advance and align addr_next again so scripts that chain-load additional blobs (e.g., firmware) can continue to reuse the helper.


115-116: Minor: echo source address range for easier debugging
Right before bootz, printing the computed ${kernel_addr_r}-${addr_next} and ${ramdisk_addr_r}-${filesize} ranges greatly simplifies debugging overlapping issues on constrained boards.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 834de5f and 1107021.

📒 Files selected for processing (1)
  • config/bootscripts/boot-mvebu.cmd (2 hunks)
🔇 Additional comments (1)
config/bootscripts/boot-mvebu.cmd (1)

72-75: Potential under-allocation after overlay failure
When overlays fail you reload the smaller original DT and call fdt resize ${fdt_extrasize}, but you do not re-compute fdt_totalsize.
If the over-laid DT had grown beyond original + extrasize, kernel_addr_r now points further away than necessary – harmless but wastes RAM.
Conversely, if fdt resize grew the blob more than the first calculation (unlikely but possible with a different ${fdt_extrasize}), kernel/ramdisk could overlap.
At minimum, please add a safety note or recompute fdt_totalsize in this branch.

@djurny
Copy link
Contributor Author
djurny commented May 7, 2025

Would be great if @0r31 (due to db6a2dd17) and @Heisath (due to this) can have a look as well.
Thanks in advance,
Groetjes

@djurny djurny marked this pull request as draft May 8, 2025 14:21
@djurny
Copy link
Contributor Author
djurny commented May 8, 2025

Testing by @igorpecovnik showed that U-Boot from a freshly built image does not have the setexpr command configured.

https://forum.armbian.com/topic/49440-helios4-doesnt-boot-after-upgrading-to-linux-6671-linux-image-current-mvebu_2520-trunk343/#findComment-218092

Notes to self:

  • Update boot.cmd with the remarks from this thread.
  • Switch to hardcoded load address values with some headroom in case setexpr not available - not sure if we can expect people to update U-Boot all the time.
  • Test with built image instead of Kobol's 2018 version.

- Updated names to reflect function better.
- Followed coding style of rest of the file, e.g. `test` instead of `itest` and `if ... ; then`.
- If `setexpr` fails, use configured addresses - either the ones defined in boot.cmd or set by armbianEnv.txt.
@github-actions github-actions bot added size/medium PR with more then 50 and less then 250 lines and removed size/small PR with less then 50 lines Ready to merge Reviewed, tested and ready for merge labels May 9, 2025
Changed the DT size back to 256KiB as there is no reason to trim it actually.
@djurny
Copy link
Contributor Author
djurny commented May 9, 2025

Changes for 17329c1:

  • Added a test if setexpr works and fallback to configured load addresses instead of calculated ones.
  • Configured load addresses have been updated to allow for the following:
    • DT: 256 KiB max (dtb + overlays + extrasize)
      Currently it's 96 KiB according to fdt header when no overlays or user_overlays are used.
    • kernel: 16 MiB max
      Current vmlinuz-6.6.87-current-mvebu is 8.5 MiB.
  • Updated the naming a bit to be more understandable after a few months/years.
  • Followed style of the rest of the bootscript, if ... ; then and test "${a}" = "" instead of itest "${a}" == "".

Testing:

  • Built image:
    TBD
  • System with U-Boot 2019.04-armbian-2019.04-S3c99-P6351-H9530-V0854-Bb703-R448a (Mar 16 2025 - 04:06:02 +0000):
    OK
    U-Boot 2019.04-armbian-2019.04-S3c99-P6351-H9530-V0854-Bb703-R448a (Mar 16 2025 - 04:06:02 +0000)
    [...]
    switch to partitions #0, OK
    mmc0 is current device
    Scanning mmc 0:1...
    Found U-Boot script /boot/boot.scr
    4800 bytes read in 416 ms (10.7 KiB/s)
    ## Executing script at 03000000
    Boot script loaded from mmc
    Loading environment from mmc to 0x00300000 ...
    176 bytes read in 402 ms (0 Bytes/s)
    Loading DT from mmc to 0x02040000 ...
    28834 bytes read in 843 ms (33.2 KiB/s)
    Unknown command 'setexpr' - try 'help'
    ** Command `setexpr` not available - using configured load addresses
    Loading kernel from mmc to 0x02060000 ...
    8858728 bytes read in 2047 ms (4.1 MiB/s)
    Loading ramdisk from mmc to 0x03060000 ...
    11504566 bytes read in 2447 ms (4.5 MiB/s)
    Booting kernel ...
    ## Loading init Ramdisk from Legacy Image at 03060000 ...
       Image Name:   uInitrd
       Created:      2025-04-22  23:15:59 UTC
       Image Type:   ARM Linux RAMDisk Image (gzip compressed)
       Data Size:    11504502 Bytes = 11 MiB
       Load Address: 00000000
       Entry Point:  00000000
       Verifying Checksum ... OK
    ## Flattened Device Tree blob at 02040000
       Booting using the fdt blob at 0x2040000
       Loading Ramdisk to 0f507000, end 0ffffb76 ... OK
       Loading Device Tree to 0f4ec000, end 0f506fff ... OK
    
    Starting kernel ...
    

@github-actions github-actions bot removed the Ready to merge Reviewed, tested and ready for merge label May 9, 2025
@djurny
Copy link
Contributor Author
djurny commented May 9, 2025

Changes for 17329c1:
Testing:

  • Built image (Armbian-unofficial_25.05.0-trunk_Helios4_bookworm_current_6.6.90_minimal.img):
    OK
    U-Boot SPL 2019.04-armbian-2019.04-S3c99-P6351-H9530-V0854-Bb703-R448a (Mar 16 2025 - 04:06:02 +0000)
    [...]
    U-Boot 2019.04-armbian-2019.04-S3c99-P6351-H9530-V0854-Bb703-R448a (Mar 16 2025 - 04:06:02 +0000)
    
    SoC:   MV88F6828-A0 at 1600 MHz
    DRAM:  2 GiB (800 MHz, 32-bit, ECC enabled)
    MMC:   mv_sdh: 0
    Loading Environment from EXT4... ** File not found /boot/boot.env **
    
    ** Unable to read "/boot/boot.env" from mmc0:1 **
    Model: Helios4
    Board: Helios4
    SCSI:  MVEBU SATA INIT
    Target spinup took 0 ms.
    Target spinup took 0 ms.
    AHCI 0001.0000 32 slots 2 ports 6 Gbps 0x3 impl SATA mode
    flags: 64bit ncq led only pmp fbss pio slum part sxs 
    
    Net:   
    Warning: ethernet@70000 (eth1) using random MAC address - 56:24:30:73:7b:ad
    eth1: ethernet@70000
    Hit any key to stop autoboot:  0 
    switch to partitions #0, OK
    mmc0 is current device
    Scanning mmc 0:1...
    Found U-Boot script /boot/boot.scr
    4800 bytes read in 378 ms (11.7 KiB/s)
    ## Executing script at 03000000
    Boot script loaded from mmc
    Loading environment from mmc to 0x00300000 ...
    158 bytes read in 365 ms (0 Bytes/s)
    Loading DT from mmc to 0x02040000 ...
    28834 bytes read in 708 ms (39.1 KiB/s)
    Unknown command 'setexpr' - try 'help'
    ** Command `setexpr` not available - using configured load addresses
    Loading kernel from mmc to 0x02060000 ...
    8809072 bytes read in 1899 ms (4.4 MiB/s)
    Loading ramdisk from mmc to 0x03060000 ...
    10519797 bytes read in 2192 ms (4.6 MiB/s)
    Booting kernel ...
    ## Loading init Ramdisk from Legacy Image at 03060000 ...
       Image Name:   uInitrd
       Created:      2025-05-09  16:01:07 UTC
       Image Type:   ARM Linux RAMDisk Image (gzip compressed)
       Data Size:    10519733 Bytes = 10 MiB
       Load Address: 00000000
       Entry Point:  00000000
       Verifying Checksum ... OK
    ## Flattened Device Tree blob at 02040000
       Booting using the fdt blob at 0x2040000
       Loading Ramdisk to 0f5f7000, end 0ffff4b5 ... OK
       Loading Device Tree to 0f5dc000, end 0f5f6fff ... OK
    
    Starting kernel ...
    
    Loading, please wait...
    Starting systemd-udevd version 252.36-1~deb12u1
    

djurny added a commit to djurny/build that referenced this pull request May 9, 2025
Follow-up for:
- armbian#8165
- armbian#8166

Enable the `setexpr` command on the U-Boot monitor commandline, to enable calculating the load addresses based on the sizes of the DT, kernel, initial ramdisk.
igorpecovnik pushed a commit that referenced this pull request May 10, 2025
Follow-up for:
- #8165
- #8166

Enable the `setexpr` command on the U-Boot monitor commandline, to enable calculating the load addresses based on the sizes of the DT, kernel, initial ramdisk.
@igorpecovnik igorpecovnik added Ready to merge Reviewed, tested and ready for merge and removed Needs review Seeking for review labels May 10, 2025
@igorpecovnik igorpecovnik merged commit 6e985c3 into armbian:main May 10, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
05 Milestone: Second quarter release Hardware Hardware related like kernel, U-Boot, ... Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines
Development

Successfully merging this pull request may close these issues.

2 participants
0