Ex3. ② OTA FW UPDATE
( 태그 : AWS_IoT_FreeRTOS, AWS_IoT )
1. OTA Job 생성
- AWS IoT 콘솔에서 Manage의 Jobs를 선택 한 후 Create a job을 클릭 합니다.
- Create OTA update job을 선택합니다.
- Update할 thing을 선택한 후 다음 단계를 진행합니다.
- Update protocol은 MQTT를 선택합니다.
- FW Image sign 방법을 Sign a new firemware image for me 로 선택합니다.
- Code signing profile를 신규로 생성해야 합니다. Create를 선택합니다.
- Signing Profile name을 입력 합니다.
stm32_sign_profile
이라고 입력할 수 있습니다. - Code signing certificate에서 생성해 놓은 인증서를 사용합니다. import를 클릭 합니다.
- Signing Certficate 생성 실습에서 생성한 Signing Certificate을 등록하는 단계입니다.
- Certificate은 ecdsasigner.crt 파일을 선택합니다.
- Certificate private key는 ecdsasigner.key 파일을 선택합니다.
- 파일 선택 후 import 버튼을 클릭 합니다
- Code signing pathname에
/device/updates
를 입력합니다. Device hardware platform의 Select를 클릭합니다.
- Device hardware platform은 Windows Simulator를 선택 하고 Create 버튼을 눌러 생성을 완료 합니다.
- Profile 생성을 완료한 후 FW Image 파일을 설정합니다.
- S3 bucket을 선택한 후 Upload한 FW Image (B-L4S5I-IOT01_aws_demos.sfb)를 선택합니다.
- Pathname of firmware image on device는
/device/updates
로 입력합니다. - OTA update job을 위한 IAM role을 선택합니다. 이전 단계에서 생성한 OTA 서비스를 위한 role을 검색하여 선택하고 다음 단계를 진행합니다.
- ID 필드에 job 이름을 입력합니다.
stm-sensor-node-ota-job
와 같이 입력할 수 있습니다. 다른 항목은 기본값을 그대로 사용합니다. Create 버튼을 누르고 생성을 마무리 합니다.
- Job 생성이 시작되면 처음 화면으로 돌아갑니다. Job 생성이 완료되면 Job List가 표시됩니다.
- Manage 아래 Things로 이동하여 Thing을 선택 후 생성한 Job의 상태를 확인할 수 있습니다.
- Manage아래의 Jobs 항목을 선택하면 Job List가 표시됩니다.
- Job을 Click하여 상세 정보를 확인할 수 있습니다.
2. OTA Job 실행
- Job이 생성되면 디바이스 에서는 OTA Agent가 FW Image를 S3 bucket에서 download 합니다.
1380 1350066 [OTA Agent Task] [prvParseJobDoc] Size of OTA_FileContext_t [64]
1381 1350074 [OTA Agent Task] [prvParseJSONbyModel] Extracted parameter [ jobId: AFR_OTA-stm-sensor-ota2 ]
1382 1350084 [OTA Agent Task] [prvParseJSONbyModel] Extracted parameter [ protocols: ["MQTT"] ]
1383 1350093 [OTA Agent Task] [prvParseJSONbyModel] Extracted parameter [ streamname: AFR_OTA-86ff54b2-8038-4367-b27c-c20a3d848e8c ]
1384 1350105 [OTA Agent Task] [prvParseJSONbyModel] Extracted parameter [ filepath: /device/updates ]
1385 1350114 [OTA Agent Task] [prvParseJSONbyModel] Extracted parameter [ filesize: 335488 ]
1386 1350123 [OTA Agent Task] [prvParseJSONbyModel] Extracted parameter [ fileid: 0 ]
1387 1350130 [OTA Agent Task] [prvParseJSONbyModel] Extracted parameter [ certfile: /device/updates ]
1388 1350140 [OTA Agent Task] [prvParseJSONbyModel] Extracted parameter [ sig-sha256-ecdsa: MEUCIQCk9co8mURHJLf0EzrnbL2hr+pL... ]
1389 1350152 [OTA Agent Task] [prvParseJobDoc] Job was accepted. Attempting to start transfer.
1390 1350685 [iot_thread] State: WaitingForJob Received: 2 Queued: 0 Processed: 0 Dropped: 0
1391 1351694 [iot_thread] State: WaitingForJob Received: 2 Queued: 0 Processed: 0 Dropped: 0
1392 1352703 [iot_thread] State: WaitingForJob Received: 2 Queued: 0 Processed: 0 Dropped: 0
1393 1353712 [iot_thread] State: WaitingForJob Received: 2 Queued: 0 Processed: 0 Dropped: 0
1394 1354345 [OTA Agent Task] [prvPAL_CreateFileForRx] Receive file created at 0x20076b20.
1395 1354353 [OTA Agent Task] [prvSetDataInterface] Data interface is set to MQTT.
1396 1354361 [OTA Agent Task] [prvProcessJobHandler] Setting OTA data inerface.
1397 1354368 [OTA Agent Task] [prvOTAAgentTask] Called handler. Current State [WaitingForJob] Event [ReceivedJobDocument] New state [CreatingFile]
1398 1354383 [OTA Agent Task] [INFO ][MQTT][1354383] (MQTT connection 0x200451f0) SUBSCRIBE operation scheduled.
1399 1354393 [OTA Agent Task] [INFO ][MQTT][1354393] (MQTT connection 0x200451f0, SUBSCRIBE operation 0x20045e08) Waiting for operation completion.
...
3242 1395099 [OTA Agent Task] W: Received offset=0004ec00 size=1024
3243 1395124 [OTA Agent Task] [prvIngestDataBlock] Remaining: 2
3244 1395131 [OTA Agent Task] [prvOTAAgentTask] Called handler. Current State [WaitingForFileBlock] Event [ReceivedFileBlock] New state [WaitingForFileBlock]
3245 1395157 [OTA Agent Task] [prvIngestDataBlock] Received file block 312, size 1024
3246 1395166 [OTA Agent Task] W: Received offset=0004e000 size=1024
3247 1395175 [iot_thread] State: WaitingForFileBlock Received: 485 Queued: 0 Processed: 0 Dropped: 0
3248 1395200 [OTA Agent Task] [prvIngestDataBlock] Remaining: 1
3249 1395207 [OTA Agent Task] [prvOTAAgentTask] Called handler. Current State [WaitingForFileBlock] Event [ReceivedFileBlock] New state [WaitingForFileBlock]
3250 1395233 [OTA Agent Task] [prvIngestDataBlock] Received file block 289, size 1024
3251 1395242 [OTA Agent Task] W: Received offset=00048400 size=1024
3252 1395265 [OTA Agent Task] [prvIngestDataBlock] Received final expected block of file.
3253 1395275 [OTA Agent Task] [prvStopRequestTimer] Stopping request timer.
3254 1395282 [OTA Agent Task] [prvPAL_CheckFileSignature] Started sig-sha256-ecdsa signature verification, file: /device/updates
3255 1395472 [iot_thread] Error: No OTA data buffers available.
3256 1395524 [iot_thread] Error: No OTA data buffers available.
3257 1395576 [iot_thread] Error: No OTA data buffers available.
3258 1395628 [iot_thread] Error: No OTA data buffers available.
3259 1395680 [iot_thread] Error: No OTA data buffers available.
3260 1395732 [iot_thread] Error: No OTA data buffers available.
3261 1395784 [iot_thread] Error: No OTA data buffers available.
3262 1395836 [iot_thread] Error: No OTA data buffers available.
3263 1395888 [iot_thread] Error: No OTA data buffers available.
3264 1395940 [iot_thread] Error: No OTA data buffers available.
3265 1395992 [iot_thread] Error: No OTA data buffers available.
3266 1396044 [iot_thread] Error: No OTA data buffers available.
3267 1396096 [iot_thread] Error: No OTA data buffers available.
3268 1396148 [iot_thread] Error: No OTA data buffers available.
3269 1396184 [iot_thread] State: WaitingForFileBlock Received: 489 Queued: 0 Processed: 0 Dropped: 14
3270 1396211 [iot_thread] Error: No OTA data buffers available.
3271 1396254 [iot_thread] Error: No OTA data buffers available.
3272 1396306 [iot_thread] Error: No OTA data buffers available.
3273 1397193 [iot_thread] State: WaitingForFileBlock Received: 489 Queued: 0 Processed: 0 Dropped: 17
3274 1398202 [iot_thread] State: WaitingForFileBlock Received: 489 Queued: 0 Processed: 0 Dropped: 17
- Download가 완료되면 코드 Signing을 verification 한 후 valid 하면 device를 제 부팅 시킵니다. 재 부팅시 다운로드된 Image가 Slot #0에 있는 것을 확인하게 됩니다.
3275 1399063 [OTA Agent Task] [prvPAL_CloseFile] sig-sha256-ecdsa signature verification passed.
3276 1399071 [OTA Agent Task] [prvIngestDataBlock] File receive complete and signature is valid.
3277 1399080 [OTA Agent Task] [prvStopRequestTimer] Stopping request timer.
3278 1399087 [OTA Agent Task] [prvUpdateJobStatus_Mqtt] Msg: {"status":"IN_PROGRESS","statusDetails":{"self_test":"ready","updatedBy":"0x90002"}}
3279 1399102 [OTA Agent Task] [INFO ][MQTT][1399102] (MQTT connection 0x200451f0) MQTT PUBLISH operation queued.
3280 1399112 [OTA Agent Task] [INFO ][MQTT][1399112] (MQTT connection 0x200451f0, PUBLISH operation 0x20045e40) Waiting for operation completion.
3281 1399185 [OTA Agent Task] [INFO ][MQTT][1399185] (MQTT connection 0x200451f0, PUBLISH operation 0x20045e40) Wait complete with result SUCCESS.
3282 1399198 [OTA Agent Task] [prvUpdateJobStatus_Mqtt] 'IN_PROGRESS' to $aws/things/Iot-stm-sensor-nodeA/jobs/AFR_OTA-stm-sensor-ota2/update
3283 1399211 [iot_thread] State: WaitingForFileBlock Received: 489 Queued: 0 Processed: 0 Dropped: 17
3284 1399220 [OTA Agent Task] Received eOTA_JobEvent_Activate callback from OTA Agent.
3285 1399228 [OTA Agent Task] [INFO ][MQTT][1399228] (MQTT connection 0x200451f0) Disconnecting connection.
3286 1399239 [OTA Agent Task] [INFO ][MQTT][1399239] (MQTT connection 0x200451f0, DISCONNECT operation 0x20045e40) Waiting for operation completion.
3287 1399255 [OTA Agent Task] [INFO ][MQTT][1399255] (MQTT connection 0x200451f0, DISCONNECT operation 0x20045e40) Wait complete with result SUCCESS.
3288 1399269 [OTA Agent Task] [INFO ][MQTT][1399269] (MQTT connection 0x200451f0) Connection disconnected.
3289 1399279 [OTA Agent Task] [INFO ][MQTT][1399278] (MQTT connection 0x200451f0) Network connection closed.
= [SBOOT] System Security Check successfully passed. Starting...
= [FWIMG] Slot #0 @: 8105000 / Slot #1 @: 8036000 / Swap @: 81d5000
- New FW Image에 대해 Validation을 확인한 후 이상이 없으면 신규 FW를 실행합니다.
- Demo Version이 1.2.1로 변경된 것을 확인할 수 있습니다.
- 10 108358 [iot_thread] OTA demo version 1.2.1
======================================================================
= (C) COPYRIGHT 2017 STMicroelectronics =
= =
= Secure Boot and Secure Firmware Update =
======================================================================
= [SBOOT] SECURE ENGINE INITIALIZATION SUCCESSFUL
= [SBOOT] STATE: CHECK STATUS ON RESET
INFO: A Reboot has been triggered by a Software reset!
Consecutive Boot on error counter = 0
INFO: Last execution detected error was:No error. Success.
= [SBOOT] STATE: CHECK NEW FIRMWARE TO DOWNLOAD
= [SBOOT] STATE: CHECK KMS BLOB TO INSTALL
= [SBOOT] STATE: CHECK USER FW STATUS
= [SBOOT] LOADING CERTS FROM SECURE ENGINEOK
= [SBOOT] Verifying the Certificate chain... OK
= [SBOOT] Verify Header Signature... OK
= [SBOOT] Verifying the Certificate chain... OK
= [SBOOT] Verify Header Signature... OK
New Clear Fw, to be re-ordered in FLASH as expected by the swap procedure
= [SBOOT] STATE: INSTALL NEW USER FIRMWARE
Image preparation done.
Swapping the firmware /lab3/images.................
Calling SFU_IMG_SetUpdateSourceFingerprint()...
OK
= [SBOOT] STATE: VERIFY USER FW SIGNATURE
= [SBOOT] Verifying the Certificate chain... OK
= [SBOOT] Verify Header Signature... OK
= [SBOOT] CHECKING IMAGE STATE
= SFU_IMG_Check/lab3/imagestate Image State = 3
= SFU_IMG_Check/lab3/imagestate Setting Image State to 2
= OK
= [SBOOT] IMAGE STATE OK
= [SBOOT] STATE: EXECUTE USER FIRMWARE
= [SBOOT] Verifying the Certificate chain... OK
= [SBOOT] Verify Header Signature... OK0 526 [Tmr Svc] WiFi module initialized.
1 532 [Tmr Svc] Device Certificate (DER), size = 401
2 537 [Tmr Svc] Device Certificate (PEM), size = 600
-----BEGIN CERTIFICATE-----
MIIBjTCCATSgAwIBAgILAgmQzSAhzCJbATkwCgYIKoZIzj0EAwIwTzELMAkGA1UE
BhMCTkwxHjAcBgNVBAoMFVNUTWljcm9lbGVjdHJvbmljcyBudjEgMB4GA1UEAwwX
U1RNIFNUU0FGRS1BIFBST0QgQ0EgMDEwIBcNMjAwMjI2MDAwMDAwWhgPMjA1MDAy
MjYwMDAwMDBaMEYxCzAJBgNVBAYTAkZSMRswGQYDVQQKDBJTVE1pY3JvZWxlY3Ry
b25pY3MxGjAYBgNVBAMMEVNUU0FGRS1BMTEwIEVWQUwyMFkwEwYHKoZIzj0CAQYI
KoZIzj0DAQcDQgAEyly2accEmT8ACQldcLB4R+gms+KkNmZlcpUwRKIruHB0tfBq
INXwoaU62tDBL36lccjcKXhvZfBypmiCf006mDAKBggqhkjOPQQDAgNHADBEAiAQ
eoU/91uTOzhsOgeVHoKRniBkCKPremzIkf/cXD7eegIgDko6cHiZMmzLVkb+0DJT
OYf+siyvGciYPio6Qz6+la8=
-----END CERTIFICATE-----
3 594 [Tmr Svc] WiFi Firmware Version C3.5.2.5.STM.
4 3678 [Tmr Svc] WiFi connected to AP andyhouse.
5 3682 [Tmr Svc] IP Address acquired 192.168.0.120
6 3687 [iot_thread] [INFO ][DEMO][3687] ---------STARTING DEMO---------
7 3694 [iot_thread] [INFO ][INIT][3694] SDK successfully initialized.
8 108341 [iot_thread] [INFO ][DEMO][108341] Successfully initialized the demo. Network type for the demo: 1
9 108351 [iot_thread] [INFO ][MQTT][108350] MQTT library successfully initialized.
10 108358 [iot_thread] OTA demo version 1.2.1
11 108362 [iot_thread] Creating MQTT Client...
12 112934 [iot_thread] Connecting to broker...
Credits
Korean version
Jongwoo Lee (rainny@)
Sejun Kim (sejun@)
Albert Lee (sehyul@)
Original Contents Author
Vanitha Ramaswami (rvanitha@)
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
메이커스페이스 G·캠프에서 만든 콘텐츠가 아니며, 서울하드웨어해커톤에서 강의가 진행될 예정입니다.
'05_Toolkit > AWS_IoT' 카테고리의 다른 글
[번역, Korean Caption ] FreeRTOS on STM32 ( 2 of 4) (0) | 2020.12.17 |
---|---|
[번역, Korean Caption ] FreeRTOS on STM32 ( 1 of 4) (0) | 2020.12.16 |
Ex3. ① OTA FW IMAGE 생성 (0) | 2020.11.26 |
Ex3. OTA FIRMWARE UPDATE (0) | 2020.11.26 |
Ex2. ② SENSOR 추가 및 제어 (0) | 2020.11.26 |