Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2959002
  • 博文数量: 685
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5303
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-19 14:17
个人简介

文章分类

全部博文(685)

文章存档

2015年(116)

2014年(569)

分类: LINUX

2014-08-02 15:28:46

原文地址:http://blog.csdn.net/manfeel/article/details/13093931

接上篇文章,AR9331系统与mt7620系统对flash的划分是不一样的,AR系统划分为Flash(可能是作为NAND来处理),而mt7620(mips)系统则划分的比较明确,用的是SPI_FLASH。

在uboot的启动界面上,可以看到这样一些信息:


  1. Please choose the operation:   
  2.    1: Load system code to SDRAM via TFTP.   
  3.    2: Load system code then write to Flash via TFTP.   
  4.    3: Boot system code via Flash (default).  
  5.    4: Entr boot command line interface.  
  6.    7: Load Boot Loader code then write to Flash via Serial.   
  7.    9: Load Boot Loader code then write to Flash via TFTP.   

于是,
  1. grep 'write to Flash via TFTP' -r .  
找到:
  1. ./lib_mips/board.c: printf("   %d: Load system code then write to Flash via TFTP. \n", SEL_LOAD_LINUX_WRITE_FLASH);  
  2. ./lib_mips/board.c: printf("   %d: Load Boot Loader code then write to Flash via TFTP. \n", SEL_LOAD_BOOT_WRITE_FLASH);  
  3. ./lib_mips/board.c:         printf("   \n%d: System Load Linux Kernel then write to Flash via TFTP. \n", SEL_LOAD_LINUX_WRITE_FLASH);  
  4. ./lib_mips/board.c:         printf("   \n%d: System Load Boot Loader then write to Flash via TFTP. (.bin)\n", SEL_LOAD_BOOT_WRITE_FLASH);  
打开board.c一看究竟。



  1. void OperationSelect(void)  
  2. {  
  3.     printf("\nPlease choose the operation: \n");  
  4.     printf("   %d: Load system code then write to Flash via Serial. \n", SEL_LOAD_LINUX_WRITE_FLASH_BY_SERIAL);  
  5.     printf("   %d: Load system code to SDRAM via TFTP. \n", SEL_LOAD_LINUX_SDRAM);  
  6.     printf("   %d: Load system code then write to Flash via TFTP. \n", SEL_LOAD_LINUX_WRITE_FLASH);  
  7.     printf("   %d: Boot system code via Flash (default).\n", SEL_BOOT_FLASH);  
  8. #ifdef RALINK_CMDLINE  
  9.     printf("   %d: Entr boot command line interface.\n", SEL_ENTER_CLI);  
  10. #endif // RALINK_CMDLINE //  
  11.   
  12. #if defined(ASUS_RTN14U)  
  13.     printf("   %d: Load Boot Loader code to SDRAM via Serial. \n", SEL_LOAD_BOOT_SDRAM_VIA_SERIAL);  
  14. #endif    
  15. #ifdef RALINK_UPGRADE_BY_SERIAL  
  16.     printf("   %d: Load Boot Loader code then write to Flash via Serial. \n", SEL_LOAD_BOOT_WRITE_FLASH_BY_SERIAL);  
  17. #endif // RALINK_UPGRADE_BY_SERIAL //  
  18.   
  19. #if defined(ASUS_RTN14U)  
  20.     printf("   %d: Load Boot Loader code to SDRAM via TFTP. \n", SEL_LOAD_BOOT_SDRAM);  
  21. #endif  
  22.     printf("   %d: Load Boot Loader code then write to Flash via TFTP. \n", SEL_LOAD_BOOT_WRITE_FLASH);  
  23. }  
