logogcn

To be a better man 专注于嵌入式开发 ARM LINUX WINCE
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

uboot-2010.03 移植到 2410( 从 nand 启动 )

Posted on 2010-12-01 10:55  logogcn  阅读(1217)  评论(0编辑  收藏  举报

uboot-2010.03 移植到 2410( 从 nand 启动 )

【环境】

<a> Ubuntu 10.04 LTS 

<b> u-boot-2010.03 

<c> FS2410 主板, SAMSUNG S3C2410A 微处理器

<d> 交叉编译器 arm-linux-gcc-4.3.2

<e> Nand: Samsung K9F1208U0B , 64M

 

【步骤】

Step1: 创建板级源码

<1> 解压

furtherchan@further:~/work$

tar -jxvf u-boot-2010.03.tar.bz2

<2> 进入板极源码目录

furtherchan@further:~/work/u-boot-2010.03/board/samsung$ ls

smdk2400  smdk2410  smdk6400  smdkc100

 

<3> 拷贝一份最相似的平台代码:

furtherchan@further:~/work/u-boot-2010.03/board/samsung$ cp -av smdk2410/ fs2410

`smdk2410/' -> `fs2410'

`smdk2410/Makefile' -> `fs2410/Makefile'

`smdk2410/config.mk' -> `fs2410/config.mk'

`smdk2410/flash.c' -> `fs2410/flash.c'

`smdk2410/smdk2410.c' -> `fs2410/smdk2410.c'

`smdk2410/lowlevel_init.S' -> `fs2410/lowlevel_init.S'

 

furtherchan@further:~/work/u-boot-2010.03/board/samsung$ ls

fs2410  smdk2400  smdk2410  smdk6400  smdkc100

furtherchan@further:~/work/u-boot-2010.03/board/samsung$ cd fs2410/

 

 

修改文件名

furtherchan@further:~/work/u-boot-2010.03/board/samsung/fs2410$ mv smdk2410.c fs2410.c

 

修改 Makefile

furtherchan@further:~/work/u-boot-2010.03/board/samsung/fs2410$ vim Makefile

COBJS    := smdk2410.o flash.o   →  COBJS    := fs2410.o flash.o

拷贝头文件

furtherchan@further:~/work/u-boot-2010.03/board/samsung/fs2410$ cd http://www.cnblogs.com/../include/configs/

furtherchan@further:~/work/u-boot-2010.03/include/configs$ cp -v smdk2410.h fs2410.h

`smdk2410.h' -> `fs2410.h'

 

退回 U-Boot 根目录

furtherchan@further:~/work/u-boot-2010.03/include/configs$ cd ../..

furtherchan@further:~/work/u-boot-2010.03$

 

 

<4> 修改顶级 Makefile

furtherchan@further:~/work/u-boot-2010.03$ vim Makefile

smdk2410_config   :      unconfig

@$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 samsung s3c24x0

 

 

在 3045 和 3046 行(即以上两句)下加入以下两句:

fs2410_config :      unconfig

@$(MKCONFIG) $(@:_config=) arm arm920t fs2410 samsung s3c24x0

 

<5> 编译

furtherchan@further:~/work/u-boot-2010.03$ make fs2410_config

furtherchan@further:~/work/u-boot-2010.03$ make

…...

arm-linux-objcopy -O srec u-boot u-boot.srec

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

furtherchan@further:~/work/u-boot-2010.03$ ll -h u-boot.bin

-rwxr-xr-x 1 furtherchan furtherchan 99K 2010-07-05 20:25 u-boot.bin

此时编译生成的 u-boot.bin 文件还无法运行在 fs2410 开发板上,需要做以下修改 .

 

Step2: 修改平台相关信息

 

<1> 修改中断禁止部分

furtherchan@further:~/work/u-boot-2010.03$ cd cpu/arm920t/

furtherchan@further:~/work/u-boot-2010.03/cpu/arm920t$ vim start.S

# if defined(CONFIG_S3C2410)

ldr   r1, =0x3ff

ldr   r0, =INTSUBMSK

str   r1, [r0]

 

修改成如下:

# if defined(CONFIG_S3C2410)

ldr   r1, =0x7ff

ldr   r0, =INTSUBMSK

str   r1, [r0]

 

<2> 修改 SDRAM 刷新周期: board/samsung/fs2410/lowlevel_init.S

#define REFCNT                  1113 /* period=15.6us, HCLK=60Mhz, (2048+1-15.6*60) */

改成:

#define REFCNT                  1268       /* period=7.8125us, HCLK=100Mhz, (2048+1-7.8125*100) */

 

Step3: U-BOOT 增加 NAND 启动支持

<1> 修改命令提示符,在 include/configs/fs2410.h 中修改如下代码:

#define    CONFIG_SYS_PROMPT            "SMDK2410 # "

改成:

#define    CONFIG_SYS_PROMPT            "fs2410 # "

<2> 修改默认载入地址

#define    CONFIG_SYS_LOAD_ADDR             0x33000000

改成:

#define CONFIG_SYS_LOAD_ADDR      0x30008000


<3> 加入支持 nand 写

#define    CONFIG_ENV_IS_IN_FLASH     1

改成:

#define    CONFIG_ENV_IS_IN_NAND      1 /* common/env_nand.c */


并增加一句:

#define CONFIG_ENV_OFFSET  0x30000

 

<4> 调试过程

U-Boot 第一阶段完成后,跳转到第二阶段的主函数 lib_arm/board.c 中 271 行: void start_armboot (void) ,在该函数中有如下定义:

#if defined(CONFIG_CMD_NAND)

       puts ("NAND:  ");

       nand_init();            /* go init the NAND */

#endif

为了支持 NAND ,在 include/configs/fs2410.h 中添加如下代码:

#define CONFIG_CMD_NAND

 

添加完先编译一下:

furtherchan@further:~/work/u-boot-2010.03$ make distclean

Generating include/autoconf.mk

furtherchan@further:~/work/u-boot-2010.03$ make fs2410_config

Configuring for fs2410 board...

furtherchan@further:~/work/u-boot-2010.03$ arm-linux-gcc -v

Using built-in specs.

Target: arm-none-linux-gnueabi

…...

gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)

 

