K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
Loading...
Searching...
No Matches
Contributing

Start a change

Keep one responsibility per branch, with the tests and docs that change needs. Save existing work before updating any repository.

From the workspace root:

git -C k-fsw status -sb
git -C k-fsw switch develop
git -C k-fsw pull --ff-only
. .venv/bin/activate
west manifest --validate
west update
./k-fsw/tools/zephyr-patch.sh

Dependencies normally end up detached at their manifest SHA. Create a branch before committing changes in one.

Branches and commits

Push changes to develop, directly or through a feature PR. Update main only by merging reviewed release changes; do not push commits directly to it. Tag the release merge only after its CI/CD checks pass. Fix failed checks through develop and merge the correction before releasing. Keep unreleased work on develop; do not move published tags.

Use <type>/<issue>-<slug>, or <type>/<slug> when no issue exists.

Type Example
Feature feature/42-command-router
Fix fix/43-storage-timeout
Refactor refactor/23-param-csp
Documentation docs/wiki-layout

Check your identity before committing:

git config user.name
git config user.email

The subject is one or two uppercase area tags, then the thing that changed as a noun phrase:

[PARAM] Remote table list descriptor changes
[SHELL] Help line width fix
[DOCS] Golden partition contents

The first tag is the layer or kind of change (SERVICES, COMMS, DOCS, TEST, BOOT, ...), the optional second one the feature. Keep it under about 72 characters, with no trailing period.

The subject is the whole message. The reason for a change goes in the code, a comment or the documentation, where the next reader of that code finds it. Make one commit per coherent change; related fixes in the same area go in the same commit.

Pull requests

Use the same title format as commits. Keep the body to the change, relevant checks, and issue number if there is one:

Group the docs by task and use the demo colours.
Checked: Doxygen, PDF, links, desktop and mobile layout.

Before opening the PR:

git status --short
git diff --stat
git diff --check

Run the checks that cover the change; Tests lists them. A docs change needs Doxygen, the PDF, the link checks and a look at the result. Record a physical test only when someone observed it on the bench.

Change a west dependency

Each reusable repository has its own branch and PR. The composition PR pins the dependency commit and contains the integration changes.

  1. Branch from the dependency's current manifest pin.
  2. Implement, test, and commit there.
  3. Publish the dependency branch and open its PR.
  4. Copy its exact SHA into k-fsw/west.yml.
  5. Test the composition and open the k-fsw PR.
  6. Merge the dependency first, then the composition.

For example, inside kfsw-services:

git status -sb
git switch -c feature/30-new-service

After publishing the dependency commit, from the workspace root:

git -C kfsw-services rev-parse HEAD
# Put this SHA in k-fsw/west.yml.
west manifest --validate
west update kfsw-services
git -C kfsw-services rev-parse HEAD

The checked-out SHA must match the manifest, and hosted CI must be able to fetch it from the declared remote.

Forked dependencies

libcsp and libparam are pinned to K-FSW forks, dgonzalez97/kfsw-libcsp and dgonzalez97/kfsw-libparam. Check west.yml for the exact revisions and each fork's KFSW.md for its changes from upstream.

Carry a change as one commit with its reason in the message, rebase the branch onto upstream instead of merging upstream into it, and move the west.yml revision the same way as any other dependency. Before tagging a release, check whether upstream has new commits or tags since the pin.

A merge commit preserves the pinned SHA. Squash or rebase produces a new SHA; update the pin and rerun composition CI if either is used. Do not rewrite a commit already pinned by another PR.

Choose the repository

Change Repository
Time, reset, watchdog, storage mechanism kfsw-platform
Reusable service behaviour kfsw-services
CSP, routing, packet buffers, transports kfsw-comms
Device or subsystem client kfsw-modules
Startup, targets, shell adapters, tools, integration tests, docs k-fsw

Public APIs go in that repository's include/kfsw/ headers and private helpers in its source tree.

For a new service, add its Kconfig dependencies, conditional build, public API, application startup, and tests for enabled and disabled configurations. Use devicetree for devices and wiring. See Architecture.

VS Code and debugging

Open the multi-repository workspace:

code k-fsw/K-FSW.code-workspace

It includes the five project repositories and build/active. Select the compilation database for the target you are editing:

./k-fsw/tools/build.sh linux
./k-fsw/tools/select-intellisense.sh linux

Use nucleo_l496zg for MCU configuration. The selector updates symlinks to the selected build; it refuses to overwrite regular files. Rebuild to refresh generated headers and compile_commands.json.

