⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fl_wrt.c

📁 sharp的arm920t 7A400的评估板附带光盘Sharp KEVLH7A400 v0.3b Welcome to the SHARP KEV7A400 Evaluation board
💻 C
📖 第 1 页 / 共 4 页
字号:
        }
        else
        {
            printf("Only %lu sectors of %lu will be %s...\n",
                   no_of_sectors, divroundup(filesize, sector_size), action);
        }
    }
    return TRUE;
}

static void ShowProgress(int sectors_done)
{
    if (!quiet /*&& ((sectors_done & 0xF) == 0)*/)
    {
        printf("%d ", sectors_done);
//        if ((sectors_done & 0xFF) == 0)
        if ((sectors_done & 0xF) == 0)
            putchar('\n');
        fflush(stdout);
    }
}

/*
Wait for the SyncFlash ISM_READY bit to set.
*/
static void sync_wait_for_ready(volatile UNS_16 * sector_ptr)
{
      /* wait for status to change to ready */
      do 
      {
         sync_flash_command(READ_STATUS_COM, sector_ptr);
      } while ( (*sector_ptr & ISM_READY) != ISM_READY);
}

/*
 *       Function: DownloadFileToFlash
 *        Purpose: Write the named file to flash ROM
 *
 *  PreConditions: 
 * 
 *         Params:
 *            Input: filename - the pathname in host form containing the
 *                              PROM image
 *                   base -     the base address of the Flash PROM in memory
 *                   sector -   the sector to start at; a sector is a block
 *                              (e.g. of 65536 bytes) in the PROM
 *
 *        Returns: none.
 * 
 * PostConditions:
 */

