Example #1
0
        public void DoKernelDump()
        {
            int       progress    = 5;
            const int maxProgress = 80;

            SetProgress(progress, maxProgress);
            SetStatus(Resources.DumpingKernel);

            var kernel = fel.ReadFlash(kernel_base_f, sector_size * 0x20,
                                       delegate(Fel.CurrentAction action, string command)
            {
                switch (action)
                {
                case Fel.CurrentAction.RunningCommand:
                    SetStatus(Resources.ExecutingCommand + " " + command);
                    break;

                case Fel.CurrentAction.ReadingMemory:
                    SetStatus(Resources.DumpingKernel);
                    break;
                }
                progress++;
                SetProgress(progress, maxProgress);
            }
                                       );

            var size = CalKernelSize(kernel);

            if (size == 0 || size > kernel_max_size)
            {
                throw new Exception(Resources.InvalidKernelSize + " " + size);
            }
            if (kernel.Length > size)
            {
                var sm_kernel = new byte[size];
                Array.Copy(kernel, 0, sm_kernel, 0, size);
                kernel = sm_kernel;
            }

            SetProgress(maxProgress, maxProgress);
            SetStatus(Resources.Done);

            var md5  = System.Security.Cryptography.MD5.Create();
            var hash = BitConverter.ToString(md5.ComputeHash(kernel)).Replace("-", "").ToLower();

            if (!correctKernels.Contains(hash))
            {
                if (MessageBox.Show(Resources.MD5Failed + " " + hash + "\r\n" + Resources.MD5Failed2 + "\r\n" + Resources.DoYouWantToContinue, Resources.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
                    == DialogResult.No)
                {
                    DialogResult = System.Windows.Forms.DialogResult.Abort;
                    return;
                }
            }

            Directory.CreateDirectory(Path.GetDirectoryName(KernelDump));
            File.WriteAllBytes(KernelDump, kernel);
        }
Example #2
0
        public byte[] ReadFlash(Fel fel, byte[] fes, byte[] uboot, UInt32 address, UInt32 length, string what = "NAND")
        {
            var size = length;

            size = (size + Fel.sector_size - 1) / Fel.sector_size;
            size = size * Fel.sector_size;

            long maxProgress = (size / 65536), progress = 0;

            var r = fel.ReadFlash(address, length,
                                  delegate(Fel.CurrentAction action, string command)
            {
                switch (action)
                {
                case Fel.CurrentAction.ReadingMemory:
                    SetStatus("Reading " + what);
                    break;
                }
                progress++;
                SetProgress?.Invoke(Math.Min(progress, maxProgress), maxProgress);
            }
                                  );

            return(r);
        }
Example #3
0
        public void WriteFlash(Fel fel, byte[] fes, byte[] uboot, UInt32 address, byte[] data, bool verify = true, string what = "NAND")
        {
            var size = data.LongLength;

            size = (size + Fel.sector_size - 1) / Fel.sector_size;
            size = size * Fel.sector_size;
            if (data.LongLength != size)
            {
                var newData = new byte[size];
                Array.Copy(data, newData, data.Length);
                data = newData;
            }


            long maxProgress = (size / 65536) * (verify ? 2 : 1), progress = 0;

            // upload kernel through fel
            fel.WriteFlash(address, data,
                           delegate(Fel.CurrentAction action, string command)
            {
                switch (action)
                {
                case Fel.CurrentAction.WritingMemory:
                    SetStatus?.Invoke("Writing " + what);
                    break;
                }
                progress++;
                SetProgress?.Invoke(Math.Min(progress, maxProgress), maxProgress);
            }
                           );

            if (verify)
            {
                var r = fel.ReadFlash((UInt32)Fel.kernel_base_f, (UInt32)data.LongLength,
                                      delegate(Fel.CurrentAction action, string command)
                {
                    switch (action)
                    {
                    case Fel.CurrentAction.ReadingMemory:
                        SetStatus("Reading " + what);
                        break;
                    }
                    progress++;
                    SetProgress?.Invoke(Math.Min(progress, maxProgress), maxProgress);
                }
                                      );

                if (!data.SequenceEqual(r))
                {
                    throw new Exception("Verify failed for " + what);
                }
            }
        }