Skip to content

Enable bootscript templating #8315

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

djurny
Copy link
Contributor

@djurny djurny commented Jun 22, 2025

  • Enable bootscript templating using envsubst for bootscripts with the filename extension .template.
  • Add generic bootscript. Plan is to have boards use this generic bootscript one by one.

Description

In order to prepare for a generic bootscript, introduce simple templating for bootscripts using envsubst. The templating is needed as some things in the generic bootscript do require customization, where templating offers easy customization using already-existing shell variables. For example, load_addr, serial consoles, memory alignment settings and family/vendor names to enable proper name resolving for DT and DT overlay files.

Documentation summary for feature / change

If bootscript name ends with the .template extension (could not find a more suitable extension), envsubst will be invoked to render the bootscript [template]. Rendering will consist of replacing any occurrance of a variable named $BOOTSCRIPT_TEMPLATE__xxx with the value in the environment of the build system at the time of rendering, in the bootscript template.

Some things to take into consideration, BOOTSCRIPT in the boards/config/xxx files can be overridden by sources/families/xxx or sources/families/includes/xxx. For example, for boards/config/orangepizero.csc, the setting for BOOTSCRIPT will be overridden by sources/families/includes/sunxi-common.inc. This can be solved with the following construct in sources/families/includes/sunxi-common.inc:

declare -g BOOTSCRIPT="${BOOTSCRIPT:-boot-sunxi.cmd}:boot.cmd"

For every board, this has to be inspected to make sure the bootscript selection is done as expected.

How Has This Been Tested?

  • [x ] Orangepi Zero
    • Change BOOTSCRIPT declaration in sources/families/includes/sunxi-common.inc.
    • Add the following to 'boards/config/orangepizero.csc`:
      DISPLAYCON=''
      SERIALCON="ttyS0:115200,ttyGS0"
      
      BOOTSCRIPT='boot-generic.cmd.template:boot.cmd'
      BOOTSCRIPT_TEMPLATE__ALIGN_TO='0x00001000'
      BOOTSCRIPT_TEMPLATE__BOARD_FAMILY="${BOARDFAMILY:-sun8i}"
      BOOTSCRIPT_TEMPLATE__BOARD_VENDOR='allwinner'
      BOOTSCRIPT_TEMPLATE__DISPLAY_CONSOLE='' # determine later on
      BOOTSCRIPT_TEMPLATE__LOAD_ADDR='0x45000000'
      BOOTSCRIPT_TEMPLATE__ROOTFS_TYPE="${ROOTFS_TYPE:-ext4}"
      BOOTSCRIPT_TEMPLATE__SERIAL_CONSOLE='' # determine later on
      
    • Compile for Orangepizero board and inspect generated (overridden and modified) boot/boot.cmd:
      [🐳|🌱] Rendering boot script template [ /armbian/config/bootscripts/boot-generic.cmd.template -> /armbian/.tmp/work-83d4164d-920e-4928-8d37-e7fa9aab818e/deb-bsp-cli-dUPmB/usr/share/armbian/boot.cmd ]
      [🐳|🔨]   '/armbian/config/bootenv/sunxi.txt' -> '/armbian/.tmp/work-83d4164d-920e-4928-8d37-e7fa9aab818e/deb-bsp-cli-dUPmB/usr/share/armbian/armbianEnv.txt'
      ...
      [🐳|🌱] Rendering boot script template [ /armbian/config/bootscripts/boot-generic.cmd.template ]
      [🐳|🔨]   '/armbian/config/bootenv/sunxi.txt' -> '/armbian/.tmp/rootfs-83d4164d-920e-4928-8d37-e7fa9aab818e/boot/armbianEnv.txt'
      ...
      
    • Resulting bootscript:
      # DO NOT EDIT THIS FILE
      #
      # Please edit /boot/armbianEnv.txt to set supported parameters
      #
      
      # This bootscript was generated on Sat, 21 Jun 2025 17:31:29 +0000
      
      # NOTE
      #       This file is the result of rendering a template using 'envsubst'.
      #       Any variable starting with 'BOOTSCRIPT_TEMPLATE__' is expected to be rendered.
      #       The build system will check if any variable is left after rendering and will
      #       exit with error if any unrendered variables are found.
      #       Check the following files for more details:
      #               lib/functions/bsp/armbian-bsp-cli-deb.sh
      #               lib/functions/rootfs/distro-agnostic.sh
      
      # NOTE
      #       If you intend to use 'outside' of 'global' variables from U-Boot, make sure that you do not change them!
      #       The boot logic will attempt a list of 'boot_targets' that all might rely on (environment) variables that
      #       have been set by U-Boot, either compile-time or as part of U-Boot's default 'bootcmd'.
      #       Any variable that this bootscript uses needs to be set explicitly and not conflict with any pre-set var>
      #       Variables that we might change will be saved in preset_x and variables we use will be copied into l_x.
      
      # default environment variables
      setenv align_overlap_oboe_avoidance "on"
      setenv align_to "0x00001000"
      setenv consoleargs_display ""
      setenv consoleargs_serial "console=ttyS0,115200 console=ttyGS0"
      setenv console "both"
      setenv docker_optimizations "on"
      setenv earlycon "off"
      setenv exit_on_critical_errors "on"
      setenv family "sun8i"
      setenv fdt_extrasize "0x00010000"
      setenv kver
      setenv load_addr_calc
      setenv overlay_error "false"
      setenv preset_fdtdir "${fdtdir}"
      setenv preset_fdtfile "${fdtfile}"
      setenv preset_kernel_comp_addr_r "${kernel_comp_addr_r}"
      setenv preset_kernel_comp_size "${kernel_comp_size}"
      setenv rootdev "/dev/mmcblk${devnum}p${distro_bootpart}"
      setenv rootfstype "ext4"
      setenv vendor "allwinner"
      setenv verbosity "1"
      
      # load addresses
      setenv load_addr "0x45000000"
      
      # NOTE
      #       No 'BOOTSCRIPT_TEMPLATE__' references beyond this point.
      

Checklist:

  • 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
  • Any dependent changes have been merged and published in downstream modules

@djurny djurny requested review from a team and igorpecovnik as code owners June 22, 2025 00:24
Copy link
Contributor

coderabbitai bot commented Jun 22, 2025

Walkthrough

A new U-Boot boot script template, boot-generic.cmd.template, has been introduced, providing comprehensive and dynamic boot logic for generic ARM boards. The build framework now supports rendering boot script templates by substituting environment variables, with validation to ensure all template variables are resolved. Functions for generating console argument strings and rendering templates have been added. The logic for deploying boot scripts is updated to distinguish between template and non-template scripts, rendering and validating templates as needed. Additionally, the gettext package is added to host dependencies, with no changes to exported function signatures except for new internal helpers.

Possibly related PRs

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

Ready to merge, size/medium

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 74e004d and 15c05f7.

