Revision d54d2f07 Host/Source/SerialBoot/main.c

View differences:

Host/Source/SerialBoot/main.c
23 23
* You should have received a copy of the GNU General Public License along with OpenBLT.
24 24
* If not, see <http://www.gnu.org/licenses/>.
25 25
*
26
* A special exception to the GPL is included to allow you to distribute a combined work 
27
* that includes OpenBLT without being obliged to provide the source code for any 
26
* A special exception to the GPL is included to allow you to distribute a combined work
27
* that includes OpenBLT without being obliged to provide the source code for any
28 28
* proprietary components. The exception text is included at the bottom of the license
29 29
* file <license.html>.
30
* 
30
*
31 31
* \endinternal
32 32
****************************************************************************************/
33 33

  
......
42 42
#include "xcpmaster.h"                                /* XCP master protocol module    */
43 43
#include "srecord.h"                                  /* S-record file handling        */
44 44
#include "timeutil.h"                                 /* time utility module           */
45
#include "stdlib.h"                                   /* ascii to integral conversion  */
45 46

  
46 47

  
47 48
/****************************************************************************************
......
95 96
* Local data declarations
96 97
****************************************************************************************/
97 98
/** \brief Name of the serial device, such as COM4 or /dev/ttyUSB0. */
98
static sb_char serialDeviceName[32]; 
99
static sb_char serialDeviceName[32];
99 100

  
100 101
/** \brief Id of the bluetooth device, such as 01:23:45:67:89:AB. */
101
static sb_char bluetoothID[18]; 
102
static sb_char bluetoothID[18];
102 103

  
103 104
/** \brief Serial communication speed in bits per second. */
104
static sb_uint32 serialBaudrate; 
105
static sb_uint32 serialBaudrate;
105 106

  
106 107
/** \brief Name of the S-record file. */
107
static sb_char *srecordFileName; 
108
static sb_char *srecordFileName;
108 109

  
109 110
/* program status */
110 111
static sb_uint8 prog_state = 1;
111 112

  
112 113
/* id of flashing target */
113
static sb_uint8 flashingTargetID = 0;
114
static sb_uint32 flashingTargetID = 0;
114 115

  
115 116
/* list of program names */
116 117
static sb_char *srecordFileNames[MAX_COUNT_FLASHING_PROGRAMS];
117 118

  
118 119
/* list of target ids */
119
static sb_uint8 flashingTargetIDs[MAX_COUNT_FLASHING_PROGRAMS];
120
static sb_uint32 flashingTargetIDs[MAX_COUNT_FLASHING_PROGRAMS];
120 121

  
121 122
/* list of errors */
122 123
static sb_uint8 errors[MAX_COUNT_FLASHING_PROGRAMS];
......
181 182
    errorDetected = ERROR_NO;
182 183
    flashingTargetID = flashingTargetIDs[flashIdx];
183 184
    srecordFileName = srecordFileNames[flashIdx];
184
    printf("\nFlash %i: Flashing %s on device %i\n\n", flashIdx+1, srecordFileName, flashingTargetID);
185
    printf("\nFlash %i: Flashing %s on device 0x%08X\n\n", flashIdx+1, srecordFileName, flashingTargetID);
