首页 > 技术文章 > mt7620 uboot

sammei 2014-08-25 16:30 原文

 

我本机装的是64位Ubuntu, SDK 里提供的 buildroot-gcc342 是32位的,无法直接运行,需要先安装 gcc-multilib.

sudo apt-get install gcc-multilib

 

之前一直做 ARM 开发, 对这里 MIPS 首先要了解一点它的 MMU 内存映射关系 。 在 MIPS 中, 0x8000,0000 ~ 0x9fff,ffff 和 0xa000,0000 ~ 0xbfff,ffff 这两段逻辑地址都直接映射 0x0000,0000 ~ 0x1fff,ffff 这段物理地址。 区别是 0x8000,0000 ~ 0x9fff,ffff 的访问是 Uncached, 而 0xa000,0000 ~ 0xbfff,ffff 的访问则经过了cached。 所以在查看 mt7620 代码里操作寄存器时, 会看到 0xb000,0000 以上的地直空间, 其对应的就是 0x1000,0000 。

 

u-boot 配置

make menuconfig

 

配置后于 uboot 根目录成生 .config 。 下面记录我阅读代码时关心的几个地方:

1. CFG_ENV_IS_IN_SPI

`make menuconfig` 时 Flash Type 选择了 SPI, 则在 .config 中有: `ON_BOARD_SPI_FLASH_COMPONENT=y`

.config 被 config.mk 包含进来。  config.mk 中有:

ifeq ($(ON_BOARD_SPI_FLASH_COMPONENT),y)
CFG_ENV_IS := IN_SPI
else
CFG_ENV_IS := IN_FLASH
endif
endif
CPPFLAGS += -DCFG_ENV_IS_$(CFG_ENV_IS)

CPPFLAGS 使得代码在预编译时 CFG_ENV_IS_IN_SPI 被宏定义。

 

2. uboot.bin 生成过程

make -n 看看生成 uboot.bin 的过程, 关键地方可以简化为:

mipsel-linux-ld -Bstatic -T board/rt2880/u-boot.lds -Ttext 0xBC000000 \
    cpu/ralink_soc/start.o \
    --start-group \
        lib_generic/libgeneric.a \
        board/rt2880/librt2880.a \
        cpu/ralink_soc/libralink_soc.a \
        lib_mips/libmips.a \
        net/libnet.a \
        drivers/libdrivers.a \
        common/libcommon.a \
    --end-group \
        -Map u-boot.map -o u-boot

mipsel-linux-objcopy --gap-fill=0xff -O binary u-boot uboot.bin

 注意这里的 -Ttext 0xBC000000 , 它将 uboot 整体运行时地址提到了 0xBC000000

3. RALINK_SPI_UPGRADE_CHECK

RALINK_SPI_UPGRADE_CHECK 默认在 config.mk 里打开, 用于在 spi_flash.c 中的写操作完成时, 再读出来比较, 以保证写入完全正确。

 

4. RALINK_UPGRADE_BY_SERIAL

 

串口下载, 烧写。

 

5. 网口初始化 LANWANPartition() 

make menuconfig 时选择了 LLLLW, 则在编译时打开了 RALINK_EV_BOARD_PVLAN 宏。  

先把五个口都设置成 security mode, 然后设置 PVID (Port-base VLAN ID), LAN口的PVID=1, WAN口的PVID=2.  

Port VLAN 是实现 VLAN 的技术手段之一, 将 switch 的商品进行VLAN 划分,前四个 LAN 都划分为VLAN1, WAN口划分到VLAN2。 同一个VLAN ID内的端口主机可以互相访问, 而VLAN1和VLAN2之间的互相访问必须经过路由器转发。

注意寄存器 VAWD1(0xB0110094) [23:16] 位, 这几个位表示 VLAN Memory Control, 由 0xef 变为 0xd0, 即 1110,1111 -> 1101, 0000 

 VLAN 的介绍可以看这里: http://www.alliedtelesis.com/media/fount/how_to_note_alliedware_plus/overview_vlans.pdf

 

6. DUAL_IMAGE_SUPPORT

内核编译后生成 vmlinuz,与 rootfs 一起打包生成 firmware。 用 mkimage 为 firmware 打一个 image_header_t 的标签,最终生成 xxx_sysupgrade.bin。

check_image_validation() 将两个 firmware 的 image_header_t 读出来作一番校验 , 如果成功了, 再对整个 firmware 作 checksum 校验。 如果1坏了, 则把2复制到1的位置上; 如果2坏了, 则把1复制到2上。 

这样就保证了有两个IMAGE在SPI flash里面。

 

7. 选择启动方式, 此时终端里会跳出如下字符:

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. 

 

有 tftp 命令的都要经过设置 ipaddr, serverip, filename 等几步。 以上各启动项执行的动作分别是:

1. tftpboot 0x80A00000 filename, 可以用来启动 Linux 内核, 然后从该地址启动

2. tftpboot 0x80100000 filename, 然后把下载的数据烧写的IMAGE1的位置上, 设置环境变量Image1Stable为1, 然后 bootm 0xBC050000 启动刚刚烧写的 firmware

3,  bootm 0xBC050000

4. 进入 uboot 命令行 

7. 从串口下载文件, 并将下载的文件数据烧写到 SPI Flash 的 0 地址上。 这个动作是用来烧写 uboot.bin 的。 烧写完之后 reset。

8. 第8个选项被隐藏起来了, 在代码里看它应该是有效的。  其动作与1差不多, 只是加载地址不同。  tftpboot 0x80100000 filename, 然后从该地址启动

9. tftpboot 0x80100000 filename, 然后烧写到0地址。

对于 tftpboot 命令, 设置 autostart 命令为 "yes" / "no" 可以配置是否tftp完成后直接启动。

 

8. SPI Flash Layout

 

 

以下是Uboot启动信息:

U-Boot 1.1.3 (Jul 3 2014 - 11:19:18)

Board: Ralink APSoC DRAM: 128 MB
relocate_code Pointer at: 87fb8000
enable ephy clock...done. rf reg 29 = 5
SSC disabled.
spi_wait_nsec: 29 
spi device id: ef 40 18 0 0 (40180000)
find flash: W25Q128BV
raspi_read: from:30000 len:1000 
raspi_read: from:30000 len:1000 
============================================ 
Ralink UBoot Version: 4.2.1.0
-------------------------------------------- 
ASIC 7620_MP (Port5<->None)
DRAM component: 1024 Mbits DDR, width 16
DRAM bus: 16 bit
Total memory: 128 MBytes
Flash component: SPI Flash
Date:Jul 3 2014 Time:11:19:18
============================================ 
icache: sets:512, ways:4, linesz:32 ,total:65536
dcache: sets:256, ways:4, linesz:32 ,total:32768

##### The CPU freq = 580 MHZ #### 
estimate memory size =128 Mbytes

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. 
2 
You choosed 4

0 
raspi_read: from:40028 len:6


4: System Enter Boot Command Line Interface.

U-Boot 1.1.3 (Jul 3 2014 - 11:19:18)
MT7620 # 

 

推荐阅读