Skip to content

Commit 75a5fb6

Browse files
michalek-noeivindj-nordic
authored andcommitted
mcumgr: img_mgmt: cut down
removed bm unneeded stuff Signed-off-by: Mateusz Michalek <mateusz.michalek@nordicsemi.no>
1 parent 70e388d commit 75a5fb6

7 files changed

Lines changed: 132 additions & 2104 deletions

File tree

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Build system
5858
DFU
5959
===
6060

61-
Image upload NVM writes are handled in synchronization with SD.
61+
* Updated the image upload NVM writes to be handled in synchronization with SD.
6262

6363
Interrupts
6464
==========

subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ config MCUMGR_GRP_IMG_IMAGE_BUFFER_CHUNK_SZ
167167
default 2048
168168
range 16 4096
169169
help
170-
This sets how much data is buffered before passing to non volatile memory.
171-
It has to be multiple of NVM write block size.
170+
This sets how much data is buffered before passing to non-volatile memory.
171+
It has to be a multiple of the NVM write block size.
172172

173173
module = MCUMGR_GRP_IMG
174174
module-str = MCUMGR_GRP_IMG

subsys/mgmt/mcumgr/grp/img_mgmt/include/img_mgmt.h

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,16 @@ enum img_mgmt_id_upload_t {
191191
};
192192

193193
extern int boot_current_slot;
194-
extern struct img_mgmt_state g_img_mgmt_state;
194+
extern struct img_mgmt_state img_mgmt_state;
195195

196196
/** Represents an individual upload request. */
197197
struct img_mgmt_upload_req {
198-
uint32_t image; /* 0 by default */
199-
size_t off; /* SIZE_MAX if unspecified */
200-
size_t size; /* SIZE_MAX if unspecified */
198+
uint32_t image; /**< 0 by default */
199+
size_t off; /**< SIZE_MAX if unspecified */
200+
size_t size; /**< SIZE_MAX if unspecified */
201201
struct zcbor_string img_data;
202202
struct zcbor_string data_sha;
203-
bool upgrade; /* Only allow greater version numbers. */
203+
bool upgrade; /**< Only allow greater version numbers. */
204204
};
205205

206206
/** Global state for upload in progress. */
@@ -235,21 +235,21 @@ struct img_mgmt_upload_action {
235235
};
236236

237237
/*
238-
* @brief Read info of an image at the specified slot number
238+
* @brief Read info of an image at the specified slot number.
239239
*
240-
* @param image_slot image slot number
241-
* @param ver output buffer for image version
242-
* @param hash output buffer for image hash
243-
* @param flags output buffer for image flags
240+
* @param image_slot Image slot number.
241+
* @param ver Output buffer for image version.
242+
* @param hash Output buffer for image hash.
243+
* @param flags Output buffer for image flags.
244244
*
245245
* @return 0 on success, non-zero on failure.
246246
*/
247247
int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash, uint32_t *flags);
248248

249249
/**
250-
* @brief Get the image version of the currently running application.
250+
* @brief Get the image version of the application running currently.
251251
*
252-
* @param ver output buffer for an image version information object.
252+
* @param ver Output buffer for an image version information object.
253253
*
254254
* @return 0 on success, non-zero on failure.
255255
*/
@@ -258,26 +258,26 @@ int img_mgmt_my_version(struct image_version *ver);
258258
/**
259259
* @brief Format version string from struct image_version
260260
*
261-
* @param ver pointer to image_version object
262-
* @param dst output buffer for image version string
261+
* @param ver Pointer to image_version object.
262+
* @param dst Output buffer for image version string.
263263
*
264264
* @return Non-negative on success, negative value on error.
265265
*/
266266
int img_mgmt_ver_str(const struct image_version *ver, char *dst);
267267

268268
/**
269-
* @brief Get active, running application slot number for an image
269+
* @brief Get active, running application slot number for an image.
270270
*
271-
* @param image image number to get active slot for.
271+
* @param image Image number to get active slot for.
272272
*
273273
* @return Non-negative slot number
274274
*/
275275
int img_mgmt_active_slot(int image);
276276

277277
/**
278-
* @brief Get active image number
278+
* @brief Get active image number.
279279
*
280-
* Gets 0 based number for running application.
280+
* Gets zero-based number for running application.
281281
*
282282
* @return Non-negative image number.
283283
*/
@@ -286,11 +286,11 @@ int img_mgmt_active_image(void);
286286
/**
287287
* @brief Check if the image slot is in use.
288288
*
289-
* The check is based on MCUboot flags, not image contents. This means that
290-
* slot with image in it, but no bootable flags set, is considered empty.
289+
* The check is based on MCUboot flags, not image contents. This means that the
290+
* slot with an image in it, but no bootable flags set, is considered empty.
291291
* Active slot is always in use.
292292
*
293-
* @param slot slot number
293+
* @param slot Slot number.
294294
*
295295
* @return 0 if slot is not used, non-0 otherwise.
296296
*/
@@ -307,7 +307,7 @@ int img_mgmt_slot_in_use(int slot);
307307
int img_mgmt_state_any_pending(void);
308308