📒 Files selected for processing (4)
  • config/bootscripts/boot-generic.cmd.template (1 hunks)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh (1 hunks)
  • lib/functions/host/prepare-host.sh (1 hunks)
  • lib/functions/rootfs/distro-agnostic.sh (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • lib/functions/host/prepare-host.sh
🚧 Files skipped from review as they are similar to previous changes (3)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh
  • config/bootscripts/boot-generic.cmd.template
  • lib/functions/rootfs/distro-agnostic.sh
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a 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 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.

@github-actions github-actions bot added 08 Milestone: Third quarter release size/large PR with 250 lines or more Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Framework Framework components labels Jun 22, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label Jun 22, 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: 0

🧹 Nitpick comments (1)
lib/functions/rootfs/distro-agnostic.sh (1)

54-68: Template rendering function: consider shellcheck annotations.
render_bootscript_template correctly exports BOOTSCRIPT_TEMPLATE__CREATE_DATE and console vars, then invokes envsubst. To silence SC2034 (unused var) and SC2046 (word splitting on export $(…)), add above the function:

# shellcheck disable=SC2034,SC2046
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3844ef9 and 5f93a68.

📒 Files selected for processing (4)
  • config/bootscripts/boot-generic.cmd.template (1 hunks)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh (1 hunks)
  • lib/functions/host/prepare-host.sh (1 hunks)
  • lib/functions/rootfs/distro-agnostic.sh (3 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
lib/functions/rootfs/distro-agnostic.sh

[warning] 58-58: BOOTSCRIPT_TEMPLATE__CREATE_DATE appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 66-66: Quote this to prevent word splitting.

(SC2046)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Shell script analysis
  • GitHub Check: Check kernel security options
🔇 Additional comments (11)
lib/functions/host/prepare-host.sh (1)

189-189: Add gettext to host dependencies: Looks correct.
Including gettext ensures that envsubst is available for template rendering. Verify that the package name matches the target distributions (e.g., Debian’s gettext-base vs. gettext).

lib/functions/bsp/armbian-bsp-cli-deb.sh (2)

145-153: Implement template rendering for .template bootscripts.
Good use of render_bootscript_template and validation via proof_rendered_bootscript_template to fail fast on unrendered placeholders.


155-159: Retain direct copy path for non-template bootscripts.
The fallback to cp -pv preserves existing behavior for plain bootscripts.

lib/functions/rootfs/distro-agnostic.sh (4)

10-30: New console export helpers look solid.
bootscript_export_display_console and bootscript_export_serial_console correctly assemble console arguments and export them under BOOTSCRIPT_TEMPLATE__DISPLAY_CONSOLE and BOOTSCRIPT_TEMPLATE__SERIAL_CONSOLE.


70-72: Proof-rendering verification is concise and accurate.
The grep against ${BOOTSCRIPT_TEMPLATE__ ensures no placeholders remain.


182-191: Resolve bootscript source path with patch override support.
The bootscript_src_path selection between USERPATCHES_PATH and default SRC/config/bootscripts is correct.


226-235: Enable templating in rootfs installation.
Differentiates .template suffix, renders via render_bootscript_template, and enforces completeness with proof_rendered_bootscript_template.

config/bootscripts/boot-generic.cmd.template (4)

1-16: Template header and documentation are clear.
The introductory comments outline templating expectations and references to implementing scripts.


24-29: Default environment variable placeholders.
ALIGN_TO, DISPLAY_CONSOLE, and SERIAL_CONSOLE placeholders are correctly positioned for substitution.


33-46: Board, rootfs, load address, and vendor placeholders.
Use of ${BOOTSCRIPT_TEMPLATE__BOARD_FAMILY}, ${BOOTSCRIPT_TEMPLATE__ROOTFS_TYPE}, ${BOOTSCRIPT_TEMPLATE__LOAD_ADDR}, and ${BOOTSCRIPT_TEMPLATE__BOARD_VENDOR} is appropriate and aligns with export functions.


49-52: Templating termination marker.
The # NOTE block correctly signals that no further BOOTSCRIPT_TEMPLATE__ variables should appear beyond this point.

@djurny
Copy link
Contributor Author

djurny commented Jun 22, 2025

Hi @The-going,
Would be great if you can have a look here as well.
Thx,
Groetjes,

@djurny djurny force-pushed the feat/bootscript-templating branch from 5f93a68 to 7d42abc Compare June 22, 2025 00:28
@github-actions github-actions bot removed the Ready to merge Reviewed, tested and ready for merge label Jun 22, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label Jun 22, 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

♻️ Duplicate comments (1)
lib/functions/rootfs/distro-agnostic.sh (1)

32-52: Duplicate logic: see previous comment

The bootscript_export_serial_console function mirrors the display-console one. Apply the same refactoring and quoting recommendations above to consolidate and secure the code.

🧹 Nitpick comments (4)
lib/functions/rootfs/distro-agnostic.sh (4)

10-30: Refactor duplicated console-export logic and harden variable handling

The two functions for display- and serial-console exports share nearly identical loops and use unquoted expansions (${DISPLAYCON//,/ }, $SRC_CMDLINE) that can lead to word‐splitting or globbing. Consider extracting a generic helper (e.g. bootscript_export_console VAR_NAME INPUT_LIST FILTER_REGEX) to DRY up both functions. Also quote parameter expansions to prevent unintended splitting.


70-72: Suppress grep output and use exit codes

proof_rendered_bootscript_template should use grep -q to avoid printing matches and make its intent clearer. For example:

-function proof_rendered_bootscript_template() {
-   ! egrep '\$\{?BOOTSCRIPT_TEMPLATE__' "${1:?}"
-}
+function proof_rendered_bootscript_template() {
+   if egrep -q '\$\{?BOOTSCRIPT_TEMPLATE__' "${1:?}"; then
+     return 1
+   fi
+   return 0
+}

182-190: Combine local declarations for clarity

Group related locals into a single declaration to improve readability and reduce boilerplate. Example:

- local bootscript_src_path
- local bootscript_src=${BOOTSCRIPT%%:*}
- local bootscript_dst=${BOOTSCRIPT##*:}
+ local bootscript_src_path bootscript_src bootscript_dst
+ bootscript_src=${BOOTSCRIPT%%:*}
+ bootscript_dst=${BOOTSCRIPT##*:}

227-240: Avoid useless use of cat

You can pipe the template directly into render_bootscript_template without cat:

- run_host_command_logged cat "${bootscript_src_path}/${bootscript_src}" \
-   | render_bootscript_template > "${SDCARD}/boot/${bootscript_dst}"
+ run_host_command_logged render_bootscript_template \
+   < "${bootscript_src_path}/${bootscript_src}" \
+   > "${SDCARD}/boot/${bootscript_dst}"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f93a68 and 7d42abc.

📒 Files selected for processing (4)
  • config/bootscripts/boot-generic.cmd.template (1 hunks)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh (1 hunks)
  • lib/functions/host/prepare-host.sh (1 hunks)
  • lib/functions/rootfs/distro-agnostic.sh (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • lib/functions/host/prepare-host.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh
  • config/bootscripts/boot-generic.cmd.template
🧰 Additional context used
🪛 Shellcheck (0.10.0)
lib/functions/rootfs/distro-agnostic.sh

[warning] 58-58: BOOTSCRIPT_TEMPLATE__CREATE_DATE appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 66-66: Quote this to prevent word splitting.

(SC2046)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Shell script analysis

@djurny djurny force-pushed the feat/bootscript-templating branch from 7d42abc to 4b06fe4 Compare June 29, 2025 08:35
@github-actions github-actions bot removed the Ready to merge Reviewed, tested and ready for merge label Jun 29, 2025
@coderabbitai coderabbitai bot added 05 Milestone: Second quarter release Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines labels Jun 29, 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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7d42abc and 4b06fe4.

📒 Files selected for processing (4)
  • config/bootscripts/boot-generic.cmd.template (1 hunks)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh (1 hunks)
  • lib/functions/host/prepare-host.sh (1 hunks)
  • lib/functions/rootfs/distro-agnostic.sh (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • lib/functions/host/prepare-host.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: EvilOlaf
PR: armbian/build#8328
File: lib/functions/compilation/patch/drivers_network.sh:542-545
Timestamp: 2025-06-24T10:08:40.313Z
Learning: In the Armbian build system, when a PR removes build support for a specific kernel version, version check issues for that removed version become practically irrelevant even if they appear incorrect in isolation. Context about which kernel versions are being deprecated/removed is important for understanding the impact of version-related code changes.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the `fdtfile` variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If `fdtfile` is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.
Learnt from: djurny
PR: armbian/build#8203
File: config/bootscripts/boot-sunxi.cmd:111-114
Timestamp: 2025-05-17T23:08:31.746Z
Learning: In U-Boot scripts, the `setexpr sub` command is valid for string operations when CONFIG_REGEX=y is enabled. This allows for pattern substitution in strings, as documented in https://docs.u-boot.org/en/latest/usage/cmd/setexpr.html. The syntax is `setexpr <variable> sub <pattern> <replacement> <string>`.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the `setexpr` command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:38-44
Timestamp: 2025-06-12T21:14:36.024Z
Learning: In config/bootscripts/boot-sunxi.cmd the unconditional "+1" increment in func_align_addr_next (when align_overlap_oboe_avoidance="on") is intentional. It compensates for a known off-by-one error in U-Boot where the end address is calculated as start+size instead of start+size-1, so the extra page prevents overlap. This behavior should not be “optimized away”.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
Learning: In U-Boot scripts, `itest.s` should be used for explicit string comparisons rather than plain `itest` with string operators like `==`.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: In U-Boot shell scripting, the `else ;` construct followed by commands on subsequent lines is valid syntax, as demonstrated by empirical testing. Both `else command` and `else ; command` forms are acceptable in U-Boot's shell implementation.
config/bootscripts/boot-generic.cmd.template (13)
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the `fdtfile` variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If `fdtfile` is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:38-44
Timestamp: 2025-06-12T21:14:36.024Z
Learning: In config/bootscripts/boot-sunxi.cmd the unconditional "+1" increment in func_align_addr_next (when align_overlap_oboe_avoidance="on") is intentional. It compensates for a known off-by-one error in U-Boot where the end address is calculated as start+size instead of start+size-1, so the extra page prevents overlap. This behavior should not be “optimized away”.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:13-23
Timestamp: 2025-06-12T21:08:11.318Z
Learning: In config/bootscripts/boot-sunxi.cmd the variable name `align_overlap_oboe_avoidance` intentionally uses the acronym “OBOE” (Off-By-One Error); it is not a typo and should not be renamed.
Learnt from: EvilOlaf
PR: armbian/build#0
File: :0-0
Timestamp: 2025-06-16T03:24:00.458Z
Learning: In Armbian board configuration files (.csc), the standard pattern is to have only one line as a comment describing the board hardware specifications. This single-line description typically includes the SoC model, core count, RAM options, and key features like connectivity options, storage interfaces, and special features.
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
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.
Learnt from: Grippy98
PR: armbian/build#8202
File: config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh:2-3
Timestamp: 2025-05-16T15:34:34.672Z
Learning: The shell scripts in the Armbian build system's desktop configuration files, such as config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh, rely on environment variables like $SRC and $destination that are expected to be set externally before the script is executed.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the `setexpr` command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: Armbian build framework extensions are NOT designed to run standalone but are called by the supervisor. The framework provides environment variables like USERPATCHES_PATH and SDCARD, and commands are executed with protection via run_host_command_logged and chroot_sdcard functions that use bash -e -o pipefail.
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: In Armbian build framework, extensions are loaded and executed via lib/functions/general/extensions.sh using call_extension_method. The framework sets set -o errexit and set -o errtrace globally, and individual commands run with pipefail protection through the command execution functions.
lib/functions/rootfs/distro-agnostic.sh (16)
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: leggewie
PR: armbian/build#8133
File: extensions/apa.sh:1-2
Timestamp: 2025-04-28T08:27:26.890Z
Learning: In the Armbian build system, extension scripts in the `extensions/` directory contain hook functions and are meant to be sourced, not executed directly. These scripts don't require a shebang or `set -euo pipefail`.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:53:10.331Z
Learning: The bash construct `export $(set | sed -En '/^BOOTSCRIPT_TEMPLATE__/s/=.*$//p')` is safe from word splitting because it extracts only variable names (by removing everything after `=`), and bash variable names cannot contain whitespace or special characters.
Learnt from: Grippy98
PR: armbian/build#8202
File: config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh:2-3
Timestamp: 2025-05-16T15:34:34.672Z
Learning: The shell scripts in the Armbian build system's desktop configuration files, such as config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh, rely on environment variables like $SRC and $destination that are expected to be set externally before the script is executed.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the `setexpr` command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: Armbian build framework extensions are NOT designed to run standalone but are called by the supervisor. The framework provides environment variables like USERPATCHES_PATH and SDCARD, and commands are executed with protection via run_host_command_logged and chroot_sdcard functions that use bash -e -o pipefail.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:13-23
Timestamp: 2025-06-12T21:08:11.318Z
Learning: In config/bootscripts/boot-sunxi.cmd the variable name `align_overlap_oboe_avoidance` intentionally uses the acronym “OBOE” (Off-By-One Error); it is not a typo and should not be renamed.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the `fdtfile` variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If `fdtfile` is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: In Armbian build framework, extensions are loaded and executed via lib/functions/general/extensions.sh using call_extension_method. The framework sets set -o errexit and set -o errtrace globally, and individual commands run with pipefail protection through the command execution functions.
Learnt from: Grippy98
PR: armbian/build#8152
File: lib/functions/configuration/interactive.sh:209-266
Timestamp: 2025-05-05T12:35:07.143Z
Learning: For the interactive kernel selection in Armbian, KERNEL_MAJOR_MINOR and KERNEL_DESCRIPTION are parsed from family.conf but deliberately not set as environment variables to avoid potential interference with other parts of the build system.
Learnt from: EvilOlaf
PR: armbian/build#8330
File: config/sources/families/sun55iw3.conf:32-36
Timestamp: 2025-06-25T03:42:09.086Z
Learning: In Armbian build system configuration files like config/sources/families/*.conf, KERNELSOURCE is explicitly declared when using unofficial or 3rd party kernel repositories (like the "dev" branch using https://github.com/apritzel/linux), but can be omitted when using the standard mainline kernel (like the "edge" branch) since it will fall back to the default mainline source.
Learnt from: EvilOlaf
PR: armbian/build#8330
File: config/sources/families/sun55iw3.conf:32-36
Timestamp: 2025-06-25T03:40:52.109Z
Learning: In Armbian build system configuration files like config/sources/families/*.conf, when KERNELSOURCE is not explicitly declared in a case branch, the system falls back to a default KERNELSOURCE value, so missing KERNELSOURCE declarations are not critical issues.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: In U-Boot shell scripting, the `else ;` construct followed by commands on subsequent lines is valid syntax, as demonstrated by empirical testing. Both `else command` and `else ; command` forms are acceptable in U-Boot's shell implementation.
🧬 Code Graph Analysis (1)
lib/functions/rootfs/distro-agnostic.sh (2)
.github/generate_CODEOWNERS.sh (1)
  • display_alert (6-6)
lib/functions/logging/runners.sh (1)
  • run_host_command_logged (204-206)
🪛 Shellcheck (0.10.0)
lib/functions/rootfs/distro-agnostic.sh

[warning] 58-58: BOOTSCRIPT_TEMPLATE__CREATE_DATE appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 66-66: Quote this to prevent word splitting.

(SC2046)

🔇 Additional comments (1)
lib/functions/rootfs/distro-agnostic.sh (1)

54-68: Template rendering pipeline looks solid

The new render_bootscript_template / proof_rendered_bootscript_template helpers integrate cleanly, re-using existing logging and subshell isolation. Dependency handling for envsubst is already covered upstream, and the variable-export construct is confirmed safe (per earlier discussion).
No further action needed.

@djurny djurny force-pushed the feat/bootscript-templating branch from 4b06fe4 to 63365b5 Compare June 30, 2025 04:00
@github-actions github-actions bot removed size/medium PR with more then 50 and less then 250 lines Ready to merge Reviewed, tested and ready for merge labels Jun 30, 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: 0

🧹 Nitpick comments (3)
lib/functions/rootfs/distro-agnostic.sh (3)

70-72: Use grep -E instead of deprecated egrep

egrep is officially deprecated in GNU grep 3.8+. Switch to grep -E to future-proof the script:

-    ! egrep '\$\{?BOOTSCRIPT_TEMPLATE__' "${1:?}"
+    ! grep -E '\$\{?BOOTSCRIPT_TEMPLATE__' "${1:?}"

55-59: Suppress ShellCheck false-positive for BOOTSCRIPT_TEMPLATE__CREATE_DATE

BOOTSCRIPT_TEMPLATE__CREATE_DATE is intentionally exported for template
substitution, so the SC2034 “unused variable” warning is a false alarm.
Consider adding a directive to keep CI quiet:

+# shellcheck disable=SC2034 # variable consumed indirectly by envsubst
 typeset BOOTSCRIPT_TEMPLATE__CREATE_DATE

63-68: Optional: silence SC2046 without altering behaviour

ShellCheck warns about possible word-splitting in export $( … ), but we've
confirmed only variable names are produced. To keep the linter quiet, append a
disable comment:

- export $(set | sed -En '/^BOOTSCRIPT_TEMPLATE__/s/=.*$//p')
+ # shellcheck disable=SC2046 # safe: list contains only variable names
+ export $(set | sed -En '/^BOOTSCRIPT_TEMPLATE__/s/=.*$//p')
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4b06fe4 and 63365b5.

📒 Files selected for processing (4)
  • config/bootscripts/boot-generic.cmd.template (1 hunks)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh (1 hunks)
  • lib/functions/host/prepare-host.sh (1 hunks)
  • lib/functions/rootfs/distro-agnostic.sh (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • lib/functions/host/prepare-host.sh
  • lib/functions/bsp/armbian-bsp-cli-deb.sh
  • config/bootscripts/boot-generic.cmd.template
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: EvilOlaf
PR: armbian/build#8328
File: lib/functions/compilation/patch/drivers_network.sh:542-545
Timestamp: 2025-06-24T10:08:40.313Z
Learning: In the Armbian build system, when a PR removes build support for a specific kernel version, version check issues for that removed version become practically irrelevant even if they appear incorrect in isolation. Context about which kernel versions are being deprecated/removed is important for understanding the impact of version-related code changes.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the `fdtfile` variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If `fdtfile` is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.
Learnt from: djurny
PR: armbian/build#8203
File: config/bootscripts/boot-sunxi.cmd:111-114
Timestamp: 2025-05-17T23:08:31.746Z
Learning: In U-Boot scripts, the `setexpr sub` command is valid for string operations when CONFIG_REGEX=y is enabled. This allows for pattern substitution in strings, as documented in https://docs.u-boot.org/en/latest/usage/cmd/setexpr.html. The syntax is `setexpr <variable> sub <pattern> <replacement> <string>`.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the `setexpr` command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:38-44
Timestamp: 2025-06-12T21:14:36.024Z
Learning: In config/bootscripts/boot-sunxi.cmd the unconditional "+1" increment in func_align_addr_next (when align_overlap_oboe_avoidance="on") is intentional. It compensates for a known off-by-one error in U-Boot where the end address is calculated as start+size instead of start+size-1, so the extra page prevents overlap. This behavior should not be “optimized away”.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
Learning: In U-Boot scripts, `itest.s` should be used for explicit string comparisons rather than plain `itest` with string operators like `==`.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: In U-Boot shell scripting, the `else ;` construct followed by commands on subsequent lines is valid syntax, as demonstrated by empirical testing. Both `else command` and `else ; command` forms are acceptable in U-Boot's shell implementation.
lib/functions/rootfs/distro-agnostic.sh (16)
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: leggewie
PR: armbian/build#8133
File: extensions/apa.sh:1-2
Timestamp: 2025-04-28T08:27:26.890Z
Learning: In the Armbian build system, extension scripts in the `extensions/` directory contain hook functions and are meant to be sourced, not executed directly. These scripts don't require a shebang or `set -euo pipefail`.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:53:10.331Z
Learning: The bash construct `export $(set | sed -En '/^BOOTSCRIPT_TEMPLATE__/s/=.*$//p')` is safe from word splitting because it extracts only variable names (by removing everything after `=`), and bash variable names cannot contain whitespace or special characters.
Learnt from: Grippy98
PR: armbian/build#8202
File: config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh:2-3
Timestamp: 2025-05-16T15:34:34.672Z
Learning: The shell scripts in the Armbian build system's desktop configuration files, such as config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh, rely on environment variables like $SRC and $destination that are expected to be set externally before the script is executed.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the `setexpr` command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: Armbian build framework extensions are NOT designed to run standalone but are called by the supervisor. The framework provides environment variables like USERPATCHES_PATH and SDCARD, and commands are executed with protection via run_host_command_logged and chroot_sdcard functions that use bash -e -o pipefail.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:13-23
Timestamp: 2025-06-12T21:08:11.318Z
Learning: In config/bootscripts/boot-sunxi.cmd the variable name `align_overlap_oboe_avoidance` intentionally uses the acronym “OBOE” (Off-By-One Error); it is not a typo and should not be renamed.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the `fdtfile` variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If `fdtfile` is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: In Armbian build framework, extensions are loaded and executed via lib/functions/general/extensions.sh using call_extension_method. The framework sets set -o errexit and set -o errtrace globally, and individual commands run with pipefail protection through the command execution functions.
Learnt from: Grippy98
PR: armbian/build#8152
File: lib/functions/configuration/interactive.sh:209-266
Timestamp: 2025-05-05T12:35:07.143Z
Learning: For the interactive kernel selection in Armbian, KERNEL_MAJOR_MINOR and KERNEL_DESCRIPTION are parsed from family.conf but deliberately not set as environment variables to avoid potential interference with other parts of the build system.
Learnt from: EvilOlaf
PR: armbian/build#8330
File: config/sources/families/sun55iw3.conf:32-36
Timestamp: 2025-06-25T03:42:09.086Z
Learning: In Armbian build system configuration files like config/sources/families/*.conf, KERNELSOURCE is explicitly declared when using unofficial or 3rd party kernel repositories (like the "dev" branch using https://github.com/apritzel/linux), but can be omitted when using the standard mainline kernel (like the "edge" branch) since it will fall back to the default mainline source.
Learnt from: EvilOlaf
PR: armbian/build#8330
File: config/sources/families/sun55iw3.conf:32-36
Timestamp: 2025-06-25T03:40:52.109Z
Learning: In Armbian build system configuration files like config/sources/families/*.conf, when KERNELSOURCE is not explicitly declared in a case branch, the system falls back to a default KERNELSOURCE value, so missing KERNELSOURCE declarations are not critical issues.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: In U-Boot shell scripting, the `else ;` construct followed by commands on subsequent lines is valid syntax, as demonstrated by empirical testing. Both `else command` and `else ; command` forms are acceptable in U-Boot's shell implementation.
🧬 Code Graph Analysis (1)
lib/functions/rootfs/distro-agnostic.sh (2)
.github/generate_CODEOWNERS.sh (1)
  • display_alert (6-6)
lib/functions/logging/runners.sh (1)
  • run_host_command_logged (204-206)
🪛 Shellcheck (0.10.0)
lib/functions/rootfs/distro-agnostic.sh

[warning] 58-58: BOOTSCRIPT_TEMPLATE__CREATE_DATE appears unused. Verify use (or export if used externally).

(SC2034)


[warning] 66-66: Quote this to prevent word splitting.

(SC2046)

🔇 Additional comments (1)
lib/functions/rootfs/distro-agnostic.sh (1)

19-27: Regex incorrectly classifies many serial consoles (e.g. ttyAMA0)

The pattern 'tty'[AGSU]* only matches tty followed by any combination of A/G/S/U.
Devices like ttyAMA0, ttyUSB0, ttyACM0, etc. are therefore mis-detected:

  • ttyAMA0 fails because the third character M is not in [AGSU].
  • ttyUSB0 fails because the second character U matches but the following S/B are outside the set.

As a result, serial consoles can leak into DISPLAY_CONSOLE or be omitted from SERIAL_CONSOLE, altering the generated kernel cmdline.

-       if [[ "${ITEM#*=}" =~ 'tty'[AGSU]* ]] ; then
+       # Match any tty* serial device (ttyS*, ttyAMA*, ttyUSB*, ttyACM*, ttyGS*, …)
+       if [[ "${ITEM#*=}" =~ ^tty[A-Za-z0-9]+ ]] ; then

Apply the same fix in both export functions.

Also applies to: 41-49

⛔ Skipped due to learnings
Learnt from: djurny
PR: armbian/build#8235
File: packages/bsp/mvebu/helios4/helios4-wol.service:0-0
Timestamp: 2025-05-29T01:56:01.604Z
Learning: For ARM-based devices like Helios4 that use DeviceTree, the expected systemd network interface naming scheme is "end[0-9]+" (DeviceTree alias index), making the regex "^(eth|en[do])[0-9]+" appropriate as it covers traditional "eth", PCI on-board "eno", and DeviceTree "end" interfaces without unnecessary "enp" (PCI slot) support.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
Learning: In U-Boot scripts, `itest.s` should be used for explicit string comparisons rather than plain `itest` with string operators like `==`.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: djurny
PR: armbian/build#8203
File: config/bootscripts/boot-sunxi.cmd:34-38
Timestamp: 2025-05-18T00:59:02.274Z
Learning: In U-Boot shell environments, `itest` silently handles non-numeric values without producing errors, unlike in bash or other standard shells. Additionally, U-Boot doesn't support stderr redirection with syntax like `2>/dev/null`. The standard pattern for verbosity checking in U-Boot is `if test "${verbosity}" != "" ; then if itest ${verbosity} -gt 0 ; then...`, which correctly handles both numeric and non-numeric values.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:53:10.331Z
Learning: The bash construct `export $(set | sed -En '/^BOOTSCRIPT_TEMPLATE__/s/=.*$//p')` is safe from word splitting because it extracts only variable names (by removing everything after `=`), and bash variable names cannot contain whitespace or special characters.
Learnt from: Grippy98
PR: armbian/build#8202
File: config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh:2-3
Timestamp: 2025-05-16T15:34:34.672Z
Learning: The shell scripts in the Armbian build system's desktop configuration files, such as config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh, rely on environment variables like $SRC and $destination that are expected to be set externally before the script is executed.

@djurny djurny force-pushed the feat/bootscript-templating branch from 63365b5 to 34f1420 Compare July 10, 2025 01:34
@coderabbitai coderabbitai bot added Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines labels Jul 10, 2025
@djurny djurny force-pushed the feat/bootscript-templating branch from 34f1420 to cd4b4c9 Compare July 11, 2025 23:37
@coderabbitai coderabbitai bot added Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines labels Jul 16, 2025
@djurny djurny force-pushed the feat/bootscript-templating branch from df2940a to 34a7536 Compare July 18, 2025 01:43
@github-actions github-actions bot removed size/medium PR with more then 50 and less then 250 lines Ready to merge Reviewed, tested and ready for merge labels Jul 18, 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 (1)
config/bootscripts/boot-generic.cmd.template (1)

127-137: No-op vendor blocks: remove or mark as future work

The marvell and rockchip clauses currently contain only # comments. Keeping empty branches bloats the script and slightly slows parsing on boards that will never match.
Either delete them or add a TODO explaining what will be added later so maintainers don’t assume it’s forgotten code.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between df2940a and 34a7536.

📒 Files selected for processing (4)
  • config/bootscripts/boot-generic.cmd.template (1 hunks)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh (1 hunks)
  • lib/functions/host/prepare-host.sh (1 hunks)
  • lib/functions/rootfs/distro-agnostic.sh (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • lib/functions/host/prepare-host.sh
  • lib/functions/rootfs/distro-agnostic.sh
  • lib/functions/bsp/armbian-bsp-cli-deb.sh
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: EvilOlaf
PR: armbian/build#8328
File: lib/functions/compilation/patch/drivers_network.sh:542-545
Timestamp: 2025-06-24T10:08:40.313Z
Learning: In the Armbian build system, when a PR removes build support for a specific kernel version, version check issues for that removed version become practically irrelevant even if they appear incorrect in isolation. Context about which kernel versions are being deprecated/removed is important for understanding the impact of version-related code changes.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the `fdtfile` variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If `fdtfile` is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.
Learnt from: djurny
PR: armbian/build#8203
File: config/bootscripts/boot-sunxi.cmd:111-114
Timestamp: 2025-05-17T23:08:31.746Z
Learning: In U-Boot scripts, the `setexpr sub` command is valid for string operations when CONFIG_REGEX=y is enabled. This allows for pattern substitution in strings, as documented in https://docs.u-boot.org/en/latest/usage/cmd/setexpr.html. The syntax is `setexpr <variable> sub <pattern> <replacement> <string>`.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the `setexpr` command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:38-44
Timestamp: 2025-06-12T21:14:36.024Z
Learning: In config/bootscripts/boot-sunxi.cmd the unconditional "+1" increment in func_align_addr_next (when align_overlap_oboe_avoidance="on") is intentional. It compensates for a known off-by-one error in U-Boot where the end address is calculated as start+size instead of start+size-1, so the extra page prevents overlap. This behavior should not be “optimized away”.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
Learning: In U-Boot scripts, `itest.s` should be used for explicit string comparisons rather than plain `itest` with string operators like `==`.
Learnt from: djurny
PR: armbian/build#8315
File: config/bootscripts/boot-generic.cmd.template:62-62
Timestamp: 2025-07-13T14:00:39.402Z
Learning: In U-Boot bootscripts, the verbosity check pattern `test "${verbosity}" = "" || itest ${verbosity} -gt 0 && echo "${l_message}"` correctly implements quiet behavior when verbosity is unset or "0", and verbose behavior when verbosity > 0, due to proper operator precedence where || has lower precedence than &&.
config/bootscripts/boot-generic.cmd.template (24)
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the `fdtfile` variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If `fdtfile` is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:38-44
Timestamp: 2025-06-12T21:14:36.024Z
Learning: In config/bootscripts/boot-sunxi.cmd the unconditional "+1" increment in func_align_addr_next (when align_overlap_oboe_avoidance="on") is intentional. It compensates for a known off-by-one error in U-Boot where the end address is calculated as start+size instead of start+size-1, so the extra page prevents overlap. This behavior should not be “optimized away”.
Learnt from: pyavitz
PR: armbian/build#8388
File: config/boards/kickpik2b.conf:1-14
Timestamp: 2025-07-17T04:12:33.125Z
Learning: In the Armbian build system, board configuration files (*.conf) follow a project standard of not including shebang lines, even though they contain bash code and are sourced by the build system. This is an established Armbian convention that individual contributors are expected to follow, and changes to this standard would require broader project maintainer approval.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:13-23
Timestamp: 2025-06-12T21:08:11.318Z
Learning: In config/bootscripts/boot-sunxi.cmd the variable name `align_overlap_oboe_avoidance` intentionally uses the acronym “OBOE” (Off-By-One Error); it is not a typo and should not be renamed.
Learnt from: EvilOlaf
PR: armbian/build#0
File: :0-0
Timestamp: 2025-06-16T03:24:00.458Z
Learning: In Armbian board configuration files (.csc), the standard pattern is to have only one line as a comment describing the board hardware specifications. This single-line description typically includes the SoC model, core count, RAM options, and key features like connectivity options, storage interfaces, and special features.
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
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.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: Grippy98
PR: armbian/build#8202
File: config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh:2-3
Timestamp: 2025-05-16T15:34:34.672Z
Learning: The shell scripts in the Armbian build system's desktop configuration files, such as config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh, rely on environment variables like $SRC and $destination that are expected to be set externally before the script is executed.
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
Learning: In U-Boot scripts, `itest.s` should be used for explicit string comparisons rather than plain `itest` with string operators like `==`.
Learnt from: djurny
PR: armbian/build#8315
File: config/bootscripts/boot-generic.cmd.template:62-62
Timestamp: 2025-07-13T14:00:39.402Z
Learning: In U-Boot bootscripts, the verbosity check pattern `test "${verbosity}" = "" || itest ${verbosity} -gt 0 && echo "${l_message}"` correctly implements quiet behavior when verbosity is unset or "0", and verbose behavior when verbosity > 0, due to proper operator precedence where || has lower precedence than &&.
Learnt from: djurny
PR: armbian/build#8203
File: config/bootscripts/boot-sunxi.cmd:34-38
Timestamp: 2025-05-18T00:59:02.274Z
Learning: In U-Boot shell environments, `itest` silently handles non-numeric values without producing errors, unlike in bash or other standard shells. Additionally, U-Boot doesn't support stderr redirection with syntax like `2>/dev/null`. The standard pattern for verbosity checking in U-Boot is `if test "${verbosity}" != "" ; then if itest ${verbosity} -gt 0 ; then...`, which correctly handles both numeric and non-numeric values.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: In U-Boot shell scripting, the `else ;` construct followed by commands on subsequent lines is valid syntax, as demonstrated by empirical testing. Both `else command` and `else ; command` forms are acceptable in U-Boot's shell implementation.
Learnt from: djurny
PR: armbian/build#8315
File: config/bootscripts/boot-generic.cmd.template:499-503
Timestamp: 2025-07-13T14:42:49.368Z
Learning: In U-Boot's current Hush shell implementation, empty then branches in if-then-else constructs (like `if kaslrseed ; then else`) do not cause syntax errors and are valid syntax, contrary to some documentation that suggests all branches must contain commands.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:63-68
Timestamp: 2025-07-13T14:03:56.219Z
Learning: The envsubst command requires the SHELL-FORMAT parameter to be enclosed in single quotes to prevent premature shell expansion of variables. In expressions like envsubst "'${SHELL_FORMAT}'", the single quotes are literal characters passed to envsubst, not shell quoting, and are necessary for proper variable substitution.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: U-Boot's Hush shell accepts the `else ;` construct followed by commands on subsequent lines as valid syntax, even though the standard documentation examples typically show else clauses without the trailing semicolon. This was confirmed through empirical testing on actual U-Boot.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the `setexpr` command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.
Learnt from: EvilOlaf
PR: armbian/build#8328
File: lib/functions/compilation/patch/drivers_network.sh:542-545
Timestamp: 2025-06-24T10:08:40.313Z
Learning: In the Armbian build system, when a PR removes build support for a specific kernel version, version check issues for that removed version become practically irrelevant even if they appear incorrect in isolation. Context about which kernel versions are being deprecated/removed is important for understanding the impact of version-related code changes.
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: Armbian build framework extensions are NOT designed to run standalone but are called by the supervisor. The framework provides environment variables like USERPATCHES_PATH and SDCARD, and commands are executed with protection via run_host_command_logged and chroot_sdcard functions that use bash -e -o pipefail.
Learnt from: EvilOlaf
PR: armbian/build#8330
File: config/sources/families/sun55iw3.conf:32-36
Timestamp: 2025-06-25T03:42:09.086Z
Learning: In Armbian build system configuration files like config/sources/families/*.conf, KERNELSOURCE is explicitly declared when using unofficial or 3rd party kernel repositories (like the "dev" branch using https://github.com/apritzel/linux), but can be omitted when using the standard mainline kernel (like the "edge" branch) since it will fall back to the default mainline source.
Learnt from: EvilOlaf
PR: armbian/build#8330
File: config/sources/families/sun55iw3.conf:32-36
Timestamp: 2025-06-25T03:40:52.109Z
Learning: In Armbian build system configuration files like config/sources/families/*.conf, when KERNELSOURCE is not explicitly declared in a case branch, the system falls back to a default KERNELSOURCE value, so missing KERNELSOURCE declarations are not critical issues.
Learnt from: EvilOlaf
PR: armbian/build#8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: In Armbian build framework, extensions are loaded and executed via lib/functions/general/extensions.sh using call_extension_method. The framework sets set -o errexit and set -o errtrace globally, and individual commands run with pipefail protection through the command execution functions.
🔇 Additional comments (2)
config/bootscripts/boot-generic.cmd.template (2)

192-197: setexpr … sub requires CONFIG_REGEX – verify all target U-Boot builds enable it

setexpr l_fdtfile_basename sub ".*/" "" "${fdtfile}" relies on the sub variant that is compiled only when CONFIG_REGEX=y.
Several vendor forks (notably some Rockchip & Marvell downstream trees) ship with CONFIG_REGEX disabled to save ~8 KB. Booting would stop here with “unknown operator” if that’s the case.
Either:

  1. keep this but add a build-time guard that rejects boards lacking CONFIG_REGEX, or
  2. fall back to a pure-shell extraction when setexpr sub fails.

Would you like a small helper that probes setexpr sub at runtime and silently switches to a POSIX-style ${var##*/} replacement if missing?


62-62: Good call on the concise verbosity helper

The operator-precedence trick keeps the script quiet on default boots while still allowing verbose debugging. Nicely done.

@igorpecovnik igorpecovnik requested review from adeepn and iav July 18, 2025 15:52
@djurny djurny force-pushed the feat/bootscript-templating branch from 34a7536 to 74e004d Compare July 30, 2025 03:07
@coderabbitai coderabbitai bot added Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines labels Jul 30, 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: 0

🧹 Nitpick comments (6)
lib/functions/rootfs/distro-agnostic.sh (4)

15-27: Broaden the regex to handle all serial-console device names

The pattern 'tty'[AGSU]* matches only ttyA*, ttyG*, ttyS*, and ttyU*.
It misses legitimate serial devices such as ttyAMA*, ttyUSB*, ttyACM*, etc., and therefore risks leaking serial consoles into the display list or, inversely, filtering out valid ones elsewhere.

Consider switching to a more inclusive expression:

-if [[ "${ITEM#*=}" =~ 'tty'[AGSU]* ]] ; then
+if [[ "${ITEM#*=}" =~ ^tty[^0] ]] ; then   # any tty* except tty0

or even:

if [[ "${ITEM#*=}" =~ ^tty[A-Za-z]*[0-9]*$ ]]; then

This keeps tty0 (frame-buffer console) intact while reliably filtering serial TTYs.


37-49: Mirror the regex improvement for the serial-console collector

The same limited pattern appears here. Align the regex with whichever broader version you adopt above to keep the two helper functions consistent.


70-72: Replace deprecated egrep with grep -E and silence output

egrep is officially deprecated. Swapping to grep -E -q avoids the warning and suppresses noisy stdout:

-! egrep '\$\{?BOOTSCRIPT_TEMPLATE__' "${1:?}"
+grep -E -q '\$\{?BOOTSCRIPT_TEMPLATE__' "${1:?}" && return 1 || return 0

This keeps the intent (non-zero if unresolved vars remain) while future-proofing the check.


230-234: Only the cat part of the pipeline is logged

run_host_command_logged wraps just cat, so the actual rendering (and any failure) bypasses the logger.
Minimal change:

-run_host_command_logged cat "${bootscript_src_path}/${bootscript_src}" | render_bootscript_template > "${SDCARD}/boot/${bootscript_dst}"
+run_host_command_logged bash -c 'cat "$1" | render_bootscript_template' _ "${bootscript_src_path}/${bootscript_src}" > "${SDCARD}/boot/${bootscript_dst}"

Grouping the whole pipeline inside the logging helper keeps diagnostics intact.

config/bootscripts/boot-generic.cmd.template (2)

139-145: Tiny nit – avoid polluting load_addr_calc with the arithmetic probe result
setexpr load_addr_calc 1 + 1 leaves the variable with the value 2 for a split second before you overwrite it with “on/off”. While harmless, it can confuse interactive debugging sessions:

-	if setexpr load_addr_calc 1 + 1 ; then
-		setenv load_addr_calc 'on'
+	if setexpr _dummy 1 + 1 ; then
+		setenv load_addr_calc 'on'

Using a throw-away variable keeps load_addr_calc strictly boolean.


258-265: Minor readability tweak – skip the leading dash when prefix is empty
When overlay_prefix is empty the first probe tries to load
.../overlay/-${each_overlay}.dtbo, an impossible filename.
Branching once avoids the pointless lookup:

-		setenv l_overlay_prefix "${overlay_prefix}"
-		setenv l_file "${l_fdtdir}/overlay/${l_overlay_prefix}-${each_overlay}.dtbo"
+		setenv l_overlay_prefix "${overlay_prefix}"
+		if test "${l_overlay_prefix}" != "" ; then
+			setenv l_file "${l_fdtdir}/overlay/${l_overlay_prefix}-${each_overlay}.dtbo"
+		else
+			setenv l_file "${l_fdtdir}/overlay/${each_overlay}.dtbo"
+		fi

Purely cosmetic; feel free to ignore if you prefer the current shorter form.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34a7536 and 74e004d.

📒 Files selected for processing (4)
  • config/bootscripts/boot-generic.cmd.template (1 hunks)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh (1 hunks)
  • lib/functions/host/prepare-host.sh (1 hunks)
  • lib/functions/rootfs/distro-agnostic.sh (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • lib/functions/host/prepare-host.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: EvilOlaf
PR: armbian/build#8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub or the PR API to get the complete picture of what files are being added or modified.
Learnt from: EvilOlaf
PR: armbian/build#8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub API (https://api.github.com/repos/armbian/build/pulls/{pr_number}/files) to get the complete picture of what files are being added or modified, especially for U-Boot patches that will be applied during the build process.
Learnt from: djurny
PR: armbian/build#8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the `${cpu}` environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.
Learnt from: EvilOlaf
PR: armbian/build#8328
File: lib/functions/compilation/patch/drivers_network.sh:542-545
Timestamp: 2025-06-24T10:08:40.313Z
Learning: In the Armbian build system, when a PR removes build support for a specific kernel version, version check issues for that removed version become practically irrelevant even if they appear incorrect in isolation. Context about which kernel versions are being deprecated/removed is important for understanding the impact of version-related code changes.
Learnt from: EvilOlaf
PR: armbian/build#0
File: :0-0
Timestamp: 2025-07-21T04:12:02.439Z
Learning: In the Armbian build system, for recurring maintenance tasks like kernel version bumping, TODO comments should use generic version formats (e.g., "MAJOR.MINOR-rc1") rather than specific version numbers (e.g., "6.17-rc1") to avoid the need for frequent comment updates that would create unnecessary maintenance overhead.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the `fdtfile` variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If `fdtfile` is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.
Learnt from: EvilOlaf
PR: armbian/build#8417
File: config/boards/orangepi5pro.csc:57-58
Timestamp: 2025-07-23T07:30:52.265Z
Learning: In the Armbian build system, BOOTPATCHDIR can contain board-specific subdirectories (e.g., board_orangepi5pro) for applying patches to specific boards only. The framework automatically checks if such board-specific subdirectories exist for the board being built and applies those patches accordingly.
Learnt from: djurny
PR: armbian/build#8203
File: config/bootscripts/boot-sunxi.cmd:111-114
Timestamp: 2025-05-17T23:08:31.746Z
Learning: In U-Boot scripts, the `setexpr sub` command is valid for string operations when CONFIG_REGEX=y is enabled. This allows for pattern substitution in strings, as documented in https://docs.u-boot.org/en/latest/usage/cmd/setexpr.html. The syntax is `setexpr <variable> sub <pattern> <replacement> <string>`.
Learnt from: djurny
PR: armbian/build#8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the `setexpr` command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.
Learnt from: djurny
PR: armbian/build#8287
File: config/bootscripts/boot-sunxi.cmd:38-44
Timestamp: 2025-06-12T21:14:36.024Z
Learning: In config/bootscripts/boot-sunxi.cmd the unconditional "+1" increment in func_align_addr_next (when align_overlap_oboe_avoidance="on") is intentional. It compensates for a known off-by-one error in U-Boot where the end address is calculated as start+size instead of start+size-1, so the extra page prevents overlap. This behavior should not be “optimized away”.
Learnt from: rpardini
PR: armbian/build#8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.
Learnt from: djurny
PR: armbian/build#8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
Learning: In U-Boot scripts, `itest.s` should be used for explicit string comparisons rather than plain `itest` with string operators like `==`.
config/bootscripts/boot-generic.cmd.template (28)

Learnt from: djurny
PR: #8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the fdtfile variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If fdtfile is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.

Learnt from: djurny
PR: #8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the ${cpu} environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.

Learnt from: djurny
PR: #8287
File: config/bootscripts/boot-sunxi.cmd:38-44
Timestamp: 2025-06-12T21:14:36.024Z
Learning: In config/bootscripts/boot-sunxi.cmd the unconditional "+1" increment in func_align_addr_next (when align_overlap_oboe_avoidance="on") is intentional. It compensates for a known off-by-one error in U-Boot where the end address is calculated as start+size instead of start+size-1, so the extra page prevents overlap. This behavior should not be “optimized away”.

Learnt from: EvilOlaf
PR: #8417
File: config/boards/orangepi5pro.csc:57-58
Timestamp: 2025-07-23T07:30:52.265Z
Learning: In the Armbian build system, BOOTPATCHDIR can contain board-specific subdirectories (e.g., board_orangepi5pro) for applying patches to specific boards only. The framework automatically checks if such board-specific subdirectories exist for the board being built and applies those patches accordingly.

Learnt from: pyavitz
PR: #8388
File: config/boards/kickpik2b.conf:1-14
Timestamp: 2025-07-17T04:12:33.125Z
Learning: In the Armbian build system, board configuration files (*.conf) follow a project standard of not including shebang lines, even though they contain bash code and are sourced by the build system. This is an established Armbian convention that individual contributors are expected to follow, and changes to this standard would require broader project maintainer approval.

Learnt from: EvilOlaf
PR: #8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub or the PR API to get the complete picture of what files are being added or modified.

Learnt from: rpardini
PR: #8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.

Learnt from: djurny
PR: #8287
File: config/bootscripts/boot-sunxi.cmd:13-23
Timestamp: 2025-06-12T21:08:11.318Z
Learning: In config/bootscripts/boot-sunxi.cmd the variable name align_overlap_oboe_avoidance intentionally uses the acronym “OBOE” (Off-By-One Error); it is not a typo and should not be renamed.

Learnt from: EvilOlaf
PR: #8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub API (https://api.github.com/repos/armbian/build/pulls/{pr_number}/files) to get the complete picture of what files are being added or modified, especially for U-Boot patches that will be applied during the build process.

Learnt from: EvilOlaf
PR: armbian/build#0
File: :0-0
Timestamp: 2025-06-16T03:24:00.458Z
Learning: In Armbian board configuration files (.csc), the standard pattern is to have only one line as a comment describing the board hardware specifications. This single-line description typically includes the SoC model, core count, RAM options, and key features like connectivity options, storage interfaces, and special features.

Learnt from: djurny
PR: #8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
Learning: In U-Boot scripts, itest.s should be used for explicit string comparisons rather than plain itest with string operators like ==.

Learnt from: djurny
PR: #8315
File: config/bootscripts/boot-generic.cmd.template:62-62
Timestamp: 2025-07-13T14:00:39.402Z
Learning: In U-Boot bootscripts, the verbosity check pattern test "${verbosity}" = "" || itest ${verbosity} -gt 0 && echo "${l_message}" correctly implements quiet behavior when verbosity is unset or "0", and verbose behavior when verbosity > 0, due to proper operator precedence where || has lower precedence than &&.

Learnt from: rpardini
PR: #8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.

Learnt from: djurny
PR: #8203
File: config/bootscripts/boot-sunxi.cmd:34-38
Timestamp: 2025-05-18T00:59:02.274Z
Learning: In U-Boot shell environments, itest silently handles non-numeric values without producing errors, unlike in bash or other standard shells. Additionally, U-Boot doesn't support stderr redirection with syntax like 2>/dev/null. The standard pattern for verbosity checking in U-Boot is if test "${verbosity}" != "" ; then if itest ${verbosity} -gt 0 ; then..., which correctly handles both numeric and non-numeric values.

Learnt from: djurny
PR: #8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: In U-Boot shell scripting, the else ; construct followed by commands on subsequent lines is valid syntax, as demonstrated by empirical testing. Both else command and else ; command forms are acceptable in U-Boot's shell implementation.

Learnt from: djurny
PR: #8315
File: config/bootscripts/boot-generic.cmd.template:499-503
Timestamp: 2025-07-13T14:42:49.368Z
Learning: In U-Boot's current Hush shell implementation, empty then branches in if-then-else constructs (like if kaslrseed ; then else) do not cause syntax errors and are valid syntax, contrary to some documentation that suggests all branches must contain commands.

Learnt from: djurny
PR: #8315
File: lib/functions/rootfs/distro-agnostic.sh:63-68
Timestamp: 2025-07-13T14:03:56.219Z
Learning: The envsubst command requires the SHELL-FORMAT parameter to be enclosed in single quotes to prevent premature shell expansion of variables. In expressions like envsubst "'${SHELL_FORMAT}'", the single quotes are literal characters passed to envsubst, not shell quoting, and are necessary for proper variable substitution.

Learnt from: djurny
PR: #8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.

Learnt from: djurny
PR: #8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: U-Boot's Hush shell accepts the else ; construct followed by commands on subsequent lines as valid syntax, even though the standard documentation examples typically show else clauses without the trailing semicolon. This was confirmed through empirical testing on actual U-Boot.

Learnt from: djurny
PR: #8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the setexpr command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.

Learnt from: EvilOlaf
PR: #8328
File: lib/functions/compilation/patch/drivers_network.sh:542-545
Timestamp: 2025-06-24T10:08:40.313Z
Learning: In the Armbian build system, when a PR removes build support for a specific kernel version, version check issues for that removed version become practically irrelevant even if they appear incorrect in isolation. Context about which kernel versions are being deprecated/removed is important for understanding the impact of version-related code changes.

Learnt from: EvilOlaf
PR: armbian/build#0
File: :0-0
Timestamp: 2025-07-21T04:12:02.439Z
Learning: In the Armbian build system, for recurring maintenance tasks like kernel version bumping, TODO comments should use generic version formats (e.g., "MAJOR.MINOR-rc1") rather than specific version numbers (e.g., "6.17-rc1") to avoid the need for frequent comment updates that would create unnecessary maintenance overhead.

Learnt from: amazingfate
PR: #8419
File: lib/functions/host/prepare-host.sh:272-275
Timestamp: 2025-07-23T10:01:41.310Z
Learning: In the Armbian build system, the design philosophy is to fail fast when host dependencies are not met rather than gracefully skipping unsupported architectures. This ensures build environment consistency and prevents silent failures. Host dependency checks should be explicit and non-negotiable.

Learnt from: pyavitz
PR: #8421
File: config/kernel/linux-sunxi64-edge.config:805-825
Timestamp: 2025-07-27T15:53:30.629Z
Learning: In the Armbian build system, kernel configurations prioritize broad hardware compatibility over optimization concerns. Even when including numerous legacy/obsolete drivers causes technical issues like increased initramfs size and slower enumeration, the project philosophy is to "appease the masses" by ensuring maximum device compatibility rather than optimizing for specific use cases.

Learnt from: EvilOlaf
PR: #8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: Armbian build framework extensions are NOT designed to run standalone but are called by the supervisor. The framework provides environment variables like USERPATCHES_PATH and SDCARD, and commands are executed with protection via run_host_command_logged and chroot_sdcard functions that use bash -e -o pipefail.

Learnt from: djurny
PR: #8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
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.

Learnt from: Grippy98
PR: #8152
File: lib/functions/configuration/interactive.sh:209-266
Timestamp: 2025-05-05T12:35:07.143Z
Learning: For the interactive kernel selection in Armbian, KERNEL_MAJOR_MINOR and KERNEL_DESCRIPTION are parsed from family.conf but deliberately not set as environment variables to avoid potential interference with other parts of the build system.

Learnt from: Grippy98
PR: #8202
File: config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh:2-3
Timestamp: 2025-05-16T15:34:34.672Z
Learning: The shell scripts in the Armbian build system's desktop configuration files, such as config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh, rely on environment variables like $SRC and $destination that are expected to be set externally before the script is executed.

lib/functions/rootfs/distro-agnostic.sh (24)

Learnt from: EvilOlaf
PR: #8417
File: config/boards/orangepi5pro.csc:57-58
Timestamp: 2025-07-23T07:30:52.265Z
Learning: In the Armbian build system, BOOTPATCHDIR can contain board-specific subdirectories (e.g., board_orangepi5pro) for applying patches to specific boards only. The framework automatically checks if such board-specific subdirectories exist for the board being built and applies those patches accordingly.

Learnt from: leggewie
PR: #8133
File: extensions/apa.sh:1-2
Timestamp: 2025-04-28T08:27:26.890Z
Learning: In the Armbian build system, extension scripts in the extensions/ directory contain hook functions and are meant to be sourced, not executed directly. These scripts don't require a shebang or set -euo pipefail.

Learnt from: rpardini
PR: #8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:73-75
Timestamp: 2025-03-31T22:20:41.849Z
Learning: When porting patches between U-Boot versions (like from 2025.01 to 2025.04), rpardini prefers to maintain patches as-is rather than introducing refactoring changes, even when potential improvements are identified. This approach prioritizes consistency and reduces the risk of introducing new issues.

Learnt from: Grippy98
PR: #8202
File: config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh:2-3
Timestamp: 2025-05-16T15:34:34.672Z
Learning: The shell scripts in the Armbian build system's desktop configuration files, such as config/desktop/trixie/environments/gnome/armbian/create_desktop_package.sh, rely on environment variables like $SRC and $destination that are expected to be set externally before the script is executed.

Learnt from: djurny
PR: #8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:53:10.331Z
Learning: The bash construct export $(set | sed -En '/^BOOTSCRIPT_TEMPLATE__/s/=.*$//p') is safe from word splitting because it extracts only variable names (by removing everything after =), and bash variable names cannot contain whitespace or special characters.

Learnt from: djurny
PR: #8315
File: lib/functions/rootfs/distro-agnostic.sh:63-68
Timestamp: 2025-07-13T14:03:56.219Z
Learning: The envsubst command requires the SHELL-FORMAT parameter to be enclosed in single quotes to prevent premature shell expansion of variables. In expressions like envsubst "'${SHELL_FORMAT}'", the single quotes are literal characters passed to envsubst, not shell quoting, and are necessary for proper variable substitution.

Learnt from: djurny
PR: #8315
File: lib/functions/rootfs/distro-agnostic.sh:54-68
Timestamp: 2025-06-22T00:45:26.182Z
Learning: In Armbian build system, external command dependencies like envsubst are handled by adding the required packages (e.g., gettext for envsubst) to host_dependencies in adaptative_prepare_host_dependencies function in lib/functions/host/prepare-host.sh, rather than checking command availability at runtime.

Learnt from: djurny
PR: #8287
File: config/bootscripts/boot-sunxi.cmd:148-161
Timestamp: 2025-06-12T21:03:39.686Z
Learning: In Armbian U-Boot bootscripts, the ${cpu} environment variable is always pre-set by U-Boot (or defaults to a valid value), so additional guards against it being unset are unnecessary.

Learnt from: djurny
PR: #8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In U-Boot bootscripts, the setexpr command will not fail if a variable is empty - it simply won't perform any substitution operations and leaves the target variable unchanged.

Learnt from: djurny
PR: #8315
File: config/bootscripts/boot-generic.cmd.template:62-62
Timestamp: 2025-07-13T14:00:39.402Z
Learning: In U-Boot bootscripts, the verbosity check pattern test "${verbosity}" = "" || itest ${verbosity} -gt 0 && echo "${l_message}" correctly implements quiet behavior when verbosity is unset or "0", and verbose behavior when verbosity > 0, due to proper operator precedence where || has lower precedence than &&.

Learnt from: amazingfate
PR: #8419
File: lib/functions/host/prepare-host.sh:272-275
Timestamp: 2025-07-23T10:01:41.310Z
Learning: In the Armbian build system, the design philosophy is to fail fast when host dependencies are not met rather than gracefully skipping unsupported architectures. This ensures build environment consistency and prevents silent failures. Host dependency checks should be explicit and non-negotiable.

Learnt from: EvilOlaf
PR: #8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: Armbian build framework extensions are NOT designed to run standalone but are called by the supervisor. The framework provides environment variables like USERPATCHES_PATH and SDCARD, and commands are executed with protection via run_host_command_logged and chroot_sdcard functions that use bash -e -o pipefail.

Learnt from: djurny
PR: #8287
File: config/bootscripts/boot-sunxi.cmd:13-23
Timestamp: 2025-06-12T21:08:11.318Z
Learning: In config/bootscripts/boot-sunxi.cmd the variable name align_overlap_oboe_avoidance intentionally uses the acronym “OBOE” (Off-By-One Error); it is not a typo and should not be renamed.

Learnt from: djurny
PR: #8235
File: packages/bsp/mvebu/helios4/helios4-wol.service:0-0
Timestamp: 2025-05-29T01:52:21.381Z
Learning: In systemd service ExecStart commands, shell variables like ${INTF} can cause issues because systemd may resolve them before the shell processes them, leading to "no device matches name" errors. Using xargs with -I{} is a more reliable approach for iterating over dynamic lists in systemd services, as it avoids variable substitution problems entirely.

Learnt from: djurny
PR: #8166
File: config/bootscripts/boot-mvebu.cmd:38-50
Timestamp: 2025-05-07T20:49:40.969Z
Learning: In U-Boot scripts, itest.s should be used for explicit string comparisons rather than plain itest with string operators like ==.

Learnt from: EvilOlaf
PR: #8328
File: lib/functions/compilation/patch/drivers_network.sh:542-545
Timestamp: 2025-06-24T10:08:40.313Z
Learning: In the Armbian build system, when a PR removes build support for a specific kernel version, version check issues for that removed version become practically irrelevant even if they appear incorrect in isolation. Context about which kernel versions are being deprecated/removed is important for understanding the impact of version-related code changes.

Learnt from: pyavitz
PR: #8388
File: config/boards/kickpik2b.conf:1-14
Timestamp: 2025-07-17T04:12:33.125Z
Learning: In the Armbian build system, board configuration files (*.conf) follow a project standard of not including shebang lines, even though they contain bash code and are sourced by the build system. This is an established Armbian convention that individual contributors are expected to follow, and changes to this standard would require broader project maintainer approval.

Learnt from: rpardini
PR: #8044
File: patch/u-boot/v2025.04/cmd-fileenv-read-string-from-file-into-env.patch:76-86
Timestamp: 2025-03-31T22:20:48.475Z
Learning: For the Armbian build project, maintaining consistency with existing patches across U-Boot versions (such as between 2025.01 and 2025.04) is prioritized over refactoring individual patches for code improvements.

Learnt from: EvilOlaf
PR: #8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub API (https://api.github.com/repos/armbian/build/pulls/{pr_number}/files) to get the complete picture of what files are being added or modified, especially for U-Boot patches that will be applied during the build process.

Learnt from: djurny
PR: #8272
File: config/bootscripts/boot-mvebu.cmd:182-186
Timestamp: 2025-06-04T23:45:38.860Z
Learning: In config/bootscripts/boot-mvebu.cmd, the fdtfile variable is mandatory for booting and is pre-set by U-Boot, but can be overridden via armbianEnv.txt. If fdtfile is empty, the subsequent device tree file search logic will eventually fail and trigger the critical error "Cannot find DT!" with proper error handling.

Learnt from: EvilOlaf
PR: #8298
File: extensions/https_proxy.sh:1-9
Timestamp: 2025-06-14T05:53:10.627Z
Learning: In Armbian build framework, extensions are loaded and executed via lib/functions/general/extensions.sh using call_extension_method. The framework sets set -o errexit and set -o errtrace globally, and individual commands run with pipefail protection through the command execution functions.

Learnt from: EvilOlaf
PR: #8330
File: config/sources/families/sun55iw3.conf:32-36
Timestamp: 2025-06-25T03:42:09.086Z
Learning: In Armbian build system configuration files like config/sources/families/*.conf, KERNELSOURCE is explicitly declared when using unofficial or 3rd party kernel repositories (like the "dev" branch using https://github.com/apritzel/linux), but can be omitted when using the standard mainline kernel (like the "edge" branch) since it will fall back to the default mainline source.

Learnt from: EvilOlaf
PR: #8330
File: config/sources/families/sun55iw3.conf:32-36
Timestamp: 2025-06-25T03:40:52.109Z
Learning: In Armbian build system configuration files like config/sources/families/*.conf, when KERNELSOURCE is not explicitly declared in a case branch, the system falls back to a default KERNELSOURCE value, so missing KERNELSOURCE declarations are not critical issues.

Learnt from: djurny
PR: #8272
File: config/bootscripts/boot-mvebu.cmd:61-63
Timestamp: 2025-06-04T23:52:39.493Z
Learning: In U-Boot shell scripting, the else ; construct followed by commands on subsequent lines is valid syntax, as demonstrated by empirical testing. Both else command and else ; command forms are acceptable in U-Boot's shell implementation.

🔇 Additional comments (3)
lib/functions/rootfs/distro-agnostic.sh (1)

54-68: Template-rendering pipeline looks solid

The subshell-scoped export, the single-quoted envsubst whitelist, and the date stamp all check out. No concerns here.

config/bootscripts/boot-generic.cmd.template (2)

6-16: Well-structured template header – no issues spotted
The introductory block clearly documents the env-subst rendering contract and points future readers to the relevant build-system helpers. Good practice and nothing to adjust.


499-503: Empty then branch intentionally kept – behaviour confirmed
The if kaslrseed ; then else construct has been validated on current U-Boot hush; it parses fine and keeps the script concise. No action required.

Copy link
Collaborator

@leggewie leggewie left a comment

Choose a reason for hiding this comment

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

Looks really awesome. I like the idea and hope it gets merged soon.

djurny added 2 commits July 31, 2025 11:31
Enable bootscript templating using `envsubst`.
Add generic bootscript.
`test` does not support `==`, but deceptively returns `true` in case you use it.
@djurny djurny force-pushed the feat/bootscript-templating branch from 74e004d to 15c05f7 Compare July 31, 2025 03:31
@github-actions github-actions bot removed size/medium PR with more then 50 and less then 250 lines Ready to merge Reviewed, tested and ready for merge labels Jul 31, 2025
@djurny djurny closed this Jul 31, 2025
@djurny djurny reopened this Jul 31, 2025
@djurny
Copy link
Contributor Author

djurny commented Jul 31, 2025

Accidentally closed the PR due to my wonderfully oversensitive touchpad.

@leggewie
Copy link
Collaborator

leggewie commented Aug 1, 2025

@djurny I would say, this needs to be documented. You already have a documentation section up there. Can you prepare a PR for docs.armbian.com as well?


# default environment variables
setenv align_overlap_oboe_avoidance "on"
setenv align_to "${BOOTSCRIPT_TEMPLATE__ALIGN_TO}"
Copy link
Member

Choose a reason for hiding this comment

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

BOOTSCRIPT_TEMPLATE__ALIGN_TO not defined anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @adeepn,
That is correct. Due to the previous comments, I prepared the PR to just add the functionality, not the "roll-out" of it.
If for example, the maintainer if Orangepi Zero wants to start using the template, the following would need to be added to 'boards/config/orangepizero.csc:

    DISPLAYCON=''
    SERIALCON="ttyS0:115200,ttyGS0"

    BOOTSCRIPT='boot-generic.cmd.template:boot.cmd'
    BOOTSCRIPT_TEMPLATE__ALIGN_TO='0x00001000'
    BOOTSCRIPT_TEMPLATE__BOARD_FAMILY="${BOARDFAMILY:-sun8i}"
    BOOTSCRIPT_TEMPLATE__BOARD_VENDOR='allwinner'
    BOOTSCRIPT_TEMPLATE__DISPLAY_CONSOLE='' # determine later on
    BOOTSCRIPT_TEMPLATE__LOAD_ADDR='0x45000000'
    BOOTSCRIPT_TEMPLATE__ROOTFS_TYPE="${ROOTFS_TYPE:-ext4}"
    BOOTSCRIPT_TEMPLATE__SERIAL_CONSOLE='' # determine later on

See the PR description where it's laid out in a little more detail.

Hope that answers your question.
Groetjes,

Copy link
Member

Choose a reason for hiding this comment

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

it used in line 56:
setexpr l_modulo ${l_addr_next} % ${align_to} ;
so you need an some non-zero default there.

Copy link
Member

@adeepn adeepn left a comment

Choose a reason for hiding this comment

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

At first, I was against the excessive complexity, but there are some interesting ideas here.
For example, calculating the lengths of the kernel, FDT, and ramdisk.
Overall, it actually turns out to be a fairly sound idea.

But at first glance, what's missing here is:

  • support for fit-image (bootm command)
  • extending the func_inform function to debug/info levels in order to separate useful information from pure debugging (for example, printing bootargs line by line)
    We can start with this and improve it further later.

fi
fi

# booting failed, restore environment variables that are not unique
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is necessary: U-Boot does not save variables automatically without an explicit command, and for quick debugging it makes sense to keep the old values.
As for the original values—I think it's better to just use clearly different var names to avoid any confusion with the originals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @adeepn,
It's not about saving them in the saveenv U-Boot sense, it's about the distro_bootcmd loop, where some variables have a compile time/runtime default and are changed by this bootscript. If for whatever reason this bootscript fails, the next bootcmd_xxx will be attempted by U-Boot. To make sure the next (fallback) bootcmd_xxx still will work, attempts were made to "re-set" variables changed by this bootscript to the values encountered by the bootscript. A bit like a push-pop thing.
For most variables a "local" variant is indeed used, as you also suggest, but some variables are used by U-Boot commands implicitly so "local" variants cannot be used, they can only be "re-set" to the initially encountered values (like bootz implicitly using kernel_comp_addr_r/kernel_comp_size_r).
Hope that makes it more clear.
Groetjes,

Copy link
Member

Choose a reason for hiding this comment

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

it's about the distro_bootcmd loop,

Hmm, I assumed that everything would stop at this script and after that we'd just end up in a regular shell. If it actually tries the next option, then I definitely agree.

some variables are used by U-Boot commands implicitly

bootz not using implicitly kernel_comp_addr_r/kernel_comp_size_r :

bootz [<addr> [<initrd>[:<size>]] [<fdt>]]
addr
  address of kernel image, defaults to the value of the environment variable $loadaddr.

initrd
  address of the initial RAM disk. Use ‘-’ to boot a kernel with a device tree but without an initial RAM disk.

https://docs.u-boot.org/en/stable/usage/cmd/bootz.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

some variables are used by U-Boot commands implicitly
bootz not using implicitly kernel_comp_addr_r/kernel_comp_size_r :

bootz [<addr> [<initrd>[:<size>]] [<fdt>]]
addr
  address of kernel image, defaults to the value of the environment variable $loadaddr.
https://docs.u-boot.org/en/stable/usage/cmd/bootz.html

Hi @adeepn,
You have a point: After re-reading the code, seems that U-Boot booti command implicitly uses the kernel_comp_addr_r and kernel_comp_size_r, instead of bootz as I mentioned.

zImage is a self-extracting version of the kernel, which needs bootz and Image needs booti which also can handle (non-self-extracting) compressed images. These compressed images need the two variables set to declare a memory area where the decompressor can use.

https://github.com/u-boot/u-boot/blob/master/doc/usage/cmd/booti.rst
https://github.com/u-boot/u-boot/blob/29d5636c6f473ac2cf273a2fd07981125197564f/cmd/booti.c#L50

Groetjes,

Copy link
Collaborator

@leggewie leggewie left a comment

Choose a reason for hiding this comment

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

I am really looking forward to this change, thank you for your work, but please let's make sure this is documented before this gets merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
05 Milestone: Second quarter release 08 Milestone: Third quarter release Framework Framework components Hardware Hardware related like kernel, U-Boot, ... Needs review Seeking for review size/large PR with 250 lines or more
Development

Successfully merging this pull request may close these issues.

4 participants