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

Basics

Type commands at the shell prompt:

kfsw:~$ status

Wait for @READY before using services. help lists the commands in the build and <command> -h shows the syntax. Tab completes command and subcommand names, but not arguments such as a node or a path. When more than one name fits, Tab lists them one per line with their help. A command with the wrong number of arguments prints its usage:

kfsw:~$ ftp generate
generate: wrong parameter count
generate - Create deterministic local data: generate <path> <bytes 0..32768>

Required arguments use <name> and optional arguments use [name]. A subcommand that takes arguments ends its help with its usage; one that takes none says nothing further. For example, ftp -h includes get <node> <remote> <local> and put <node> <local> <remote>.

Commands and build options

The shell needs CONFIG_KFSW_DEBUG_SHELL. Each command group depends on its service (app/CMakeLists.txt):

Command Build option
status, version, time, log always
csp, comms CONFIG_KFSW_CSP
comms uart CONFIG_KFSW_CSP_KISS_UART
comms can CONFIG_KFSW_CSP_CAN
param CONFIG_KFSW_PARAM; saving needs CONFIG_KFSW_PARAM_PERSISTENCE
table CONFIG_KFSW_TABLE
storage CONFIG_KFSW_STORAGE
ftp CONFIG_KFSW_FTP
event CONFIG_KFSW_EVENT
journal CONFIG_KFSW_JOURNAL and CONFIG_KFSW_COMMAND
cmd CONFIG_KFSW_COMMAND
reboot CONFIG_KFSW_COMMAND and CONFIG_REBOOT
hk CONFIG_KFSW_HK
fbo CONFIG_KFSW_FBO
fwu CONFIG_KFSW_FWU_STANDARD
fwu_lite CONFIG_KFSW_FWU_LITE_CSP
golden CONFIG_KFSW_GOLDEN, or CONFIG_KFSW_BOOT_STORE with CONFIG_KFSW_PARAM
watchdog CONFIG_KFSW_WATCHDOG
health CONFIG_KFSW_HEALTH
gndwdt CONFIG_KFSW_GNDWDT
resmon CONFIG_KFSW_RESMON
limits CONFIG_KFSW_LIMITS
scrub CONFIG_KFSW_SCRUB
remexec CONFIG_KFSW_REMEXEC
comms uhf CONFIG_KFSW_RADIO_UHF_SHELL
temp CONFIG_KFSW_TEMP_EXAMPLE_SHELL
button_test, test CONFIG_KFSW_BUTTON_TEST_SHELL

Two registries

help lists the shell. cmd list lists the command registry. A name in one need not be in the other.

A shell command is a Zephyr SHELL_CMD_REGISTER group: text in, text out, reachable only from a terminal. It exists only where CONFIG_SHELL is on. The golden recovery profile builds without it, because the shell is a quarter of that image and nobody can reach the console of a node in orbit.

A registered command is an entry in the command service: a name, a numeric ID, up to four typed arguments and a typed result. The registry is a static array of CONFIG_KFSW_COMMAND_MAX_COMMANDS entries (16 by default), fixed once startup ends. A composition whose definition sets exceed that count fails startup with -ENOSPC.

The registry is what everything other than a terminal calls:

Caller Names the command
The ground, on CSP port 11 by ID
A shell group by name, through kfsw_shell_run_command()
File procedures and the time-tagged queue by name, read from the file
Limits, when a parameter crosses a bound by name, from the limit
The ground watchdog, on another node by name

Each caller reaches the same definition and the same handler. With CONFIG_KFSW_EVENT, every dispatch records a COMMAND_INVOKED, COMMAND_UNKNOWN or COMMAND_REJECTED event carrying the command ID, the source node and the status. A shell group that calls a service API directly leaves none of that behind, so an action the ground or a procedure has to run belongs in the registry even when an operator reaches it by typing.

Table 28 counts the same outcomes in cmd_invoked, cmd_failed, cmd_unknown and cmd_rejected. They start at zero at each boot and wrap at 2^32; the ICD gives each one's definition.

remexec goes the other way: it runs an allowlisted shell line on another node, on CSP port 8, and returns the text that line printed.

cmd reads the registry and runs nothing:

Command Prints
cmd list Every command this node carries, with its ID and flags
cmd describe The same, with each argument type and the help
cmd show <name> One command

