Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions generated/include/infuse/rpc/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ struct rpc_last_reboot_response {
uint32_t param_2;
/** Running thread at reboot */
char thread[8];
/** Exception stack frame values */
uint32_t esf[];
} __packed;

/** Get state of a data logger */
Expand Down
4 changes: 2 additions & 2 deletions scripts/network_key_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import argparse
import pathlib
import random
import secrets
import sys
import yaml

Expand All @@ -29,7 +29,7 @@ def hexint_presenter(dumper, data):

contents = {
"id": args.id,
"key": random.randbytes(32),
"key": secrets.token_bytes(32),
}
yaml.add_representer(int, hexint_presenter)

Expand Down
3 changes: 2 additions & 1 deletion scripts/west_commands/cloud_definitions/rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@
{"name": "uptime", "type": "uint32_t", "description": "Uptime before reboot (seconds)"},
{"name": "param_1", "type": "uint32_t", "description": "Program counter/Watchdog Info/Other"},
{"name": "param_2", "type": "uint32_t", "description": "Link Register/Watchdog Info/Other"},
{"name": "thread", "type": "char", "num": 8, "description": "Running thread at reboot"}
{"name": "thread", "type": "char", "num": 8, "description": "Running thread at reboot"},
{"name": "esf", "type": "uint32_t", "num": 0, "description": "Exception stack frame values"}
]
},
"13": {
Expand Down
14 changes: 7 additions & 7 deletions scripts/west_commands/cloud_definitions/tdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,32 +464,32 @@
"name": "LORA_RX",
"description": "Received LoRa packet",
"fields": [
{"name": "snr", "type": "int8_t", "description": "Signal to Noise ratio (dB)"},
{"name": "rssi", "type": "int16_t", "description": "Received signal strength (dBm)"},
{"name": "payload", "type": "uint8_t", "num": 0, "description": "Packet payload"}
{"name": "snr", "type": "int8_t", "description": "Signal to Noise ratio (dB)", "display": {"postfix": "dB"}},
{"name": "rssi", "type": "int16_t", "description": "Received signal strength (dBm)", "display": {"postfix": "dBm"}},
{"name": "payload", "type": "uint8_t", "num": 0, "description": "Packet payload", "display": {"fmt": "hex", "digits": 2}}
]
},
"45": {
"name": "LORA_TX",
"description": "Transmitted LoRa packet",
"fields": [
{"name": "payload", "type": "uint8_t", "num": 0, "description": "Payload"}
{"name": "payload", "type": "uint8_t", "num": 0, "description": "Payload", "display": {"fmt": "hex", "digits": 2}}
]
},
"46": {
"name": "IDX_ARRAY_FREQ",
"description": "Sample frequency metadata for a TDF_DATA_FORMAT_IDX_ARRAY array",
"fields": [
{"name": "tdf_id", "type": "uint16_t", "description": "TDF ID that is being described"},
{"name": "frequency", "type": "uint32_t", "description": "Frequency of samples in Hertz"}
{"name": "frequency", "type": "uint32_t", "description": "Frequency of samples in Hertz", "display": {"postfix": "Hz"}}
]
},
"47": {
"name": "IDX_ARRAY_PERIOD",
"description": "Sample frequency metadata for a TDF_DATA_FORMAT_IDX_ARRAY array",
"fields": [
{"name": "tdf_id", "type": "uint16_t", "description": "TDF ID that is being described"},
{"name": "period", "type": "uint32_t", "description": "Period between samples in nanoseconds"}
{"name": "period", "type": "uint32_t", "description": "Period between samples in nanoseconds", "display": {"postfix": "ns"}}
]
},
"48": {
Expand Down Expand Up @@ -525,7 +525,7 @@
"name": "EXCEPTION_STACK_FRAME",
"description": "Generic exception stack frame",
"fields": [
{"name": "frame", "type": "uint32_t", "num":0, "description": "Stack frame value"}
{"name": "frame", "type": "uint32_t", "num":0, "description": "Stack frame value", "display": {"fmt": "hex", "digits": 8}}
]
}
}
Expand Down
8 changes: 4 additions & 4 deletions scripts/west_commands/release-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from west.commands import WestCommand

try:
from infuse_iot.cpatch import diff
from infuse_iot.cpatch import cpatch
except ImportError:
diff = None
cpatch = None

EXPORT_DESCRIPTION = """\
This command generates a diff file between two application releases.
Expand Down Expand Up @@ -116,7 +116,7 @@ def expect_match(field):
# The trailing TLV's can change on device, so exclude them from the original image knowledge
with open(input_path, "rb") as f_input:
with open(output_path, "rb") as f_output:
patch = diff.generate(
patch = cpatch.generate(
f_input.read(-1)[:-input_tlv_len],
f_output.read(-1),
True,
Expand Down Expand Up @@ -175,7 +175,7 @@ def expect_match(field):
print(f"\t xdelta: {x_size} {100 * x_size / output_len:.2f}%")

def do_run(self, args, _unknown_args):
if diff is None:
if cpatch is None:
sys.exit("infuse-iot.diff not found")

for original in args.input:
Expand Down
11 changes: 10 additions & 1 deletion subsys/rpc/commands/last_reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct net_buf *rpc_command_last_reboot(struct net_buf *request)
{
struct rpc_last_reboot_response rsp = {0};
struct infuse_reboot_state state;
struct net_buf *response;

infuse_common_boot_last_reboot(&state);
rsp.reason = state.reason;
Expand Down Expand Up @@ -50,5 +51,13 @@ struct net_buf *rpc_command_last_reboot(struct net_buf *request)
}
memcpy(rsp.thread, state.thread_name, sizeof(rsp.thread));

return rpc_response_simple_req(request, 0, &rsp, sizeof(rsp));
/* Allocate the response object */
response = rpc_response_simple_req(request, 0, &rsp, sizeof(rsp));

if (state.info_type == INFUSE_REBOOT_INFO_EXCEPTION_ESF) {
/* Push the exception stack frame into the response */
net_buf_add_mem(response, &state.info.exception_full,
sizeof(state.info.exception_full));
}
return response;
}
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ struct rpc_last_reboot_response {
uint32_t param_2;
/** Running thread at reboot */
char thread[8];
/** Exception stack frame values */
uint32_t esf[];
} __packed;

/** Get state of a data logger */
Expand Down
28 changes: 28 additions & 0 deletions tests/subsys/rpc/commands/last_reboot/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include <infuse/epacket/packet.h>
#include <infuse/epacket/interface/epacket_dummy.h>

static void null_dereference(void)
{
epoch_time_set_reference(TIME_SOURCE_NONE, NULL);
}

static void send_last_reboot_command(uint32_t request_id)
{
const struct device *epacket_dummy = DEVICE_DT_GET(DT_NODELABEL(epacket_dummy));
Expand Down Expand Up @@ -67,6 +72,7 @@ ZTEST(rpc_command_last_reboot, test_reboot_query)
KV_KEY_TYPE(KV_KEY_REBOOTS) reboots;
struct rpc_last_reboot_response *response;
struct net_buf *rsp;
int esf_values;
ssize_t rc;

/* KV store should have been initialised and populated with a reboot count */
Expand All @@ -80,11 +86,13 @@ ZTEST(rpc_command_last_reboot, test_reboot_query)
/* Validate the response */
rsp = expect_last_reboot_response(1);
response = (void *)rsp->data;
esf_values = (rsp->len - sizeof(*response)) / sizeof(response->esf[0]);
zassert_equal(INFUSE_REBOOT_UNKNOWN, response->reason);
zassert_equal(TIME_SOURCE_NONE, response->epoch_time_source);
zassert_equal(0, response->epoch_time);
zassert_equal(0, response->param_1);
zassert_equal(0, response->param_2);
zassert_equal(0, esf_values);
net_buf_unref(rsp);

struct timeutil_sync_instant reference = {
Expand All @@ -104,11 +112,31 @@ ZTEST(rpc_command_last_reboot, test_reboot_query)
/* Validate the response */
rsp = expect_last_reboot_response(333);
response = (void *)rsp->data;
esf_values = (rsp->len - sizeof(*response)) / sizeof(response->esf[0]);
zassert_equal(INFUSE_REBOOT_DFU, response->reason);
zassert_equal(TIME_SOURCE_GNSS, response->epoch_time_source);
zassert_not_equal(0, response->epoch_time);
zassert_equal(0x1234, response->param_1);
zassert_equal(0x98765432, response->param_2);
zassert_equal(0, esf_values);
net_buf_unref(rsp);

/* Trigger a fault */
null_dereference();
zassert_unreachable("Test did not reboot");
break;
case 3:
/* Validate previous initial reboot info */
send_last_reboot_command(444);
rsp = expect_last_reboot_response(444);
response = (void *)rsp->data;
esf_values = (rsp->len - sizeof(*response)) / sizeof(response->esf[0]);
zassert_equal(K_ERR_CPU_EXCEPTION, response->reason);
zassert_equal(TIME_SOURCE_GNSS | TIME_SOURCE_RECOVERED,
response->epoch_time_source);
zassert_not_equal(0, response->epoch_time);
/* Expect a full exception stack frame to be part of the response */
zassert_equal(sizeof(struct arch_esf) / sizeof(uint32_t), esf_values);
net_buf_unref(rsp);
break;
default:
Expand Down