309309
/**
310-
* @brief Returns state flags set to slot.
310+
* @brief Return state flags set to the slot.
311311
*
312312
* Flags are translated from MCUboot image state flags.
313313
* Returned value is zero if no flags are set or a combination of:
@@ -316,29 +316,29 @@ int img_mgmt_state_any_pending(void);
316316
* IMG_MGMT_STATE_F_ACTIVE
317317
* IMG_MGMT_STATE_F_PERMANENT
318318
*
319-
* @param query_slot slot number
319+
* @param query_slot Slot number.
320320
*
321-
* @return return the state flags.
321+
* @return the state flags.
322322
*
323323
*/
324324
uint8_t img_mgmt_state_flags(int query_slot);
325325

326326
/**
327-
* @brief Sets the pending flag for the specified image slot.
327+
* @brief Set the pending flag for the specified image slot.
328328
*
329-
* Sets specified image slot to be used as active slot during next boot,
330-
* either for test or permanently. Non-permanent image will be reverted
331-
* unless image confirms itself during next boot.
329+
* Sets the specified image slot to be used as the active slot during next boot,
330+
* either for test or permanently. A non-permanent image will be reverted
331+
* unless the image confirms itself during next boot.
332332
*
333-
* @param slot slot number
334-
* @param permanent permanent or test only
333+
* @param slot Slot number.
334+
* @param permanent Permanent or test only.
335335
*
336336
* @return 0 on success, non-zero on failure
337337
*/
338338
int img_mgmt_state_set_pending(int slot, int permanent);
339339

340340
/**
341-
* @brief Confirms the current image state.
341+
* @brief Confirm the current image state.
342342
*
343343
* Prevents a fallback from occurring on the next reboot if the active image
344344
* is currently being tested.
@@ -348,10 +348,10 @@ int img_mgmt_state_set_pending(int slot, int permanent);
348348
int img_mgmt_state_confirm(void);
349349

350350
/**
351-
* Compares two image version numbers in a semver-compatible way.
351+
* Compare two image version numbers in a semver-compatible way.
352352
*
353-
* @param a The first version to compare
354-
* @param b The second version to compare
353+
* @param a The first version to compare.
354+
* @param b The second version to compare.
355355
*
356356
* @return -1 if a < b
357357
* @return 0 if a = b

subsys/mgmt/mcumgr/grp/img_mgmt/include/mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h

Lines changed: 13 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,7 @@ extern "C" {
2727
#endif
2828

2929
/**
30-
* @brief Ensures the spare slot (slot 1) is fully erased.
31-
*
32-
* @param slot A slot to erase.
33-
*
34-
* @return 0 on success, MGMT_ERR_[...] code on failure.
35-
*/
36-
int img_mgmt_erase_slot(int slot);
37-
38-
/**
39-
* @brief Marks the image in the specified slot as pending. On the next reboot,
40-
* the system will perform a boot of the specified image.
41-
*
42-
* @param slot The slot to mark as pending. In the typical use case, this is 1.
43-
* @param permanent Whether the image should be used permanently or only tested once:
44-
* 0=run image once, then confirm or revert.
45-
* 1=run image forever.
46-
*
47-
* @return 0 on success, MGMT_ERR_[...] code on failure.
48-
*/
49-
int img_mgmt_write_pending(int slot, bool permanent);
50-
51-
/**
52-
* @brief Marks the image in slot 0 as confirmed. The system will continue
53-
* booting into the image in slot 0 until told to boot from a different slot.
54-
*
55-
* @return 0 on success, MGMT_ERR_[...] code on failure.
56-
*/
57-
int img_mgmt_write_confirmed(void);
58-
59-
/**
60-
* @brief Reads the specified chunk of data from an image slot.
30+
* @brief Read the specified chunk of data from an image slot.
6131
*
6232
* @param slot The index of the slot to read from.
6333
* @param offset The offset within the slot to read from.
@@ -69,7 +39,7 @@ int img_mgmt_write_confirmed(void);
6939
int img_mgmt_read(int slot, unsigned int offset, void *dst, unsigned int num_bytes);
7040

7141
/**
72-
* @brief Writes the specified chunk of image data to slot 1.
42+
* @brief Write the specified chunk of image data to slot 1.
7343
*
7444
* @param offset The offset within slot 1 to write to.
7545
* @param data The image data to write.
@@ -84,35 +54,9 @@ int img_mgmt_write_image_data(unsigned int offset, const void *data, unsigned in
8454
bool last);
8555

8656
/**
87-
* @brief Indicates the type of swap operation that will occur on the next
88-
* reboot, if any, between provided slot and it's pair.
89-
* Querying any slots of the same pair will give the same result.
90-
*
91-
* @param slot An slot number;
92-
*
93-
* @return An IMG_MGMT_SWAP_TYPE_[...] code.
94-
*/
95-
int img_mgmt_swap_type(int slot);
96-
97-
/**
98-
* @brief Returns image that the given slot belongs to.
57+
* @brief Get the slot number of an alternate (inactive) image pair.
9958
*
100-
* @param slot A slot number.
101-
*
102-
* @return 0 based image number.
103-
*/
104-
static inline int img_mgmt_slot_to_image(int slot)
105-
{
106-
__ASSERT(slot >= 0 && slot < (CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER << 1),
107-
"Impossible slot number");
108-
109-
return (slot >> 1);
110-
}
111-
112-
/**
113-
* @brief Get slot number of alternate (inactive) image pair
114-
*
115-
* @param slot A slot number.
59+
* @param slot A slot number.
11660
*
11761
* @return Number of other slot in pair
11862
*/
@@ -137,27 +81,27 @@ enum img_mgmt_next_boot_type {
13781
};
13882

