public override bool WriteU8(UInt32 Addr, UInt32 Count, byte[] data) { GCHandle addr_hndl = GCHandle.Alloc(data, GCHandleType.Pinned); IntPtr addr_data = addr_hndl.AddrOfPinnedObject(); bool status = (JLinkARM.JLINKARM_WriteMem(Addr, Count, addr_data) >= 0) ? true : false; addr_hndl.Free(); return(status); }
public bool FlashWrite(UInt32 Addr, UInt32 Size, byte[] Data) { bool status = false; bool fullflasharray = false; Int32 Size_Left = (Int32)Size; if (IsInited & Data.Length >= Size & Size > 0) { Int32 len = 0; Int32 len_actual = 0; UInt32 offset = 0; UInt32 offset_flash = 0; fullflasharray = Data.Length == FlashSize; CallbackLog?.Invoke(String.Format("Flash Write at 0x{0:X}, size {1}", Addr, Size)); if (Size > FlashSize) { CallbackError?.Invoke(String.Format("Error! Size {0} > {1}", Size, FlashSize)); return(status); } status = true; TimeSpan time = StopwatchUtil.Time(() => { while (Size_Left > 0 & status) { len = Size_Left; if (len > AmebaA_Addresses.Size) { len = (Int32)AmebaA_Addresses.Size; } offset_flash = Addr + offset; len_actual = len; if ((len_actual & 0xff) > 0) { len_actual = (Int32)((len_actual & 0xffffff00) + 0x100); } byte[] Data_RAW = new byte[len_actual]; if (fullflasharray) { Array.Copy(Data, offset_flash, Data_RAW, 0, len_actual); } else { Array.Copy(Data, offset, Data_RAW, 0, len_actual); } GCHandle Data_RAW_hndl = GCHandle.Alloc(Data_RAW, GCHandleType.Pinned); IntPtr Data_RAW_Ptr = Data_RAW_hndl.AddrOfPinnedObject(); JLinkARM.JLINKARM_WriteMem(AmebaA_Addresses.Addr + 0x20, (UInt32)len_actual, Data_RAW_Ptr); Data_RAW_hndl.Free(); //WriteU8(RTL8195_Addresses.Addr + 0x20, (UInt32)len_actual, Data_RAW); UInt32 len_check = offset_flash; while (len_check < (offset_flash + len_actual /*len*/) & status) { UInt32 sector = (UInt32)len_check /*len_actual*/ / AmebaA_Addresses.FlashSectorSize; //CallbackLog?.Invoke(String.Format("Erase Sector {0}, Offset {0:X}...", sector, len_check)); if (!EraseSector(sector)) { CallbackError?.Invoke(String.Format("Erase Block Error! Sector {0}", sector)); status = false; break; } len_check += AmebaA_Addresses.FlashSectorSize; } if (!StartWriteBlock(offset_flash, (UInt32)len_actual /*len*/) & status) { CallbackError?.Invoke(String.Format("Write Block Error! Offset {0:X} Len {1}", offset_flash, len_actual /*len*/)); status = false; break; } if (VerifyFlashWrite & status) { if (!StartVerifyBlock(offset_flash, (UInt32)len_actual /*len*/)) { CallbackError?.Invoke(String.Format("Verify Block Error! Offset {0:X} Len {1}", offset_flash, len_actual /*len*/)); status = false; break; } } offset += (UInt32)len_actual; // len; Size_Left -= len_actual; // len; } }); CallbackLog?.Invoke(String.Format("Time {0:0.00} ms, Speed {1:0.00} KB/s", time.TotalMilliseconds, (double)((double)Size / time.TotalMilliseconds))); } if (status) { CallbackLog?.Invoke("Full Flash Write Done!"); } return(status); }
public bool FlashWrite(UInt32 Addr, UInt32 Size, byte[] Data) { bool status = false; Int32 Size_Left = (Int32)Size; Int32 len_actual = 0; UInt32 offset = 0; if (IsInited & Data.Length >= Size & Size > 0) { CallbackLog?.Invoke(String.Format("Flash Write at 0x{0:X}, size {1}", Addr, Size)); status = true; TimeSpan time = StopwatchUtil.Time(() => { //JLinkARM.JLINKARM_SetBP(0, AmebaZ_Addresses.FlasherBreakpoint); JLinkARM.JLINKARM_SetBPEx(AmebaZ_Addresses.FlasherBreakpoint, (0x000000F0 | 0xFFFFFF00 | 0x1)); //Thread.Sleep(25); //JLinkARM.JLINKARM_GoEx(0x8000_0000, 1); while (status) { len_actual = Size_Left; if (len_actual > AmebaZ_Addresses.FlasherDataLen) { len_actual = (Int32)AmebaZ_Addresses.FlasherDataLen; } int halted = JLinkARM.JLINKARM_WaitForHalt(2000); if (halted == 0) { CallbackError?.Invoke(String.Format("Wait for flasher Timeout!")); status = false; break; } else if (halted < 0) { CallbackError?.Invoke(String.Format("SoC Halt Error!")); status = false; break; } byte[] Data_RAW = new byte[len_actual]; Array.Copy(Data, offset, Data_RAW, 0, len_actual); GCHandle Data_RAW_hndl = GCHandle.Alloc(Data_RAW, GCHandleType.Pinned); IntPtr Data_RAW_Ptr = Data_RAW_hndl.AddrOfPinnedObject(); JLinkARM.JLINKARM_WriteMem(AmebaZ_Addresses.FlasherData, (UInt32)len_actual, Data_RAW_Ptr); Data_RAW_hndl.Free(); WriteU32(AmebaZ_Addresses.FlasherWriteAddr, Addr + offset); WriteU32(AmebaZ_Addresses.FlasherBlockWriteSize, (UInt32)len_actual); // старт записи Size_Left -= len_actual; offset += (UInt32)len_actual; if (Size_Left == 0) { break; } //JLinkARM.JLINKARM_Go(); JLinkARM.JLINKARM_GoEx(0x8000_0000, 1); } }); WriteU8(AmebaZ_Addresses.FlasherSetComplete, 0x01); // выходим из загрузчика //JLinkARM.JLINKARM_Go(); JLinkARM.JLINKARM_GoEx(0x8000_0000, 1); CallbackLog?.Invoke(String.Format("Time {0:0.00} ms, Speed {1:0.00} KB/s", time.TotalMilliseconds, (double)((double)Size / time.TotalMilliseconds))); } return(status); }