TI am335x U-boot移植(正常启动)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tbadolph/article/details/78105783

 ******************************************************************

                                 深圳南山 2017/09/26

*******************************************************************

Ti  am335x u_boot 启动:利用串口(UART)写。

http://processors.wiki.ti.com/index.php/AM335x_U-Boot_User%27s_Guide#NAND_2

http://processors.wiki.ti.com/index.php/Linux_Kernel_Users_Guide

1.    U-boot源码中的屏蔽i2c的代码:

static structam335x_baseboard_id __attribute__((section (".data"))) header;  //定义的全局变量。

static intread_eeprom(void)            //读取eeprom的参数。

{

         /* Check if baseboard eeprom is available */

         puts("board/ti/am335x/board.c/read_eeprom()\n");   //打印信息

         memcpy(header.name,"A335X_SK",HDR_NAME_LEN);    //赋予全局变量header结构体中的name变量为A335X_SK

#if 0

         if(i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {

                   puts("Could not probethe EEPROM; something fundamentally "

                            "wrong on theI2C bus.\n");

                   return -ENODEV;

         }

         /* read the eeprom using i2c */

         if(i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,

                                                                 sizeof(header))){

                   puts("Could not read theEEPROM; something fundamentally"

                            " wrong on theI2C bus.\n");

                   return -EIO;

         }

         if (header.magic != 0xEE3355AA) {

                   /*

                    * read the eeprom using i2c again,

                    * but use only a 1 byte address

                    */

                   if(i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,

                                               (uchar*)&header, sizeof(header))) {

                            puts("Could notread the EEPROM; something "

                                     "fundamentallywrong on the I2C bus.\n");

                            return -EIO;

                   }

                   if (header.magic !=0xEE3355AA) {

                            printf("Incorrectmagic number (0x%x) in EEPROM\n",

                                               header.magic);

                            return -EINVAL;

                   }

         }

#endif

 

         return 0;

}

 

void s_init(void)

 {

//__maybe_unused structam335x_baseboard_id header;     将定义的局部变量注释掉

#if 0

         if(i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {

                   puts("Could not probethe EEPROM; something fundamentally "

                            "wrong on theI2C bus.\n");

         }

         /* read the eeprom using i2c */

 

         if(i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,

                                                                 sizeof(header))){

                   puts("Could not read theEEPROM; something fundamentally"

                            " wrong on theI2C bus.\n");

         }

         if (header.magic != 0xEE3355AA) {

                   /*

                    * read the eeprom using i2c again,

                    * but use only a 1 byte address

                    */

                   if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR,0, 1,

                                               (uchar*)&header, sizeof(header))) {

                            puts("Could notread the EEPROM; something "

                                     "fundamentallywrong on the I2C bus.\n");

                            hang();

                   }

                   if (header.magic !=0xEE3355AA) {

                            printf("Incorrectmagic number (0x%x) in EEPROM\n",

                                               header.magic);

                            hang();

                   }

         }

#endif

if (!strncmp("A335XS",header.name, HDR_NAME_LEN))

/*   A335X_SK改名 A335XS,和header.name 比较,更改默认的DDR3启动*/

                   config_ddr(303, MT41J128MJT125_IOCTRL_VALUE,&ddr3_data,

                              &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data);

         else if (!strncmp("A335BNLT", header.name, 8))

                   config_ddr(400, MT41K256M16HA125E_IOCTRL_VALU

#endif

}

2.    编译源码:写个脚本start.sh自动编译

该脚本放在u-boot源码的根目录下面:start.sh

#!/bin/sh

   cd/usr/local/ti-sdk-am335x-evm/board-support/u-boot-2013.01.01-psp06.00.00.00

   [ -d ./am335x ] && sudo rm -rf./am335x

   make O=am335xCROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm am335x_evm

   cp/usr/local/ti-sdk-am335x-evm/board-support/u-boot-2013.01.01-psp06.00.00.00/am335x/spl/u-boot-spl.bin/mnt/hgfs/share/

   cp/usr/local/ti-sdk-am335x-evm/board-support/u-boot-2013.01.01-psp06.00.00.00/am335x/u-boot.img/mnt/hgfs/share

   cp/usr/local/ti-sdk-am335x-evm/board-support/u-boot-2013.01.01-psp06.00.00.00/am335x/MLO/mnt/hgfs/share/

具体的路径和自身的目录进行修改。

 

*如果不用独立的目录放生成文件的,用下命令清除生成的文件:

$   make CROSS_COMPILE=arm-linux-gnueabihf- distclean

*如果用独立的目录放生成的文件,直接删除目录就好了,O=am335x_evm  :

$    rm -rf ./am335x_evm

 

3.用工具下载编译生成的文件

建议选择超级终端作为软件。

