Esempio n. 1
0
        //
        //         Program by performing sector erases.
        //
        public virtual double _scan_pages_for_same(Action <double> progress_cb = null)
        {
            progress_cb = progress_cb ?? FlashBuilderConsts._stub_progress;
            double progress   = 0;
            var    count      = 0;
            var    same_count = 0;

            foreach (FlashBuilderConsts.flash_page page in this.page_list)
            {
                // Read page data if unknown - after this page.same will be True or False
                if (page.same == null)
                {
                    var data = this.flash.target.readBlockMemoryUnaligned8(page.addr, (UInt32)page.data.Count);
                    page.same = FlashBuilderConsts._same(page.data, data);
                    progress += page.getVerifyWeight();
                    count    += 1;
                    if ((bool)page.same)
                    {
                        same_count += 1;
                    }
                    // Update progress
                    progress_cb((float)(progress) / (float)(this.page_erase_weight));
                }
            }
            return(progress);
        }
Esempio n. 2
0
        //
        //         Estimate how many pages are the same.
        //
        //         Quickly estimate how many pages are the same.  These estimates are used
        //         by page_erase_program so it is recommended to call this before beginning programming
        //         This is done automatically by smart_program.
        //
        public virtual Tuple <UInt32, double> _compute_page_erase_pages_and_weight_sector_read()
        {
            // Quickly estimate how many pages are the same
            UInt32 page_erase_count  = 0;
            double page_erase_weight = 0;

            foreach (var page in this.page_list)
            {
                // Analyze pages that haven't been analyzed yet
                if (page.same == null)
                {
                    UInt32      size      = Math.Min(FlashBuilderConsts.PAGE_ESTIMATE_SIZE, (UInt32)page.data.Count);
                    List <byte> data      = this.flash.target.readBlockMemoryUnaligned8(page.addr, size);
                    bool        page_same = FlashBuilderConsts._same(data, page.data.GetRange(0, (int)size));
                    if (page_same == false)
                    {
                        page.same = false;
                    }
                }
            }
            // Put together page and time estimate
            foreach (var page in this.page_list)
            {
                if (page.same == false)
                {
                    page_erase_count  += 1;
                    page_erase_weight += page.getEraseProgramWeight();
                }
                else if (page.same == null)
                {
                    // Page is probably the same but must be read to confirm
                    page_erase_weight += page.getVerifyWeight();
                }
                else if (page.same == true)
                {
                    // Page is confirmed to be the same so no programming weight
                }
            }
            this.page_erase_count  = page_erase_count;
            this.page_erase_weight = page_erase_weight;
            return(Tuple.Create(page_erase_count, page_erase_weight));
        }
Esempio n. 3
0
        //
        //         Program by performing sector erases.
        //
        public virtual byte _page_erase_program(Action <double> progress_cb = null)
        {
            progress_cb = progress_cb ?? FlashBuilderConsts._stub_progress;
            UInt32 actual_page_erase_count  = 0;
            double actual_page_erase_weight = 0;
            double progress = 0;

            progress_cb(0.0);
            foreach (var page in this.page_list)
            {
                // If the page is not the same
                if (page.same == false)
                {
                    progress += page.getEraseProgramWeight();
                }
                // Read page data if unknown - after this page.same will be True or False
                if (page.same == null)
                {
                    var data = this.flash.target.readBlockMemoryUnaligned8(page.addr, (UInt32)page.data.Count);
                    page.same = FlashBuilderConsts._same(page.data, data);
                    progress += page.getVerifyWeight();
                }
                // Program page if not the same
                if (page.same == false)
                {
                    this.flash.erasePage(page.addr);
                    this.flash.programPage(page.addr, page.data);
                    actual_page_erase_count  += 1;
                    actual_page_erase_weight += page.getEraseProgramWeight();
                }
                // Update progress
                if (this.page_erase_weight > 0)
                {
                    progress_cb((float)(progress) / (float)(this.page_erase_weight));
                }
            }
            progress_cb(1.0);
            Trace.TraceInformation("Estimated page erase count: {0}", this.page_erase_count);
            Trace.TraceInformation("Actual page erase count: {0}", actual_page_erase_count);
            return(FlashBuilder.FLASH_PAGE_ERASE);
        }
Esempio n. 4
0
        //
        //         Compute the number of erased pages.
        //
        //         Determine how many pages in the new data are already erased.
        //
        public virtual Tuple <UInt32, double> _compute_chip_erase_pages_and_weight()
        {
            UInt32 chip_erase_count  = 0;
            double chip_erase_weight = 0;

            chip_erase_weight += (double)this.flash.getFlashInfo().erase_weight;
            foreach (var page in this.page_list)
            {
                if (page.erased == null)
                {
                    page.erased = FlashBuilderConsts._erased(page.data);
                }
                if (!(bool)page.erased)
                {
                    chip_erase_count  += 1;
                    chip_erase_weight += page.getProgramWeight();
                }
            }
            this.chip_erase_count  = chip_erase_count;
            this.chip_erase_weight = chip_erase_weight;
            return(Tuple.Create(chip_erase_count, chip_erase_weight));
        }