小程序
传感搜
传感圈

LwM2M: Remote Firmware Updates for IoT Devices Demystified

2023-06-09 05:12:42
关注

Illustration: © IoT For All

As more and more resource-constrained IoT devices are being deployed, firmware updates over the air (FOTA) are becoming increasingly important. As physical access is often expensive, or even impossible to realize when operating large deployments in remote, hard-to-reach locations, FOTA provides a way to fix bugs, patch security vulnerabilities, or add functionality throughout the lifespan of a connected device. Lightweight M2M (LwM2M) defines the process for remote firmware updates in detail. When following the standardized guidelines provided by the protocol, updating the firmware of resource-constrained devices remotely can be accomplished effortlessly, regardless of the device or platform used.

“As more and more resource-constrained IoT devices are being deployed, firmware updates over the air (FOTA) are becoming increasingly important.“

Updating Firmware with LwM2M

Every platform or device vendor can develop a custom FOTA mechanism, also known as FUOTA (Firmware Update OTA) or DFU (Device Firmware Upgrade). As there is no globally unified method to update device firmware, many different implementations can be found on the market.

Embedded developers can simply get one of the available libraries from their specific hardware vendor or cloud service provider to manage the update process. However, these implementations are specific to the vendor or platform and cannot be easily ported to other systems. Adopting a new platform usually means redesigning the FOTA process from scratch.

The problem of vendor compatibility can be resolved by adopting the LwM2M standard, which is hardware agnostic and can be implemented on any hardware platform. The standard provides clear guidelines on how devices should report their data, how remote configuration can be performed using server commands, and how firmware updates can be executed, regardless of the device manufacturer, firmware version, or hardware platform used.

Firmware Update Process

Generally speaking, the LwM2M firmware update process consists of four steps:

  1. The IoT device (referred to as the LwM2M Client) is triggered to initiate the firmware update process.

  2. The LwM2M Client downloads the firmware and reports to the LwM2M Server when the download is finished.

  3. The LwM2M Client performs the firmware update after validating the integrity and authenticity of the new firmware which is done through a process called secure boot.

  4. The Client attempts to run the new firmware and reports the status to the Server. If succeeded, the device starts running the new firmware, if an error is encountered the device performs a rollback to the earlier firmware version.

This procedure is defined in detail in the LwM2M specifications (see LwM2M specifications). To add firmware update capabilities to a device, the Firmware Update Object /5 needs to be implemented containing all essential functionalities for conducting the update and reporting the status. Several LwM2M Clients natively support this Firmware Update Object.

Updating a device’s firmware

Downloading New Firmware

Timing is critical when it comes to firmware updates. If the radio signal quality is poor, transferring data can take a lot of time due to low throughput caused by lost data packets that need to get retransmitted. Since the device’s radio module must be in the connected state for a long time, downloading the file in such circumstances results in a faster battery drain.

The LwM2M standard defines two methods to perform a firmware update, allowing either the Server or the Client to decide on the best moment to initiate the firmware download process. The two methods are PULL and PUSH:

PULL

With the p0ull method, a device receives the location of the file that is to be downloaded and pulls the file from it. In the PULL scenario, the LwM2M Server provides the device with the address of the server containing the firmware file known as the package URI. The device subsequently downloads the firmware from the so-called firmware repository at the earliest available opportunity.

PUSH

An LwM2M Server pushes the firmware file to the device. In the PUSH scenario, the LwM2M Server determines the moment to initiate the firmware download, ideally based on the connectivity conditions. The device must have access to information such as Radio Signal Strength and Link Quality to support such server-side decision-making these resources are available in the LwM2M Connectivity Monitoring Object /4.

Pull vs. push

Firmware Update Object

The FOTA process is defined in the Firmware Update Object /5. This Object defines the update process using four states(defined by Resource/5/*/3), as well as multiple update results(defined by Resource/5/*/5) representing the most common outcomes of the firmware update process.