*The release package does not contain thebinary for UART boot. Please follow the steps mentioned herefor compiling u-boot and use the spl/u-boot-spl.bin file that isproduced.

1.  Switch ON EVM withswitch settings for UARTboot. When “CCCC” characters appear on TeraTerm window, from the File Menuselect Transfer --> XMODEM --> Send (1K mode)

2.  Select “u-boot-spl.bin” for the transfer

3.  After image issuccessfully downloaded, the ROM code will boot it.

4.  When “CCCC”characters appear on TeraTerm window, from the File Menu select Transfer -->YMODEM --> Send (1K mode)

5.  Select “u-boot.img” for the transfer

6.  After image is successfullydownloaded, U-Boot will boot it.

7.  Hit enter and getto u-boot prompt “U-Boot# ”

3.1Flash SPL (MLO) to NAND by executing the followingcommands

nand erase 0x0 0x20000
loadb 0x82000000         (  tftp 0x82000000 MLO  )
  • From TeraTerm Menu click “File -> Transfer -> Kermit -> Send”.
  • Select the 1st stage u-boot image “MLO” and click “OPEN” button
  • Wait for download to complete and then run following commands in u-boot prompt
nand write 0x82000000 0x0 0x20000
nand erase 0x80000 0x1E0000               
loadb 0x82000000         (  tftp 0x82000000 u-boot.img  )
  • From TeraTerm Menu click “File -> Transfer -> Kermit -> Send”.
  • Select the 2nd stage u-boot image “u-boot.img” and click “OPEN” button
  • Wait for download to complete and then run following commands in U-Boot prompt
 
nand write 0x82000000 0x80000 0x1E0000
 
不出问题的,就可以:boot了。
然后将拨动到NAND启动。
 
内核的下载:
nand erase 0x280000 0x500000
loadb 0x82000000    tftp 0x82000000 uImage   )
nand write 0x82000000 0x280000 0x500000
 
 

3.2利用am3358开发产品,开始是在SD卡中调试,没问题后都烧写到nand中。命令如下:(有待验证)

http://www.deyisupport.com/question_answer/dsp_arm/sitara_arm/f/25/t/62170.aspx

4.U-Boot Network configuration

To set a different MAC address use thefollowing command

U-Boot# set ethaddr <random MAC address eg- 08:11:23:32:12:77>
In case a static ip is not available run the dhcp command to obtain the ip address from the DHCP server on the network to which the EVM is connected
U-Boot# setenv serverip <tftp server in your network>
U-Boot# setenv ipaddr xxx.xxx.x.xx
U-Boot#  setenv  netmask 255.255.255.0
U-Boot#  setenv gatewayip 192.168.1.1
U-Boot# dhcp
U-Boot# saveenv
 
U-Boot#  mtdparts                     查看NAND的分区段
         nand erase.part <partition name>
U-Boot#  nand erase.part NAND.kernel
U-Boot#  nand erase.chip       擦除芯片NAND
 
         
U-Boot# env default –f –a           恢复默认的环境变量
 

In case a static ip is available run the following commands

U-Boot# setenv ipaddr <your static ip>
U-Boot# saveenv

5.Flash Kernel

TFTP the kernel uImage to DDR.

U-Boot# tftp 0x82000000 <kernel_image>
U-Boot# nand erase 0x00280000 0x500000
U-Boot# nand write 0x82000000 0x00280000 0x500000
*Image_size should be aligned to page size of 2048 (0x800) bytes

6.移植uboot时以太网的修改

以太网部分修改很简单,修改以太网引脚配置,在mux.c文件里面,然后在evm.c文件里面修改evm_phy_init(),cpsw_slaves[],cpsw_data,board_eth_init()

6.1 引脚配置:

1./board/ti/am335x里面的Board.c 中的s_init()函数调用enable_board_pin_mux();

2./board/ti/am335x里面的Mux.c 中的enable_board_pin_mux()调用configure_module_pin_mux(rmii1_pin_mux)配置引脚;

/*                           Mux.c       */

static structmodule_pin_mux rmii1_pin_mux[]={

         {OFFSET(mii1_txen), MODE(1)}, /*RMII1_TXEN */

         {OFFSET(mii1_txd1), MODE(1)}, /*RMII1_TXD1 */

         {OFFSET(mii1_txd0), MODE(1)}, /*RMII1_TXD1 */

         {OFFSET(mii1_rxd1), MODE(1) |RXACTIVE}, /* RMII1_RXD1 */

         {OFFSET(mii1_rxd0), MODE(1) |RXACTIVE}, /* RMII1_RXD1 */

         {OFFSET(mdio_data), MODE(0) | RXACTIVE| PULLUP_EN},/* MDIO_DATA */

         {OFFSET(mdio_clk), MODE(0) |PULLUP_EN}, /* MDIO_CLK */

         {OFFSET(mii1_crs), MODE(1) | RXACTIVE},/* RMII1_CRS_DV */

         {OFFSET(rmii1_refclk), MODE(0) |RXACTIVE}, /* RMII1_REFCLK */

         {-1},

};

