Skip to content

Commit a79b36f

Browse files
chuyue-luo-armurutva
authored andcommitted
components: Update AWS IoT Jobs library to send and receive updatedBy
An OTA image should be accepted only if the update version is higher than the current firmware version. This commit adds an out-of-tree patch to the Jobs-for-AWS-IoT-embedded-sdk library which adds functionality for sending the updatedBy version to the cloud and retrieving it when the device reboots. Signed-off-by: Chuyue Luo <[email protected]>
1 parent 9a3eb6c commit a79b36f

File tree

4 files changed

+186
-2
lines changed

4 files changed

+186
-2
lines changed

components/aws_iot/jobs_for_aws_iot_embedded_sdk/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ else()
1717
set(PATCH_FILES
1818
"${PATCH_FILES_DIRECTORY}/0001-Check-for-RSA-signature-instead-of-ECDSA.patch"
1919
"${PATCH_FILES_DIRECTORY}/0002-Use-custom-strnlen-implementation.patch"
20+
"${PATCH_FILES_DIRECTORY}/0003-Add-functionality-for-sending-and-retrieving-updated.patch"
2021
)
2122
iot_reference_arm_corstone3xx_apply_patches("${jobs-for-aws-iot-embedded-sdk_SOURCE_DIR}" "${PATCH_FILES}")
2223

components/aws_iot/jobs_for_aws_iot_embedded_sdk/integration/patches/0001-Check-for-RSA-signature-instead-of-ECDSA.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 6ea98c733a2ea3c9d8cfdf4d3b689598ffdf8d54 Mon Sep 17 00:00:00 2001
22
From: Chuyue Luo <[email protected]>
33
Date: Wed, 4 Dec 2024 15:20:34 +0000
4-
Subject: [PATCH 1/2] Check for RSA signature instead of ECDSA
4+
Subject: [PATCH 1/3] Check for RSA signature instead of ECDSA
55

66
The Jobs-for-AWS-IoT-embedded-sdk library assumes the OTA job is signed
77
using ECDSA, but we currently use RSA. Thus, change the check for an

components/aws_iot/jobs_for_aws_iot_embedded_sdk/integration/patches/0002-Use-custom-strnlen-implementation.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 02b777ed41b393163c3f793d8ff3b608ac0b9634 Mon Sep 17 00:00:00 2001
22
From: Chuyue Luo <[email protected]>
33
Date: Wed, 4 Dec 2024 15:24:44 +0000
4-
Subject: [PATCH 2/2] Use custom `strnlen` implementation
4+
Subject: [PATCH 2/3] Use custom `strnlen` implementation
55

