void test_error_on_missing_eof(void) { char* s = ":10010000214601360121470136007EFE09D2190140\r\n"; ihex_recordset_t *records UNUSED = ihex_rs_from_string(s); CU_ASSERT_EQUAL(ihex_errno(), IHEX_ERR_NO_EOF); CU_ASSERT_PTR_NOT_NULL(ihex_error()); }
void test_no_error_on_correct_checksum(void) { char* s = ":10010000214601360121470136007EFE09D2190140\r\n:00000001FF\r\n"; ihex_recordset_t *records UNUSED = ihex_rs_from_string(s); CU_ASSERT_EQUAL(ihex_errno(), 0); CU_ASSERT_PTR_NULL(ihex_error()); }
int image_ihex_merge_file(const char *filename, const nvm_symbol *list, int list_size, size_t blob_size) { ihex_recordset_t *rs; uint32_t start, end; char *blob; int symbols = 0; if (! filename || ! blob_size) return -1; //invalid parameters rs = ihex_rs_from_file(filename); if (! rs) { switch (ihex_errno()) { case IHEX_ERR_INCORRECT_CHECKSUM: case IHEX_ERR_NO_EOF: case IHEX_ERR_PARSE_ERROR: case IHEX_ERR_WRONG_RECORD_LENGTH: case IHEX_ERR_UNKNOWN_RECORD_TYPE: // Parse error, not a well-formed Intel Hex file return 0; case IHEX_ERR_NO_INPUT: case IHEX_ERR_MMAP_FAILED: case IHEX_ERR_READ_FAILED: // File not accessible symbols = -2; break; case IHEX_ERR_MALLOC_FAILED: default: // System error symbols = -3; break; } fprintf(stderr, _("Cannot open image \"%s\" (%s)\n"), filename, ihex_error()); return symbols; } if (0 != ihex_rs_get_address_range(rs, &start, &end)) { fprintf(stderr, _("Could not determine data range in Intel Hex file \"%s\" (%s)\n"), filename, ihex_error()); symbols = -4; } else if (rs->ihrs_count == 0 || start >= end) { fprintf(stderr, _("Image file \"%s\" is empty\n"), filename); } else { if (DEBUG) printf(_("%s: %s contains range 0x%04" PRIx32 " to 0x%04" PRIx32 "\n"), __func__, filename, start, end > 0 ? end - 1 : 0); if (blob_size > end) { fprintf(stderr, _("Image file \"%s\" is too small, %zu of %zu bytes missing\n"), filename, blob_size - end, blob_size); blob_size = end; } // Allocate and initialize memory for needed ihex content blob = calloc(1, blob_size); if (! blob) { fprintf(stderr, _("Could not copy data from Intel Hex file \"%s\" (%s)\n"), filename, strerror(errno)); symbols = -3; } else { if (0 != ihex_byte_copy(rs, (void*) blob, blob_size, 0)) { fprintf(stderr, _("Could not copy data from Intel Hex file \"%s\" (%s)\n"), filename, ihex_error()); symbols = -4; } else { symbols = image_raw_merge_mem(blob, list, list_size, blob_size); } free(blob); } } ihex_rs_free(rs); return symbols; }