From 2e07a79d4ddd78bc0ac06bf87c9e86979cce414b Mon Sep 17 00:00:00 2001 From: Alexey 'Cluster' Avdyukhin Date: Mon, 16 Jan 2017 13:24:26 +0300 Subject: Code cleanup --- FelLib/Fel.cs | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'FelLib') diff --git a/FelLib/Fel.cs b/FelLib/Fel.cs index 549e71b8..ba618d6d 100644 --- a/FelLib/Fel.cs +++ b/FelLib/Fel.cs @@ -11,7 +11,7 @@ namespace com.clusterrr.FelLib public class Fel { public byte[] Fes1Bin; - public byte[] UBootBin; + byte[] uBootBin; public enum CurrentAction { RunningCommand, ReadingMemory, WritingMemory } public delegate void OnFelProgress(CurrentAction action, string command); @@ -25,20 +25,40 @@ namespace com.clusterrr.FelLib UInt16 vid, pid; bool DramInitDone = false; - const UInt32 cmdOffset = 0x604FF; - const UInt32 fes1_base_m = 0x2000; - const UInt32 dram_base = 0x40000000; - const UInt32 flash_mem_base = 0x43800000; - const UInt32 flash_mem_size = 0x20; - const UInt32 uboot_base_m = 0x47000000u; - const UInt32 sector_size = 0x20000; - const UInt32 uboot_base_f = 0x100000; - const UInt32 kernel_base_f = (sector_size * 0x30); - const UInt32 kernel_base_m = flash_mem_base; - const UInt32 kernel_max_size = (uboot_base_m - flash_mem_base); - const UInt32 kernel_max_flash_size = (sector_size * 0x20); + int cmdOffset = -1; + public const UInt32 fes1_base_m = 0x2000; + public const UInt32 dram_base = 0x40000000; + public const UInt32 flash_mem_base = 0x43800000; + public const UInt32 flash_mem_size = 0x20; + public const UInt32 uboot_base_m = 0x47000000u; + public const UInt32 sector_size = 0x20000; + public const UInt32 uboot_base_f = 0x100000; + public const UInt32 kernel_base_f = (sector_size * 0x30); + public const UInt32 kernel_base_m = flash_mem_base; + public const UInt32 kernel_max_size = (uboot_base_m - flash_mem_base); + public const UInt32 kernel_max_flash_size = (sector_size * 0x20); const string fastboot = "fastboot_test"; + public byte[] UBootBin + { + get + { + return uBootBin; + } + + set + { + uBootBin = value; + var prefix = "bootcmd="; + for (int i = 0; i < uBootBin.Length - prefix.Length; i++) + if (Encoding.ASCII.GetString(uBootBin, i, prefix.Length) == prefix) + { + cmdOffset = i + prefix.Length; + break; + } + } + } + public static bool DeviceExists(UInt16 vid, UInt16 pid) { var fel = new Fel(); @@ -82,14 +102,14 @@ namespace com.clusterrr.FelLib { inEndp = pipe.Address; #if DEBUG - DebugLog("IN endpoint found: "+ inEndp); + DebugLog("IN endpoint found: " + inEndp); #endif } else { outEndp = pipe.Address; #if DEBUG - DebugLog("Out endpoint found: "+outEndp); + DebugLog("Out endpoint found: " + outEndp); #endif } } @@ -329,7 +349,8 @@ namespace com.clusterrr.FelLib public void RunUbootCmd(string command, bool noreturn = false, OnFelProgress callback = null) { - if (callback != null) callback(CurrentAction.RunningCommand, command); + callback?.Invoke(CurrentAction.RunningCommand, command); + if (cmdOffset < 0) throw new Exception("Invalid Unoot binary, command variable not found"); const UInt32 testSize = 0x20; if (UBootBin == null || UBootBin.Length < testSize) throw new FelException("Can't init Uboot, incorrect Uboot binary"); -- cgit v1.2.3