-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA new U-Boot boot script template, Possibly related PRs
Suggested labels
✨ Finishing Touches
🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 exportsBOOTSCRIPT_TEMPLATE__CREATE_DATE
and console vars, then invokesenvsubst
. To silence SC2034 (unused var) and SC2046 (word splitting onexport $(…)
), add above the function:# shellcheck disable=SC2034,SC2046
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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.
Includinggettext
ensures thatenvsubst
is available for template rendering. Verify that the package name matches the target distributions (e.g., Debian’sgettext-base
vs.gettext
).lib/functions/bsp/armbian-bsp-cli-deb.sh (2)
145-153
: Implement template rendering for.template
bootscripts.
Good use ofrender_bootscript_template
and validation viaproof_rendered_bootscript_template
to fail fast on unrendered placeholders.
155-159
: Retain direct copy path for non-template bootscripts.
The fallback tocp -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
andbootscript_export_serial_console
correctly assemble console arguments and export them underBOOTSCRIPT_TEMPLATE__DISPLAY_CONSOLE
andBOOTSCRIPT_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.
Thebootscript_src_path
selection betweenUSERPATCHES_PATH
and defaultSRC/config/bootscripts
is correct.
226-235
: Enable templating in rootfs installation.
Differentiates.template
suffix, renders viarender_bootscript_template
, and enforces completeness withproof_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
, andSERIAL_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 furtherBOOTSCRIPT_TEMPLATE__
variables should appear beyond this point.
Hi @The-going, |
Enable bootscript templating using `envsubst`. Add generic bootscript.
5f93a68
to
7d42abc
Compare
There was a problem hiding this 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 commentThe
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 handlingThe 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 usegrep -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 clarityGroup 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 ofcat
You can pipe the template directly into
render_bootscript_template
withoutcat
:- 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
📒 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
envsubst
for bootscripts with the filename extension.template
.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 andfamily
/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 theboards/config/xxx
files can be overridden bysources/families/xxx
orsources/families/includes/xxx
. For example, forboards/config/orangepizero.csc
, the setting forBOOTSCRIPT
will be overridden bysources/families/includes/sunxi-common.inc
. This can be solved with the following construct insources/families/includes/sunxi-common.inc
:For every board, this has to be inspected to make sure the bootscript selection is done as expected.
How Has This Been Tested?
BOOTSCRIPT
declaration insources/families/includes/sunxi-common.inc
.boot/boot.cmd
:Checklist: