2018-04-23 22:50:01 +08:00
|
|
|
/*
|
2023-01-02 19:00:21 +08:00
|
|
|
* Copyright (c) 2018-2023 O.S.Systems
|
2018-04-23 22:50:01 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2023-01-02 19:00:21 +08:00
|
|
|
#include <zephyr/logging/log.h>
|
|
|
|
LOG_MODULE_DECLARE(updatehub, CONFIG_UPDATEHUB_LOG_LEVEL);
|
|
|
|
|
|
|
|
#include <zephyr/dfu/mcuboot.h>
|
2022-05-06 17:12:04 +08:00
|
|
|
#include <zephyr/storage/flash_map.h>
|
2023-01-02 19:00:21 +08:00
|
|
|
#include <zephyr/sys/printk.h>
|
2020-05-15 09:03:39 +08:00
|
|
|
|
2018-04-23 22:50:01 +08:00
|
|
|
#include "updatehub_firmware.h"
|
|
|
|
|
2023-01-02 19:00:21 +08:00
|
|
|
bool updatehub_get_firmware_version(const uint32_t partition_id,
|
|
|
|
char *version, int version_len)
|
2018-04-23 22:50:01 +08:00
|
|
|
{
|
|
|
|
struct mcuboot_img_header header;
|
|
|
|
|
2023-01-02 19:00:21 +08:00
|
|
|
if (boot_read_bank_header(partition_id, &header,
|
|
|
|
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!");
|
2018-04-23 22:50:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintk(version, version_len, "%d.%d.%d",
|
|
|
|
header.h.v1.sem_ver.major,
|
|
|
|
header.h.v1.sem_ver.minor,
|
|
|
|
header.h.v1.sem_ver.revision);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|