Esempio n. 1
0
        /// <summary>
        /// dump flash using the given dumper, print time taken after dump finished
        /// </summary>
        /// <param name="d">the dumper to dump with</param>
        /// <param name="startAddress">the start address</param>
        /// <param name="endAddress">the end address</param>
        /// <param name="blockSize">the block size for dumping</param>
        /// <param name="output">the output memory stream</param>
        static void DumpTimed(Dumper d, long startAddress, long endAddress, int blockSize, out MemoryStream output)
        {
            //prepare output stream first
            output = new MemoryStream();

            //start timer
            Stopwatch sw = new Stopwatch();

            sw.Restart();

            // dump
            int errorCount = d.DumpAdr(output, startAddress, endAddress, blockSize);

            //stop timer and print time taken
            sw.Stop();
            Console.WriteLine($"finished dumping {output.Length} bytes after {Math.Floor(sw.Elapsed.TotalSeconds)} seconds with {errorCount} errors");

            //warn if there were errors while dumping
            if (errorCount != 0)
            {
                Console.WriteLine("!! Warning: there were errors while dumping");
            }
        }
Esempio n. 2
0
        static void WriteUI()
        {
            #region User interface
            //show user interface
            SerialUserIF(out string port);
            UploadUserIF(out long targetAddress, out string filePath, out bool shouldVerify, out bool shouldVerboseLog);

            //print infos and make user confirm
            long fileSize = new FileInfo(filePath).Length;
            Console.Clear();
            Console.WriteLine($@"
Target Device: {port}

File: {filePath}
File Size: {fileSize}
Upload Target Address: 0x{ToHex(targetAddress)}
Upload End Address:    0x{ToHex(targetAddress + fileSize)}

Verify Data: {(shouldVerify ? "YES" : "NO")}
Verbose Log: {(shouldVerboseLog ? "YES" : "NO")}

Press <ENTER> to start write");
            Console.ReadLine();

            // double- confirm if any writes are outside of RAM
            if (targetAddress < BRNBootConstants.START_OF_RAM ||
                targetAddress > BRNBootConstants.END_OF_RAM ||
                fileSize > BRNBootConstants.RAM_SIZE)
            {
                Console.WriteLine($@"
!! WARNING !!
The Address you entered results in writes OUTSIDE of RAM
RAM Start: {ToHex(BRNBootConstants.START_OF_RAM)}
RAM End: {ToHex(BRNBootConstants.END_OF_RAM)}
RAM Size: {BRNBootConstants.RAM_SIZE}

Press <ENTER> 3x to write anyways");
                Console.ReadLine();
                Console.ReadLine();
                Console.ReadLine();
            }
            #endregion

            //initailize memory writer and connect
            Console.WriteLine("initialize writer");
            CrappyUpload up = new CrappyUpload
            {
                EnableDebugPrints = shouldVerboseLog
            };

            Console.WriteLine($"connecting to target device on {port}...");
            up.Open(port);

            // open file
            using (FileStream file = File.OpenRead(filePath))
            {
                // start upload timer
                Console.WriteLine("Start memory write...");
                Stopwatch sw = new Stopwatch();
                sw.Restart();

                // write to device
                up.Write(file, targetAddress);

                //stop timer and print time taken
                sw.Stop();
                up.Close();
                Console.WriteLine($"Finished writing to device after {Math.Floor(sw.Elapsed.TotalSeconds)} seconds");

                // verify what was actually written if enabled
                if (shouldVerify)
                {
                    // initialize dumper and connect
                    Console.WriteLine("Verifying written data...");
                    Dumper d = new Dumper
                    {
                        EnableDebugPrints = shouldVerboseLog
                    };

                    Console.WriteLine($"connecting to target device on {port}...");
                    d.Open(port);

                    // dump the memory
                    Console.WriteLine("Dumping memory...");
                    DumpTimed(d, targetAddress, targetAddress + fileSize, 10000, out MemoryStream verify);
                    d.Close();

                    // compare streams
                    if (CheckStreamsEqual(file, verify))
                    {
                        Console.WriteLine("Verification Success");
                    }
                    else
                    {
                        Console.WriteLine("!! Verification failed!");
                    }
                }
            }
        }
Esempio n. 3
0
        static void DumperUI()
        {
            #region user interface
            //show user interface
            SerialUserIF(out string port);
            DumperUserIF(out long startAddress, out long endAddress, out int blockSize, out bool shouldVerifyDump, out bool shouldVerboseLog);

            //print infos and make user confirm
            long dumpLenghtBytes = endAddress - startAddress;
            Console.Clear();
            Console.WriteLine($@"
Target Device: {port}

Will dump {dumpLenghtBytes} bytes
Start Address: 0x{ToHex(startAddress)}
End Address  : 0x{ToHex(endAddress)}
Block size   : {blockSize}

Dump verification is {(shouldVerifyDump ? "ON" : "OFF")}
Verbose logging is {(shouldVerboseLog ? "ON" : "OFF")}
Dumping will take {(dumpLenghtBytes / blockSize) * (shouldVerifyDump ? 2 : 1)} calls

Press <ENTER> to start dumping");
            Console.ReadLine();
            #endregion

            // initialize dumper and connect
            Console.WriteLine("initialize dumper...");
            Dumper d = new Dumper
            {
                EnableDebugPrints = shouldVerboseLog
            };

            Console.WriteLine($"connecting to target device on {port}...");
            d.Open(port);

            // dump the memory
            Console.WriteLine("Dumping memory...");
            DumpTimed(d, startAddress, endAddress, blockSize, out MemoryStream dump);

            // verification, if enabled
            if (shouldVerifyDump)
            {
                // dump memory a second time
                Console.WriteLine("Dumping memory, verification pass...");
                DumpTimed(d, startAddress, endAddress, blockSize, out MemoryStream verify);

                // check both dumps are equal, byte- by- byte
                if (!CheckStreamsEqual(dump, verify))
                {
                    Console.WriteLine("!! Dump verification failed!");
                }
            }

            // write dump to file
            Console.WriteLine("Writing dump to file...");
            Stopwatch sw = new Stopwatch();
            sw.Restart();

            // write to file
            using (MemoryStream source = dump)
                using (FileStream target = File.Create("dump.bin"))
                {
                    source.Seek(0, SeekOrigin.Begin);
                    source.CopyTo(target);
                }

            //stop timer and print time taken
            sw.Stop();
            Console.WriteLine($"Finished writing to file after {Math.Floor(sw.Elapsed.TotalSeconds)} seconds");
        }