mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
* fix(drivers/uavcannode): make CANNODE_NODE_ID the sole node ID policy
The startup bootloader_app_shared_write() never reached the bootloader:
it only accepts App-signed data and invalidates the shared region on
every boot. The only consumer was uavcannode itself on a restart
without a reset (nsh stop/start), where the persisted bus_speed=0 made
the CAN driver init fail and left the node off the bus. The bootloader
learns our node ID exclusively through the firmware update handoff in
cb_beginfirmware_update, which already carries the static ID.
CANNODE_NODE_ID now overrides the bootloader handoff only when nonzero,
so the default (0) reuses the ID the bootloader already allocated
instead of running allocation a second time. The handoff is ignored
unless it carries a valid bitrate, healing regions poisoned by firmware
that wrote bus_speed=0. Max is 125 because 126/127 are reserved for
debug tools by DroneCAN convention, matching UAVCAN_NODE_ID.
* fix(drivers/uavcannode): harden bootloader handoff validation
Invalidate the shared region whenever it was read valid, not only when
the handoff is accepted, so stale data cannot linger on boards whose
bootloader never invalidates it. Require a plausible bitrate (the
CANNODE_BITRATE minimum) rather than nonzero: the canbootloader alt-app
update path can hand off bus_speed = CAN_UNDEFINED (999). Reword the
invalid-param error, which claimed dynamic allocation while keeping the
bootloader handoff.
---------
(cherry picked from commit 0524a374d9)
Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
1 parent
cc28d51849
commit
db02ded027
11 files changed
+32
-26
No files matched your search
@@ -85,7 +85,7 @@ On the ARK CANnode, you may need to configure the following parameters:
|
||||
|
||||
| Parameter | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-127 to use a static node ID. |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-125 to use a static node ID. |
|
||||
| <a id="CANNODE_TERM"></a>[CANNODE_TERM](../advanced_config/parameter_reference.md#CANNODE_TERM) | CAN built-in bus termination. |
|
||||
|
||||
## LED Meanings
|
||||
|
||||
@@ -112,7 +112,7 @@ On the ARK Flow, you may need to configure the following parameters:
|
||||
|
||||
| Parameter | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-127 to use a static node ID. |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-125 to use a static node ID. |
|
||||
| <a id="CANNODE_TERM"></a>[CANNODE_TERM](../advanced_config/parameter_reference.md#CANNODE_TERM) | CAN built-in bus termination. |
|
||||
|
||||
## LED Meanings
|
||||
|
||||
@@ -107,7 +107,7 @@ You may need to [configure the following parameters](../dronecan/index.md#qgc-ca
|
||||
|
||||
| Parameter | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-127 to use a static node ID. |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-125 to use a static node ID. |
|
||||
| <a id="CANNODE_TERM"></a>[CANNODE_TERM](../advanced_config/parameter_reference.md#CANNODE_TERM) | CAN built-in bus termination. |
|
||||
|
||||
## LED Meanings
|
||||
|
||||
@@ -99,7 +99,7 @@ You may need to [configure the following parameters](../dronecan/index.md#qgc-ca
|
||||
|
||||
| Parameter | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-127 to use a static node ID. |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-125 to use a static node ID. |
|
||||
| <a id="CANNODE_TERM"></a>[CANNODE_TERM](../advanced_config/parameter_reference.md#CANNODE_TERM) | CAN built-in bus termination. Set to `1` if this is the last node on the CAN bus. |
|
||||
|
||||
## LED Meanings
|
||||
|
||||
@@ -94,7 +94,7 @@ You may need to [configure the following parameters](../dronecan/index.md#qgc-ca
|
||||
|
||||
| Parameter | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-127 to use a static node ID. |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-125 to use a static node ID. |
|
||||
| <a id="CANNODE_TERM"></a>[CANNODE_TERM](../advanced_config/parameter_reference.md#CANNODE_TERM) | CAN built-in bus termination. Set to `1` if this is the last node on the CAN bus. |
|
||||
|
||||
### Setting Up Rover and Fixed Base
|
||||
|
||||
@@ -93,7 +93,7 @@ You may need to [configure the following parameters](../dronecan/index.md#qgc-ca
|
||||
|
||||
| Parameter | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-127 to use a static node ID. |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-125 to use a static node ID. |
|
||||
| <a id="CANNODE_TERM"></a>[CANNODE_TERM](../advanced_config/parameter_reference.md#CANNODE_TERM) | CAN built-in bus termination. Set to `1` if this is the last node on the CAN bus. |
|
||||
|
||||
### Setting Up Rover and Fixed Base
|
||||
|
||||
@@ -96,7 +96,7 @@ You may need to [configure the following parameters](../dronecan/index.md#qgc-ca
|
||||
|
||||
| Parameter | Description |
|
||||
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-127 to use a static node ID. |
|
||||
| <a id="CANNODE_NODE_ID"></a>[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) | CAN node ID (0 for dynamic allocation). If set to 0 (default), dynamic node allocation is used. Set to 1-125 to use a static node ID. |
|
||||
| <a id="CANNODE_TERM"></a>[CANNODE_TERM](../advanced_config/parameter_reference.md#CANNODE_TERM) | CAN built-in bus termination. Set to `1` if this is the last node on the CAN bus. |
|
||||
|
||||
### Setting Up Rover and Fixed Base
|
||||
|
||||
@@ -103,7 +103,7 @@ The parameter is set to 1 by default.
|
||||
|
||||
Devices running the [PX4 DroneCAN firmware](px4_cannode_fw.md) (such as [ARK CANnode](ark_cannode.md)) can use the
|
||||
[CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) parameter to set a static node ID.
|
||||
Set it to 0 (default) for dynamic allocation, or to a value between 1-127 to use a specific static node ID.
|
||||
Set it to 0 (default) for dynamic allocation, or to a value between 1-125 to use a specific static node ID.
|
||||
:::
|
||||
|
||||
:::warning
|
||||
@@ -300,7 +300,7 @@ For example, the screenshot below shows the parameters for a CAN GPS with node i
|
||||
|
||||
Common CANNODE parameters that you can configure include:
|
||||
|
||||
- [CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID): Set a static node ID (1-127) or use 0 for dynamic allocation. See [PX4 DroneCAN Firmware > Static Node ID](px4_cannode_fw.md#static-node-id) for more information.
|
||||
- [CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID): Set a static node ID (1-125) or use 0 for dynamic allocation. See [PX4 DroneCAN Firmware > Static Node ID](px4_cannode_fw.md#static-node-id) for more information.
|
||||
- [CANNODE_TERM](../advanced_config/parameter_reference.md#CANNODE_TERM): Enable CAN bus termination on the last node in the bus.
|
||||
|
||||
## Device Specific Setup
|
||||
|
||||
@@ -38,7 +38,7 @@ However, you can configure a static node ID using the [CANNODE_NODE_ID](../advan
|
||||
|
||||
To configure a static node ID:
|
||||
|
||||
1. Set [CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) to a value between 1-127 using [QGroundControl](index.md#qgc-cannode-parameter-configuration)
|
||||
1. Set [CANNODE_NODE_ID](../advanced_config/parameter_reference.md#CANNODE_NODE_ID) to a value between 1-125 using [QGroundControl](index.md#qgc-cannode-parameter-configuration)
|
||||
2. Reboot the device
|
||||
|
||||
To return to dynamic allocation, set `CANNODE_NODE_ID` back to 0.
|
||||
|
||||
@@ -360,7 +360,8 @@ int UavcanNode::init(uavcan::NodeID node_id, UAVCAN_DRIVER::BusEvent &bus_events
|
||||
{
|
||||
_node.setName(board_get_uavcan_hw_name());
|
||||
|
||||
// Was the node_id supplied by the bootloader?
|
||||
// Nonzero node_id came from the bootloader handoff or CANNODE_NODE_ID;
|
||||
// zero means dynamic node ID allocation runs in Run()
|
||||
|
||||
if (node_id != 0) {
|
||||
_node.setNodeID(node_id);
|
||||
@@ -836,14 +837,19 @@ extern "C" int uavcannode_start(int argc, char *argv[])
|
||||
valid = bootloader_app_shared_read(&shared, BootLoader);
|
||||
}
|
||||
|
||||
// Consume the region even when the handoff is rejected below: on boards
|
||||
// booted by a non-PX4 bootloader nothing else ever invalidates it
|
||||
if (valid == 0) {
|
||||
bootloader_app_shared_invalidate();
|
||||
}
|
||||
|
||||
// Trust the handoff only if it carries a plausible bitrate (CANNODE_BITRATE
|
||||
// minimum), healing regions poisoned by firmware running previous code
|
||||
if (valid == 0 && shared.bus_speed >= 20000) {
|
||||
|
||||
bitrate = shared.bus_speed;
|
||||
node_id = shared.node_id;
|
||||
|
||||
// Invalidate to prevent deja vu
|
||||
bootloader_app_shared_invalidate();
|
||||
|
||||
} else {
|
||||
// Node ID
|
||||
#if defined(SUPPORT_ALT_CAN_BOOTLOADER)
|
||||
@@ -858,24 +864,20 @@ extern "C" int uavcannode_start(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
// Use a static node ID if the parameter is set and in range
|
||||
// CANNODE_NODE_ID == 0 (default) keeps dynamic node ID allocation, reusing an ID the
|
||||
// bootloader may have already allocated. 1..125 sets a static node ID, overriding
|
||||
// anything the bootloader negotiated. The bootloader never sees this parameter: it
|
||||
// learns our node ID only through the firmware update handoff in cb_beginfirmware_update.
|
||||
int32_t cannode_node_id = 0;
|
||||
param_get(param_find("CANNODE_NODE_ID"), &cannode_node_id);
|
||||
|
||||
if (cannode_node_id < 0 || cannode_node_id > uavcan::NodeID::Max) {
|
||||
PX4_ERR("Invalid static node ID %ld, using dynamic allocation", cannode_node_id);
|
||||
node_id = 0;
|
||||
if (cannode_node_id < 0 || cannode_node_id > uavcan::NodeID::MaxRecommendedForRegularNodes) {
|
||||
PX4_ERR("Invalid CANNODE_NODE_ID %" PRId32 ", ignoring", cannode_node_id);
|
||||
|
||||
} else {
|
||||
} else if (cannode_node_id > 0) {
|
||||
node_id = cannode_node_id;
|
||||
}
|
||||
|
||||
// Persist the node ID for the bootloader
|
||||
bootloader_app_shared_t shared_write = {};
|
||||
shared_write.node_id = node_id;
|
||||
shared_write.bus_speed = 0; // we always want to autobaud
|
||||
bootloader_app_shared_write(&shared_write, BootLoader);
|
||||
|
||||
if (
|
||||
#if defined(SUPPORT_ALT_CAN_BOOTLOADER)
|
||||
board_booted_by_px4() &&
|
||||
|
||||
@@ -5,10 +5,14 @@ parameters:
|
||||
CANNODE_NODE_ID:
|
||||
description:
|
||||
short: UAVCAN CAN node ID (0 for dynamic allocation)
|
||||
long: |-
|
||||
Set to 0 (default) to use dynamic node ID allocation (DNA).
|
||||
Set to 1-125 to use a static node ID, which must be unique on the bus.
|
||||
type: int32
|
||||
default: 0
|
||||
min: 0
|
||||
max: 127
|
||||
max: 125
|
||||
reboot_required: true
|
||||
CANNODE_BITRATE:
|
||||
description:
|
||||
short: UAVCAN CAN bus bitrate
|
||||
|
||||
Reference in new issue
Block a user