加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

uboot_mt7620对SPI flash操作的分析

发布时间:2020-12-15 17:52:52 所属栏目:百科 来源:网络整理
导读:接上篇文章,AR9331系统与mt7620系统对flash的划分是不一样的,AR系统划分为Flash(可能是作为NAND来处理),而mt7620(mips)系统则划分的比较明确,用的是SPI_FLASH。 在uboot的启动界面上,可以看到这样一些信息: Please choose the operation: 1: Load

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

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

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

于是,
grep 'write to Flash via TFTP' -r .
找到:
./lib_mips/board.c:	printf("   %d: Load system code then write to Flash via TFTP. n",SEL_LOAD_LINUX_WRITE_FLASH);
./lib_mips/board.c:	printf("   %d: Load Boot Loader code then write to Flash via TFTP. n",SEL_LOAD_BOOT_WRITE_FLASH);
./lib_mips/board.c:			printf("   n%d: System Load Linux Kernel then write to Flash via TFTP. n",SEL_LOAD_LINUX_WRITE_FLASH);
./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一看究竟。

void OperationSelect(void)
{
	printf("nPlease choose the operation: n");
	printf("   %d: Load system code then write to Flash via Serial. n",SEL_LOAD_LINUX_WRITE_FLASH_BY_SERIAL);
	printf("   %d: Load system code to SDRAM via TFTP. n",SEL_LOAD_LINUX_SDRAM);
	printf("   %d: Load system code then write to Flash via TFTP. n",SEL_LOAD_LINUX_WRITE_FLASH);
	printf("   %d: Boot system code via Flash (default).n",SEL_BOOT_FLASH);
#ifdef RALINK_CMDLINE
	printf("   %d: Entr boot command line interface.n",SEL_ENTER_CLI);
#endif // RALINK_CMDLINE //

#if defined(ASUS_RTN14U)
	printf("   %d: Load Boot Loader code to SDRAM via Serial. n",SEL_LOAD_BOOT_SDRAM_VIA_SERIAL);
#endif	
#ifdef RALINK_UPGRADE_BY_SERIAL
	printf("   %d: Load Boot Loader code then write to Flash via Serial. n",SEL_LOAD_BOOT_WRITE_FLASH_BY_SERIAL);
#endif // RALINK_UPGRADE_BY_SERIAL //

#if defined(ASUS_RTN14U)
	printf("   %d: Load Boot Loader code to SDRAM via TFTP. n",SEL_LOAD_BOOT_SDRAM);
#endif
	printf("   %d: Load Boot Loader code then write to Flash via TFTP. n",SEL_LOAD_BOOT_WRITE_FLASH);
}
调用层次为:【./cpu/ralink_soc/start.S: la t9,board_init_r】→【board_init_r】→【OperationSelect】

		case '2':
			printf("   n%d: System Load Linux Kernel then write to Flash via TFTP. n",SEL_LOAD_LINUX_WRITE_FLASH);
			printf(" Warning!! Erase Linux in Flash then burn new one. Are you sure?(Y/N)n");
			confirm = getc();
			if (confirm != 'y' && confirm != 'Y') {
				printf(" Operation terminatedn");
				break;
			}
			tftp_config(SEL_LOAD_LINUX_WRITE_FLASH,argv);
			argc= 3;
			setenv("autostart","no");
			do_tftpb(cmdtp,argc,argv);

#if defined (CFG_ENV_IS_IN_NAND)
			if (1) {
				unsigned int load_address = simple_strtoul(argv[1],NULL,16);
				ranand_erase_write((u8 *)load_address,CFG_KERN_ADDR-CFG_FLASH_BASE,NetBootFileXferSize);
			}
#elif defined (CFG_ENV_IS_IN_SPI)
			if (1) {
				unsigned int load_address = simple_strtoul(argv[1],16);
				raspi_erase_write((u8 *)load_address,NetBootFileXferSize);
			}
#else //CFG_ENV_IS_IN_FLASH
#if (defined (ON_BOARD_8M_FLASH_COMPONENT) || defined (ON_BOARD_16M_FLASH_COMPONENT)) && (defined (RT2880_ASIC_BOARD) || defined (RT2880_FPGA_BOARD) || defined (RT3052_MP1))
			//erase linux
			if (NetBootFileXferSize <= (0x400000 - (CFG_BOOTLOADER_SIZE + CFG_CONFIG_SIZE + CFG_FACTORY_SIZE))) {
				e_end = CFG_KERN_ADDR + NetBootFileXferSize;
				if (0 != get_addr_boundary(&e_end))
					break;
				printf("Erase linux kernel block !!n");
				printf("From 0x%X To 0x%Xn",CFG_KERN_ADDR,e_end);
				flash_sect_erase(CFG_KERN_ADDR,e_end);
			}
			else if (NetBootFileXferSize <= CFG_KERN_SIZE) {
				e_end = PHYS_FLASH_2 + NetBootFileXferSize - (0x400000 - (CFG_BOOTLOADER_SIZE + CFG_CONFIG_SIZE + CFG_FACTORY_SIZE));
				if (0 != get_addr_boundary(&e_end))
					break;
				printf("Erase linux kernel block !!n");
				printf("From 0x%X To 0x%Xn",CFG_FLASH_BASE+0x3FFFFF);
				flash_sect_erase(CFG_KERN_ADDR,CFG_FLASH_BASE+0x3FFFFF);
				printf("Erase linux file system block !!n");
				printf("From 0x%X To 0x%Xn",PHYS_FLASH_2,e_end);
				flash_sect_erase(PHYS_FLASH_2,e_end);
			}
#else
			if (NetBootFileXferSize <= (bd->bi_flashsize - (CFG_BOOTLOADER_SIZE + CFG_CONFIG_SIZE + CFG_FACTORY_SIZE))) {
				e_end = CFG_KERN_ADDR + NetBootFileXferSize;
				if (0 != get_addr_boundary(&e_end))
					break;
				printf("Erase linux kernel block !!n");
				printf("From 0x%X To 0x%Xn",e_end);
			}
#endif
			else {
				printf("***********************************n");
				printf("The Linux Image size is too big !! n");
				printf("***********************************n");
				break;
			}

			//cp.linux
			argc = 4;
			argv[0]= "cp.linux";
			do_mem_cp(cmdtp,argv);
#endif //CFG_ENV_IS_IN_FLASH

#ifdef DUAL_IMAGE_SUPPORT
			/* Don't do anything to the firmware upgraded in Uboot,since it may be used for testing */
			setenv("Image1Stable","1");
			saveenv();
#endif

			//bootm bc050000
			argc= 2;
			sprintf(addr_str,"0x%X",CFG_KERN_ADDR);
			argv[1] = &addr_str[0];
			do_bootm(cmdtp,argv);            
			break;
调用的是 raspi_erase_write 方法来对spi flash进行擦除和写入。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读