void test_memory_is_copied_1(void)
{
    uint32_t addr_min;
    uint32_t addr_max;
	ihex_recordset_t *rs;
    int rv;
	uint8_t *dst;
    ulong_t size;
    ulong_t ofst;
    ulong_t n;

    rs  = ihex_rs_from_file("C:/ble_nrf51/tandd/nrf51/examples/ble_peripheral/ble_app_K1/pca10028/s110/arm4/_build/nrf51422_xxac_s110.hex");
 
    size = ihex_rs_get_size(rs);
    printf("ihex_rs_get_size: size = %d\n", size);

    rv = ihex_rs_get_address_range(rs, &addr_min, &addr_max);
    printf("ihex_rs_get_address_range: rv = %d, addr_min = 0x%08x, addr_max = 0x%08x\n", rv, addr_min, addr_max);

    dst = (uint8_t*) malloc(0x30000);//8192);

	if (rs == NULL)
	{
		//CU_FAIL("File \"res/big-a.hex\" does not exist.");
		return;
	}
	
	//rv = ihex_mem_copy(rs, dst, 0x30000/*8192*/, IHEX_WIDTH_8BIT, IHEX_ORDER_BIGENDIAN);

    ofst = 0;
    n = 0x20;
    rv = ihex_mem_copy_from_offset(rs, dst, ofst, n, IHEX_WIDTH_8BIT, IHEX_ORDER_BIGENDIAN);
    printf("rv = %d\n", rv);

    ofst = 0x08;
    n = 0x10;
    rv = ihex_mem_copy_from_offset(rs, dst, ofst, n, IHEX_WIDTH_8BIT, IHEX_ORDER_BIGENDIAN);
    printf("rv = %d\n", rv);

    ofst = 0x2744;
    n = 0x100;
    rv = ihex_mem_copy_from_offset(rs, dst, ofst, n, IHEX_WIDTH_8BIT, IHEX_ORDER_BIGENDIAN);
    printf("rv = %d\n", rv);

    free(dst);
}
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;
}