static void DownloadFileToFlash()
{
    int sectors_done;
    int endflag = 0,value_read = 0, offset;
    int errors=0;
    int sectors_to_program;
    UNS_16 * sector_ptr;

    if (file_defined)
        openFile();
    
    RomInfo("Programming Flash ROM\n");
    
    needStartSector();
    if (!file_defined)
    {
        needFilename();
        openFile();
        FileInfo();
    }
    
    romsize = no_of_sectors * sector_size;
    
    if (!checkFileSize("written"))
        return;
    
    sectors_to_program = divroundup(filesize, sector_size);
    if (no_of_sectors < (start_sector + sectors_to_program) )
    {
       printf("error: only %ld sectors; require %ld sectors\n",
               no_of_sectors, start_sector + sectors_to_program);
    }
      
    if (!quiet)
        printf("Now programming flash from sector 0x%lx - please wait\n",
               start_sector);
    /* Write the Image file to the FLASH Device in the required sector sizes */
    
    if (sectors_per_segment == 0)
       offset = sector_size * start_sector;
    else
    {
       offset = (start_sector / sectors_per_segment) * segment_spacing;
       offset += (start_sector % sectors_per_segment) * sector_size;
    }

    sectors_done=0;
    endflag = 0;

   /* remove locks from all blocks */
   if (use_sync_interface)
   {
      
      /* unlock all blocks */
      sector_ptr = (UNS_16 *)base_address;
      sync_flash_command(UNLOCK_COM1, sector_ptr);
      *sector_ptr = UNLOCK_COM2;
      
      /* clear status */
      sync_flash_command(CLR_STATUS_COM, sector_ptr);
      sync_wait_for_ready(sector_ptr);
   }
   else
   {
      if (!sector_unlockable)
      {
         cmd_write(base_address, UNLOCK_COM1);
         cmd_write(base_address, UNLOCK_COM2);
      }
   }     
   
   while (!endflag && 
          (sectors_done + start_sector) < no_of_sectors && 
          errors < MAX_ERRORS_ALLOWED)
   {
          int finish_sector;

        
        /* read Image file and write in sector sizes until not enough data
         * to fill sector
         */
        if ((value_read = fread((char*)sector, 1, sector_size, image)) !=
            sector_size)
        {
           if (value_read == 0)
           {
              /* 
              Exactly enough bytes read last time
              Close the external file and return 
              */
              fclose(image);
    
              if (errors==0)
                  printf("\nFlash written and verified successfully\n");
              else if (errors >= MAX_ERRORS_ALLOWED)
                  printf("\nFlash write aborted: too many errors.\n");
              else
                  printf("\nFlash write failed with %i verify errors\n",errors);
              return;
           }
           else
           {
               /* fill remaining sector data with fill pattern (usually 0xff) */
               for (finish_sector = value_read; finish_sector < sector_size ;
                    finish_sector++) {
                   ((char *)sector)[finish_sector] = (char)FILL_PATTERN;
                   endflag++;
               }
           }
		}
        
        /* if there are boot block sectors and this not one of them */
        if ((!top_boot && !bottom_boot) ||
            (bottom_boot && 
               (boot_param_sectors == 0 || 
               sectors_done != 0 ||
               start_sector != 0) 
            ) ||
            (top_boot &&
                (boot_param_sectors == 0 || 
                start_sector + sectors_done != no_of_sectors - 1)
            ) )
        {
           /* Write the image file to the specified device at the
              offset required */
           errors += write_sector(base_address, base_address + offset,
                               sector_size, sector);
   
           sectors_done++;
           ShowProgress(sectors_done);
           /* increment the offset for the address write - increment is the
            * sector size
            */
           if (sectors_per_segment == 0)
              offset += sector_size;
           else
           {
              offset = ((start_sector + sectors_done) / sectors_per_segment) 
                       * segment_spacing;
              offset += ((start_sector + sectors_done) % sectors_per_segment) 
                       * sector_size;
           }
        }
        else /* otherwise, deal with the smaller boot block sectors */
        {
           int i;
           /* note: current_sector will be 0 for bottom boot flash */
           int current_sector = start_sector + sectors_done;
           /* in boot block--write one small block at a time */
           for (i = 0; 
                i < boot_param_sectors && 
                  (( (int)offset - (sector_size * current_sector )) < value_read); 
                i++)
           {
              errors += write_sector(base_address, base_address + offset,
                               boot_param_sector_size, 
                               sector + 
                               (i * boot_param_sector_size / sizeof(sector[0])) );
              offset += boot_param_sector_size;
           }
           sectors_done++;
           ShowProgress(sectors_done);
        }
        
    }

        
    /* Close the external file and return */
    fclose(image);
    
    if (errors==0)
        printf("\nFlash written and verified successfully\n");
    else if (errors >= MAX_ERRORS_ALLOWED)
        printf("\nFlash write aborted: too many errors.\n");
    else
        printf("\nFlash write failed with %i verify errors\n",errors);
}

/*
 *       Function: BlankFlash
 *        Purpose: Write zero sectors to flash ROM
 *
 *  PreConditions: 
 * 
 *         Params:
 *            Input: 
 *
 *        Returns: none.
 * 
 * PostConditions:
 */
static void BlankFlash()
{
    int sectors_done;
    int offset;
    int errors=0;
    int romsize = 0;

    RomInfo("Blanking Flash ROM\n");
    
    needStartSector();
    
    romsize = no_of_sectors * sector_size;
    if (!quiet)
        printf("Now blanking flash from sector 0x%lx - please wait\n",
               start_sector);

    /* blank out sector */
    for (offset = 0; offset < sizeof(sector) ; offset++)
        *(((char *)sector) + offset) = FILL_PATTERN; /* all ones is the erased state */

    /* remove locks from all blocks */
    if (!sector_unlockable)
    {
       cmd_write(base_address, UNLOCK_COM1);
       cmd_write(base_address, UNLOCK_COM2);
    }

    /* Write the Image file to the FLASH Device in the required sector sizes */
    sectors_done=0;
    for (offset = sector_size * start_sector;
         offset < romsize && errors < MAX_ERRORS_ALLOWED; offset += sector_size)
    {

        if (boot_param_sectors == 0 || start_sector != 0)
        {
           /* Write the image file to the specified device at the
              offset required */
           errors += write_sector(base_address, base_address + offset,
                               sector_size, sector);
   
           sectors_done++;
           ShowProgress(sectors_done);
        }
        else
        {
           int i;
           /* in boot block--write one small block at a time */
           for (i = 0; i < boot_param_sectors; i++)
           {
              errors += write_sector(base_address, 
                               base_address + offset + i*boot_param_sector_size,
                               boot_param_sector_size, sector);
           }
        }        
        ++sectors_done;
        ShowProgress(sectors_done);
    }

    if (errors == 0)
        printf("\nFlash written and verified successfully\n");
    else if (errors == MAX_ERRORS_ALLOWED)
        printf("\nFlash write aborted: too many errors.\n");
    else
        printf("\nFlash write failed with %i verify errors\n",errors);
}