Identity and time

Command Prints
status [node] Role, name, CSP node, board, hardware ID, uptime, and the revision of each repository
version K-FSW version, repository revisions, Zephyr version, board, SoC, hardware ID and the boot trial counters
time Milliseconds and microseconds since boot
kfsw:~$ status
K-FSW status
Role: flight
Name: kfsw
CSP node: 1
board: native_sim/native/64
unit: 007f0101
uptime_ms: 10
revisions:
k-fsw: 3516c1a1
kfsw-platform: 049b7289
kfsw-services: ed838173
kfsw-comms: b4289702
kfsw-modules: ad39ef41
kfsw-libcsp: d62491f5
kfsw-libparam: c8a7c104

A trailing + marks a repository with uncommitted changes at build time. status 2 runs the info command on node 2, which returns its uptime and storage state, then reads its revisions from its boot_revisions parameter.

Role and name are labels set in the build. time is time since boot; wall time is in csp clock. An image is identified by its revision, the git describe of the build. No compile date is reported, because the date a file was compiled says little about the image it ends up in.

Logging

Command Arguments Meaning
log test none One message at each level compiled into the image
log level [<module> [0..4]] Show or set the level of each module
log history none Recent retained messages, with sequence, uptime, module, level and truncation
log remote <node> [count] [min level] Another node's newest messages, text or dictionary
journal remote <node> [count] Another node's newest journal records, in one read

log history needs CONFIG_KFSW_LOG_HISTORY and holds CONFIG_KFSW_LOG_HISTORY_DEPTH messages, 32 by default and 16 in the golden profiles. The log_level and log_levels parameters set the same filters as log level.

log_remote_format on the serving node picks text (0) or dictionary (1). Dictionary lines show pkg=00000000:<hex> crc32=<hex>; tools/ground/log-decode.py --elf turns them back into text. See Logging.

UHF radio

comms uhf status prints the radio implementation, the expected hardware and serial settings, and the link state. With CONFIG_KFSW_RADIO_UHF_CRYPTO, comms uhf connect starts new encrypted sessions with the configured peer.

kfsw-gnd-uhf# comms uhf status
UHF radio
enabled: yes
implementation: holybro-sik
expected hardware: RFD SiK 2.0 on HM-TRP
configuration source: build-time expectation, not hardware readback
expected serial: 57600 8N1
expected flow control: none
hardware status: unavailable
RF link: unknown

comms uhf status doesn't talk to the modem. Traffic and errors are in comms uart info and csp interfaces.

Button and LED example

Command Arguments Meaning
button_test status none Press count, last press and LED states

| test led | <green|blue|red> <on|off> | Switch one LED |

kfsw:~$ button_test status
press_count: 0
last_press_s: 0
led_green: off
led_blue: off
led_red: off
debounce_ms: 30

Holding the button counts one press, and the counts reset at boot. temp status prints the temperature example's cached die temperature and read counters.

CSP

Command Arguments Meaning
csp info none Local address, identity, revision, libcsp tag, CSP protocol version and free buffers
csp ident [node] Hostname, model, revision and clock
csp interfaces none Interfaces with addresses and packet, error and drop counters
csp ifstat <node> <interface> Remote interface packet/byte/error counters
csp routes none Route table
csp ping [node] Ping with CRC32 and a one-second timeout; this node without one
csp counters [clear] libcsp error counters; see CSP and links
csp debug [on\|off] Log every packet in and out
csp rdp [0..2] RDP trace detail
csp clock [set <utc>] or <node> [sync] Read or set wall time
csp reboot <node> <pin> [--retry] Restart a node
kfsw:~$ csp routes
0/0 -> KISS direct
kfsw:~$ csp ping 2
CSP ping 2: success
rtt_ms: ...

csp debug on logs each packet's source and destination node and port, priority, flags, size and interface, so the trace also lands in log history. It is off by default and affects only this node.

kfsw:~$ csp debug on
CSP packet trace: on
kfsw:~$ csp ping 2
[INFO] OUT: S 33, D 2, Dp 1, Sp 17, Pr 2, Fl 0x01, Sz 10 VIA: CAN (2), Tms 51060
[INFO] INP: S 2, D 33, Dp 17, Sp 1, Pr 2, Fl 0x01, Sz 14 VIA: CAN, Tms 51120
CSP ping 2: success
rtt_ms: 60.000

