build icon indicating copy to clipboard operation
build copied to clipboard

sunxi: bootscript load address calculation a.o.

Open djurny opened this issue 6 months ago • 7 comments

Description

Attempt to work towards one U-Boot bootscript for (at least) mvebu, sunxi and rockchip64. This adds:

  • (Aligned) load address calculations This will remove the need to update any kernel_load_addr_r or ramdisk_addr_r in case kernel image increases. Calculation is based on either
    • Flat kernel image image_size + text_offset as specified in the vmlinux(/Image) header info
    • Compressed kernel image filesize (vmlinuz/zImage)
  • Clear warnings to user in case files are not found, not able to load or application failed.
  • Merge of armbianEnv.txt kernel options was attempted for sunxi, mvebu and rockchip64.
  • DT folder determination based on sunxi approach.
  • DT file determination based on sunxi approach.
  • Compat with /boot/dtb/fdtfile.dtb and /boot/dtb/vendor/fdtfile.dtb.
  • Simplified some constructs by assuming U-Boot has successfully sourced us with a set of pre-set variables, like ${prefix} ${devtype} etc.
  • Actively set the ${kernel_comp_*} parameters based on calculations of load addresses.
  • Ability to select different kernel/initrd by setting kver in armbianEnv.txt

Also:

  • Any warning or error includes a 10 second delay to make sure the user is able to see and read them.
  • Any "informative" message added by the bootscript can be silenced by setting verbosity to 0
  • Attempted to make the bootscript 'reentrant' in away: all variables required for proper (re)execution are set, which should allow for the entire bootscript to be re-run on a next boot_target.
  • All variables used in for-loops are actively cleared from the environment to ensure for loops work as expected.
  • Any pre-set variable that might be used in next boot_target will be reset whenever necessary.

Documentation summary for feature / change

  • [ ] short description (copy / paste of PR title)
  • [x] summary (description relevant for end users) Load address calculation can be disabled by adding load_addr_calc=off to armbianEnv.txt Load address calculation OBOE avoidance can be disabled by adding align_overlap_oboe_avoidance=off to armbianEnv.txt User can set custom fdtdir and fdtfile in armbianEnv.txt, but make sure to only specify DT filename in fdtfile. fdtdir will be used to both load DT, DT overlays and fixup scripts
  • [ ] example of usage (how to see this in function)