调用层次为:【./cpu/ralink_soc/start.S: la t9, board_init_r】→【board_init_r】→【OperationSelect】



  1.         case '2':  
  2.             printf("   \n%d: System Load Linux Kernel then write to Flash via TFTP. \n", SEL_LOAD_LINUX_WRITE_FLASH);  
  3.             printf(" Warning!! Erase Linux in Flash then burn new one. Are you sure?(Y/N)\n");  
  4.             confirm = getc();  
  5.             if (confirm != 'y' && confirm != 'Y') {  
  6.                 printf(" Operation terminated\n");  
  7.                 break;  
  8.             }  
  9.             tftp_config(SEL_LOAD_LINUX_WRITE_FLASH, argv);  
  10.             argc= 3;  
  11.             setenv("autostart""no");  
  12.             do_tftpb(cmdtp, 0, argc, argv);  
  13.   
  14. #if defined (CFG_ENV_IS_IN_NAND)  
  15.             if (1) {  
  16.                 unsigned int load_address = simple_strtoul(argv[1], NULL, 16);  
  17.                 ranand_erase_write((u8 *)load_address, CFG_KERN_ADDR-CFG_FLASH_BASE, NetBootFileXferSize);  
  18.             }  
  19. #elif defined (CFG_ENV_IS_IN_SPI)  
  20.             if (1) {  
  21.                 unsigned int load_address = simple_strtoul(argv[1], NULL, 16);  
  22.                 raspi_erase_write((u8 *)load_address, CFG_KERN_ADDR-CFG_FLASH_BASE, NetBootFileXferSize);  
  23.             }  
  24. #else //CFG_ENV_IS_IN_FLASH  
  25. #if (defined (ON_BOARD_8M_FLASH_COMPONENT) || defined (ON_BOARD_16M_FLASH_COMPONENT)) && (defined (RT2880_ASIC_BOARD) || defined (RT2880_FPGA_BOARD) || defined (RT3052_MP1))  
  26.             //erase linux  
  27.             if (NetBootFileXferSize <= (0x400000 - (CFG_BOOTLOADER_SIZE + CFG_CONFIG_SIZE + CFG_FACTORY_SIZE))) {  
  28.                 e_end = CFG_KERN_ADDR + NetBootFileXferSize;  
  29.                 if (0 != get_addr_boundary(&e_end))  
  30.                     break;  
  31.                 printf("Erase linux kernel block !!\n");  
  32.                 printf("From 0x%X To 0x%X\n", CFG_KERN_ADDR, e_end);  
  33.                 flash_sect_erase(CFG_KERN_ADDR, e_end);  
  34.             }  
  35.             else if (NetBootFileXferSize <= CFG_KERN_SIZE) {  
  36.                 e_end = PHYS_FLASH_2 + NetBootFileXferSize - (0x400000 - (CFG_BOOTLOADER_SIZE + CFG_CONFIG_SIZE + CFG_FACTORY_SIZE));  
  37.                 if (0 != get_addr_boundary(&e_end))  
  38.                     break;  
  39.                 printf("Erase linux kernel block !!\n");  
  40.                 printf("From 0x%X To 0x%X\n", CFG_KERN_ADDR, CFG_FLASH_BASE+0x3FFFFF);  
  41.                 flash_sect_erase(CFG_KERN_ADDR, CFG_FLASH_BASE+0x3FFFFF);  
  42.                 printf("Erase linux file system block !!\n");  
  43.                 printf("From 0x%X To 0x%X\n", PHYS_FLASH_2, e_end);  
  44.                 flash_sect_erase(PHYS_FLASH_2, e_end);  
  45.             }  
  46. #else  
  47.             if (NetBootFileXferSize <= (bd->bi_flashsize - (CFG_BOOTLOADER_SIZE + CFG_CONFIG_SIZE + CFG_FACTORY_SIZE))) {  
  48.                 e_end = CFG_KERN_ADDR + NetBootFileXferSize;  
  49.                 if (0 != get_addr_boundary(&e_end))  
  50.                     break;  
  51.                 printf("Erase linux kernel block !!\n");  
  52.                 printf("From 0x%X To 0x%X\n", CFG_KERN_ADDR, e_end);  
  53.                 flash_sect_erase(CFG_KERN_ADDR, e_end);  
  54.             }  
  55. #endif  
  56.             else {  
  57.                 printf("***********************************\n");  
  58.                 printf("The Linux Image size is too big !! \n");  
  59.                 printf("***********************************\n");  
  60.                 break;  
  61.             }  
  62.   
  63.             //cp.linux  
  64.             argc = 4;  
  65.             argv[0]= "cp.linux";  
  66.             do_mem_cp(cmdtp, 0, argc, argv);  
  67. #endif //CFG_ENV_IS_IN_FLASH  
  68.   
  69. #ifdef DUAL_IMAGE_SUPPORT  
  70.             /* Don't do anything to the firmware upgraded in Uboot, since it may be used for testing */  
  71.             setenv("Image1Stable""1");  
  72.             saveenv();  
  73. #endif  
  74.   
  75.             //bootm bc050000  
  76.             argc= 2;  
  77.             sprintf(addr_str, "0x%X", CFG_KERN_ADDR);  
  78.             argv[1] = &addr_str[0];  
  79.             do_bootm(cmdtp, 0, argc, argv);              
  80.             break;  

调用的是 raspi_erase_write 方法来对spi flash进行擦除和写入。
阅读(1821) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~