With several links, csp routes shows the interface and next hop of each route (CSP 1 prints /5 prefixes instead of /14):

kfsw:~$ csp routes
10/14 -> KISS_1 direct
11/14 -> KISS_2 via 11

Routes are set at build time and can't be changed from the shell. Every request to another node that gets no answer is logged as a warning and kept in log history, for example [WARNING] csp ping: node 5 did not answer. No answer can mean no peer, a wrong address or route, framing errors or no free buffers; check csp interfaces, csp routes and comms uart info.

Restarting a node

csp reboot <node> <pin> restarts a node if the pin matches, and reboot <pin> restarts this one:

kfsw:~$ csp reboot 2 1234
reboot: denied, wrong pin
kfsw:~$ csp reboot 2 0000
node: 2
rebooting in 500 ms

The pin is reboot_pin in table 2: 0000 by default, persistent, and settable from the ground. It is text, so 0007 doesn't match 7. It travels in clear text and guards only against rebooting the wrong node by mistake.

After a restart the boot table shows why the previous run ended:

kfsw:~$ param table 2 32
32 0x30 last_reason u8 r 1 commanded
32 0x34 last_detail x32 r 0x00000000 the faulting address, for a fault
32 0x38 last_uptime_ms u32 r 5427214

All three at zero means no valid reset note was found: power loss, or a reset before a note was written. Check the hardware reset cause as well.

Links: <tt>comms</tt>

Each link a composition carries is a subcommand of comms.

Command Arguments Meaning
comms uart info none Each CSP UART with baud, state, KISS name, address and counters
comms uart test [node] Check that the route uses a UART/KISS link, then ping with a 128-byte payload
comms can info none The CSP CAN interface: bitrate, address and counters
comms can test <node> Check that the route uses CAN, then ping with a 64-byte payload
comms uhf status none See UHF radio, above

A test refuses this node's own address, whose packets never reach the link. Name the node to test one link of several, for example comms uart test 10. On the NUCLEO the commands run on the ST-LINK console and the packets leave on USART3.

Parameters

Command Arguments Meaning
param whichtables [node] The tables a node carries, without values
param table [node] <id> The parameters of one table, with values
param listall [node] Every parameter of a node, with values
param get [node] <name> Read a value
param set [node] <name> <value> Write a value
param describe [table] What each parameter is, with its unit

layer names the part of K-FSW that defines a table and holds describes its contents. Local output also has kept, the number of persistent values. Remote table summaries carry their own names and descriptions. For an older node without table-list support, names and descriptions come from this build by table ID; an unknown table is named -.

kfsw:~$ param whichtables
id layer name params kept holds
--- ------- ------------ ------ ---- -----
1 core board 11 0 Node identity and what the board carries
2 core system 3 3 Boot delay, report period, reboot pin
3 core telemetry 5 0 Uptime, storage and CSP buffers
4 core csp 15 0 CSP counters and the route table
5 core storage 4 0 Filesystem size, free space, mount
25 service log 5 2 Log levels, colour and counters
kfsw:~$ param listall
table addr name type mode value
---------- ---- -------------------------------- ------ ---- -----
board 0x00 node_id u16 r 1
system 0x00 boot_delay_ms u16 wpb 0
system 0x02 app_report_ms u16 wp 1000
telemetry 0x00 uptime_s u32 r 0
log 0x00 log_level u8 wp 1

Mode letters: r read-only, w writable, p saved in the snapshot, b applied at the next boot. Strings are printed quoted and arrays as lists. Input is parsed with the parameter's type; overflow, negative unsigned values and bad numbers are rejected.

echo_enabled makes the console repeat what it receives, and is off by default. Zephyr ignores Tab and the arrow keys while echo is off, so run param set echo_enabled 1 for completion and command history.

kfsw:~$ param set echo_enabled 1
kfsw:~$ status <- repeated by the shell
K-FSW status

Remote nodes

With CONFIG_KFSW_PARAM_CSP, put the node before the other arguments:

kfsw:~$ param get 2 log_level
2:log_level = 1
kfsw:~$ param set 2 log_level 2
2:log_level = 2
kfsw:~$ param table 2 25