Firmware update

Firmware Update Object States

State 0: Idle

Before downloading and after successfully updating the firmware, the device reports its state as idle.

State 1: Downloading

The new firmware is on the way from the firmware repository to the Client.

Possible Update Results Errors:

URI resolution failed due to:
Unsupported package type (result 6)
Invalid URI (result 7)
Unsupported protocol (result 9)

Download failed due to:
Insufficient flash memory (result 2)
Insufficient RAM (result 3)
Connection loss (result 4)
Integrity check failed (result 5)

State 2: Downloaded

The firmware download is completed and all packets are received successfully.

State 3: Updating

When the update resource is triggered, the LwM2M Client starts updating its firmware. If the update was performed successfully, the state changes back to Idle (state 0).

Possible Update Results:
Firmware update failed (result 8)
Integrity check failed (result 5)
Firmware updated successfully (result 1)

State 0: Idle

After successfully updating the firmware, the device reports its state as idle and its Update Result as Firmware Updated Successfully.

Firmware updated successfully

Essential Device Updates

Remote IoT device updates are essential for the long-term success of IoT applications. Software bugs and security vulnerabilities will be found when deploying devices in the field which should be operational for years. As physical access to devices is often impossible to realize, FOTA is required for each, if not all IoT deployments.

Updating firmware remotely poses some serious challenges. Devices are constrained in terms of (flash) memory, battery capacity, and available bandwidth, and often use unstable connections to the cloud. The LwM2M standard proposes a method to update the firmware of resource-constrained IoT devices. Through a structured approach with standardized states and error codes, developers can be assured that new firmware images can be safely sent to their fleet of devices in the field, regardless of the hardware vendor or cloud platform used.

Tweet

Share

Share

Email

  • Connectivity
  • Data Analytics
  • Hardware Components
  • Machine Learning
  • Network and Protocols

  • Connectivity
  • Data Analytics
  • Hardware Components
  • Machine Learning
  • Network and Protocols