How Has This Been Tested?

  • [x] Orangepi Zero (first gen):
    [12:39:52] U-Boot SPL 2024.01-armbian-2024.01-S866c-P6b16-Ha5c2-V367a-Bb703-R448a (Apr 29 2025 - 02:50:09 +0000)
    [12:39:52] DRAM: 512 MiB
    [12:39:52] Trying to boot from MMC1
    [12:39:53] ns16550_serial serial@1c28000: pinctrl_select_state_full: uclass_get_device_by_phandle_id: err=-19
    
    
    [12:39:53] U-Boot 2024.01-armbian-2024.01-S866c-P6b16-Ha5c2-V367a-Bb703-R448a (Apr 29 2025 - 02:50:09 +0000) Allwinner Technology
    
    [12:39:53] CPU:   Allwinner H3 (SUN8I 1680)
    [12:39:53] Model: Xunlong Orange Pi Zero
    [12:39:53] DRAM:  512 MiB
    [12:39:53] Core:  70 devices, 19 uclasses, devicetree: separate
    [12:39:53] WDT:   Not starting watchdog@1c20ca0
    [12:39:53] MMC:   mmc@1c0f000: 0, mmc@1c10000: 1
    [12:39:53] Loading Environment from FAT... Unable to use mmc 0:1...
    [12:39:53] In:    serial,usbkbd
    [12:39:53] Out:   serial
    [12:39:53] Err:   serial
    [12:39:53] Starting SCP...
    [12:39:53] Net:   SCP/INF: Crust v0.6.10000
    [12:39:53] eth0: ethernet@1c30000
    [12:39:53] starting USB...
    [12:39:53] Bus usb@1c1a000: sun4i_usb_phy phy@1c19400: External vbus detected, not enabling our own vbus
    [12:39:53] USB EHCI 1.00
    [12:39:53] Bus usb@1c1a400: USB OHCI 1.0
    [12:39:53] Bus usb@1c1b000: USB EHCI 1.00
    [12:39:53] Bus usb@1c1b400: USB OHCI 1.0
    [12:39:53] Bus usb@1c1c000: USB EHCI 1.00
    [12:39:53] Bus usb@1c1c400: USB OHCI 1.0
    [12:39:53] scanning bus usb@1c1a000 for devices... 1 USB Device(s) found
    [12:39:54] scanning bus usb@1c1a400 for devices... 1 USB Device(s) found
    [12:39:55] scanning bus usb@1c1b000 for devices... 1 USB Device(s) found
    [12:39:56] scanning bus usb@1c1b400 for devices... 1 USB Device(s) found
    [12:39:57] scanning bus usb@1c1c000 for devices... 1 USB Device(s) found
    [12:39:59] scanning bus usb@1c1c400 for devices... 1 USB Device(s) found
    [12:40:00]        scanning usb for storage devices... 0 Storage Device(s) found
    [12:40:00] Autoboot in 1 seconds, press <Space> to stop
    [12:40:01] switch to partitions #0, OK
    [12:40:01] mmc0 is current device
    [12:40:01] Scanning mmc 0:1...
    [12:40:01] Found U-Boot script /boot/boot.scr
    [12:40:01] 18117 bytes read in 4 ms (4.3 MiB/s)
    [12:40:01] ## Executing script at 43100000
    [12:40:01] Boot script loaded from mmc 0:1.
    [12:40:01] 687 bytes read in 3 ms (223.6 KiB/s)
    [12:40:01] Loaded/imported environment /boot/armbianEnv.txt to/from 0x45000000.
    [12:40:01] Found mainline kernel configuration.
    [12:40:01] 35473 bytes read in 11 ms (3.1 MiB/s)
    [12:40:01] Loaded DT /boot/dtb/sun8i-h2-plus-orangepi-zero.dtb to 0x43000000.
    [12:40:01] Working FDT set to 43000000
    [12:40:01] Loading kernel provided DT overlay(s) from /boot/dtb/overlay to 0x45000000 ..
    [12:40:01] 504 bytes read in 10 ms (48.8 KiB/s)
    [12:40:01] Applied DT overlay usbhost2 (/boot/dtb/overlay/sun8i-h3-usbhost2.dtbo).
    [12:40:01] 504 bytes read in 10 ms (48.8 KiB/s)
    [12:40:01] Applied DT overlay usbhost3 (/boot/dtb/overlay/sun8i-h3-usbhost3.dtbo).
    [12:40:01] 617 bytes read in 10 ms (59.6 KiB/s)
    [12:40:01] Applied DT overlay tve (/boot/dtb/overlay/sun8i-h3-tve.dtbo).
    [12:40:01] 374 bytes read in 9 ms (40 KiB/s)
    [12:40:01] Applied DT overlay i2c0 (/boot/dtb/overlay/sun8i-h3-i2c0.dtbo).
    [12:40:01] Loading user provided DT overlay(s) from /boot/overlay-user to 0x45000000 ..
    [12:40:01] 835 bytes read in 3 ms (271.5 KiB/s)
    [12:40:01] Applied user DT overlay rtc0-i2c-ds3231-rtc1-soc (/boot/overlay-user/rtc0-i2c-ds3231-rtc1-soc.dtbo).
    [12:40:01] 4185 bytes read in 10 ms (408.2 KiB/s)
    [12:40:01] ## Executing script at 45000000
    [12:40:01] Loaded/sourced fixup script /boot/dtb/overlay/sun8i-h3-fixup.scr to/at 0x45000000.
    [12:40:02] 10554192 bytes read in 441 ms (22.8 MiB/s)
    [12:40:02] Loaded compressed kernel image /boot/zImage to 4300a000.
    [12:40:02] Using compressed kernel image filesize 0xa10b50 bytes to calculate initial ramdisk load address.
    [12:40:02] 11621101 bytes read in 484 ms (22.9 MiB/s)
    [12:40:02] Loaded initial ramdisk /boot/uInitrd to 43a1b000.
    [12:40:02] Unknown command 'kaslrseed' - try 'help'
    [12:40:02] Not able to prepare for KASLR.
    [12:40:02] Kernel commandline arguments:
    [12:40:02]   root=/dev/nfs
    [12:40:02]   rootfstype=nfs
    [12:40:02]   rootwait
    [12:40:02]   splash=verbose
    [12:40:02]   earlycon
    [12:40:02]   console=ttyS0,115200
    [12:40:02]   consoleblank=0
    [12:40:02]   loglevel=8
    [12:40:02]   ubootpart=81f6566a-01
    [12:40:02]   usb-storage.quirks=0x2537:0x1066:u,0x2537:0x1068:u,0x174c:0x55aa:u
    [12:40:02]   dwc_otg.fiq_enable=0
    [12:40:02]   net.ifnames=0
    [12:40:02]   ipv6.disable=1
    [12:40:02]   rw
    [12:40:02]   nfsroot=192.168.2.34:/export/rootfs/blippi
    [12:40:02]   ip=dhcp
    [12:40:02]   nfsrootdebug
    [12:40:02]   nfs.enable_ino64=0
    [12:40:02]   cgroup_enable=cpuset
    [12:40:02]   cgroup_memory=1
    [12:40:02]   cgroup_enable=memory
    [12:40:02] Kernel image @ 0x4300a000 [ 0x000000 - 0xa10b50 ]
    [12:40:02] ## Loading init Ramdisk from Legacy Image at 43a1b000 ...
    [12:40:02]    Image Name:   uInitrd
    [12:40:02]    Image Type:   ARM Linux RAMDisk Image (gzip compressed)
    [12:40:02]    Data Size:    11621037 Bytes = 11.1 MiB
    [12:40:02]    Load Address: 00000000
    [12:40:02]    Entry Point:  00000000
    [12:40:02]    Verifying Checksum ... OK
    [12:40:02] ## Flattened Device Tree blob at 43000000
    [12:40:02]    Booting using the fdt blob at 0x43000000
    [12:40:02] Working FDT set to 43000000
    [12:40:02]    Loading Ramdisk to 494ea000, end 49fff2ad ... OK
    [12:40:02]    Loading Device Tree to 494de000, end 494e9fff ... OK
    [12:40:02] Working FDT set to 494de000
    
    [12:40:02] Starting kernel ...
    
    [12:40:03] [    0.000000] Booting Linux on physical CPU 0x0
    
  • [x] Orangepi zero (first gen): OK
    U-Boot SPL 2024.01-armbian (Feb 23 2024 - 10:47:39 +0000)
    DRAM: 256 MiB
    Trying to boot from MMC1
    ns16550_serial serial@1c28000: pinctrl_select_state_full: uclass_get_device_by_phandle_id: err=-19
    
    
    U-Boot 2024.01-armbian (Feb 23 2024 - 10:47:39 +0000) Allwinner Technology
    
    CPU:   Allwinner H3 (SUN8I 1680)
    Model: Xunlong Orange Pi Zero
    DRAM:  256 MiB
    Core:  70 devices, 19 uclasses, devicetree: separate
    WDT:   Not starting watchdog@1c20ca0
    MMC:   mmc@1c0f000: 0, mmc@1c10000: 1
    Loading Environment from FAT... Unable to use mmc 0:1...
    In:    serial,usbkbd
    Out:   serial
    Err:   serial
    Starting SCP...
    Net:   SCP/INF: Crust v0.6.10000
    eth0: ethernet@1c30000
    starting USB...
    Bus usb@1c1a000: sun4i_usb_phy phy@1c19400: External vbus detected, not enabling our own vbus
    USB EHCI 1.00
    Bus usb@1c1a400: USB OHCI 1.0
    Bus usb@1c1b000: USB EHCI 1.00
    Bus usb@1c1b400: USB OHCI 1.0
    Bus usb@1c1c000: USB EHCI 1.00
    Bus usb@1c1c400: USB OHCI 1.0
    scanning bus usb@1c1a000 for devices... 1 USB Device(s) found
    scanning bus usb@1c1a400 for devices... 1 USB Device(s) found
    scanning bus usb@1c1b000 for devices... 1 USB Device(s) found
    scanning bus usb@1c1b400 for devices... 1 USB Device(s) found
    scanning bus usb@1c1c000 for devices... 1 USB Device(s) found
    scanning bus usb@1c1c400 for devices... 1 USB Device(s) found
           scanning usb for storage devices... 0 Storage Device(s) found
    Autoboot in 1 seconds, press <Space> to stop
    switch to partitions #0, OK
    mmc0 is current device
    Scanning mmc 0:1...
    Found U-Boot script /boot/boot.scr
    18202 bytes read in 5 ms (3.5 MiB/s)
    ## Executing script at 43100000
    Boot script loaded from mmc 0:1.
    265 bytes read in 4 ms (64.5 KiB/s)
    Loaded/imported environment /boot/armbianEnv.txt to/from 0x45000000.
    Found mainline kernel configuration.
    35473 bytes read in 9 ms (3.8 MiB/s)
    Loaded DT /boot/dtb/sun8i-h2-plus-orangepi-zero.dtb to 0x43000000.
    Working FDT set to 43000000
    Loading kernel provided DT overlay(s) from /boot/dtb/overlay to 0x45000000 ..
    504 bytes read in 11 ms (43.9 KiB/s)
    Applied DT overlay usbhost2 (/boot/dtb/overlay/sun8i-h3-usbhost2.dtbo).
    504 bytes read in 12 ms (41 KiB/s)
    Applied DT overlay usbhost3 (/boot/dtb/overlay/sun8i-h3-usbhost3.dtbo).
    4185 bytes read in 11 ms (371.1 KiB/s)
    ## Executing script at 45000000
    Loaded/sourced fixup script /boot/dtb/overlay/sun8i-h3-fixup.scr to/at 0x45000000.
    10554192 bytes read in 442 ms (22.8 MiB/s)
    Loaded compressed kernel image /boot/zImage to 4300a000.
    Using compressed kernel image filesize 0xa10b50 bytes to calculate initial ramdisk load address.
    11867098 bytes read in 497 ms (22.8 MiB/s)
    Loaded initial ramdisk /boot/uInitrd to 43a1b000.
    Unknown command 'kaslrseed' - try 'help'
    Not able to prepare for KASLR.
    Kernel commandline arguments:
      root=PARTUUID=1c01f668-02
      rootfstype=f2fs
      rootwait
      splash=verbose
      console=ttyS0,115200
      consoleblank=0
      loglevel=8
      ubootpart=1c01f668-01
      usb-storage.quirks=0x2537:0x1066:u,0x2537:0x1068:u,0x174c:0x55aa:u
      net.ifnames=0
      ipv6.disable=1
      cgroup_enable=cpuset
      cgroup_memory=1
      cgroup_enable=memory
    Kernel image @ 0x4300a000 [ 0x000000 - 0xa10b50 ]
    ## Loading init Ramdisk from Legacy Image at 43a1b000 ...
       Image Name:   uInitrd
       Image Type:   ARM Linux RAMDisk Image (gzip compressed)
       Data Size:    11867034 Bytes = 11.3 MiB
       Load Address: 00000000
       Entry Point:  00000000
       Verifying Checksum ... OK
    ## Flattened Device Tree blob at 43000000
       Booting using the fdt blob at 0x43000000
    Working FDT set to 43000000
       Loading Ramdisk to 494ae000, end 49fff39a ... OK
       Loading Device Tree to 494a2000, end 494adfff ... OK
    Working FDT set to 494a2000
    
    Starting kernel ...
    