The node is a decimal number. Remote listings show the table number instead of its name, because table names are not sent over the link.

Saving

Command Effect
param save Write all persistent values to the snapshot
param persist <table> Write the snapshot and show that table's share
param load Apply the saved snapshot
param defaults Reset persistent values to their defaults, in RAM only
param clear Delete the snapshot; RAM is unchanged

These act on the local node. With param_autosave on, a change to a persistent value is saved without param save. See Services.

Storage

Command Arguments Meaning
storage info none Filesystem, backend, mount point, state, total and free bytes
storage test none Create, write, read, overwrite and delete a test file
storage test write <value> Write the persistence test value
storage test read <value> Read and compare the persistence test value
kfsw:~$ storage info
K-FSW storage
filesystem: LittleFS
backend: flash-controller@0
mount_point: /kfsw
ready: yes
total_bytes: 262144
free_bytes: 237568
tmp_mount_point: /kfsw/tmp
tmp_ready: yes
tmp_total_bytes: 32768
tmp_free_bytes: 31744

storage test writes to flash. The tmp_ lines are the RAM volume, formatted at every boot.

File transfer

Paths are virtual and rooted at /kfsw/ftp on the node.

Command Arguments Meaning
ftp ls [node] [directory] List a directory
ftp stat [node] <path> Kind, size and CRC
ftp mkdir [node] <directory> Create a directory
ftp rm [node] <path> Remove a file or empty directory
ftp put <node> <local> <remote> Upload a file
ftp get <node> <remote> <local> Download a file
ftp generate <path> <bytes> Create a test file of up to 32768 bytes
ftp verify <first> <second> Compare two local files

Without a node, ls, stat, mkdir and rm act on this node, without a connection; put and get need another node. A transfer that would leave less than CONFIG_KFSW_FTP_SPACE_MARGIN_BYTES (4096) free on its volume is refused before any data moves: not enough free space.

ftp rm refuses directories with entries, read-only paths and the storage root. It does not delete recursively. Removing a missing path reports not found.

Listing / also shows these directories when they exist:

Directory Holds Writable
boot firmware slots, see Firmware update no
hk housekeeping sample files no
tmp RAM, empty after every boot: 32 KB on Linux and the NUCLEO, 16 KB on the Pico W yes

Each entry starts with its kind:

Kind Meaning
dir directory
file file
img firmware image, in /boot
hk housekeeping samples, in /hk
proc procedure, in /procedures
kfsw:~$ ftp ls /
FTP ls 1 /
dir 0 build
dir 0 boot
dir 0 tmp
entries: 3
kfsw:~$ ftp generate /build/sample.bin 1024
kfsw:~$ ftp mkdir 2 /exchange
kfsw:~$ ftp put 2 /build/sample.bin /exchange/sample.bin
kfsw:~$ ftp stat 2 /exchange/sample.bin
kfsw:~$ ftp get 2 /exchange/sample.bin /build/returned.bin
kfsw:~$ ftp verify /build/sample.bin /build/returned.bin

Paths must start with / and can't contain .. or empty components.

Another node

Groups that can ask another node take the node first, as param does: status 2, event stats 2, journal tail 2 0, hk period 2 0 1000, csp reboot 2 <pin>, gndwdt feed 2. A node gets cmd_timeout_ms (3000 by default) to answer; one that does not is logged as a warning. The reply comes back one field per line, after the node it came from:

kfsw:~$ status 2
node: 2
uptime_ms: 4140
storage: ready
free_bytes: 12288

Each of these is a command of the command service, sent over CSP port 11; the commands are the wire protocol a ground tool speaks. The name is looked up in the local registry before the request is sent, so both nodes need the same command IDs. A remote request that changes the node can end in --retry, for example csp reboot 2 0000 --retry; see Scripts, below. Remote commands need CONFIG_KFSW_COMMAND_CSP. The command service does not authenticate callers: radio encryption can protect that link, and other interfaces need their own access policy.

Identifiers

Four kinds of number are part of the wire contract. Two nodes must agree on each, and none is reused once it has been given out.

Command IDs. Composition commands are defined in app/src/commands/command_definitions.c; a service command carries its ID in the service's header.

