- section[image->num_sections].private = &ihex->buffer[cooked_bytes];
- section[image->num_sections].base_address = 0x0;
- section[image->num_sections].size = 0x0;
- section[image->num_sections].flags = 0;
-
- while (fileio_fgets(fileio, 1023, lpszLine) == ERROR_OK)
- {
- uint32_t count;
- uint32_t address;
- uint32_t record_type;
- uint32_t checksum;
- uint8_t cal_checksum = 0;
- size_t bytes_read = 0;
-
- if (sscanf(&lpszLine[bytes_read], ":%2" SCNx32 "%4" SCNx32 "%2" SCNx32 , &count, &address, &record_type) != 3)
- {
- return ERROR_IMAGE_FORMAT_ERROR;
- }
- bytes_read += 9;
-
- cal_checksum += (uint8_t)count;
- cal_checksum += (uint8_t)(address >> 8);
- cal_checksum += (uint8_t)address;
- cal_checksum += (uint8_t)record_type;
-
- if (record_type == 0) /* Data Record */
- {
- if ((full_address & 0xffff) != address)
- {
- /* we encountered a nonconsecutive location, create a new section,
- * unless the current section has zero size, in which case this specifies
- * the current section's base address
- */
- if (section[image->num_sections].size != 0)
- {
- image->num_sections++;
- if (image->num_sections >= IMAGE_MAX_SECTIONS)
- {
- /* too many sections */
- LOG_ERROR("Too many sections found in IHEX file");
- return ERROR_IMAGE_FORMAT_ERROR;
+
+ while (!fileio_feof(fileio)) {
+ full_address = 0x0;
+ section[image->num_sections].private = &ihex->buffer[cooked_bytes];
+ section[image->num_sections].base_address = 0x0;
+ section[image->num_sections].size = 0x0;
+ section[image->num_sections].flags = 0;
+
+ while (fileio_fgets(fileio, 1023, lpszLine) == ERROR_OK) {
+ uint32_t count;
+ uint32_t address;
+ uint32_t record_type;
+ uint32_t checksum;
+ uint8_t cal_checksum = 0;
+ size_t bytes_read = 0;
+
+ /* skip comments and blank lines */
+ if ((lpszLine[0] == '#') || (strlen(lpszLine + strspn(lpszLine, "\n\t\r ")) == 0))
+ continue;
+
+ if (sscanf(&lpszLine[bytes_read], ":%2" SCNx32 "%4" SCNx32 "%2" SCNx32, &count,
+ &address, &record_type) != 3)
+ return ERROR_IMAGE_FORMAT_ERROR;
+ bytes_read += 9;
+
+ cal_checksum += (uint8_t)count;
+ cal_checksum += (uint8_t)(address >> 8);
+ cal_checksum += (uint8_t)address;
+ cal_checksum += (uint8_t)record_type;
+
+ if (record_type == 0) { /* Data Record */
+ if ((full_address & 0xffff) != address) {
+ /* we encountered a nonconsecutive location, create a new section,
+ * unless the current section has zero size, in which case this specifies
+ * the current section's base address
+ */
+ if (section[image->num_sections].size != 0) {
+ image->num_sections++;
+ if (image->num_sections >= IMAGE_MAX_SECTIONS) {
+ /* too many sections */
+ LOG_ERROR("Too many sections found in IHEX file");
+ return ERROR_IMAGE_FORMAT_ERROR;
+ }
+ section[image->num_sections].size = 0x0;
+ section[image->num_sections].flags = 0;
+ section[image->num_sections].private =
+ &ihex->buffer[cooked_bytes];