6.2 以太网初始化

2.Board.c(board/ti/am335x)中的board_eth_init()先读MAC地址,在写寄存器选择模式的值,最后注册cpsw_register();

board_eth_init(){

···

if (board_is_bone() || board_is_bone_lt() ||board_is_idk()) {

               writel(MII_MODE_ENABLE,&cdev->miisel);

                  cpsw_slaves[0].phy_if =cpsw_slaves[1].phy_if =

                                  PHY_INTERFACE_MODE_MII;

      }else {                                                                    

      writel(RMII_MODE_ENABLE,&cdev->miisel);                    

printf("MII isseted RMII\n");                                                  //----Tbao---

               cpsw_slaves[0].phy_if= cpsw_slaves[1].phy_if =

                                  PHY_INTERFACE_MODE_RMII;

      }

···

}

注释如下:

writel(RMII_MODE_ENABLE,&cdev->miisel); 将选择的RMII模式写到寄存器里面。

定义宏:#define RMII_MODE_ENABLE        0xC5

在芯片手册里找到寄存器miisel,看每个管脚位的配置,根据硬件确定0xC5值:

个slave,cpsw_slaves[0]/ cpsw_slaves[1].

/*   Board.c (Board/ti/am335x)   */

static  struct  cpsw_slave_data cpsw_slaves[] = {

         {

                   .slave_reg_ofs          = 0x208,

                   .sliver_reg_ofs         = 0xd80,

                   .phy_id              =1,                           //phy_id =1    -----Tbao-----

         },

         {

                   .slave_reg_ofs          = 0x308,

                   .sliver_reg_ofs         = 0xdc0,

                   .phy_id              = 2,                                                 //phy_id=2   -----Tbao-----

         },

};

所以将结构体中的cpsw_data的slaves 改成2。

Static  struct  cpsw_platform_data  cpsw_data = {

         .mdio_base               = AM335X_CPSW_MDIO_BASE,

         .cpsw_base               = AM335X_CPSW_BASE,

         .mdio_div                   = 0xff,

         .channels          = 8,

         .cpdma_reg_ofs                = 0x800,

         .slaves                        = 2,                       //hacve 2 slaves    ----Tbao---

         .slave_data               = cpsw_slaves,

         .ale_reg_ofs              = 0xd00,

         .ale_entries               = 1024,

         .host_port_reg_ofs = 0x108,

         .hw_stats_reg_ofs  = 0x900,

         .mac_control            = (1 << 5),

         .control             = cpsw_control,

         .host_port_num                = 0,

         .version             = CPSW_CTRL_VERSION_2,

};

#endif

 

6.3. arch/arm/lib/中的函数Board.c中的board_init_r()开始:

1.  #if defined(CONFIG_CMD_NET)              //      InitialNet   ---Tbao----

         puts("Net:   ");

         printf("File=%s,Function=%s,Line=%d\n",__FILE__,__FUNCTION__,__LINE__); 

         eth_initialize(gd->bd);

#ifdefined(CONFIG_RESET_PHY_R)

         debug("Reset EthernetPHY\n");

         reset_phy();

#endif

#endif

3.      Eth.c 中的eth_initialize()

eth_initialize(){

······

miipyy_init();

 

phy_init();

 

board_eth_init();(回到/ti/am335x中的board.c函数)

·····

}

4.      在phy_init()(drivers/net/phy)中初始化

初始化DP83848i芯片。

static struct phy_driver DP83848_driver = {

       .name = "NatSemi DP83848",

       .uid = 0x20005c90,

       .mask = 0x2000ff90,

     .features = PHY_BASIC_FEATURES,

      .config = &dp838xx_config,

       .startup = &dp83848_startup,

      .shutdown = &genphy_shutdown,

};

int phy_natsemi_init(void)

{

       //phy_register(&DP83630_driver);

       //phy_register(&DP83865_driver);

       phy_register(&DP83848_driver);

      return 0;

}

8.     文件系统的建立

8.1文件系统的烧写

http://processors.wiki.ti.com/index.php/UBIFS_Support#Creating_UBIFS_file_system

在烧u-boot或者内核、文件系统之前,应先将NAND flash 擦除一下,否则后面可能有问题。

nand erase.chip   或者暴力擦除:  nand scrub.chip  (慎用)

nand erase 0x0 0x10000000

U-BOOT#  nand erase 0x780000 0xf880000

U-BOOT#  tftp 0x82000000 ubi.img

U-BOOT#  nand write 0x82000000  0x780000 0x7880000

猜你喜欢

转载自blog.csdn.net/tbadolph/article/details/78105783