/*
 *       Function: VerifyFileInFlash
 *        Purpose: Verify the named file matches the data in flash ROM
 *
 *  PreConditions: 
 * 
 *         Params:
 *            Input: none.
 *
 *        Returns: none.
 * 
 * PostConditions:
 */
static void VerifyFileInFlash()
{
    int sectors_done;
    int endflag = 0,value_read = 0, offset;
    int errors=0;
    
    if (file_defined)
        openFile();
    
    RomInfo("Verifying Flash ROM\n");

    needBaseAddress();
    needStartSector();
    if (!file_defined)
    {
        needFilename();
        openFile();
        FileInfo();
    }

    romsize = no_of_sectors * sector_size;
    
    if (!checkFileSize("verified"))
        return;
    
    if (!quiet)
        printf("Now verifying flash from sector 0x%lx - please wait\n",
               start_sector);

    /* Check the Image file to the FLASH Device in the required sector sizes */
    offset = sector_size * start_sector;
    sectors_done=0;
    endflag = 0;
    while (!endflag && offset < romsize && errors < MAX_ERRORS_ALLOWED)
    {
        int finish_sector;

        /* read Image file and write in sector sizes until not enough data
         * to fill sector
         */
        if ((value_read = fread(sector, 1, sector_size, image)) != sector_size)
        {
            /* fill remaining sector data with fill pattern 0x5a */
            for (finish_sector = value_read;
                 finish_sector < sector_size ; finish_sector++)
            {
                ((char *)sector)[finish_sector] = (char)FILL_PATTERN;
                endflag++;
            }
        }

        /* Verify the image file to the specified device at the
           offset required */
        errors += verify_sector(base_address + offset, sector_size, sector);
        
        sectors_done++;
        ShowProgress(sectors_done);
        
        /* increment the offset for the address write - increment is the
         * sector size
         */
        offset += sector_size;
    }

    /* Close the external file and return */
    fclose(image);
    
    if (errors==0)
        printf("\nFlash verified successfully\n");
    else if (errors == MAX_ERRORS_ALLOWED)
        printf("\nFlash verify aborted: too many errors.\n");
    else
        printf("\nFlash verify failed with %i verify errors\n",errors);
}

int verify_sector(unsigned long start_address, int sector_size, 
                  unsigned int sector_data[])
{
    int verify_errors = 0;
    int i;

    ASSERT(rom_identified);
    
    /* check that the sector size is not greater than the maximum */
    if (sector_size > MAX_SECTOR_SIZE) {
        printf ("Error: Sector size too large\n");
        return 1;
    }
        
    for (i = 0; 
         i < (sector_size/4) && verify_errors < MAX_ERRORS_ALLOWED; 
         i++)
    { 
        if (((volatile int *) start_address)[i] != sector_data[i])
        {
            printf("\nError: Verify Failed at address %lx\n",
                   start_address + (WORD_SIZE*i));
            verify_errors++;
        }
    }

    /* Return the number of cycles required to write the data */
    return verify_errors;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -