tockloader: fix address-truthiness bugs around a valid 0x0 - #142
Merged
Conversation
Several places in the codebase distinguish "no address given/known" from "an address was given/known" using plain truthiness (`if addr:`) on a value that is `None` when unset. That conflates "unset" with an address of exactly `0x0`, which is a normal, valid flash and/or app base address (e.g. any Cortex-M board, or Tock's qemu_arm_mps2 boards). Fix all of these to check `is not None` instead: - `main.py` `command_local_board_set()`: an explicit `--app-address 0x0`/`--flash-address 0x0` was validated but then silently omitted from the status output, making it look like the flag was ignored. - `flash_file.py` `set_local_board()`: the same values were then silently dropped from the persisted `local-board` TOML config, discarding the deliberate setting entirely. - `flash_file.py` `FlashFile.get_flash_address()`: a stored `flash_address == 0` was reported as `None` (unknown) instead of `0`. - `board_interface.py` `BoardInterface.get_apps_start_address()`: a configured `app_address == 0` was ignored in favor of querying the board's `appaddr` attribute (or returning `None` if that's absent). - `tockloader.py` `_get_apps_start_address()`: a cached value of `0`, an explicit `--app-address 0x0` on any command (not just `local-board set`), or a channel-reported address of `0` were all treated as "unknown" and silently overridden by lower-priority defaults. - `tockloader.py` `_get_flash_start_address()`: a channel-reported flash address of `0` was treated as "unknown" and replaced with the function's own hardcoded `0` default -- harmless today only because that default happens to also be `0`. - `tockloader.py` `_get_memory_start_address()`: same cached-value pattern as above, for the app RAM start address. Verified with `local-board set zerotest --arch cortex-m3 --app-address 0x0 --flash-address 0x0`: both values now appear in the status output and are correctly persisted as `0` (not omitted) in the TOML config. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTQ6pWrckM3jp9vfBo4bhk
bradjc
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update
ifchecks around addresses to explicitly compare toNone, so that an address of0x0doesn't accidentally evaluate asFalse.Claude's essay
Several places in the codebase distinguish "no address given/known" from "an address was given/known" using plain truthiness (
if addr:) on a value that isNonewhen unset. That conflates "unset" with an address of exactly0x0, which is a normal, valid flash and/or app base address (e.g. any Cortex-M board, or Tock's qemu_arm_mps2 boards). Fix all of these to checkis not Noneinstead:main.pycommand_local_board_set(): an explicit--app-address 0x0/--flash-address 0x0was validated but then silently omitted from the status output, making it look like the flag was ignored.flash_file.pyset_local_board(): the same values were then silently dropped from the persistedlocal-boardTOML config, discarding the deliberate setting entirely.flash_file.pyFlashFile.get_flash_address(): a storedflash_address == 0was reported asNone(unknown) instead of0.board_interface.pyBoardInterface.get_apps_start_address(): a configuredapp_address == 0was ignored in favor of querying the board'sappaddrattribute (or returningNoneif that's absent).tockloader.py_get_apps_start_address(): a cached value of0, an explicit--app-address 0x0on any command (not justlocal-board set), or a channel-reported address of0were all treated as "unknown" and silently overridden by lower-priority defaults.tockloader.py_get_flash_start_address(): a channel-reported flash address of0was treated as "unknown" and replaced with the function's own hardcoded0default -- harmless today only because that default happens to also be0.tockloader.py_get_memory_start_address(): same cached-value pattern as above, for the app RAM start address.Verified with
local-board set zerotest --arch cortex-m3 --app-address 0x0 --flash-address 0x0: both values now appear in the status output and are correctly persisted as0(not omitted) in the TOML config.Claude-Session: https://claude.ai/code/session_01KTQ6pWrckM3jp9vfBo4bhk