Bootstrap Service Fw Development Examples
1) Definition and Purpose
LwM2M Bootstrap is a provisioning phase where a Bootstrap Server configures the client before normal LwM2M registration begins.
It enables:
- zero-touch provisioning
- remote credential injection/rotation
- late binding to deployment server
- recovery through re-bootstrap
In practice, bootstrap provides the device with:
- target LwM2M server URI(s)
- security mode and credentials
- server parameters (lifetime, binding, and related settings)
2) Scope and Assumptions
Assumptions for this guide:
- Hardware: nRF9151
- Connectivity: LTE-M and/or NB-IoT
- Stack: Zephyr/Nordic LwM2M client flow
- Bootstrap type: device-initiated bootstrap
- Firmware has modem bring-up and persistent storage enabled
3) Architecture Overview
Bootstrap should be treated as a first-class runtime phase, not just a registration failure fallback.
Core layers:
- application state machine
- LwM2M client library
- bootstrap/security handling
- modem + IP + DTLS
- persistent settings storage
4) Platform Requirements
4.1 Cellular and IP
- modem init works
- network registration works
- IP transport is available
4.2 Persistence
The firmware must persist object data across reboot/power loss:
- Security Object (Object 0)
- Server Object (Object 1)
- bootstrap completion related state
Typical Zephyr setup uses settings/flash-backed storage.
5) Bootstrap State Machine Design
Recommended high-level flow:
- STARTUP
- Load persisted LwM2M config
- Validate Security/Server object consistency
- If valid: register directly
- If invalid/missing: enter bootstrap mode
Bootstrap should also be re-entered on repeated unrecoverable registration/authentication failures.
6) Project-Specific Configuration (samples/lwm2m client)
When bootstrap is enabled in the project, the client starts with bootstrap credentials CONFIG_LWM2M_CLIENT_UTILS_BOOTSTRAP_TLS_TAG and then transitions to server credentials CONFIG_LWM2M_CLIENT_UTILS_SERVER_TLS_TAG.
Relevant config:
CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP=yCONFIG_LWM2M_CLIENT_UTILS_SERVER="coap://bootstrap.iec.iot.telekom.de:5783"CONFIG_LWM2M_CLIENT_UTILS_BOOTSTRAP_TLS_TAG=100CONFIG_LWM2M_CLIENT_UTILS_SERVER_TLS_TAG=101
See:
overlay-leshan-bootstrap.confprj.conf
7) Startup and Bootstrap Decision (main.c + lwm2m_security.c)
7.1 Initialization Path
At startup, main() calls lwm2m_setup():
lwm2m_init_sec(&client, endpoint_name, NULL)apn_obj11_init(CONFIG_PDN_DEFAULT_APN)apn_obj11_apply_modem(bootstrap_flags)
7.2 Bootstrap Decision
Bootstrap is determined by lwm2m_sec_needs_bootstrap().
Bootstrap is required if:
- persistent keys/settings are missing
- or server credentials for final server are missing in modem storage
If true, app uses:
LWM2M_RD_CLIENT_FLAG_BOOTSTRAP
8) Security Bootstrap Internals (lwm2m_security.c)
8.1 lwm2m_init_sec() behavior
With bootstrap support enabled, it:
- Registers create/delete callbacks for Objects 0 and 1
- Initializes and loads settings subtree
- Recreates object instances from persisted data as needed
- Removes conflicting default instances when persisted/bootstrap-managed data exists
8.2 Credentials to Modem
Credential loader selects TLS tag by mode:
- bootstrap mode: bootstrap tag (
100) - normal mode: server tag (
101)
It avoids unnecessary rewrites, handles modem state transitions, and writes required credentials into modem key storage.
8.3 Persistence Callbacks
Post-write callbacks persist bootstrap writes:
- Security object writes
- Server object writes
During settings restore, object instances are recreated before resources are restored.
9) Runtime Event Flow (main.c)
State machine includes bootstrap-aware states:
STARTCONNECTINGBOOTSTRAPCONNECTEDAPN_SWITCHNETWORK_ERROR
Important events:
LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_COMPLETELWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE
After transfer complete, app enters APN_SWITCH, performs LTE offline/online transition, applies APN selection, then resumes registration path.
10) Custom Object 11 APN Behavior (lwm2m_obj11_apn.c)
This project uses custom Object 11 for APN profiles.
Highlights:
- Object ID
11, multiple APN instances - values persisted via settings
- bootstrap-time and post-bootstrap APN selection differ intentionally
Selection logic summary:
- during bootstrap: force bootstrap APN path/default
- after bootstrap: prefer Server Object APN link (
/1/0/10) when valid - fallback to enabled APN profiles
11) End-to-End Sequences
11.1 First Boot
- Device starts and initializes modem/LwM2M
- Settings likely empty
lwm2m_sec_needs_bootstrap()returns true- RD client starts in bootstrap mode
- Device registers to bootstrap server
- Bootstrap server writes Object 0/Object 1
- Writes are persisted
- Credentials are stored in modem tags
- Bootstrap transfer completes
- APN switch logic runs
- Device registers to final server
11.2 Subsequent Boot
- Persisted objects are loaded
- Modem credential presence is checked
- If valid, bootstrap is skipped
- Device registers directly to final server
12) Re-Bootstrap and Failure Handling
Recommended triggers for re-bootstrap:
- repeated DTLS/auth failures
- repeated registration failures/timeouts
- explicit local reset request
Project behavior includes delayed retries and guarded transitions during APN switch to avoid incorrect auto-restart behavior.
13) Common Pitfalls
- treating bootstrap as normal registration
- not persisting DELETE operations from bootstrap server
- allowing registration before bootstrap finish
- mismatched SSID between Security and Server objects
- incomplete or non-atomic persistence during provisioning
14) Validation Checklist
- Bootstrap succeeds on blank device
- Reset during bootstrap does not brick configuration
- Provisioned data survives reboot/power cycle
- Re-bootstrap path works after credential breakage
- Registration never happens before bootstrap completion
- Logs show bootstrap complete then registration complete
15) Project Debugging Checklist
If bootstrap fails, verify:
- bootstrap URI/transport (
coap://vscoaps://) is correct - bootstrap credentials exist under tag
100 - final server credentials exist under tag
101after bootstrap - settings backend is enabled in config
- endpoint format matches server expectation
- APN switching does not leave modem in wrong state
16) Bootstrap Portal Setup Guide
This section is the operator flow to configure the bootstrap server side.
16.1 Prerequisites
- Access to:
Device Bootstrap ManagementBootstrap Target ProfilesBootstrap IMEI Configurations
- Target LwM2M server URI is known
- Device onboarding data is available (
IMEI, PSK ID, PSK Key)
16.2 Steps
- Add a new target profile
Go to
Device Bootstrap Management->Bootstrap Target Profiles->Add. - Configure the target profile:
- In Basic: set
Tenant,Profile Name, optionalDescription. - In Target System: set
Target System URI; optionally set APN/credentials. - In Bootstrap Operations: add custom operations only if needed.
- Keep
Base Bootstrap Operations (System-Generated)as-is (read-only).
- In Basic: set
- Save the target profile.
- Add a new device
Go to
Bootstrap IMEI Configurations->Add. - Add device mapping:
- Select
Profile - Enable
Bootstrap allowed - Fill required fields:
IMEITarget PSK Id(for PSK mode)Target PSK Key(for PSK mode, correct format B64/HEX)
- Optional:
IMSI,ICCID,LwM2M Endpoint,Customer Device Id,Package Id
- Select
- Save configuration.
16.3 Firmware-Side Alignment
Ensure firmware values match portal onboarding data:
- bootstrap enabled in build config
- bootstrap URI set correctly
- endpoint/PSK identity/key aligned with portal entries
16.4 Validation
After provisioning:
- reboot device
- confirm logs show bootstrap registration and transfer complete
- confirm final registration to target server