ID Command Defined in
1 to 3 noop, info, reboot k-fsw composition
4, 5 event_stats, event_tail k-fsw composition
6 to 8 hk_define, hk_period, hk_clear k-fsw composition
9 to 11 journal_stats, journal_tail, journal_time k-fsw composition
12 to 15 free
16 ground_wtd kfsw-services, gndwdt.h
17 to 19 free
20 to 23 fbo_run, fbo_sched_add, fbo_sched_cancel, fbo_sched_clear kfsw-services, fbo.h
24 golden_install k-fsw composition
40 to 43 gpredict_select, gpredict_enable, gpredict_park, gpredict_clear kfsw-modules, gpredict.h
64 temp_clear kfsw-modules, temperature_sensor_example.h

CSP ports. 0 is management (CMP) and 1 ping, both from libcsp. K-FSW serves 8 remote shell execution, 9 file transfer, 10 parameter values, 11 commands, 12 parameter descriptors, 13 FWU lite, 14 housekeeping, 15 housekeeping beacons on the receiving node, and 16 log history. Each has a Kconfig option; see CSP and links.

Parameter tables. 1 to 24 are core (1 board, 2 system, 3 telemetry, 4 csp, 5 storage), 25 to 49 services (25 log through 40 limits) and 50 to 99 modules (50 radio-uhf, 51 temp_example, 67 hw_test). param whichtables lists what a node carries.

Node addresses. Under CSP 2, the default, nodes are 1 to 16382 and 16383 is broadcast; under CSP 1 nodes are 1 to 30 and 31 is broadcast. A command given a node outside that range is refused before anything is sent, for example Node must be 1..30: 31. Flight nodes use 1 to 15 and ground roles start at 16, which tools/k-ground enforces.

Running another node's shell commands: remexec

remexec reads which shell commands a node offers and runs one of them, on CSP port 8. It needs CONFIG_KFSW_REMEXEC, which the Linux, NUCLEO-L496ZG and Pico W images set.

Command Meaning
remexec <node> get The commands that node offers, one a line
remexec <node> get <command> That command and its subcommands, with their help
remexec <node> run "command args" Run it there and print what it produced
kfsw-ops# remexec 1 get
node: 1
time
version
storage info
resmon show
event stats
kfsw-ops# remexec 1 get storage
node: 1
storage info Filesystem totals and mount state
kfsw-ops# remexec 1 run time
node: 1
command: time
output: 36 bytes
monotonic_ms: 4140
monotonic_us: 4140210
status: ok

The serving node's allowlist decides, and get reports that list. A command not on it is refused by name:

kfsw-ops# remexec 1 run storage test
node: 1
command: storage test
remexec: 'storage test' is not offered for remote execution

Marking a command marks its arguments as well, so a composition marks only commands whose whole argument space is safe from the ground. The list lives in app/src/remexec/remexec_allowlist.c; Services has the allowlist, the output cap and the limits.

A reply that could not carry everything says how much went missing, separately from whether the command itself succeeded:

output: 200 of 264 bytes, truncated, 64 dropped

remexec always names another node; a node cannot run its own commands this way. remexec_refused and remexec_refusal in table 38 show what a node refused and why, without reading its log.

Events

Command Meaning
event list Held records, oldest first
event stats [node] Held, capacity, recorded, overwritten and rejected counts
event tail [node] <age> One record by age, newest is 0
event clear Discard held records; counters are kept
kfsw:~$ event list
SEQ TIME_MS SOURCE SEVERITY ID PAYLOAD
0 0 boot info 1 0000000800
Events listed: 1

Payloads are printed as bytes; their layout is in the producer's header. A gap in SEQ means records were overwritten; event stats counts them. The ring is lost at reset. For another node:

kfsw:~$ event tail 2 0
node: 2
seq: 8
t_ms: 8120
src: ftp
id: 1
sev: 0
data: 0002000001000ce9d363

Housekeeping

