Skip to content

Commit 689d7cb

Browse files
nandojvecarlescufi
authored andcommitted
mgmt: updatehub: Clean-up firmware headers
Move header includes to source file. Currently firmware source files have a hardcode partition identificator. This moves identificators to updatehub core. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent f3159e3 commit 689d7cb

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

subsys/mgmt/updatehub/shell.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 O.S.Systems
2+
* Copyright (c) 2018-2023 O.S.Systems
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -56,10 +56,12 @@ static int cmd_info(const struct shell *shell, size_t argc, char **argv)
5656
ARG_UNUSED(argv);
5757

5858
char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE);
59-
char *firmware_version = k_malloc(BOOT_IMG_VER_STRLEN_MAX);
59+
char *firmware_version = k_malloc(FIRMWARE_IMG_VER_STRLEN_MAX);
6060

6161
updatehub_get_device_identity(device_id, DEVICE_ID_HEX_MAX_SIZE);
62-
updatehub_get_firmware_version(firmware_version, BOOT_IMG_VER_STRLEN_MAX);
62+
updatehub_get_firmware_version(FIXED_PARTITION_ID(slot0_partition),
63+
firmware_version,
64+
FIRMWARE_IMG_VER_STRLEN_MAX);
6365

6466
shell_fprintf(shell, SHELL_NORMAL, "Unique device id: %s\n",
6567
device_id);

subsys/mgmt/updatehub/updatehub.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ static int report(enum updatehub_state state)
620620
int ret = -1;
621621
const char *exec = state_name(state);
622622
char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE);
623-
char *firmware_version = k_malloc(BOOT_IMG_VER_STRLEN_MAX);
623+
char *firmware_version = k_malloc(FIRMWARE_IMG_VER_STRLEN_MAX);
624624

625625
if (device_id == NULL || firmware_version == NULL) {
626626
LOG_ERR("Could not alloc device_id or firmware_version memory");
@@ -631,7 +631,9 @@ static int report(enum updatehub_state state)
631631
goto error;
632632
}
633633

634-
if (!updatehub_get_firmware_version(firmware_version, BOOT_IMG_VER_STRLEN_MAX)) {
634+
if (!updatehub_get_firmware_version(FIXED_PARTITION_ID(slot0_partition),
635+
firmware_version,
636+
FIRMWARE_IMG_VER_STRLEN_MAX)) {
635637
goto error;
636638
}
637639

@@ -769,7 +771,7 @@ enum updatehub_response updatehub_probe(void)
769771
char *metadata = k_malloc(MAX_DOWNLOAD_DATA);
770772
char *metadata_copy = k_malloc(MAX_DOWNLOAD_DATA);
771773
char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE);
772-
char *firmware_version = k_malloc(BOOT_IMG_VER_STRLEN_MAX);
774+
char *firmware_version = k_malloc(FIRMWARE_IMG_VER_STRLEN_MAX);
773775

774776
size_t sha256size;
775777

@@ -786,7 +788,9 @@ enum updatehub_response updatehub_probe(void)
786788
goto error;
787789
}
788790

789-
if (!updatehub_get_firmware_version(firmware_version, BOOT_IMG_VER_STRLEN_MAX)) {
791+
if (!updatehub_get_firmware_version(FIXED_PARTITION_ID(slot0_partition),
792+
firmware_version,
793+
FIRMWARE_IMG_VER_STRLEN_MAX)) {
790794
ctx.code_status = UPDATEHUB_METADATA_ERROR;
791795
goto error;
792796
}

subsys/mgmt/updatehub/updatehub_firmware.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
/*
2-
* Copyright (c) 2018 O.S.Systems
2+
* Copyright (c) 2018-2023 O.S.Systems
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include <zephyr/sys/printk.h>
7+
#include <zephyr/logging/log.h>
8+
LOG_MODULE_DECLARE(updatehub, CONFIG_UPDATEHUB_LOG_LEVEL);
9+
10+
#include <zephyr/dfu/mcuboot.h>
811
#include <zephyr/storage/flash_map.h>
12+
#include <zephyr/sys/printk.h>
913

1014
#include "updatehub_firmware.h"
1115

12-
bool updatehub_get_firmware_version(char *version, int version_len)
16+
bool updatehub_get_firmware_version(const uint32_t partition_id,
17+
char *version, int version_len)
1318
{
1419
struct mcuboot_img_header header;
1520

16-
if (boot_read_bank_header(FIXED_PARTITION_ID(slot0_partition), &header,
17-
version_len) != 0) {
21+
if (boot_read_bank_header(partition_id, &header,
22+
sizeof(struct mcuboot_img_header)) != 0) {
23+
LOG_DBG("Error when executing boot_read_bank_header function");
24+
return false;
25+
}
26+
27+
if (header.mcuboot_version != 1) {
28+
LOG_DBG("MCUboot header version not supported!");
1829
return false;
1930
}
2031

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/*
2-
* Copyright (c) 2018 O.S.Systems
2+
* Copyright (c) 2018-2023 O.S.Systems
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#ifndef __UPDATEHUB_FIRMWARE_H__
88
#define __UPDATEHUB_FIRMWARE_H__
99

10-
#include <zephyr/drivers/flash.h>
11-
#include <zephyr/dfu/mcuboot.h>
12-
#include <zephyr/dfu/flash_img.h>
10+
/* 255.255.65535\0 */
11+
#define FIRMWARE_IMG_VER_STRLEN_MAX 14
1312

14-
bool updatehub_get_firmware_version(char *version, int version_len);
13+
bool updatehub_get_firmware_version(const uint32_t partition_id,
14+
char *version, int version_len);
1515

1616
#endif /* __UPDATEHUB_FIRMWARE_H__ */

0 commit comments

Comments
 (0)