//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // #define GXIMAGE_BUFFER_CAPACITY 0x8000 // static uint8_t sm_gxImage_buffer[GXIMAGE_BUFFER_CAPACITY]; // static W_ihexMemImage_t sm_gxImage0; //----------------------------------------------------------------------------- public int test_1(String fileName) { int r; W_ihexMemImage_t pI = new W_ihexMemImage_t(); //pI = &sm_gxImage0; //pI.gx_bin = sm_gxImage_buffer; //pI.gx_binCapacity = sizeof(sm_gxImage_buffer); //GXIMAGE_BUFFER_CAPACITY //pI.gx_binCapacity = 0x8000; //fake GXIMAGE_BUFFER_CAPACITY r = ks_ihex_LoadToMem.W_ihex_LoadToMem(pI, fileName); if (r != 0) { return (r); } Console.Write("=== test_1 ===\n"); Console.Write(" Binary length = 0x{0:x04}, {1:d5}\n", pI.image_length, pI.image_length); Console.Write(" Binary CRC = 0x{0:x04}, {1:d5}\n", pI.image_crc, pI.image_crc); // Console.Write(" Binary CRC = 0x%04x, %5d\n", pI.image_crc, pI.image_crc); Console.Write("\n"); r = test_1_save_bin_to_file("dfu_temp.bin", pI.image_array, pI.image_length); if (r != 0) { return (r); } r = test_1_save_DFUInit_data("dfu_temp.dat", pI.image_crc); if (r != 0) { return (r); } r = test_1_print_DFUInit_json("manifest.json", "dfu_temp.bin", "dfu_temp.dat", pI.image_crc); if (r != 0) { return (r); } return (0); }
public static Int32 W_ihex_LoadToMem(W_ihexMemImage_t pI, String filename) { int i; UInt16 crc16; intelStuff.ihex_recordset_t rs; int rv; UInt64 offset; //UInt64 UInt64 count; //UInt64 Console.Write("\nW_ihexLoadToMem\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"); //rs = ihex_rs_from_file("C:/ble_nrf51/tandd/nrf51/examples/ble_peripheral/ble_app_K2/pca10028/s110/arm4/_build/nrf51422_xxac_s110.hex"); //----- Step 1: Load the file into the rs Record Set array ----- rs = intelStuff.ihex_rs_from_file(filename); if (rs == null) { Console.Write("Failed to get records from hex file\n"); return (-1); } //----- Setep ?: get total bye count of all data in record set ? ----- /* pI._gx_size = (UInt32)intelStuff.ihex_rs_get_size(rs); //Note gets total size of all records Console.Write(" ihex_rs_get_size() . _gx_size = {0}\n", pI._gx_size); if (pI._gx_size > pI.gx_binCapacity) { Console.Write(" Image File is too big for alotted memory. Image size = {0}, Memory size = {1}\n\n", pI._gx_size, pI.gx_binCapacity); return (-1); } */ //----- Step ?: Get the address range ----- rv = intelStuff.ihex_rs_get_address_range(rs, ref pI.image_start, ref pI.image_stop); if (rv != 0) { Console.Write(" ihex_rs_get_address_range() rv = {0}, . image_start = 0x{1:x08}, . image_stop = 0x{2:x08}\n", rv, pI.image_start, pI.image_stop); return (rv); } //rv = ihex_mem_copy(rs, dst, 0x30000/*8192*/, IHEX_WIDTH_8BIT, IHEX_ORDER_BIGENDIAN); offset = 0; count = (pI.image_stop + 1) - pI.image_start; //pI.image_array = new Byte[count]; //Real solution pI.image_array = new Byte[count + 256]; //Room to fiddle arout rv = intelStuff.ihex_mem_copy_from_offset(rs, ref pI.image_array, offset, count, intelStuff.ihex_width_t.IHEX_WIDTH_8BIT, intelStuff.ihex_byteorder_t.IHEX_ORDER_BIGENDIAN); //Console.Write(" ihex_mem_copy_from_offset() rv = {0}\n", rv); /* testing offset = 0x08; count = 0x10; rv = ihex_mem_copy_from_offset(rs, pI.image_array, offset, count, IHEX_WIDTH_8BIT, IHEX_ORDER_BIGENDIAN); Console.Write("rv = {0}\n", rv); offset = 0x2744; count = 0x100; rv = ihex_mem_copy_from_offset(rs, pI.image_array, offset, count, IHEX_WIDTH_8BIT, IHEX_ORDER_BIGENDIAN); Console.Write("rv = {0}\n", rv); */ /**/ //testing - start pI.image_length = (pI.image_stop + 1) - pI.image_start; // Real pI.image_length -= 5; for (i = 0; i < 10; i++) { pI.image_length++; crc16 = 0xFFFF; //crc16 = dfu_crc16.crc16_compute(pI.image_array, (UInt16)pI.image_length, crc16);// = 0xffff); crc16 = dfu_crc16.calc_crc16(pI.image_array, crc16); Console.Write(" image_length = {0} (0x{1:x}), data[{2:x04}] = 0x{3:x02}, crc16={4:x04} \n", pI.image_length, pI.image_length, pI.image_length - 1, pI.image_array[pI.image_length - 1], crc16); } //testing - start /**/ // real pI.image_length = (pI.image_stop + 1) - pI.image_start; // Real crc16 = 0xFFFF; //crc16 = dfu_crc16.crc16_compute(pI.image_array, (UInt16)pI.image_length, crc16);// = 0xffff); crc16 = dfu_crc16.calc_crc16(pI.image_array, crc16); pI.image_crc = crc16; Console.Write("\n"); Console.Write(" (image_stop - image_start) image_length = {0} (0x{1:x}), data[{2:x04}] = 0x{3:x02}, crc16={4:x04} \n", pI.image_length, pI.image_length, pI.image_length-1, pI.image_array[pI.image_length-1], pI.image_crc); Console.Write("\n"); return (0); }