Skip to content
Permalink
Browse files

lib: updatehub: Add UpdateHub.io support

UpdateHub is an enterprise-grade solution which makes simple to
remotely update all your embedded devices in the field. It
handles all aspects related to sending Firmware Over-the-Air(FOTA)
updates with maximum security and efficiency, while you focus in
adding value to your product.

Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
  • Loading branch information...
chtavares592 authored and carlescufi committed Apr 23, 2018
1 parent 5a2c6d3 commit 297ac3765f6c8ab7ee3cf7524c7064b6c8e30fdf
@@ -254,6 +254,7 @@
/include/sys_io.h @andrewboie @andyross
/include/toolchain.h @andrewboie @andyross @nashif
/include/toolchain/ @andrewboie @andyross
/include/updatehub.h @chtavares592 @otavio
/include/zephyr.h @andrewboie @andyross
/kernel/ @andrewboie @andyross
/lib/gui/ @vanwinkeljan
@@ -270,6 +271,8 @@
/samples/basic/minimal/ @carlescufi
/samples/basic/servo_motor/*microbit* @jhe
/samples/bluetooth/ @joerchan @jhedberg @Vudentz
/lib/updatehub/ @chtavares592 @otavio
/samples/bluetooth/ @sjanc @jhedberg @Vudentz
/samples/boards/intel_s1000_crb/ @sathishkuttan @dcpleung @nashif
/samples/display/ @vanwinkeljan
/samples/drivers/CAN/ @alexanderwachter
@@ -282,6 +285,8 @@
/samples/net/sockets/coap_*/ @rveerama1
/samples/net/sockets/ @jukkar @tbursztyka @pfalcon
/samples/sensor/ @MaureenHelm
/samples/net/updatehub/ @chtavares592 @otavio
/samples/sensor/ @bogdan-davidoaia
/samples/subsys/logging/ @nordic-krch @jarz-nordic
/samples/subsys/shell/ @jarz-nordic @nordic-krch
/samples/subsys/usb/ @jfischer-phytec-iot @finikorg
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2018 O.S.Systems
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @brief UpdateHub Firmware Over-the-Air for Zephyr Project.
* @defgroup updatehub UpdateHub Firmware Over-the-Air
* @ingroup lib
* @{
*/

#ifndef _UPDATEHUB_H_
#define _UPDATEHUB_H_

/**
* @brief Responses messages from UpdateHub.
*
* @details These messages are used to inform the server and the
* user about the process status of the UpdateHub and also
* used to standardize the errors that may occur.
*
*/
enum updatehub_response {
UPDATEHUB_NETWORKING_ERROR = 0,
UPDATEHUB_INCOMPATIBLE_HARDWARE,
UPDATEHUB_UNCONFIRMED_IMAGE,
UPDATEHUB_METADATA_ERROR,
UPDATEHUB_DOWNLOAD_ERROR,
UPDATEHUB_INSTALL_ERROR,
UPDATEHUB_FLASH_INIT_ERROR,
UPDATEHUB_OK,
UPDATEHUB_HAS_UPDATE,
UPDATEHUB_NO_UPDATE,
};

/**
* @brief Runs UpdateHub probe and UpdateHub update automatically.
*
* @details The updatehub_autohandler handles the whole process
* in pre-determined time intervals.
*/
void updatehub_autohandler(void);

/**
* @brief The UpdateHub probe verify if there is some update to be performed.
*
* @return UPDATEHUB_HAS_UPDATE has an update available.
* @return UPDATEHUB_NO_UPDATE no update available.
* @return UPDATEHUB_NETWORKING_ERROR fail to connect to the UpdateHub server.
* @return UPDATEHUB_INCOMPATIBLE_HARDWARE if Incompatible hardware.
* @return UPDATEHUB_METADATA_ERROR fail to parse or to encode the metadata.
*/
enum updatehub_response updatehub_probe(void);

/**
* @brief Apply the update package.
*
* @details Must be used after the UpdateHub probe, if you have updates to
* be made, will perform the installation of the new image and the hardware
* will rebooting.
*
* @return Return UPDATEHUB_OK if success
* @return UPDATEHUB_NETWORKING_ERROR if fail to connect to the server.
* @return UPDATEHUB_DOWNLOAD_ERROR fail while downloading the update package.
* @return UPDATEHUB_INSTALL_ERROR fail while installing the update package.
* @return UPDATEHUB_FLASH_INIT_ERROR fail to initilialize the flash.
*/
enum updatehub_response updatehub_update(void);

/**
* @}
*/

#endif /* _UPDATEHUB_H_ */
@@ -8,3 +8,4 @@ add_subdirectory_ifdef(CONFIG_CMSIS_RTOS_V1 cmsis_rtos_v1)
add_subdirectory_ifdef(CONFIG_CMSIS_RTOS_V2 cmsis_rtos_v2)
add_subdirectory(gui)
add_subdirectory(os)
add_subdirectory_ifdef(CONFIG_UPDATEHUB updatehub)
@@ -18,4 +18,6 @@ source "lib/os/Kconfig"

source "lib/posix/Kconfig"

source "lib/updatehub/Kconfig"

endmenu
@@ -0,0 +1,12 @@
#
# Copyright (c) 2018 O.S.Systems
#
# SPDX -License-Identifier: Apache-2.0
#

zephyr_library()

zephyr_library_sources_ifdef(CONFIG_UPDATEHUB updatehub.c)
zephyr_library_sources_ifdef(CONFIG_UPDATEHUB updatehub_device.c)
zephyr_library_sources_ifdef(CONFIG_UPDATEHUB updatehub_firmware.c)
zephyr_library_sources_ifdef(CONFIG_UPDATEHUB_SHELL shell.c)
@@ -0,0 +1,85 @@
#
# Copyright (c) 2018 O.S.Systems
#
# SPDX -License-Identifier: Apache-2.0
#

menuconfig UPDATEHUB
bool"UpdateHub Firmware Over-the-Air support"
select FLASH
select REBOOT
select IMG_MANAGER
select BOOTLOADER_MCUBOOT
select MPU_ALLOW_FLASH_WRITE
select NETWORKING
select NEWLIB_LIBC
select NET_UDP
select NET_SOCKETS
select NET_SOCKETS_POSIX_NAMES
select COAP
select NET_CONFIG_NEED_IPV4
select NET_CONFIG_SETTINGS
select DNS_RESOLVER
select JSON_LIBRARY
select TINYCRYPT
select TINYCRYPT_SHA256
select HWINFO
help
UpdateHub is an enterprise-grade solution which makes simple to
remotely update all your embbeded devices in the field. It
handles all aspects related to sending Firmware Over-the-Air
(FOTA) updates with maximum security and efficiency, while you
focus in adding value to your product.

config UPDATEHUB_POLL_INTERVAL
int "Time to poll interval (in minutes)"
default 1440
range 0 43200
depends on UPDATEHUB
help
Set the interval that the UpdateHub update server will be polled.
This time interval is zero and 43200 minutes(30 days).

config UPDATEHUB_PRODUCT_UID
string "Product Unique Identifier (UID)"
depends on UPDATEHUB
help
The product unique identifier is used when communicating
with the UpdateHub server.

config UPDATEHUB_SUPPORTED_HARDWARE_MAX
int "Max number of supported hardware"
default 1
range 1 100
depends on UPDATEHUB
help
Configure the max number of supported hardware
by the same image.

config UPDATEHUB_CE
bool "Use UpdateHub Community Edition Sever"
depends on UPDATEHUB
help
Allow the use of UpdateHub Community
Server (updatehub-ce) as alternative to the
updatehub.io enterprise server.

config UPDATEHUB_SERVER
string "User address for the updatehub-ce-server"
depends on UPDATEHUB_CE
help
This configuration is default, if need to use
other address, must be set on the UpdateHub shell

config UPDATEHUB_SHELL
bool "Enable UpdateHub shell utilities"
depends on UPDATEHUB
depends on SHELL
select KERNEL_SHELL
help
Activate shell module that provides UpdateHub commands like

module = UPDATEHUB
module-str = Log level for UpdateHub
module-help = Enables logging for UpdateHub code.
source "subsys/logging/Kconfig.template.log_config"
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2018 O.S.Systems
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <shell/shell.h>
#include <flash.h>
#include <dfu/mcuboot.h>
#include <dfu/flash_img.h>
#include <updatehub.h>
#include "updatehub_firmware.h"
#include "updatehub_device.h"

#if defined(CONFIG_UPDATEHUB_CE_SERVER)
#define UPDATEHUB_SERVER CONFIG_UPDATEHUB_SERVER
#else
#define UPDATEHUB_SERVER "coap.updatehub.io"
#endif

static int cmd_run(const struct shell *shell, size_t argc,
char **argv)
{
int ret = -1;

shell_fprintf(shell, SHELL_INFO, "Starting UpdateHub run...\n");

switch (updatehub_probe()) {
case UPDATEHUB_HAS_UPDATE:
switch (updatehub_update()) {
case UPDATEHUB_OK:
ret = 0;
break;
default:
shell_fprintf(shell, SHELL_ERROR, "Error installing update.\n");
break;
}
break;

case UPDATEHUB_NO_UPDATE:
shell_fprintf(shell, SHELL_INFO, "No update found\n");
ret = 0;
break;

default:
shell_fprintf(shell, SHELL_ERROR, "Invalid response\n");
break;
}

return ret;
}

static int cmd_info(const struct shell *shell, size_t argc, char **argv)
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);