Checklist:

  • [ ] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [ ] My changes generate no new warnings New warnings introduced:
    • Environment load failed
    • Environment import failed
    • DT load/application failed
    • DT (user) overlay load/application failed
    • Initial ramdisk load failed
    • Kernel image load failed
    • Boot failed
  • [x] Any dependent changes have been merged and published in downstream modules Prequisite U-Boot setexpr command already merged via https://github.com/armbian/build/pull/8260.

djurny avatar Jun 09 '25 19:06 djurny

[!IMPORTANT]

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

## Walkthrough

The boot-sunxi.cmd script was extensively rewritten to enhance the handling of environment variables, device tree blob (DTB) loading, overlay application, kernel and ramdisk image loading, and boot command execution. The changes introduce explicit default and preset environment variables, helper functions for error handling and messaging, improved disk-based environment loading, and more robust kernel command line construction. The script now searches for DTB files across multiple paths, applies overlays and fixups with error checking, dynamically calculates load addresses for kernel and ramdisk images, and selects the appropriate boot command based on kernel image type, with detailed logging and fallback mechanisms.

## Possibly related PRs

- armbian/build#8166: Both PRs focus on improving U-Boot boot scripts by enhancing device tree handling, dynamic load address calculation, and kernel/ramdisk loading with alignment and error handling, indicating a strong relation in their boot script refactoring approaches.  
- armbian/build#8272: The main PR and the retrieved PR both refactor and enhance the U-Boot bootscript for different platforms (sunxi vs mvebu) with closely matching improvements in environment variable handling, device tree and overlay loading, dynamic load address calculation, kernel image type detection, and boot command execution, indicating they are strongly related in purpose and implementation.  
- armbian/build#8189: The main PR’s extensive refactoring and enhancement of the boot-sunxi.cmd script, including improved environment handling, DTB and overlay loading, error reporting, and dynamic load address calculation, directly relates to the retrieved PR’s similar bootscript fixes and enhancements focused on error handling, address alignment, DT resizing, and overlay application in boot-mvebu.cmd.  

