Skip to content

make: let user-provided options win over target defaults - #972

Open
danielinux wants to merge 4 commits into
wolfSSL:masterfrom
danielinux:fix-makefile-assignments
Open

danielinux wants to merge 4 commits into
wolfSSL:masterfrom
danielinux:fix-makefile-assignments

Conversation

@danielinux

Copy link
Copy Markdown
Member

Target-specific assignments in arch.mk/options.mk/board.mk used hard '=', silently clobbering values the user set via command line, environment, or a sourced .config (e.g. LSCRIPT_IN from PR #958 was defeated on every target with a dedicated script).

Convert the target-default assignments to '?=' (first-set wins) and, for LSCRIPT_IN, capture the user value before the target files are parsed so the last-resort default (hal/$(TARGET).ld) and the ARMClang .sct default only apply when the user provided nothing.

CMake: WOLFBOOT_LSCRIPT_TEMPLATE had the same flaw (plain set() over a user -D value); guard it with NOT DEFINED and let test-app use an absolute user template as-is.

Document LSCRIPT_IN as a user option in docs/compile.md.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical make assignment and linker-script selection errors can break builds, use incorrect memory layouts, overwrite custom templates, and leave ChaCha code in flash when encrypted self-updates require it in RAM.

7 open issues
What changed in this PR

This PR adjusts wolfBoot’s Make and CMake configuration so user-provided options take precedence over target defaults, extending the custom linker-script support introduced in #958.

Changes:

  • Converts target defaults to conditional assignments and defers the Make linker-script fallback.
  • Preserves CMake linker-template overrides and supports absolute template paths.
  • Documents the LSCRIPT_IN option and its usage.
File Description
tools/​config.mk Makes the multi-sector erase default conditional.
test-app/​CMakeLists.txt Handles absolute bootloader template paths.
options.mk Makes the ChaCha RAM linker-script selection conditional.
Makefile Captures user script selection and defers fallback defaults.
hal/​boards/​stm32wba55cg_nucleo/​board.mk Makes the board linker-script default conditional.
hal/​boards/​stm32wb_nucleo/​board.mk Makes the board linker-script default conditional.
docs/​compile.md Documents custom linker-script configuration.
CMakeLists.txt Guards linker-template defaults against user overrides.
arch.mk Converts architecture-specific linker-script defaults to conditional assignments.

Review effort: Balanced

Comment thread arch.mk Resolved
Comment thread arch.mk Resolved
Comment thread arch.mk Resolved
Comment thread arch.mk Resolved
Comment thread arch.mk Resolved
Comment thread options.mk Resolved
Comment thread test-app/CMakeLists.txt Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active moderate findings remain in configuration persistence, stage1 override handling, and CMake path quoting, so the change is not ready for approval.

1 open issue
3 previously missed issues

In code that hasn't changed since last review

Medium severity Persist LSCRIPT_IN in generated .config

Makefile:44

LSCRIPT_IN is documented as a .config option, but config/Makefile regenerates .config exclusively from CONFIG_VARS, and that list does not contain LSCRIPT_IN. Therefore make config silently deletes a custom linker-script path before this capture runs, and the next build falls back to the target default. Add LSCRIPT_IN to the persisted configuration variables.

Medium severity Quote linker-template paths in CMake arguments

test-app/​CMakeLists.txt:114

This new path is intended to accept an arbitrary absolute user template, but the unquoted expansion is split into multiple CMake arguments when the path contains whitespace. That makes IS_ABSOLUTE (and then configure_file) fail for valid user paths such as /work trees/custom.ld; quote the template, resolved source, and destination arguments.

Medium severity Persist FLASH_MULTI_SECTOR_ERASE in generated config

tools/​config.mk:105

Changing this to ?= only preserves a value while it is present in .config; config/Makefile rebuilds that file from CONFIG_VARS, which omits FLASH_MULTI_SECTOR_ERASE. A user setting from a generated configuration is consequently discarded and this default becomes 0 again, defeating the precedence change. Add FLASH_MULTI_SECTOR_ERASE to CONFIG_VARS as well.

7 resolved since last review

Review effort: Lite

Comment thread stage1/Makefile Resolved
Target-specific assignments in arch.mk/options.mk/board.mk used hard
'=', silently clobbering values the user set via command line,
environment, or a sourced .config (e.g. LSCRIPT_IN from PR wolfSSL#958 was
defeated on every target with a dedicated script).

Convert the target-default assignments to '?=' (first-set wins) and,
for LSCRIPT_IN, capture the user value before the target files are
parsed so the last-resort default (hal/$(TARGET).ld) and the ARMClang
.sct default only apply when the user provided nothing.

CMake: WOLFBOOT_LSCRIPT_TEMPLATE had the same flaw (plain set() over a
user -D value); guard it with NOT DEFINED and let test-app use an
absolute user template as-is.

Document LSCRIPT_IN as a user option in docs/compile.md.

The x86 FSP TGL boards (kontron_vx3060_s2, nai_68int6) share
hal/x86_fsp_tgl_stage1.ld; arch.mk selects it via 'LSCRIPT_IN ?=', but
the hard default here ran first, so the stage1 build of those boards
looked for a non-existent hal/kontron_vx3060_s2_stage1.ld (CI:
'kontron_vx3060_s2 build test', red on master).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Two moderate active issues remain: generated configuration drops LSCRIPT_IN, and root-invoked stage1 builds resolve user-supplied relative linker-script paths from the wrong directory.

2 open issues
1 resolved since last review

Review effort: Lite

Comment thread docs/compile.md Resolved
Comment thread stage1/Makefile Resolved
Copilot review follow-ups:

- tools/config.mk: add LSCRIPT_IN to CONFIG_VARS so 'make config'
  persists it; it was documented as a .config option but the
  regeneration silently dropped it
- Makefile: pass a user-provided LSCRIPT_IN to the recursive stage1
  build as an absolute path (abspath), since the sub-make resolves
  relative paths from stage1/ while the top-level link resolves them
  from the repo root; target-derived stage1 defaults are untouched

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical linker-script configuration bugs leave empty values from make config and mishandle absolute custom paths, causing normal and x86 FSP builds to fail until defaults and user-provided scripts are handled correctly.

3 open issues
2 resolved since last review

Review effort: Lite

Comment thread Makefile Resolved
Comment thread tools/config.mk Resolved
Comment thread Makefile Resolved
Copilot review follow-ups:

- config/Makefile: skip emitting a variable whose value is empty, so
  'make config' with a blank LSCRIPT_IN prompt no longer persists a
  defined-but-empty 'LSCRIPT_IN?=' (quoted test -n: unquoted, bash's
  test returns true for a missing operand)
- Makefile: the last-resort hal/$(TARGET).ld default now keys on
  strip(LSCRIPT_IN) being empty, so a persisted empty value falls
  back correctly
- stage1/x86_fsp.mk: the .ld.in generation rule only applies to the
  target-derived script; a user-provided LSCRIPT_IN is used as-is
  (it previously produced a bogus hal/<abs path>.in prerequisite)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An active moderate Makefile issue causes empty LSCRIPT_IN values to bypass the intended target-specific linker-script selection, so changes are required.

1 open issue
3 resolved since last review

Review effort: Lite

Comment thread Makefile Resolved
Copilot review follow-up: ?= considers a defined-but-empty LSCRIPT_IN
(stale LSCRIPT_IN?= line in .config, exported empty env var) already
set, so it skipped every target-specific default and fell through to
the last-resort hal/$(TARGET).ld - e.g. TARGET=stm32l5 TZEN=0 lost its
hal/stm32l5-ns.ld layout. The strip-based last-resort check only fixed
that one line, not the 32 target sites.

Add the LSCRIPT_IN_DEFAULT helper in tools/config.mk (assigns only when
LSCRIPT_IN is undefined or empty) and convert all 29 arch.mk, 2
board.mk and 1 stage1/Makefile sites to it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because moderate hidden findings reveal a shared command-line precedence issue in fallback linker-script assignments, making the documented empty-value behavior unreliable across targets.

No open issues 🎉

1 resolved since last review

Review effort: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants