lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42273?usp=email )
Change subject: WIP: dfu-download: flash the first block into manifest phase
......................................................................
WIP: dfu-download: flash the first block into manifest phase
To prevent half flashed applications, erase the first page
when dfu downloading starts and save the first block for later.
In manifest stage, flash the first block.
If the first 4 byte are 0xffffffff, the board won't boot
into application and go into the dfu bootloader.
TODO: Needs testing.
Change-Id: I894f3ee71587ccb287e92d7025039954991c631f
---
M usb/class/dfu/device/dfudf.c
M usb/class/dfu/device/dfudf.h
M usb_start.c
3 files changed, 51 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/73/42273/1
diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c
index bca0a6b..2af1998 100644
--- a/usb/class/dfu/device/dfudf.c
+++ b/usb/class/dfu/device/dfudf.c
@@ -45,6 +45,11 @@
/* flashed the last given block */
uint8_t dfu_download_data[512];
volatile uint16_t dfu_download_length = 0;
+
+/* buffer the first block, to write it last */
+uint8_t dfu_download_data_first[512];
+uint16_t dfu_download_data_first_length = 0;
+
volatile size_t dfu_download_offset = 0;
/* only when flash done is true, flash rc is valid */
diff --git a/usb/class/dfu/device/dfudf.h b/usb/class/dfu/device/dfudf.h
index b9db46f..bbfb58b 100644
--- a/usb/class/dfu/device/dfudf.h
+++ b/usb/class/dfu/device/dfudf.h
@@ -52,6 +52,9 @@
/** Offset of where the downloaded data should be flashed in bytes */
extern volatile size_t dfu_download_offset;
+extern uint8_t dfu_download_data_first[512];
+extern uint16_t dfu_download_length_first;
+
/** when flash done is true, flash status is valid */
extern volatile bool dfu_flash_done;
/** Result of the last blocked flashed. */
diff --git a/usb_start.c b/usb_start.c
index e9dce79..6de384c 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -156,6 +156,7 @@
LED_SYSTEM_on(); // switch LED on to indicate USB DFU stack is ready
uint32_t application_start_address = BL_SIZE_BYTE;
+ int rc;
ASSERT(application_start_address > 0);
while (true) { // main DFU infinite loop
@@ -170,9 +171,21 @@
LED_SYSTEM_off(); // switch LED off to indicate we are flashing
if (dfu_download_length > 0) { // there is some data to be flashed
- int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset,
- dfu_download_data,
- dfu_download_length); // write downloaded data chunk to flash
+ /* The first block will be only erased, to ensure the
+ * full firmware has been written.
+ * In case of a power loss, the bootloader won't boot applications
+ * if the first 4 byte are 0xffffffff
+ */
+ if (dfu_download_offset == 0) {
+ dfu_download_length_first = dfu_download_length;
+ memcpy(dfu_download_data_first, dfu_download_data, dfu_download_length);
+ /* erasing the first page is enough, flash_write will keep care of the remaining ones */
+ rc = flash_erase(&FLASH_0, application_start_address, 1);
+ } else {
+ rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset,
+ dfu_download_data, dfu_download_length);
+ }
+
CRITICAL_SECTION_ENTER();
switch (rc) {
case ERR_NONE:
@@ -194,16 +207,37 @@
}
LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume
break;
- case USB_DFU_STATE_DFU_MANIFEST: // we can start manifestation (finish flashing)
- // in theory every DFU files should have a suffix to with a CRC to check the data
- // in practice most downloaded files are just the raw binary with DFU suffix
+ case USB_DFU_STATE_DFU_MANIFEST:
+ /* finish flashing by writing the first block */
+ rc = flash_write(&FLASH_0, application_start_address,
+ dfu_download_data_first, dfu_download_length_first);
+ switch (rc) {
+ case ERR_NONE:
+ break;
+ case ERR_BAD_ADDRESS:
+ dfu_flash_status = USB_DFU_STATUS_ERR_ADDRESS;
+ break;
+ case ERR_DENIED:
+ dfu_flash_status = USB_DFU_STATUS_ERR_WRITE;
+ break;
+ default:
+ dfu_flash_status = USB_DFU_STATUS_ERR_PROG;
+ break;
+ }
+
+ /* try to clear it, to ensure it doesn't boot into a broken application */
+ if (dfu_flash_status != ERR_NONE) {
+ flash_erase(&FLASH_0, application_start_address, 1);
+ }
+
CRITICAL_SECTION_ENTER();
dfu_manifestation_complete = true; // we completed flashing and all checks
- if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT) {
+ if (dfu_flash_status != ERR_NONE)
+ dfu_state = USB_DFU_STATE_DFU_ERROR;
+ else if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT)
dfu_state = USB_DFU_STATE_DFU_MANIFEST_SYNC;
- } else {
+ else
dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET;
- }
CRITICAL_SECTION_LEAVE();
break;
case USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET:
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42273?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: I894f3ee71587ccb287e92d7025039954991c631f
Gerrit-Change-Number: 42273
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Attention is currently required from: neels.
dexter has posted comments on this change by neels. ( https://gerrit.osmocom.org/c/pysim/+/41845?usp=email )
Change subject: personalization: add param_source.py, add batch.py
......................................................................
Patch Set 6:
(14 comments)
Patchset:
PS6:
I have looked through this now. Many of the comments are about cosmetic things. I think the only real problem I saw was that the get_next method of RandomHexDigitSource returns a byte array instead of hex digits. I would recommend to add a unit-test to be sure that the various value generators in param_source.py work as expected.
File pySim/esim/saip/batch.py:
https://gerrit.osmocom.org/c/pysim/+/41845/comment/8d49fed9_a5e0cf4d?usp=em… :
PS6, Line 65: params: list[ParamAndSrc]=None,
why not use [] as default? ...
https://gerrit.osmocom.org/c/pysim/+/41845/comment/e943de47_0f674ba4?usp=em… :
PS6, Line 80: self.params = params or []
... then you could write self.params = params here. Maybe this is easier?
https://gerrit.osmocom.org/c/pysim/+/41845/comment/e4dbb645_ad12fe16?usp=em… :
PS6, Line 92: csv_columns = next(self.csv_rows)
In the above comment you say that self.csv_rows can also be a list. I think next() would not work on lists. Is the comment still up to date? or is something missing here?
https://gerrit.osmocom.org/c/pysim/+/41845/comment/56c19288_ec4788f0?usp=em… :
PS6, Line 97: csv_row = None
As far as I understand self.csv_rows is an optional parameter? From what I can see, the code should work fine as long as CsvSource is not used in this case.
File pySim/esim/saip/param_source.py:
https://gerrit.osmocom.org/c/pysim/+/41845/comment/f724aaf0_158e7a7f?usp=em… :
PS6, Line 31: class ParamSource:
As far as I understand this is an abstract class. Maybe declare it as
class ParamSource(abc.ABC)
But when I look more closely, this is not really an abstract class. When I get you correctly you want users to be able to use this class as it is as a bare minimum. It wouldn't do anything useful, but it also wouldn't crash the application.
https://gerrit.osmocom.org/c/pysim/+/41845/comment/587dd973_a74cc8f0?usp=em… :
PS6, Line 42: so the user can enter '0000' to get a four digit random number."""
If this should work as the bare minimum, we should also have some kind of dummy constructor that can accept the string.
https://gerrit.osmocom.org/c/pysim/+/41845/comment/4eb02f63_a84a2c51?usp=em… :
PS6, Line 51:
Excess linebreak? (the other classes are only separated with one)
https://gerrit.osmocom.org/c/pysim/+/41845/comment/58bb5fe7_8ecd4faf?usp=em… :
PS6, Line 65: def __init__(self, num_digits, first_value, last_value):
Maybe add type annotations and agree on one distinct type? At the moment this function can accepts anything that can be casted to int. This is fine, but may also be a bit confusing. (see below)
https://gerrit.osmocom.org/c/pysim/+/41845/comment/1bada13b_f050cff7?usp=em… :
PS6, Line 80:
If this is a private/internal method, I would mark it with double underscore or single underscore?
https://gerrit.osmocom.org/c/pysim/+/41845/comment/67ab85f0_e87a96f7?usp=em… :
PS6, Line 95: last_value = int(last_str) if last_str is not None else "9" * len(first_str)
Here last_value is either an int or it is a string with an integer number. For the constructor this is ok (see above), but it may be confusing still.
https://gerrit.osmocom.org/c/pysim/+/41845/comment/f9f5cb63_dc1aa1d8?usp=em… :
PS6, Line 121: val = random.randbytes(self.num_digits // 2) # TODO secure random source?
As far as I understand this should return a bytearray but what you actually want is a hexstring. Maybe return b2h(val) instead of val directly?
https://gerrit.osmocom.org/c/pysim/+/41845/comment/b44471ae_26d9b7ba?usp=em… :
PS6, Line 149: if val > self.val_first_last[1]:
self.last_value would be easier to read.
https://gerrit.osmocom.org/c/pysim/+/41845/comment/12fdbdf0_b38d9d6d?usp=em… :
PS6, Line 174: return val
You could just do if csv_row: return csv_row.get(self.csv_column) else: raise ...?
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/41845?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I01ae40a06605eb205bfb409189fcd2b3a128855a
Gerrit-Change-Number: 41845
Gerrit-PatchSet: 6
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: dexter <pmaier(a)sysmocom.de>
Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 04 Mar 2026 16:51:51 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: neels.
laforge has posted comments on this change by neels. ( https://gerrit.osmocom.org/c/pysim/+/42268?usp=email )
Change subject: saip: add numeric_base indicator to ConfigurableParameter and ParamSource
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42268?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ib0977bbdd9a85167be7eb46dd331fedd529dae01
Gerrit-Change-Number: 42268
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 04 Mar 2026 15:36:20 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: lynxis lazus.
csaba.sipos has posted comments on this change by csaba.sipos. ( https://gerrit.osmocom.org/c/osmo-bsc/+/42246?usp=email )
Change subject: nokia_site: Add new BTS types to the list
......................................................................
Patch Set 1:
(1 comment)
File src/osmo-bsc/bts_nokia_site.c:
https://gerrit.osmocom.org/c/osmo-bsc/+/42246/comment/10d0177c_df04802f?usp… :
PS1, Line 584: 800
> I mean something like this, to reduce the confusion a little bit. […]
Fix applied.
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/42246?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: Ia0dbbf148394d8205dc9219b41cfba3cf62bdeaa
Gerrit-Change-Number: 42246
Gerrit-PatchSet: 1
Gerrit-Owner: csaba.sipos <metro4(a)freemail.hu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: falconia <falcon(a)freecalypso.org>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Comment-Date: Wed, 04 Mar 2026 15:21:23 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: falconia <falcon(a)freecalypso.org>
Comment-In-Reply-To: csaba.sipos <metro4(a)freemail.hu>
Comment-In-Reply-To: lynxis lazus <lynxis(a)fe80.eu>