char *device_id = k_malloc(DEVICE_ID_MAX_SIZE);
char *firmware_version = k_malloc(BOOT_IMG_VER_STRLEN_MAX);

updatehub_get_firmware_version(firmware_version, BOOT_IMG_VER_STRLEN_MAX);
updatehub_get_device_identity(device_id, DEVICE_ID_MAX_SIZE);

shell_fprintf(shell, SHELL_NORMAL, "Unique device id: %s\n",
device_id);
shell_fprintf(shell, SHELL_NORMAL, "Firmware Version: %s\n",
firmware_version);
shell_fprintf(shell, SHELL_NORMAL, "Product uid: %s\n",
CONFIG_UPDATEHUB_PRODUCT_UID);
shell_fprintf(shell, SHELL_NORMAL, "UpdateHub Server: %s\n",
UPDATEHUB_SERVER);

k_free(device_id);
k_free(firmware_version);
return 0;
}

SHELL_STATIC_SUBCMD_SET_CREATE(sub_updatehub, SHELL_CMD(info, NULL, "Dump UpdateHub information",
cmd_info),
SHELL_CMD(run, NULL, "Trigger an UpdateHub update run", cmd_run),
SHELL_SUBCMD_SET_END);

SHELL_CMD_REGISTER(updatehub, &sub_updatehub, "UpdateHub commands", NULL);

0 comments on commit 297ac37

Please sign in to comment.
You can’t perform that action at this time.