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 <gerson.budke@ossystems.com.br>
This commit is contained in:
Gerson Fernando Budke 2023-01-02 12:00:21 +01:00 committed by Carles Cufí
commit 689d7cb085
4 changed files with 34 additions and 17 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018 O.S.Systems * Copyright (c) 2018-2023 O.S.Systems
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -56,10 +56,12 @@ static int cmd_info(const struct shell *shell, size_t argc, char **argv)
ARG_UNUSED(argv); ARG_UNUSED(argv);
char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE); char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE);
char *firmware_version = k_malloc(BOOT_IMG_VER_STRLEN_MAX); char *firmware_version = k_malloc(FIRMWARE_IMG_VER_STRLEN_MAX);
updatehub_get_device_identity(device_id, DEVICE_ID_HEX_MAX_SIZE); updatehub_get_device_identity(device_id, DEVICE_ID_HEX_MAX_SIZE);
updatehub_get_firmware_version(firmware_version, BOOT_IMG_VER_STRLEN_MAX); updatehub_get_firmware_version(FIXED_PARTITION_ID(slot0_partition),
firmware_version,
FIRMWARE_IMG_VER_STRLEN_MAX);
shell_fprintf(shell, SHELL_NORMAL, "Unique device id: %s\n", shell_fprintf(shell, SHELL_NORMAL, "Unique device id: %s\n",
device_id); device_id);

View file

@ -620,7 +620,7 @@ static int report(enum updatehub_state state)
int ret = -1; int ret = -1;
const char *exec = state_name(state); const char *exec = state_name(state);
char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE); char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE);
char *firmware_version = k_malloc(BOOT_IMG_VER_STRLEN_MAX); char *firmware_version = k_malloc(FIRMWARE_IMG_VER_STRLEN_MAX);
if (device_id == NULL || firmware_version == NULL) { if (device_id == NULL || firmware_version == NULL) {
LOG_ERR("Could not alloc device_id or firmware_version memory"); LOG_ERR("Could not alloc device_id or firmware_version memory");
@ -631,7 +631,9 @@ static int report(enum updatehub_state state)
goto error; goto error;
} }
if (!updatehub_get_firmware_version(firmware_version, BOOT_IMG_VER_STRLEN_MAX)) { if (!updatehub_get_firmware_version(FIXED_PARTITION_ID(slot0_partition),
firmware_version,
FIRMWARE_IMG_VER_STRLEN_MAX)) {
goto error; goto error;
} }
@ -769,7 +771,7 @@ enum updatehub_response updatehub_probe(void)
char *metadata = k_malloc(MAX_DOWNLOAD_DATA); char *metadata = k_malloc(MAX_DOWNLOAD_DATA);
char *metadata_copy = k_malloc(MAX_DOWNLOAD_DATA); char *metadata_copy = k_malloc(MAX_DOWNLOAD_DATA);
char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE); char *device_id = k_malloc(DEVICE_ID_HEX_MAX_SIZE);
char *firmware_version = k_malloc(BOOT_IMG_VER_STRLEN_MAX); char *firmware_version = k_malloc(FIRMWARE_IMG_VER_STRLEN_MAX);
size_t sha256size; size_t sha256size;
@ -786,7 +788,9 @@ enum updatehub_response updatehub_probe(void)
goto error; goto error;
} }
if (!updatehub_get_firmware_version(firmware_version, BOOT_IMG_VER_STRLEN_MAX)) { if (!updatehub_get_firmware_version(FIXED_PARTITION_ID(slot0_partition),
firmware_version,
FIRMWARE_IMG_VER_STRLEN_MAX)) {
ctx.code_status = UPDATEHUB_METADATA_ERROR; ctx.code_status = UPDATEHUB_METADATA_ERROR;
goto error; goto error;
} }

View file

@ -1,20 +1,31 @@
/* /*
* Copyright (c) 2018 O.S.Systems * Copyright (c) 2018-2023 O.S.Systems
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <zephyr/sys/printk.h> #include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(updatehub, CONFIG_UPDATEHUB_LOG_LEVEL);
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/storage/flash_map.h> #include <zephyr/storage/flash_map.h>
#include <zephyr/sys/printk.h>
#include "updatehub_firmware.h" #include "updatehub_firmware.h"
bool updatehub_get_firmware_version(char *version, int version_len) bool updatehub_get_firmware_version(const uint32_t partition_id,
char *version, int version_len)
{ {
struct mcuboot_img_header header; struct mcuboot_img_header header;
if (boot_read_bank_header(FIXED_PARTITION_ID(slot0_partition), &header, if (boot_read_bank_header(partition_id, &header,
version_len) != 0) { sizeof(struct mcuboot_img_header)) != 0) {
LOG_DBG("Error when executing boot_read_bank_header function");
return false;
}
if (header.mcuboot_version != 1) {
LOG_DBG("MCUboot header version not supported!");
return false; return false;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018 O.S.Systems * Copyright (c) 2018-2023 O.S.Systems
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -7,10 +7,10 @@
#ifndef __UPDATEHUB_FIRMWARE_H__ #ifndef __UPDATEHUB_FIRMWARE_H__
#define __UPDATEHUB_FIRMWARE_H__ #define __UPDATEHUB_FIRMWARE_H__
#include <zephyr/drivers/flash.h> /* 255.255.65535\0 */
#include <zephyr/dfu/mcuboot.h> #define FIRMWARE_IMG_VER_STRLEN_MAX 14
#include <zephyr/dfu/flash_img.h>
bool updatehub_get_firmware_version(char *version, int version_len); bool updatehub_get_firmware_version(const uint32_t partition_id,
char *version, int version_len);
#endif /* __UPDATEHUB_FIRMWARE_H__ */ #endif /* __UPDATEHUB_FIRMWARE_H__ */