For NUCLEO debugging, run these in separate terminals:

./k-fsw/tools/debugserver.sh nucleo_l496zg
./k-fsw/tools/debug.sh nucleo_l496zg

Use build/nucleo_l496zg/zephyr/zephyr.elf and check that build's .config and zephyr.dts when diagnosing target-specific behaviour.

Documentation

Edit guides under docs/ and document public C APIs in their headers. For a procedure, give the command, the expected result and its limits. Link to upstream references for RTOS and protocol background.

Draw diagrams as fenced code blocks marked mermaid. GitHub draws them in place, and tools/docs/build.sh passes them through tools/docs/mermaid-filter.py so the HTML manual draws the same source with a pinned Mermaid release. To read the manual offline, point KFSW_MERMAID_JS at a local mermaid.min.js before building. The PDF shows the diagram source.

From the workspace root:

./k-fsw/tools/docs/build.sh
./k-fsw/tools/docs/pdf.sh
git -C k-fsw diff --check

Check navigation, images, tables, and links in HTML and PDF. Keep generated output out of Git. Update Project status from source and recorded test results when capabilities change.

Bench gate before a tag

Software CI shows that the code builds and behaves in simulation. Whether the board keeps a log across a reset, answers over CAN, or comes back from an interrupted update needs the bench, so the bench runs before a tag. Back the bench up first.

Step Command Needs
1 tests/hil/preflight.sh device inventory; confirm wiring separately
2 tools/ci/all.sh --suite board software first, then every available automatic board check; reflashes and resets boards
3 tests/hil/shell-smoke.sh rpi_pico_w a person to copy the UF2 and reconnect the console
4 tests/hil/button-test/button-acceptance.sh a person to press the button and judge its behaviour

Step 2 reports steps 3 and 4 as NOT RUN. CAN acceptance and encrypted radio need prepared baselines and inputs (Tests); run them separately if another fixture has replaced those baselines.

Record which steps ran, which were skipped for want of hardware, and the exact output of each. The tag notes list the skipped steps.

Preconditions that nothing checks for you

Every one of these has cost a bench session at least once.

  • Export the devices. run.sh <shape> does it from preflight.sh. Calling a fixture directly does not, and the numbered /dev/ttyACM* you get by default is whichever board enumerated first.
  • Flash the image the fixture expects. can.robot runs the CAN fixture with --no-build, so it tests whatever is already on the board. Build and flash it first, or run the fixture without Robot so it builds.
  • Clear the CAN error counters. They saturate and stay saturated. The CAN fixture refuses to start unless the interface is ERROR-ACTIVE, and one of its assertions wants the counters at zero, so a bus that misbehaved earlier fails a run that is otherwise clean. Bring it up again: sudo tests/hil/stm32/nucleo-l496zg/can-up.sh 500000 normal
  • Set the SocketCAN transmit queue. The same can-up.sh command sets and verifies txqueuelen 1000. Check ip -details link show can0 for qlen 1000 or higher. The default queue of 10 can drop CFP1 FWU frames and leave the native driver's CAN TX waiting for a completion that never arrives. The board-can preflight and both CAN FWU scripts reject a short or missing queue length. Software tests on the default vcan0 do not use this queue.
  • One ground profile per build directory. tools/k-ground includes the profile and node number in each build directory, so kfsw-gnd-can, kfsw-gnd-uhf and a local -bench.env variant never overwrite each other's configuration. For example, CAN uses build/k-ground/kfsw-gnd-can-node-17; CSP v1 adds the -csp1 suffix.
  • A serial bridge needs its driver. On a kernel that builds ftdi_sio as a module it has to be loaded, and a module whose BTF does not validate has to have that section stripped before it will load.

Firmware update over CAN

This one changes the board: it installs MCUboot and moves the application into a signed slot. Back the board up first, and keep the backup until the tag is out.

OCD=$ZEPHYR_SDK_INSTALL_DIR/hosttools/sysroots/x86_64-pokysdk-linux/usr/bin/openocd
S=$ZEPHYR_SDK_INSTALL_DIR/hosttools/sysroots/x86_64-pokysdk-linux/usr/share/openocd/scripts
$OCD -s $S -f ../zephyr/boards/st/nucleo_l496zg/support/openocd.cfg \
-c init -c "reset halt" \
-c "dump_image board-backup.bin 0x08000000 0x100000" \
-c "reset run" -c shutdown
sha256sum board-backup.bin > board-backup.sha256

