@@ -106,6 +106,10 @@ static uint32_t calculate_crc(int fd, struct nxboot_img_header *header)
106
106
off += readsiz ;
107
107
remain -= readsiz ;
108
108
crc = crc32part ((uint8_t * )buf , readsiz , crc );
109
+ if ((remain % 25 ) == 0 )
110
+ {
111
+ nxboot_progress (nxboot_progress_dot );
112
+ }
109
113
}
110
114
111
115
free (buf );
@@ -202,6 +206,10 @@ static int copy_partition(int from, int where, struct nxboot_state *state,
202
206
203
207
off += readsiz ;
204
208
remain -= readsiz ;
209
+ if ((remain % 25 ) == 0 )
210
+ {
211
+ nxboot_progress (nxboot_progress_dot );
212
+ }
205
213
}
206
214
207
215
free (buf );
@@ -218,6 +226,7 @@ static bool validate_image(int fd)
218
226
return false;
219
227
}
220
228
229
+ syslog (LOG_INFO , "Validating image.\n" );
221
230
return calculate_crc (fd , & header ) == header .crc ;
222
231
}
223
232
@@ -268,18 +277,24 @@ static enum nxboot_update_type
268
277
struct nxboot_img_header * update_header ,
269
278
struct nxboot_img_header * recovery_header )
270
279
{
280
+ nxboot_progress (nxboot_progress_start , validate_primary );
271
281
bool primary_valid = validate_image (primary );
282
+ nxboot_progress (nxboot_progress_end );
272
283
284
+ nxboot_progress (nxboot_progress_start , validate_update );
273
285
if (update_header -> magic == NXBOOT_HEADER_MAGIC && validate_image (update ))
274
286
{
275
287
if (primary_header -> crc != update_header -> crc ||
276
288
!compare_versions (& primary_header -> img_version ,
277
289
& update_header -> img_version ) || !primary_valid )
278
290
{
291
+ nxboot_progress (nxboot_progress_end );
279
292
return NXBOOT_UPDATE_TYPE_UPDATE ;
280
293
}
281
294
}
282
295
296
+ nxboot_progress (nxboot_progress_end );
297
+
283
298
if (IS_INTERNAL_MAGIC (recovery_header -> magic ) && state -> recovery_valid &&
284
299
((IS_INTERNAL_MAGIC (primary_header -> magic ) &&
285
300
!state -> primary_confirmed ) || !primary_valid ))
@@ -292,6 +307,7 @@ static enum nxboot_update_type
292
307
293
308
static int perform_update (struct nxboot_state * state , bool check_only )
294
309
{
310
+ int successful ;
295
311
int update ;
296
312
int recovery ;
297
313
int primary ;
@@ -331,18 +347,25 @@ static int perform_update(struct nxboot_state *state, bool check_only)
331
347
recovery = secondary ;
332
348
}
333
349
350
+ nxboot_progress (nxboot_progress_start , validate_primary );
334
351
if (state -> next_boot == NXBOOT_UPDATE_TYPE_REVERT &&
335
352
(!check_only || !validate_image (primary )))
336
353
{
354
+ nxboot_progress (nxboot_progress_end );
337
355
if (state -> recovery_valid )
338
356
{
339
357
syslog (LOG_INFO , "Reverting image to recovery.\n" );
358
+ nxboot_progress (nxboot_progress_start , recovery_revert );
340
359
copy_partition (recovery , primary , state , false);
360
+ nxboot_progress (nxboot_progress_end );
341
361
}
342
362
}
343
363
else
344
364
{
365
+ nxboot_progress (nxboot_progress_end );
366
+ nxboot_progress (nxboot_progress_start , validate_primary );
345
367
primary_valid = validate_image (primary );
368
+ nxboot_progress (nxboot_progress_end );
346
369
if (primary_valid && check_only )
347
370
{
348
371
/* Skip if primary image is valid (does not mather whether
@@ -368,21 +391,33 @@ static int perform_update(struct nxboot_state *state, bool check_only)
368
391
*/
369
392
370
393
syslog (LOG_INFO , "Creating recovery image.\n" );
394
+ nxboot_progress (nxboot_progress_start , recovery_create );
371
395
copy_partition (primary , recovery , state , false);
372
- if (!validate_image (recovery ))
396
+ nxboot_progress (nxboot_progress_end );
397
+ nxboot_progress (nxboot_progress_start , validate_recovery );
398
+ successful = validate_image (recovery );
399
+ nxboot_progress (nxboot_progress_end );
400
+ if (!successful )
373
401
{
374
- syslog (LOG_INFO , "New recovery is not valid, stop update.\n" );
402
+ syslog (LOG_INFO ,
403
+ "New recovery is not valid,stop update.\n" );
404
+ nxboot_progress (nxboot_info , recovery_invalid );
375
405
goto perform_update_done ;
376
406
}
377
407
378
408
syslog (LOG_INFO , "Recovery image created.\n" );
409
+ nxboot_progress (nxboot_info , recovery_created );
379
410
}
380
411
381
- if (validate_image (update ))
412
+ nxboot_progress (nxboot_progress_start , validate_update );
413
+ successful = validate_image (update );
414
+ nxboot_progress (nxboot_progress_end );
415
+ if (successful )
382
416
{
383
417
/* Perform update only if update slot contains valid image. */
384
418
385
419
syslog (LOG_INFO , "Updating from update image.\n" );
420
+ nxboot_progress (nxboot_progress_start , update_from_update );
386
421
if (copy_partition (update , primary , state , true) >= 0 )
387
422
{
388
423
/* Erase the first sector of update partition. This marks the
@@ -393,6 +428,8 @@ static int perform_update(struct nxboot_state *state, bool check_only)
393
428
394
429
flash_partition_erase_first_sector (update );
395
430
}
431
+
432
+ nxboot_progress (nxboot_progress_end );
396
433
}
397
434
}
398
435
@@ -403,6 +440,46 @@ static int perform_update(struct nxboot_state *state, bool check_only)
403
440
return OK ;
404
441
}
405
442
443
+ #ifdef CONFIG_NXBOOT_COPY_TO_RAM
444
+ int nxboot_ramcopy (void )
445
+ {
446
+ int ret = OK ;
447
+ int primary ;
448
+ struct nxboot_img_header header ;
449
+ ssize_t bytes ;
450
+ static uint8_t * buf ;
451
+
452
+ primary = flash_partition_open (CONFIG_NXBOOT_PRIMARY_SLOT_PATH );
453
+ if (primary < 0 )
454
+ {
455
+ return ERROR ;
456
+ }
457
+
458
+ get_image_header (primary , & header );
459
+ buf = malloc (header .size );
460
+ if (!buf )
461
+ {
462
+ ret = ERROR ;
463
+ goto exit_with_error ;
464
+ }
465
+
466
+ bytes = pread (primary , buf , header .size , header .header_size );
467
+ if (bytes != header .size )
468
+ {
469
+ ret = ERROR ;
470
+ goto exit_with_error ;
471
+ }
472
+
473
+ memcpy ((uint32_t * )CONFIG_NXBOOT_RAMSTART , buf , header .size );
474
+
475
+ exit_with_error :
476
+ flash_partition_close (primary );
477
+ free (buf );
478
+
479
+ return ret ;
480
+ }
481
+ #endif
482
+
406
483
/****************************************************************************
407
484
* Public Functions
408
485
****************************************************************************/
@@ -528,7 +605,9 @@ int nxboot_get_state(struct nxboot_state *state)
528
605
state -> update = NXBOOT_TERTIARY_SLOT_NUM ;
529
606
}
530
607
608
+ nxboot_progress (nxboot_progress_start , validate_recovery );
531
609
state -> recovery_valid = validate_image (recovery );
610
+ nxboot_progress (nxboot_progress_end );
532
611
state -> recovery_present = primary_header .crc == recovery_header -> crc ;
533
612
534
613
/* The image is confirmed if it has either NXBOOT_HEADER_MAGIC or a
@@ -611,7 +690,7 @@ int nxboot_get_confirm(void)
611
690
int recovery ;
612
691
int recovery_pointer ;
613
692
char * path ;
614
- int ret = 0 ;
693
+ int ret = OK ;
615
694
struct nxboot_img_header primary_header ;
616
695
struct nxboot_img_header recovery_header ;
617
696
@@ -799,6 +878,7 @@ int nxboot_perform_update(bool check_only)
799
878
*/
800
879
801
880
syslog (LOG_ERR , "Update process failed: %s\n" , strerror (errno ));
881
+ nxboot_progress (nxboot_error , update_failed );
802
882
}
803
883
}
804
884
@@ -823,3 +903,4 @@ int nxboot_perform_update(bool check_only)
823
903
824
904
return ret ;
825
905
}
906
+
0 commit comments