Command Arguments Meaning
hk define [node] <report> [class=N] <[node:]table:offset> ... [--retry] Set what a report collects
hk clear [node] <report> [--retry] Delete a report
hk show none Reports and counters
hk collect <report> Collect now
hk get <report> [count] Print collected samples
hk period [node] <report> <ms> [--retry] Collect periodically, 0 to stop
hk store <report> <ms> Also write samples to a file, 0 to stop
hk store_clear <report> Stop storing and delete the file
hk stored <report> [from=] [to=] [since=] [until=] [skip=] Print stored samples
hk extract <report> <path> [from=] [to=] [since=] [until=] [skip=] Copy stored samples to a file
hk beacon <report> <node> <ms> Send the latest sample periodically, 0 to stop
hk save none Save the report settings

--retry applies when a destination node is given.

A leading node sets up that node's reports: hk define 2 0 3:0 3:8 asks node 2 to collect its own uptime and free storage as report 0. An entry always holds a :, so the node is told apart from the report. See Ground station for Yamcs and the ground bridge.

File based operations

Command Arguments Meaning
fbo run <name> Run a procedure file
fbo stop none Stop the running procedure
fbo status none Procedure, current line and counters
fbo sched add <+s\|@utc> <node> "<command>" Release a command later
fbo sched cancel <index> Cancel a scheduled entry
fbo sched clear none Empty the queue
fbo sched list none Every queued entry with its state
fbo sched status none Queue counters and the next deadline

Firmware update

Command Arguments Meaning
fwu status none State, slot geometry and checksums
fwu begin <size> <crc32> Start a transfer by hand
fwu finish none Verify the image and offer it to the bootloader
fwu abort none Abandon a transfer and erase the slot
fwu_lite send <node> <path> Upload an image to a node, or resume an upload
fwu_lite status [node] Progress here, or of an upload this node owns
fwu_lite validate <node> Have the node read back and check the stored bytes
fwu_lite flash <node> Activate a validated image
fwu_lite abort <node> Erase this sender's transfer
golden status none Whether the golden partition holds an image
golden install [node] <pin> Install the recovery image and restart
golden attempts [count] Read or set the startups left before recovery

fwu_lite needs CONFIG_KFSW_FWU_LITE_CSP. fwu_lite send reports how many blocks had to be resent. Check link counters if retries increase. A transfer that stops part way continues from where it left off rather than starting again, which is why validate is a separate step.

After a transfer, check swap_scheduled in fwu status. If it is not set, MCUboot has nothing to swap and boots the old image. Firmware update has the procedures.

Recovery image

golden status whether the golden partition holds an image
golden install [node] <pin> install it and restart
golden attempts [count] startups left before recovery, or set the budget

install takes a confirmation pin, so a mistyped command cannot replace the running image. attempts without a count reads the budget; with one it writes it, and the value is persisted. Fault detection and recovery has what spends an attempt.

Watchdog and health

Services, under Watchdogs, says what feeds each of the three.

gndwdt show [node] ground watchdog countdown, here or on a node
gndwdt feed <node> feed another node's ground watchdog
gndwdt on | off arm or disarm the local countdown
gndwdt timeout <seconds> silence allowed before a reset
watchdog status configuration and activity
watchdog feed feed once
watchdog starve confirm stop feeding; the board resets
health status whether the watchdog is being fed
health list watched components and deadlines
health report <handle> report a component as alive
health watch <name> <ms> confirm watch a component that never reports

The watchdog commands need CONFIG_KFSW_WATCHDOG and a kfsw,watchdog devicetree property. watchdog status shows the state (unconfigured, configured, running or starved), the timeout, the feed interval, the number of feeds and the time since the last one.

watchdog starve confirm can't be undone: the STM32 independent watchdog can't be disarmed, and the board resets within one timeout. health watch also ends in a reset once the deadline passes. The next boot marker shows the cause:

@BOOT sw=v1.0.1 board=nucleo_l496zg/stm32l496xx unit=203037324d46500c0010001f reset=0x00000011 reset_rc=0 reset_cause=watchdog

The raw mask is printed as well because several causes can be latched at once; 0x11 is the reset pin and the watchdog.

Scripts

Remote requests are not retried. With CONFIG_KFSW_COMMAND_RETRY, ending one with --retry sends it with a ticket that suppresses duplicates within that invocation. A new invocation is a new operation. A timeout can mean the reply was lost after the command ran, so check the state before sending it again.

To drive the shell from a script:

  1. Wait for @READY.
  2. Send one command and wait for the prompt before sending the next.
  3. Use the C APIs or the CSP services instead when the script needs a stable output format.