编译,出现错误:

furtherchan@further:~/work/u-boot-2010.03$ make CROSS_COMPILE=arm-linux-

make[1]: Entering directory `/home/furtherchan/work/u-boot-2010.03/drivers/mtd/nand'

…...   -o nand.o nand.c -c

nand.c:29: error: 'CONFIG_SYS_MAX_NAND_DEVICE' undeclared here (not in a function)

nand.c:32: error: 'CONFIG_SYS_NAND_BASE' undeclared here (not in a function)

make[1]: *** [nand.o] Error 1

make[1]: Leaving directory `/home/furtherchan/work/u-boot-2010.03/drivers/mtd/nand'

make: *** [drivers/mtd/nand/libnand.a] Error 2

 

在 include/configs/fs2410.h 中继续添加代码:

#define  CONFIG_SYS_MAX_NAND_DEVICE       1

#define  CONFIG_SYS_NAND_BASE      0x4E000000  

 

继续编译,出现错误:

furtherchan@further:~/work/u-boot-2010.03$ make CROSS_COMPILE=arm-linux-

make[1]: Leaving directory `/home/furtherchan/work/u-boot-2010.03/cpu/arm920t'

…...

drivers/mtd/nand/libnand.a(nand.o): In function `nand_init_chip':

/home/furtherchan/work/u-boot-2010.03/drivers/mtd/nand/nand.c:48: undefined reference to `board_nand_init'

make: *** [u-boot] Error 1

板级 nand 初始化函数找不到,在 drivers/mtd/nand/ 目录下有个 s3c2410_nand.c 文件,一直不知道是什么时候用的,估计是需要调用该文件中的 board_nand_init() 。

查看 drivers/mtd/nand/nand.c ,其中 nand_init_chip 调用了 board_nand_init() ,同时在 /drivers/mtd/nand/s3c2410_nand.c 中有 board_nand_init() 函数,下面就要考虑如何把 s3c2410_nand.c 的 board_nand_init() 整到 nand.c 中。

分析该目录下的 Makefile ,用 s3c2410 关键字查询到如下内容:

COBJS-$( CONFIG_NAND_S3C2410 ) += s3c2410_nand.o

 

要使该行编译进工程,需定义 CONFIG_NAND_S3C2410 ,同样,在 include/configs/fs2410.h 中继续添加代码:

#define   CONFIG_NAND_S3C2410

 

继续编译:

furtherchan@further:~/work/u-boot-2010.03$ make CROSS_COMPILE=arm-linux-


编译成功,烧写板子,输出如下信息:

fs2410 #


U-Boot 2010.03 (Jul 06 2010 - 13:22:17)

DRAM:  64 MB

Flash: 512 kB

NAND:  64 MiB

*** Warning - bad CRC or NAND, using default environment

In:    serial

Out:   serial

Err:   serial

Net:   CS8900-0


fs2410 # nand info

Device 0: NAND 64MiB 3,3V 8-bit, sector size 16 KiB

fs2410 # saveenv

Saving Environment to NAND...

Erasing Nand...

Erasing at 0x3c00000000001 --   0% complete.

Writing to Nand... done

fs2410 #


可见 nand 读写成功。

设好环境参数后启动,出现如下错误:

fs2410 # boot

NAND read: device 0 offset 0x40000, size 0x200000

  2097152 bytes read: OK

## Starting application at 0x30008000 ...

Uncompressing Linux................................................................................................................. done, booting the kernel.

Error: unrecognized/unsupported machine ID (r1 = 0x33f4fb6c).

Available machine support:

ID (hex)  NAME

000000c1       SMDK2410

0000015b       IPAQ-H1940

00000290       Acer-N30

0000014b       Simtec-BAST

000002a8       Nex Vision - Otom 1.1

00000400       AML_M5900

000001db       Thorcom-VR1000

00000454       QT2410

000003fe SMDK2413

000003f1 SMDK2412

00000377       S3C2413

00000474       VSTMS

000002de       Simtec-Anubis

0000034a       Simtec-OSIRIS

00000250       IPAQ-RX3715

0000016a       SMDK2440

000002a9       NexVision - Nexcoder 2440

0000043c       SMDK2443


Please check your kernel config and/or bootloader.

以上信息可见, machine Id 不匹配,由于本人的 zImage 之前在板子上跑是正确的,基本可断定 u-boot 平台 ID 传递错误:

fs2410 # bdinfo

arch_number = 0x000000C1

env_t       = 0x00000000

boot_params = 0x30000100

DRAM bank   = 0x00000000

-> start     = 0x30000000

-> size     = 0x04000000

ethaddr     = aa:2c:33:44:55:66

ip_addr     = 192.168.1.212

baudrate    = 115200 bps

以上 arch_number 转换成 10 进制即 193 ,在内核源码文件 include/asm-arm/mach-types.h 中有相应定义,在 u-boot 文件 include/asm-arm/mach-types.h

存在相同定义:

#define MACH_TYPE_SMDK2410             193

在 board/samsung/fs2410/fs2410.c 中有如下定义:

       /* arch number of SMDK2410-Board */

       gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;

       /* adress of boot parameters */

       gd->bd->bi_boot_params = 0x30000100;

 

看来的确是 uboot 没有把参数传递给内核。

 

board/samsung/fs2410/fs2410.c

  : #include <asm/arch/s3c24x0_cpu.h>

include/asm-arm/arch-s3c24x0/s3c24x0_cpu.h

s3c24x0_cpu.h

内容如下 :

#ifdef CONFIG_S3C2400

       #include <asm/arch/s3c2400.h>

#elif defined CONFIG_S3C2410

       #include <asm/arch/s3c2410.h>

#else

       #error Please define the s3c24x0 cpu type

#endif

 

需要定义: CONFIG_S3C2410 ,在 fs2410.h 中已有该定义

 

解决:在 common/cmd_boot.c 中 do_go() 函数修改如下:

int

do_go (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])

{

  ulong addr, rc;

  int rcode = 0;

/************* Add by FurtherChan ************/

         char *commandline = getenv ("bootargs" );

         struct param_struct *my_params = (struct param_struct *) 0x30000100;

         memset (my_params, 0, sizeof (struct param_struct));

         my_params->u1.s.page_size = 4096;

         my_params->u1.s.nr_pages = 0x4000000 >> 12;

         memcpy (my_params->commandline, commandline, strlen (commandline) + 1);

/***************** Add end *******************/

  if (argc < 2)

    {

      cmd_usage (cmdtp);

      return 1;

    }

  addr = simple_strtoul (argv[1], NULL, 16);

  printf ("## Starting application at 0x%08lX ...\n" , addr);

  /*    * pass address parameter as argv[0] (aka command name),

   * and all remaining args

   */

/*************** Add by FurtherChan *************/

__asm__ ("mov r1, #193\n"

              "mov      ip, #0\n"

              "mcr      p15, 0, ip, c13, c0, 0\n"

              "mcr      p15, 0, ip, c7, c7, 0\n"

              "mcr      p15, 0, ip, c7, c10, 4\n"

              "mcr      p15, 0, ip, c8, c7, 0\n"

              "mrc      p15, 0, ip, c1, c0, 0\n"

              "bic ip, ip, #0x0001\n"

              "mov pc, %0\n" "nop\n"

              :

              :"r" (addr)

              );

/***************** Add end ********************/

  rc = do_go_exec ((void *) addr, argc - 1, argv + 1);

  if (rc != 0)

    rcode = 1;

  printf ("## Application terminated, rc = 0x%lX\n" , rc);

  return rcode;

}

 

重新编译后,烧写,启动板子:

fs2410 # boot


NAND read: device 0 offset 0x40000, size 0x200000

  2097152 bytes read: OK

## Starting application at 0x30008000 ...

Uncompressing Linux................................................................................................................. done, booting the kernel.

Linux version 2.6.22.6 (furtherchan@further) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #25 Thu Jul 1 16:25:29 CST 2010

CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177

Machine: SMDK2410

ATAG_INITRD is deprecated; please update your bootloader.

Memory policy: ECC disabled, Data cache writeback

CPU S3C2410A (id 0x32410002)

S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz

…...

 

启动成功!

 


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/furtherchan/archive/2010/07/06/5716940.aspx