Esempio n. 1
0
        static public void UpdateChecksum(string filename, bool autoFixFooter)
        {
            csumArea = new csum_area_t[16];
            for (int i = 0; i < csumArea.Length; i++)
            {
                csumArea[i] = new csum_area_t();
            }

            T7FileHeader t7InfoHeader = new T7FileHeader();

            t7InfoHeader.init(filename, autoFixFooter);

            int  sramOffset           = t7InfoHeader.getSramOffset();
            int  fwLength             = t7InfoHeader.getFWLength();
            int  calculatedFWChecksum = calculateFWChecksum(filename, sramOffset);
            uint calculatedF2Checksum = calculateF2Checksum(filename, 0, fwLength);
            int  calculatedFBChecksum = calculateFBChecksum(filename, 0, fwLength);

            logger.Debug("calculatedF2Checksum = " + calculatedF2Checksum.ToString("X8"));
            logger.Debug("calculatedFBChecksum = " + calculatedFBChecksum.ToString("X8"));
            logger.Debug("calculatedFWChecksum = " + calculatedFWChecksum.ToString("X8"));

            updateChecksum(filename, t7InfoHeader, calculatedFWChecksum, calculatedF2Checksum, calculatedFBChecksum, sramOffset);
        }
Esempio n. 2
0
        static public ChecksumResult VerifyChecksum(string filename, bool autocorrect, bool autofixFooter, ChecksumDelegate.ChecksumUpdate delegateShouldUpdate)
        {
            csumArea = new csum_area_t[16];
            for (int i = 0; i < csumArea.Length; i++)
            {
                csumArea[i] = new csum_area_t();
            }

            ChecksumResult result = ChecksumResult.Ok;

            T7FileHeader t7InfoHeader = new T7FileHeader();

            t7InfoHeader.init(filename, autofixFooter);

            int  sramOffset           = t7InfoHeader.getSramOffset();
            int  fwLength             = t7InfoHeader.getFWLength();
            int  calculatedFWChecksum = calculateFWChecksum(filename, sramOffset);
            uint calculatedF2Checksum = calculateF2Checksum(filename, 0, fwLength);
            int  calculatedFBChecksum = calculateFBChecksum(filename, 0, fwLength);

            int readF2checksum = t7InfoHeader.getChecksumF2();
            int readFBchecksum = t7InfoHeader.getChecksumFB();

            if (readF2checksum != 0)
            {
                if (t7InfoHeader.getChecksumF2() != (int)calculatedF2Checksum)
                {
                    result = ChecksumResult.ChecksumF2Failed;
                }
            }
            if (t7InfoHeader.getChecksumFB() != calculatedFBChecksum)
            {
                result = ChecksumResult.ChecksumFBFailed;
            }
            if (getFWChecksum(filename, sramOffset) != calculatedFWChecksum)
            {
                result = ChecksumResult.ChecksumFWFailed;
            }

            if (result != ChecksumResult.Ok)
            {
                logger.Debug("Checksum was invalid, should be updated!");
                logger.Debug("calculatedF2Checksum = " + calculatedF2Checksum.ToString("X8") + " readF2checksum = " + readF2checksum.ToString("X8"));
                logger.Debug("calculatedFBChecksum = " + calculatedFBChecksum.ToString("X8") + " readFBchecksum = " + readFBchecksum.ToString("X8"));
                logger.Debug("calculatedFWChecksum = " + calculatedFWChecksum.ToString("X8") + " getFWChecksum = " + getFWChecksum(filename, sramOffset).ToString("X8"));

                if (autocorrect)
                {
                    result = updateChecksum(filename, t7InfoHeader, calculatedFWChecksum, calculatedF2Checksum, calculatedFBChecksum, sramOffset);
                }
                else
                {
                    if (delegateShouldUpdate(null, null, null))
                    {
                        result = updateChecksum(filename, t7InfoHeader, calculatedFWChecksum, calculatedF2Checksum, calculatedFBChecksum, sramOffset);
                    }
                }
            }

            return(result);
        }