43
43
#include <crc/crc16.h>
44
44
#include <base64/base64.h>
45
45
#include <tinycbor/cbor.h>
46
- #include <tinycbor/cbor_buf_reader.h>
47
46
#endif /* __ZEPHYR__ */
48
47
49
48
#include <flash_map_backend/flash_map_backend.h>
60
59
#include "bootutil_priv.h"
61
60
#endif
62
61
62
+ #include "serial_recovery_cbor.h"
63
+
63
64
MCUBOOT_LOG_MODULE_DECLARE (mcuboot );
64
65
65
66
#define BOOT_SERIAL_INPUT_MAX 512
@@ -226,26 +227,20 @@ bs_list(char *buf, int len)
226
227
static void
227
228
bs_upload (char * buf , int len )
228
229
{
229
- CborParser parser ;
230
- struct cbor_buf_reader reader ;
231
- struct CborValue root_value ;
232
- struct CborValue value ;
233
- uint8_t img_data [512 ];
230
+ const uint8_t * img_data = NULL ;
234
231
long long int off = UINT_MAX ;
235
232
size_t img_blen = 0 ;
236
233
uint8_t rem_bytes ;
237
234
long long int data_len = UINT_MAX ;
238
235
int img_num ;
239
236
size_t slen ;
240
- char name_str [8 ];
241
237
const struct flash_area * fap = NULL ;
242
238
int rc ;
243
239
#ifdef CONFIG_BOOT_ERASE_PROGRESSIVELY
244
240
static off_t off_last = -1 ;
245
241
struct flash_sector sector ;
246
242
#endif
247
243
248
- memset (img_data , 0 , sizeof (img_data ));
249
244
img_num = 0 ;
250
245
251
246
/*
@@ -258,99 +253,36 @@ bs_upload(char *buf, int len)
258
253
* }
259
254
*/
260
255
261
- /*
262
- * Object comes within { ... }
263
- */
264
- cbor_buf_reader_init (& reader , (uint8_t * )buf , len );
265
- cbor_parser_init (& reader .r , 0 , & parser , & root_value );
266
-
267
- if (!cbor_value_is_container (& root_value )) {
268
- goto out_invalid_data ;
269
- }
270
- if (cbor_value_enter_container (& root_value , & value )) {
256
+ Upload_t upload ;
257
+ if (!cbor_decode_Upload ((const uint8_t * )buf , len , & upload )) {
271
258
goto out_invalid_data ;
272
259
}
273
- while (cbor_value_is_valid (& value )) {
274
- /*
275
- * Decode key.
276
- */
277
- if (cbor_value_calculate_string_length (& value , & slen )) {
278
- goto out_invalid_data ;
279
- }
280
- if (!cbor_value_is_text_string (& value ) ||
281
- slen >= sizeof (name_str ) - 1 ) {
282
- goto out_invalid_data ;
283
- }
284
- if (cbor_value_copy_text_string (& value , name_str , & slen , & value )) {
285
- goto out_invalid_data ;
286
- }
287
- name_str [slen ] = '\0' ;
288
- if (!strcmp (name_str , "data" )) {
289
- /*
290
- * Image data
291
- */
292
- if (value .type != CborByteStringType ) {
293
- goto out_invalid_data ;
294
- }
295
- if (cbor_value_calculate_string_length (& value , & slen ) ||
296
- slen >= sizeof (img_data )) {
297
- goto out_invalid_data ;
298
- }
299
- if (cbor_value_copy_byte_string (& value , img_data , & slen , & value )) {
300
- goto out_invalid_data ;
301
- }
302
- img_blen = slen ;
303
- } else if (!strcmp (name_str , "off" )) {
304
- /*
305
- * Offset of the data.
306
- */
307
- if (value .type != CborIntegerType ) {
308
- goto out_invalid_data ;
309
- }
310
- if (cbor_value_get_int64 (& value , & off )) {
311
- goto out_invalid_data ;
312
- }
313
- if (cbor_value_advance (& value )) {
314
- goto out_invalid_data ;
315
- }
316
- } else if (!strcmp (name_str , "len" )) {
317
- /*
318
- * Length of the image. This should only be present in the first
319
- * block of data; when offset is 0.
320
- */
321
- if (value .type != CborIntegerType ) {
322
- goto out_invalid_data ;
323
- }
324
- if (cbor_value_get_int64 (& value , & data_len )) {
325
- goto out_invalid_data ;
326
- }
327
- if (cbor_value_advance (& value )) {
328
- goto out_invalid_data ;
329
- }
330
- } else if (!strcmp (name_str , "image" )) {
331
- /*
332
- * In a multi-image system, image number to upload to, if not
333
- * present will upload to slot 0 of image set 0.
334
- */
335
- if (value .type != CborIntegerType ) {
336
- goto out_invalid_data ;
337
- }
338
- if (cbor_value_get_int (& value , & img_num )) {
339
- goto out_invalid_data ;
340
- }
341
- if (cbor_value_advance (& value )) {
342
- goto out_invalid_data ;
343
- }
344
- } else {
345
- /*
346
- * Unknown keys.
347
- */
348
- if (cbor_value_advance (& value )) {
349
- goto out_invalid_data ;
350
- }
260
+
261
+ for (int i = 0 ; i < upload ._Upload_members_count ; i ++ ) {
262
+ _Member_t * member = & upload ._Upload_members [i ];
263
+ switch (member -> _Member_choice ) {
264
+ case _Member_image :
265
+ img_num = member -> _Member_image ;
266
+ break ;
267
+ case _Member_data :
268
+ img_data = member -> _Member_data .value ;
269
+ slen = member -> _Member_data .len ;
270
+ img_blen = slen ;
271
+ break ;
272
+ case _Member_len :
273
+ data_len = member -> _Member_len ;
274
+ break ;
275
+ case _Member_off :
276
+ off = member -> _Member_off ;
277
+ break ;
278
+ case _Member_sha :
279
+ default :
280
+ /* Nothing to do. */
281
+ break ;
351
282
}
352
283
}
353
- if (off == UINT_MAX ) {
284
+
285
+ if (off == UINT_MAX || img_data == NULL ) {
354
286
/*
355
287
* Offset must be set in every block.
356
288
*/
0 commit comments