参考译文
LwM2M:揭秘物联网设备的远程固件更新
插图:© IoT For All --> 随着越来越多资源受限的物联网设备投入使用,通过空中下载(FOTA)进行固件更新变得越来越重要。当在偏远、难以到达的区域部署大量设备时,由于物理访问成本高昂,甚至难以实现,FOTA 提供了一种方式,可以在设备的整个生命周期中修复错误、修补安全漏洞或添加新功能。轻量级 M2M(LwM2M)详细定义了远程固件更新的流程。遵循该协议提供的标准化指南,可以轻松地对资源受限的设备进行远程固件更新,无论使用何种设备或平台。“随着越来越多资源受限的物联网设备投入使用,通过空中下载(FOTA)进行固件更新变得越来越重要。” 通过 LwM2M 更新固件 每个平台或设备供应商都可以开发自定义的 FOTA 机制,也称为 FUOTA(固件空中更新)或 DFU(设备固件升级)。由于没有全球统一的设备固件更新方法,市场上的实现方式多种多样。嵌入式开发人员只需从特定的硬件供应商或云服务提供商获取现有的库之一,即可管理更新过程。然而,这些实现方式特定于供应商或平台,无法轻松移植到其他系统中。通过采用 LwM2M 标准可以解决供应商兼容性问题,该标准与硬件无关,可以在任何硬件平台上实现。该标准提供了明确的指导方针,说明设备应该如何报告数据、如何通过服务器命令执行远程配置,以及如何执行固件更新,无论设备制造商、固件版本或硬件平台如何。 固件更新过程 一般来说,LwM2M 固件更新过程包括四个步骤: 物联网设备(称为 LwM2M 客户端)被触发以启动固件更新过程。LwM2M 客户端下载固件,并在下载完成后向 LwM2M 服务器报告。LwM2M 客户端在验证新固件的完整性与真实性后(通过一个称为安全启动的流程),执行固件更新。客户端尝试运行新固件,并向服务器报告状态。如果成功,设备将开始运行新固件;如果遇到错误,则设备将回滚到之前的固件版本。这一流程在 LwM2M 规范中有详细定义(参见 LwM2M 规范)。 要在设备上添加固件更新功能,需要实现固件更新对象 /5,该对象包含执行更新和报告状态所需的所有关键功能。一些 LwM2M 客户端原生支持此固件更新对象。 更新设备固件 下载新固件 在进行固件更新时,时机至关重要。如果无线电信号质量差,由于数据包丢失需要重传,低吞吐量会导致传输数据花费大量时间。由于设备的无线电模块必须长时间保持连接状态,在这种情况下下载文件会导致电池消耗更快。LwM2M 标准定义了两种执行固件更新的方法,允许服务器或客户端决定启动固件下载过程的最佳时机。两种方法分别为 PULL 和 PUSH: PULL 在 PULL 方法中,设备接收需要下载的文件位置,并从该位置拉取文件。在 PULL 情形中,LwM2M 服务器为设备提供包含固件文件的服务器地址,称为包 URI。设备随后在最早可用的机会从所谓的固件存储库中下载固件。 PUSH LwM2M 服务器将固件文件推送到设备。在 PUSH 情形中,LwM2M 服务器决定启动固件下载的时机,理想情况下是基于连接状况。设备必须能够访问诸如无线电信号强度和链路质量等信息,以支持服务器端决策,这些资源可在 LwM2M 连接监控对象 /4 中获取。 Pull 与 push 固件更新对象 FOTA 流程在固件更新对象 /5 中定义。该对象通过四个状态(由资源 /5/*/3 定义)定义更新流程,以及多个更新结果(由资源 /5/*/5 定义),表示固件更新过程的常见结果。 固件更新 固件更新对象状态 状态 0:空闲 在下载前以及成功更新固件后,设备报告其状态为空闲。 状态 1:正在下载 新固件正在从固件存储库传输到客户端。可能出现的更新结果 错误:URI 解析失败,原因如下: 不支持的包类型(结果 6) 无效的 URI(结果 7) 不支持的协议(结果 9) 下载失败,原因如下: 闪存内存不足(结果 2) RAM 不足(结果 3) 连接中断(结果 4) 完整性检查失败(结果 5) 状态 2:已下载 固件下载完成,所有数据包已成功接收。 状态 3:正在更新 当更新资源被触发时,LwM2M 客户端开始更新其固件。如果更新成功,状态将返回到空闲(状态 0)。可能出现的更新结果: 固件更新失败(结果 8) 完整性检查失败(结果 5) 固件更新成功(结果 1) 状态 0:空闲 在成功更新固件后,设备报告其状态为空闲,其更新结果为固件更新成功。 固件更新成功 远程设备更新 远程物联网设备更新对于物联网应用的长期成功至关重要。当在实地部署设备时,软件错误和安全漏洞将被发现,而这些设备通常需要运行多年。由于对设备的物理访问通常难以实现,因此对于几乎所有物联网部署,FOTA 都是必不可少的。远程更新固件带来了一些严峻的挑战。设备在闪存内存、电池容量和可用带宽方面受到限制,且通常使用不稳定的连接连接到云端。LwM2M 标准提出了一种方法,用于更新资源受限的物联网设备的固件。通过结构化方法与标准化状态和错误代码,开发人员可以确保新固件镜像能够安全地发送到其部署在实地的设备,无论使用何种硬件供应商或云平台。TweetShareShareEmail 连接性 数据分析 硬件组件 机器学习 网络与协议 --> 连接性 数据分析 硬件组件 机器学习 网络与协议
您觉得本篇内容如何
评分

评论

您需要登录才可以回复|注册

提交评论

广告

iotforall

这家伙很懒,什么描述也没留下

关注

点击进入下一篇

灯杆智慧化 推动城市新发展

提取码
复制提取码
点击跳转至百度网盘