@@ -78,16 +78,16 @@ typedef enum modem_app_state_e {
7878 MODEM_FW_UPGRADE_DONE
7979} modem_app_state_t ;
8080
81- // application control block
81+ /* application control block */
8282typedef struct modem_app_cb_s {
83- // wlan application state
83+ /* wlan application state */
8484 modem_app_state_t state ;
8585} modem_app_cb_t ;
8686
87- // application control block
87+ /* application control block */
8888modem_app_cb_t modem_app_cb ;
8989
90- // FW send variable, buffer
90+ /* FW send variable, buffer */
9191static uint32_t chunk_cnt = 0u , chunk_check = 0u , offset = 0u , fw_image_size = 0u , remainder = 0u ;
9292static uint8_t recv_buff_hdr [UA_HEADER_SIZE ] = { 0 };
9393static uint8_t recv_buff_1k [1024 ] = { 0 };
@@ -259,15 +259,13 @@ int dfu_send_ioctl(int cmd, int numofbytes) {
259259 switch (cmd ) {
260260 case AT_GET_FILE_MODE :
261261 res = fcntl_ptr (sd , GET_FILE_MODE , recv_buff_hdr );
262-
263262 if (res < 0 ) {
264263 printf ("GET_FILE_MODE failed\n" );
265264 }
266265 break ;
267266
268267 case AT_GET_CHKSUM_ABILITY :
269268 res = fcntl_ptr (sd , GET_CHKSUM_ABILITY , recv_buff_hdr );
270-
271269 if (res < 0 ) {
272270 printf ("GET_CHKSUM_ABILITY failed\n" );
273271 }
@@ -284,7 +282,6 @@ int dfu_send_ioctl(int cmd, int numofbytes) {
284282 init_xfer_params .imagecrc );
285283
286284 res = fcntl_ptr (sd , INIT_FW_XFER , & init_xfer_params );
287-
288285 if (res < 0 ) {
289286 printf ("\tINIT_FW_XFER failed with update.ua, error %d\n" , res );
290287 }
@@ -295,7 +292,6 @@ int dfu_send_ioctl(int cmd, int numofbytes) {
295292
296293 case AT_SEND_FW_HEADER :
297294 res = fcntl_ptr (sd , SEND_FW_HEADER , recv_buff_hdr );
298-
299295 if (res < 0 ) {
300296 printf ("\tSEND_FW_HEADER failed\n" );
301297 } else if (recv_buff_hdr [0 ] == 0 ) {
@@ -323,7 +319,6 @@ int dfu_send_ioctl(int cmd, int numofbytes) {
323319 send_params .len = numofbytes ;
324320
325321 res = fcntl_ptr (sd , SEND_FW_DATA , & send_params );
326-
327322 if (res < 0 ) {
328323 printf ("\tSEND_FW_DATADONE failed, error %d\n" , res );
329324 } else {
@@ -332,9 +327,7 @@ int dfu_send_ioctl(int cmd, int numofbytes) {
332327 break ;
333328
334329 case AT_INIT_FW_UPGRADE :
335- // AT%UPGCMD="UPGVRM","b:/update.ua"
336330 res = fcntl_ptr (sd , INIT_FW_UPGRADE , "b:/update.ua" );
337-
338331 if (res < 0 ) {
339332 printf ("\tAT_INIT_FW_UPGRADE failed with update.ua\n" );
340333 }
@@ -371,7 +364,6 @@ int dfu_send_ioctl(int cmd, int numofbytes) {
371364
372365 case AT_RESET_MODEM :
373366 res = fcntl_ptr (sd , RESET_MODEM , NULL );
374-
375367 if (res < 0 ) {
376368 printf ("\tAT_RESET_MODEM failed\n" );
377369 }
@@ -475,7 +467,6 @@ static int32_t dfu_modem_write_image(const struct dfu_file_t *dfu_file)
475467 }
476468
477469 printf ("\tSending image header\n" );
478- // printf("\tHeader -> %s\n", recv_buff_hdr);
479470 int res = dfu_send_ioctl (AT_SEND_FW_HEADER , UA_HEADER_SIZE );
480471 if (res < 0 ) {
481472 return -1 ;
@@ -493,19 +484,13 @@ static int32_t dfu_modem_write_image(const struct dfu_file_t *dfu_file)
493484
494485 /* Loop until all the chunks are read and written */
495486 while (offset <= fw_image_size ) {
496- if (chunk_cnt == chunk_check ) {
497- /* printf("Murata 1SC FW update started\n"); */
498- // break;
499- }
500-
501487 if (chunk_cnt < (chunk_check - 1 )) {
502488 readsize = DFU_CHUNK_SIZE ;
503489 }
504490 else {
505491 readsize = remainder ;
506492 }
507493
508- // printf("readsize: %d chunk_cnt: %d total %d\n", readsize, chunk_cnt, chunk_check);
509494 if (readsize > 0 ) {
510495 if (file_read_flash (dfu_file , readsize ) != 0 ) {
511496 printf ("file system flash read failed\n" );
@@ -532,7 +517,6 @@ static int32_t dfu_modem_write_image(const struct dfu_file_t *dfu_file)
532517 }
533518 modem_app_cb .state = MODEM_FW_UPGRADE_DONE ;
534519 } else {
535- //printf("\tModem FW update continues with in-between chunks\n");
536520 printk ("." );
537521 dfu_send_ioctl (AT_SEND_FW_DATA , readsize );
538522 if (status != 0 ) {
@@ -626,6 +610,24 @@ int dfu_modem_is_golden()
626610 return -1 ;
627611}
628612
613+ int select_modem_file (char * filename ) {
614+ char * token ;
615+ char * rest = filename ;
616+ int idx = 0 ;
617+ char from [10 ];
618+
619+ while ((token = strtok_r (rest , "." , & rest ))) {
620+ if (idx == 1 ) {
621+ strcpy (from , token );
622+ } else if (idx == 2 ) {
623+ if (!strcmp (from , "20161" ) && !strcmp (token , "20351" ))
624+ return 1 ;
625+ }
626+ idx ++ ;
627+ }
628+ return 0 ;
629+ }
630+
629631int dfu_modem_firmware_upgrade (const struct dfu_file_t * dfu_file )
630632{
631633 int ret = 0 ;
@@ -637,14 +639,7 @@ int dfu_modem_firmware_upgrade (const struct dfu_file_t *dfu_file)
637639 printf ("Murata 1SC FW update has aborted - reading the Murata 1SC FW version has failed !\n" );
638640 }
639641
640- if (strstr (dfu_file -> lfile , "sample" ) != NULL )
641- selected_murata_file = 1 ;
642- else if (strstr (dfu_file -> lfile , "golden" ) != NULL )
643- selected_murata_file = 2 ;
644- else {
645- printf ("Murata FW is invalid\n" );
646- return -1 ;
647- }
642+ selected_murata_file = select_modem_file ((char * )dfu_file -> rfile );
648643
649644 int is_golden = dfu_modem_is_golden ();
650645
0 commit comments