186

  
185 187
    if (flashProgram() == PROG_RESULT_ERROR) {
186 188
      closeSerialPort();
187 189
      openSerialPortConnect(0);
......
278 280
  printf("Programming will start immediately in following order:\n");
279 281
  sb_uint8 idx;
280 282
  for (idx=0; idx<countFlashingPrograms; idx++) {
281
    printf("  %i) device %i: %s\n", idx+1, flashingTargetIDs[idx], srecordFileNames[idx]);
283
    printf("  %i) device 0x%08X: %s\n", idx+1, flashingTargetIDs[idx], srecordFileNames[idx]);
282 284
  }
283 285
}
284 286

  
285 287

  
286 288
/************************************************************************************//**
287 289
** \brief     Parses the command line arguments. A fixed amount of arguments is expected.
288
**            The program should be called as: 
290
**            The program should be called as:
289 291
**              SerialBoot -d[device] -b[baudrate] [s-record file]
290 292
** \param     argc Number of program parameters.
291 293
** \param     argv array to program parameter strings.
......
330 332
        printf("The bluetooth ID %s has not the format xx:xx:xx:xx:xx:xx\n", &argv[paramIdx][2]);
331 333
        return SB_FALSE;
332 334
      }
333
      // copy the bluetooth id and set flag that this parameter was found 
335
      // copy the bluetooth id and set flag that this parameter was found
334 336
      strcpy(serialDeviceName, &argv[paramIdx][2]);
335 337
      paramAfound = SB_TRUE;
336 338
      comIsUart = SB_FALSE;
......
359 361
      }
360 362
      if (registerRTSvalue > 1 || registerRTSvalue < 0 || setValue[1] != 0x0) {
361 363
        registerRTSvalue = 0;
362
	printf("Not allowed value for RTS register. RTS=[0,1]\n");
364
        printf("Not allowed value for RTS register. RTS=[0,1]\n");
363 365
        return SB_FALSE;
364 366
      }
365 367
      paramRTSfound = SB_TRUE;
......
414 416
      srecordfound = SB_TRUE;
415 417
    }
416 418
  }
417
  
419

  
418 420
  /* verify if all parameters were found */
419 421
  if ( ( ((paramDfound == SB_FALSE) || (paramBfound == SB_FALSE)) && (paramAfound == SB_FALSE)) || (srecordfound == SB_FALSE) )
420 422
  {
......
445 447
      printf("\n%i ERRORs detected!\nOnly in the following %i cases SerialBoot updated the firmware:\n", detected, countFlashingPrograms-detected);
446 448
      for (errorIdx=0; errorIdx<countFlashingPrograms; errorIdx++) {
447 449
        if (errors[errorIdx] == ERROR_NO) {
448
          printf(" * Flash %i: %s on device %i\n", errorIdx+1, srecordFileNames[errorIdx], flashingTargetIDs[errorIdx]);
450
          printf(" * Flash %i: %s on device 0x%08X\n", errorIdx+1, srecordFileNames[errorIdx], flashingTargetIDs[errorIdx]);
449 451
        }
450 452
      }
451 453
      printf("In the following %i cases SerialBoot could not update the firmware:\n", detected);
......
459 461
          case ERROR_FILE:
460 462
            printf("The file %s couldn't be read!\n", srecordFileNames[errorIdx]); break;
461 463
          case ERROR_DEVICE:
462
            printf("No connection to device %i!\n", flashingTargetIDs[errorIdx]); break;
464
            printf("No connection to device 0x%08X!\n", flashingTargetIDs[errorIdx]); break;
463 465
          default:
464 466
            printf("Couldn't specify the error. Please check output above!\n"); break;
465 467
        }
......
504 506
  tSrecordLineParseResults lineParseResults;
505 507

  
506 508
  /* -------------------- start the firmware update procedure ------------------------ */
507
  printf("Starting firmware update for \"%s\" on device %i (0x", srecordFileName, flashingTargetID);
508
  if (flashingTargetID < 16)
509
  {
510
    printf("0");
511
  }
512
  printf("%X)\nUsing %s @ %u bits/s\n", flashingTargetID, serialDeviceName, serialBaudrate);
509
  printf("Starting firmware update for \"%s\" on device 0x%08X\n", srecordFileName, flashingTargetID);
510
  printf("Using %s @ %u bits/s\n", serialDeviceName, serialBaudrate);
513 511

  
514 512
  /* -------------------- prepare programming session -------------------------------- */
515 513
  if (prepareProgrammingSession(&hSrecord, &fileParseResults) == PROG_RESULT_ERROR) {
......
707 705
    } else if (flashingTargetID == 0) {
708 706
      printf("Try to connect to device...");
709 707
    } else {
710
      printf("Try to connect to device 0x");
711
      if (flashingTargetID < 16) {
712
        printf("0");
713
      }
714
      printf("%X...", flashingTargetID);
708
      printf("Try to connect to device 0x%08X...", flashingTargetID);
715 709
    }
716 710
  }
717 711
  /* now keep retrying until we get a response */

Also available in: Unified diff