66
The Arm Compiler for Embedded (v6.21) does not support the `strnlen`
77
function. Therefore, use our own implementation (`app_strnlen`) instead.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
From b2eb23684950fb835cc77ad852a3a4e37ac43f39 Mon Sep 17 00:00:00 2001
2+
From: Chuyue Luo <[email protected]>
3+
Date: Fri, 10 Jan 2025 11:50:45 +0000
4+
Subject: [PATCH 3/3] Add functionality for sending and retrieving updatedBy
5+
version
6+
7+
An OTA image should be accepted only if the update firmware version is
8+
higher than the current firmware version. This patch adds functionality
9+
for sending the updatedBy version to the cloud and retrieving it when
10+
the device reboots.
11+
12+
Signed-off-by: Chuyue Luo <[email protected]>
13+
---
14+
source/include/jobs.h | 6 +++++
15+
source/jobs.c | 6 ++++-
16+
source/otaJobParser/include/job_parser.h | 33 ++++++++++++++++++++++++
17+
source/otaJobParser/job_parser.c | 32 +++++++++++++++++++++++
18+
4 files changed, 76 insertions(+), 1 deletion(-)
19+
20+
diff --git a/source/include/jobs.h b/source/include/jobs.h
21+
index 11caba6..9a04cb9 100644
22+
--- a/source/include/jobs.h
23+
+++ b/source/include/jobs.h
24+
@@ -1,6 +1,8 @@
25+
/*
26+
* AWS IoT Jobs v1.5.1
27+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
28+
+ * Copyright 2024 Arm Limited and/or its affiliates
29+
30+
*
31+
* SPDX-License-Identifier: MIT
32+
*
33+
@@ -841,6 +843,8 @@ JobsStatus_t Jobs_Update( char * buffer,
34+
* @param status Current status of the job
35+
* @param expectedVersion The version that is expected
36+
* @param expectedVersionLength The length of the expectedVersion string
37+
+ * @param updatedBy The app firmware version before the update
38+
+ * @param updatedByLength The length of the updatedBy string
39+
* @param buffer The buffer to be written to
40+
* @param bufferSize the size of the buffer
41+
*
42+
@@ -878,6 +882,8 @@ JobsStatus_t Jobs_Update( char * buffer,
43+
size_t Jobs_UpdateMsg( JobCurrentStatus_t status,
44+
const char * expectedVersion,
45+
size_t expectedVersionLength,
46+
+ const char * updatedBy,
47+
+ size_t updatedByLength,
48+
char * buffer,
49+
size_t bufferSize );
50+
/* @[declare_jobs_updatemsg] */
51+
diff --git a/source/jobs.c b/source/jobs.c
52+
index 0f83c27..0281008 100644
53+
--- a/source/jobs.c
54+
+++ b/source/jobs.c
55+
@@ -820,6 +820,8 @@ JobsStatus_t Jobs_Update( char * buffer,
56+
size_t Jobs_UpdateMsg( JobCurrentStatus_t status,
57+
const char * expectedVersion,
58+
size_t expectedVersionLength,
59+
+ const char * updatedBy,
60+
+ size_t updatedByLength,
61+
char * buffer,
62+
size_t bufferSize )
63+
{
64+
@@ -853,7 +855,9 @@ size_t Jobs_UpdateMsg( JobCurrentStatus_t status,
65+
( void ) strnAppend( buffer, &start, bufferSize, jobStatusString[ status ], jobStatusStringLengths[ status ] );
66+
( void ) strnAppend( buffer, &start, bufferSize, JOBS_API_EXPECTED_VERSION, JOBS_API_EXPECTED_VERSION_LENGTH );
67+
( void ) strnAppend( buffer, &start, bufferSize, expectedVersion, expectedVersionLength );
68+
- ( void ) strnAppend( buffer, &start, bufferSize, "\"}", ( CONST_STRLEN( "\"}" ) ) );
69+
+ ( void ) strnAppend( buffer, &start, bufferSize, "\",\"statusDetails\":{\"updatedBy\":\"", ( CONST_STRLEN( "\",\"statusDetails\":{\"updatedBy\":\"" ) ));
70+
+ ( void ) strnAppend( buffer, &start, bufferSize, updatedBy, updatedByLength );
71+
+ ( void ) strnAppend( buffer, &start, bufferSize, "\"}}", ( CONST_STRLEN( "\"}}" ) ) );
72+
}
73+
74+
return start;
75+
diff --git a/source/otaJobParser/include/job_parser.h b/source/otaJobParser/include/job_parser.h
76+
index 3fcf537..7e87d3b 100644
77+
--- a/source/otaJobParser/include/job_parser.h
78+
+++ b/source/otaJobParser/include/job_parser.h
79+
@@ -1,6 +1,9 @@
80+
/*
81+
* AWS IoT Jobs v1.5.1
82+
* Copyright (C) 2023 Amazon.com, Inc. and its affiliates. All Rights Reserved.
83+
+ * Copyright 2024 Arm Limited and/or its affiliates
84+
85+
+ *
86+
* SPDX-License-Identifier: MIT
87+
*
88+
* Licensed under the MIT License. See the LICENSE accompanying this file
89+
@@ -61,6 +64,20 @@ typedef struct
90+
uint32_t fileType;
91+
} AfrOtaJobDocumentFields_t;
92+
93+
+/**
94+
+ * @ingroup jobs_structs
95+
+ * @brief struct containing the entries within the statusDetails field of an AFR
96+
+ * OTA Job Document
97+
+ */
98+
+typedef struct
99+
+{
100+
+ /** @brief The app firmware version prior to the update */
101+
+ const char * updatedBy;
102+
+
103+
+ /** @brief Length of updatedBy string */
104+
+ size_t updatedByLen;
105+
+} AfrOtaJobDocumentStatusDetails_t;
106+
+
107+
/**
108+
* @brief Populate the fields of 'result', returning
109+
* true if successful.
110+
@@ -79,4 +96,20 @@ bool populateJobDocFields( const char * jobDoc,
111+
AfrOtaJobDocumentFields_t * result );
112+
/* @[declare_populatejobdocfields] */
113+
114+
+/**
115+
+ * @brief Populate the fields of 'result', returning true if successful.
116+
+ *
117+
+ * @param jobDoc FreeRTOS OTA job document
118+
+ * @param jobDocLength OTA job document length
119+
+ * @param result Job document statusDetails structure to populate
120+
+ * @return true Job document statusDetails fields were parsed from the document
121+
+ * @return false Job document statusDetails fields were not parsed from the
122+
+ * document
123+
+ */
124+
+/* @[declare_populatejobstatusdetailsfields] */
125+
+bool populateJobStatusDetailsFields( const char * jobDoc,
126+
+ const size_t jobDocLength,
127+
+ AfrOtaJobDocumentStatusDetails_t * result );
128+
+/* @[declare_populatejobstatusdetailsfields] */
129+
+
130+
#endif /* JOB_PARSER_H */
131+
diff --git a/source/otaJobParser/job_parser.c b/source/otaJobParser/job_parser.c
132+
index 8638dc0..eb63777 100644
133+
--- a/source/otaJobParser/job_parser.c
134+
+++ b/source/otaJobParser/job_parser.c
135+
@@ -19,6 +19,11 @@
136+
#include "core_json.h"
137+
#include "job_parser.h"
138+
139+
+/**
140+
+ * @brief Get the length of a string literal.
141+
+ */
142+
+#define CONST_STRLEN( x ) ( sizeof( ( x ) ) - 1U )
143+
+
144+
/**
145+
* @brief Populates common job document fields in result
146+
*
147+
@@ -184,6 +189,33 @@ bool populateJobDocFields( const char * jobDoc,
148+
return populatedJobDocFields;
149+
}
150+
151+
+bool populateJobStatusDetailsFields( const char * jobDoc,
152+
+ const size_t jobDocLength,
153+
+ AfrOtaJobDocumentStatusDetails_t * result )
154+
+{
155+
+ bool populatedJobStatusDetailsFields = false;
156+
+ JSONStatus_t jsonResult = JSONNotFound;
157+
+ const char * jsonValue = NULL;
158+
+ size_t jsonValueLength = 0U;
159+
+
160+
+ jsonResult = JSON_SearchConst( jobDoc,
161+
+ jobDocLength,
162+
+ "execution.statusDetails.updatedBy",
163+
+ CONST_STRLEN("execution.statusDetails.updatedBy"),
164+
+ &jsonValue,
165+
+ &jsonValueLength,
166+
+ NULL );
167+
+
168+
+ if( jsonResult == JSONSuccess )
169+
+ {
170+
+ result->updatedBy = jsonValue;
171+
+ result->updatedByLen = ( uint32_t ) jsonValueLength;
172+
+ populatedJobStatusDetailsFields = true;
173+
+ }
174+
+
175+
+ return populatedJobStatusDetailsFields;
176+
+}
177+
+
178+
static JSONStatus_t populateCommonFields( const char * jobDoc,
179+
const size_t jobDocLength,
180+
int32_t fileIndex,
181+
--
182+
2.47.1
183+

0 commit comments

Comments
 (0)