## Suggested labels

`ready to merge`

## Suggested reviewers

- igorpecovnik
✨ Finishing Touches
🧪 Generate Unit Tests
  • [ ] Create PR with Unit Tests
  • [ ] Post Copyable Unit Tests in Comment

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 auto-generate unit tests to generate unit tests for 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.

coderabbitai[bot] avatar Jun 09 '25 19:06 coderabbitai[bot]

one U-Boot bootscript for (at least) mvebu, sunxi and rockchip64.

Great idea. Also when ready, remove deprecated scripts and perhaps name this common differently. Like generic, common or similar?

igorpecovnik avatar Jun 12 '25 19:06 igorpecovnik

Hi @igorpecovnik, For now it's generic but still copy/modify for some specifics. Would be nice to have a real common base and have the specials add-in with extra scripts, like how the DT fixup scripts are done at the moment. PS Would be great to have some template action going on with this, so the boot.cmd can be templated during build time based on the board that's being built. Groetjes,

djurny avatar Jun 12 '25 20:06 djurny

so the boot.cmd can be templated during build time based on the board that's being built.

Aha, it still need changes for board / family specifics. This can probably be integrated right where cp is executing conditioned on this generic boot script and leaving legacy as is.

igorpecovnik avatar Jun 12 '25 22:06 igorpecovnik

