Azure / iot-hub-device-update

Device Update for IoT Hub agent
MIT License
52 stars 40 forks source link

RaspBery Pi ADU Issue #482

Closed djalpiza closed 11 months ago

djalpiza commented 1 year ago

Expected Behavior

Update OTA in RaspBerry Pi 3B+

Current Behavior

Extended result code 806355203

Steps to Reproduce

I am following the Tutorial: https://learn.microsoft.com/en-us/azure/iot-hub-device-update/device-update-raspberry-pi

Device Information

RaspBerry Pi 3B+

Logs

N/A, this is part of my inquiry, is there any error logs that can be reviewed with further information?

Additional Information

Please provide any additional information that may be helpful in understanding the issue.

djalpiza commented 1 year ago

Log information:

2023-05-25T12:58:02.3209Z 224[300] [I] Action 'Download' complete. Result: 0 (failed), 806355203 (0x30100103) [ADUC_Workflow_WorkCompletionCallback] 2023-05-25T12:58:02.3209Z 224[300] [I] WorkCompletionCallback: Download failed. Going to state Failed [ADUC_Workflow_WorkCompletionCallback] 2023-05-25T12:58:02.3209Z 224[300] [I] Setting UpdateState to Failed [ADUC_Workflow_SetUpdateStateHelper] 2023-05-25T12:58:02.3212Z 224[300] [D] Queueing message (t:0, c:0x75203a18, m:{"deviceUpdate":{"__t":"c","agent":{"lastInstallResult":{"stepResults":{"step_0":{"resultCode":0,"extendedResultCode":0,"resultDetails":null}},"resultCode":0,"extendedResultCode":806355203,"resultDetails":""},"state":255,"workflow":{"action":3,"id":"c09a2baf-e32d-4956-aac8-da0ceaec816a","retryTimestamp":"2023-05-25T12:57:57.6403938Z"}}}}) [ADUC_D2C_Message_SendAsync] 2023-05-25T12:58:02.3212Z 224[300] [I] Workflow is Complete. [ADUC_Workflow_AutoTransitionWorkflow] 2023-05-25T12:58:02.7221Z 224[224] [D] context:0x597690 [DefaultIoTHubSendReportedStateCompletedCallback] 2023-05-25T12:58:02.7221Z 224[224] [D] D2C message processed successfully (t:0, r:0, content:0xa177a0 ) [DefaultIoTHubSendReportedStateCompletedCallback] 2023-05-25T12:58:02.7221Z 224[224] [D] Send message completed (status:3) [OnUpdateResultD2CMessageCompleted] 2023-05-25T12:58:02.7224Z 224[224] [D] context:0x5976ec [DefaultIoTHubSendReportedStateCompletedCallback] 2023-05-25T12:58:02.7224Z 224[224] [D] D2C message processed successfully (t:1, r:0, content:0x9ff068 ) [DefaultIoTHubSendReportedStateCompletedCallback] 2023-05-25T12:58:02.7224Z 224[224] [D] Send message completed (status:3) [OnUpdateResultD2CMessageCompleted] 2023-05-25T12:58:02.7225Z 224[224] [D] Sending D2C message (t:0, retries:0). [ProcessMessage] 2023-05-25T12:58:02.7225Z 224[224] [D] Sending D2C message:

eshashah-msft commented 1 year ago

Hi @djalpiza, this doc covers how to troubleshoot using the result and error codes : https://github.com/Azure/iot-hub-device-update/blob/main/docs/agent-reference/device-update-agent-extended-result-codes.md

The error code: 806355203 is indicating there was incorrect number of swu file as part of update. Looks like the download failed. Can you share the DO logs as well?

djalpiza commented 1 year ago

Thanks for the answer @eshashah-msft.

I have a question regarding the OS that should be running in the Raspberry Pi in order to use ADU service. In the tutorial it is provided a base image that rus Yocto OS, however this image lacks many tools required for other applications. So my question is if there is any way to connect my Raspberry Pi to Azure ADU while using Raspbian as OS?

I am trying to follow the steps explained in this guide: https://learn.microsoft.com/en-us/azure/iot-hub-device-update/device-update-agent-provisioning Specifically under the section: On Iot Linux devices without IoT Edge installed. However when it comes to the step: 3. "Finally install the Device Update agent. We provide sample images in Assets here, the swUpdate file is the base image that you can flash onto a Raspberry Pi B3+ board, and the .gz file is the update you would import through Device Update for IoT Hub. See example of how to flash the image to your IoT Hub device."

I am not able to understand what command is supposed to be run there inorder to enable the installation of the Device Update agent. I also tried running: "sudo apt-get install deviceupdate-agent". However I get this error message: root@raspberrypi:~# sudo apt-get install deviceupdate-agent Reading package lists... Done Building dependency tree... Done Reading state information... Done E: Unable to locate package deviceupdate-agent

jw-msft commented 1 year ago

Raspian os and debian 11 on RPi is work scheduled for future release.

However, building custom embedded os using yocto (or maybe buildroot) is very flexibile and can reduce the size of your OS images to minimum needed such as the < 300MB image in the demo.

For building the ADU Yocto custom embedded os, see: https://github.com/Azure/iot-hub-device-update-yocto