That is the whole 1 MB, so it covers the application, the golden region at 0x080c0000 and LittleFS at 0x080f0000 without having to reason about which matters. Restore it the same way with flash write_image erase.

Program only the bootloader and the image slots. Do not pass --erase to west flash: the openocd runner has stm32l4x mass_erase 0 configured as its erase command, which takes the golden region and LittleFS with it.

Then follow tests/hil/fwu/README.md, which builds the ground node and the two signed images, installs the baseline, and runs the acceptance.

The acceptance leaves the board running the candidate, and a second run refuses because the candidate and running revisions must differ. Reinstall and confirm the baseline between runs.

Robot runs the same acceptance when both images are named:

export KFSW_FWU_CAN_GROUND=$B/ground/zephyr/zephyr.exe
export KFSW_FWU_CAN_IMAGE=$B/after/app/zephyr/zephyr.signed.bin
tests/hil/run.sh board-can

Without them that case is skipped and reported as NOT RUN.

Release builds

tools/release.py checks the source and signing inputs, builds twice, and compares the unsigned application payloads. It verifies both signatures and the bootloader's trust key. It does not create a tag or publish artifacts.

Use the MCUboot profiles in Firmware update, then set:

Input Value
KFSW_IMAGE_VERSION MCUboot version, for example 1.0.0+0
KFSW_RELEASE_SOURCE Full k-fsw commit SHA
KFSW_RELEASE_MANIFEST Frozen manifest from tools/release.py freeze
SOURCE_DATE_EPOCH Fixed source timestamp, in Unix seconds
ZEPHYR_SDK_INSTALL_DIR SDK directory
KFSW_RELEASE_COMPILER_SHA256 SHA256 of the SDK's arm-zephyr-eabi-gcc
KFSW_MCUBOOT_KEY Private ECDSA P-256 signing key; development keys are rejected

From k-fsw, with the workspace virtual environment active:

python tools/release.py check
python tools/release.py build --output ../build/release-1.0.0

The output directory must be new. Keep artifacts/release.json with the images; it records sources, tool versions, public-key fingerprint, and artifact hashes.

The image to upload is artifacts/kfsw-<target>-<version>.signed.bin, for example kfsw-nucleo_l496zg-v1.1.0.signed.bin, where the version is git describe of the release commit. Images for different targets and versions can then sit side by side on a node or a ground station. The name is at most 64 characters of letters, digits, ., _ and -, so it always fits an FTP path; a longer or odd name stops the release instead of being cut. The build output itself stays zephyr.signed.bin.

The recovery image

A release also carries kfsw-<target>-recovery.signed.bin, built from the same tree by tools/golden.sh and recorded in release.json as recovery_image. It is the composition in config/profiles/nucleo-golden.conf: CSP over the UART and CAN links, remote parameters, the command server and both update routes, and nothing else. No console, no filesystem, no housekeeping. It exists to be reachable and to take a new image, and tools/golden.sh checks that it fits the 188 KiB golden partition. A target without that partition has no recovery image and recovery_image is null.

Flash it once per board, at 0x080C0000, with tools/golden.sh flash. The release does not flash it, and it stays the same when the flight image changes.

How recovery works

The bootloader only boots the slots, so the image in the golden partition is never run from there. Installing it means copying it into the secondary slot and asking for a swap, which is what the update service already does for an uploaded image, so recovery reuses it rather than writing to flash itself.

Two things can ask for that:

  • golden_install <pin>, a command like reboot, over CSP or from the shell. An operator who already knows the image is bad does not have to wait.
  • The early boot service, when boot_attempts_left reaches zero. The count and boot_attempts_max live in a dedicated flash record, independent of the parameter snapshot. The boot budget section of Firmware update has the details.

The swap is a trial, so if the recovery image cannot boot either, the bootloader reverts. The recovery image confirms itself once it has finished starting (CONFIG_KFSW_BOOT_CONFIRM_AT_START), because a node in trouble may have no operator to confirm it. An image the operator confirms leaves that option off.

The early budget survives both confirmation and MCUboot revert. A node with no ground contact can exhaust it even when MCUboot restores the previous image. tests/boot-budget-smoke.sh exercises that budget and installation through a hosted bootloader model, and tests/hil/golden-recovery-smoke.sh installs the image on command and checks the recovery parameter set over CAN. Automatic expiry and real power cuts are bench work.