@djurny I strongly recommend that you do not modify existing files. Instead, copy the underlying file and save it as boot-common.cmd or boot-generic.cmd. This is necessary so that the device maintainers can verify the correct operation for their device and the u-boot version.

There are also related changes for here

The-going avatar Jun 13 '25 09:06 The-going

Hi @The-going, Thanks for your remarks! Let me paraphrase to make sure I understand your concern and proposal.

  • Keep current boot-sunxi.cmd as-is.
  • Add boot-generic.cmd (or any name indicating this bootscript is for generic use) with the boot-sunxi.cmd as in this PR.

Not sure how to switch between the generic and current bootscripts though. Any ideas on that?

Do let me know if I got the point (or not).

Groetjes,

djurny avatar Jun 13 '25 21:06 djurny

Hi @The-going, Thanks for your remarks! Let me paraphrase to make sure I understand your concern and proposal.

* Keep current `boot-sunxi.cmd` as-is.

* Add `boot-generic.cmd` (or any name indicating this bootscript is for generic use) with the `boot-sunxi.cmd` as in this PR.

Yes, you got it right.

Not sure how to switch between the generic and current bootscripts though. Any ideas on that?

The maintainer of this device will decide which script to use, old or new. It explicitly states which script to use for this subfamily. config/sources/families/sun50iw9-bpi.conf or directly in the device configuration file.