13983
/**
140-
* @brief Get next boot slot number for a given image.
84+
* @brief Get the next boot slot number for a given image.
14185
*
14286
* @param image An image number.
143-
* @param type Type of next boot
87+
* @param type Type of next boot.
14488
*
14589
* @return Number of slot, from pair of slots assigned to image, that will
146-
* boot on next reset. User needs to compare this slot against active slot
147-
* to check whether application image will change for the next boot.
148-
* @return -1 in case when next boot slot can not be established.
90+
* boot on next reset. You need to compare this slot against an active slot
91+
* to check whether the application image will change for the next boot.
92+
* @return -1 if the next boot slot cannot be established.
14993
*/
15094
int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type);
15195

15296
/**
153-
* Collects information about the specified image slot.
97+
* Collect information about the specified image slot.
15498
*
15599
* @return Flags of the specified image slot
156100
*/
157101
uint8_t img_mgmt_state_flags(int query_slot);
158102

159103
/**
160-
* Erases image data at given offset
104+
* Erase the image data at given offset.
161105
*
162106
* @param offset The offset within slot 1 to erase at.
163107
* @param num_bytes The number of bytes to erase.
@@ -167,24 +111,9 @@ uint8_t img_mgmt_state_flags(int query_slot);
167111
int img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes);
168112

169113
/**
170-
* Erases a flash sector as image upload crosses a sector boundary.
171-
* Erasing the entire flash size at one time can take significant time,
172-
* causing a bluetooth disconnect or significant battery sag.
173-
* Instead we will erase immediately prior to crossing a sector.
174-
* We could check for empty to increase efficiency, but instead we always erase
175-
* for consistency and simplicity.
176-
*
177-
* @param off Offset that is about to be written
178-
* @param len Number of bytes to be written
179-
*
180-
* @return 0 if success ERROR_CODE if could not erase sector
181-
*/
182-
int img_mgmt_erase_if_needed(uint32_t off, uint32_t len);
183-
184-
/**
185-
* Verifies an upload request and indicates the actions that should be taken
114+
* Verifies an upload request and indicates the actions to be taken
186115
* during processing of the request. This is a "read only" function in the
187-
* sense that it doesn't write anything to flash and doesn't modify any global
116+
* sense that it does not write anything to flash or modify any global
188117
* variables.
189118
*
190119
* @param req The upload request to inspect.
@@ -197,26 +126,9 @@ int img_mgmt_erase_if_needed(uint32_t off, uint32_t len);
197126
int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
198127
struct img_mgmt_upload_action *action);
199128

200-
/**
201-
* @brief Takes the image management lock (if enabled) to prevent other
202-
* threads interfering with an ongoing operation.
203-
*/
204-
void img_mgmt_take_lock(void);
205-
206-
/**
207-
* @brief Releases the held image management lock (if enabled) to allow
208-
* other threads to use image management operations.
209-
*/
210-
void img_mgmt_release_lock(void);
211-
212129
#define ERASED_VAL_32(x) (((x) << 24) | ((x) << 16) | ((x) << 8) | (x))
213-
int img_mgmt_erased_val(int slot, uint8_t *erased_val);
214130

215-
int img_mgmt_find_by_hash(uint8_t *find, struct image_version *ver);
216-
int img_mgmt_find_by_ver(struct image_version *find, uint8_t *hash);
217131
int img_mgmt_state_read(struct smp_streamer *ctxt);
218-
int img_mgmt_state_write(struct smp_streamer *njb);
219-
int img_mgmt_flash_area_id(int slot);
220132

221133
#ifdef __cplusplus
222134
}

0 commit comments

Comments
 (0)