One can add a layer with additional recipes to get the tools/apps you need in the image: https://wiki.yoctoproject.org/wiki/Building_your_own_recipes_from_first_principles#Using_a_new_layer_for_recipes

Check out and try: https://wiki.yoctoproject.org/wiki/Building_your_own_recipes_from_first_principles#Yocto_Project_Quick_Build Here is repo to build the image: https://github.com/Azure/iot-hub-device-update-yocto

The ADU Agent recipes are here: https://github.com/Azure/meta-azure-device-update

By doing this, the advantage is one can get deterministic A/B image updating and a reproducible, and minimal size build of the image.

LaudixGit commented 1 year ago

Done E: Unable to locate package deviceupdate-agent

Raspian os and debian 11 on RPi is work scheduled for future release.

I have the same needs. And I observe the same results. While RaspiOS is not suitable for a production system (neither is the Raspberry HW IMO) it is the reference OS used in nearly all tutorials. Use of RaspiOS reduces the variables/challenges for initial testing.

The ADU Yocto build may be a fantastic solution for production, but I am unable, as a newbie, able to leap from the known functionality of RaspiOS to the advanced builds of Yocto.

LaudixGit commented 1 year ago

@jw-msft Why doesn't ADU support MSFT's Tier1 systems?

It sure looks like all the prerequisites are met. (note: the green oval indicates the success of command "sudo iotedge check --verbose") image

jw-msft commented 1 year ago

Original Issue

Error code 806355203 (0x30100103)

Going back to the original issue of @djalpiza for the 806355203 error code, the swupdate v1 handler requires exactly one update payload (the .swu file) and swupdate v2 handler requires at least one (the first payload must be the script that will run) as can be seen here:

https://github.com/search?q=repo%3AAzure%2Fiot-hub-device-update%20ADUC_ERC_SWUPDATE_HANDLER_DOWNLOAD_FAILURE_WRONG_FILECOUNT&type=code

swupdate handler "files" requirements

Notice that the EDS-ADUClient.yocto-update.1.0.2.2.importmanifest included in Tutorial_RaspberryPi.zip from the learn.microsoft.com Tutorial: Device Update for Azure IoT Hub using the Raspberry Pi 3 B+ reference image has 2 files specified in "files" section:

and the corresponding "scriptFileName" and "swuFileName" under instructions -> steps -> handlerProperties:

"handlerProperties": {
  "scriptFileName":  "example-a-b-update.sh",
  ...
  ...
  "swuFileName":  "adu-update-image-raspberrypi3-1.0.2-2.swu"
}

swupdate v2 handler expects the 1st update payload to be the script that would in turn invoke swupdate utility with desired set of cmd-line arguments.

Additional Questions about RPi OS / Deb 11

@LaudixGit and @djalpiza, As for the questions about using Raspberry Pi OS or Debian 11 on arm32 RPi without using Yocto, currently one could build agent on the target device (with some tweaking of the build scripts) and ensure the AducIotAgent object dependencies are met.

To find obj deps: ldd /usr/bin/AducIotAgent or more securely (some versions of ldd run the executable with linux loader) use: objdump -p /usr/bin/AducIotAgent | grep NEEDED

Deb11 partial support work already completed

Commits https://github.com/Azure/iot-hub-device-update/commit/150076b028f06d8374399ffd06033938fac39779 and https://github.com/Azure/iot-hub-device-update/commit/e283cf1a34dded4b7f59e66ad4b9b64679b7073d in the develop branch to facilitate building core agent on deb11.

In develop branch, core agent no longer has a dep on libdeliveryoptimization.so (it's a dep only for libdeliveryoptimization_content_downloader.so now), so that makes building it slightly easier.

Near future work for RPiOS / Deb11 / other targets

We are working on cross compile config/toolchain for RPi targets (and others) that may include build assets for these (tentatively by October timeframe). The same cross-compile support with RPi toolchains would need to be added to DO content downloader if using DO for downloading, which is highly recommended for production.

jw-msft commented 1 year ago

See this issue: https://github.com/Azure/iot-hub-device-update/issues/484

I was able to do a docker build for Debian 11 arm64 using the packer from commit: https://github.com/Azure/iot-hub-device-update/commit/f9c8828320f57a9f9db90d72ddd5a6f15cd6909f

and built DO agent dep via docker for arm64 Deb11 as well with Dockerfile from DO commit https://github.com/microsoft/do-client/commit/6459cc59426d38990ed75a6f103460ae148a95db and found it all worked on an RPi4 flashed with RPi OS Lite 64-bit.

Publishing the Debian 11 .deb pkgs out to packages.microsoft.com for both DO and DU agents would come with a future release.

I'll see if I can try it out for arm32 in the near future.

jw-msft commented 1 year ago

it was taking way too long using arm32hf packer due to the current state of develop that is building openssl. Will try again once moving to openssl 3.x compatible crypto EVP API; otherwise, this would need proper cross-compilation or a plain Dockerfile to run to resolve in a tractable way.

jw-msft commented 11 months ago

Closing stale issue.

jw-msft commented 11 months ago

@jw-msft Why doesn't ADU support MSFT's Tier1 systems?

It sure looks like all the prerequisites are met. (note: the green oval indicates the success of command "sudo iotedge check --verbose") image

Linking to https://github.com/Azure/iot-hub-device-update/issues/543 for coverage of this