armbian/build> grep -nr 'BOOTSCRIPT=' ./config/*
./config/boards/rock-s0.conf:30:        declare -g BOOTSCRIPT="boot-rockchip64-ttyS0.cmd:boot.cmd"
./config/boards/aml-s805-mxq.tvb:8:BOOTSCRIPT="boot-aml-s805-mxq.cmd:boot.cmd"
./config/boards/qemu-uboot-arm64.csc:20:        declare -g BOOTSCRIPT="boot-qemu-arm64.cmd:boot.cmd"
./config/boards/onecloud.csc:8:BOOTSCRIPT="boot-onecloud.cmd:boot.cmd"
./config/boards/qemu-uboot-x86.csc:23:  declare -g BOOTSCRIPT="boot-qemu-x86.cmd:boot.cmd"
./config/boards/rockpi-s.conf:30:       declare -g BOOTSCRIPT="boot-rockchip64-ttyS0.cmd:boot.cmd"
./config/boards/odroidc1.conf:15:BOOTSCRIPT="boot-odroid-c1.ini:boot.ini"
........

Before switching to a new script for the devices that I support, I would like to test this thoroughly. You have published tests for two devices. You can specify which script to use directly in the configuration file for these two devices. This leaves the option of choice (maneuver) for other escorts.

Do let me know if I got the point (or not).

Groetjes,

The-going avatar Jun 14 '25 20:06 The-going

Hi @The-going @igorpecovnik, I've been looking into the remarks and came to a solution for using a generic bootscript that can be selected in the board configuration.

As the generic approach still needs some customization, I opted to use the basic template engine envsubst, to keep it as simple as possible. In order to make that work, the following changes would have to be made to distro-agnostic.sh and armbian-bsp-cli-deb.sh:

  • Added gettext to prepare_host.sh.
  • Added 4 functions to distro-agnostic.sh:
    • One to distill a display console from both $DISPLAYCON and $SRC_CMDLINE.
    • One to distill a serial console from both $SERIALCON and $SRC_CMDLINE.
    • One to render a bootscript template file.
    • One to proof a rendered bootscript template file.
  • Added a test for bootscript type (template or plain) and in case of template use the 'render' function to render the bootscript template into the image.

It seems that the $BOOTSCRIPT is deployed twice (at least for the boards I am using at the mo'), in lib/functions/bsp/armbian-bsp-cli-deb.sh and in lib/functions/rootfs/distro-agnostic.sh. In order to make sure maintainers can select the bootscript in the board config file, added the construct below in the family configuration (include) files.

BOOTSCRIPT="${BOOTSCRIPT:-boot-mvebu.cmd:boot.cmd}"

The generic bootscript itself will have placeholders prefixed with $BOOTSCRIPT_TEMPLATE__, which will be rendered out by envsubst based on the currently set $BOOTSCRIPT_TEMPLATE__ variables. After rendering, a check will be done to make sure all placeholders have been rendered.

For the boards I am aiming at this will need the following items to be added to the board configuration:

## generic bootscript and template variables
BOOTSCRIPT='boot-generic.cmd.template:boot.cmd'
BOOTSCRIPT_TEMPLATE__BOARD_FAMILY="${BOARDFAMILY:-mvebu}"
BOOTSCRIPT_TEMPLATE__BOARD_VENDOR='marvell'
BOOTSCRIPT_TEMPLATE__ALIGN_TO="0x1000"
BOOTSCRIPT_TEMPLATE__LOAD_ADDR="0x00300000"
BOOTSCRIPT_TEMPLATE__DEFAULT_ROOTFSTYPE='ext4'

(The align_to will be different for aarch64 kernels, the default_rootfstype will be following the commandline option to compile.sh.)

Before I continue this effort, would like to hear your thoughts on this approach.

Thanks, Groetjes,

djurny avatar Jun 20 '25 16:06 djurny