ok6410 u-boot-2012.04.01移植七完善u-boot移植(u-boot移植结束)

时间:2022-06-20 17:51:10

继ok6410 u-boot-2012.04.01移植六后,开发板已支持MLC NAND、DM9000等。但还需要完善比如环境变量、mtdpart分区、裁剪、制作补丁等。下面的工作就是完善移植的u-boot。

开发环境:
系统:ubuntu 10.04.4
单板:ok6410
NAND FLASH:K9GAG08U0D 2048MB
NOR Flash:EN29LV160AB 2MB
DDR:K4X1G163PCX2 256MB
NET:DM9000AEP
编译器:arm-linux-gcc-4.3.2
搭建开发环境详见ubuntu 10.04.4开发环境配置。
目标:
1.板级初始化,支持单板ok6410
2.修改u-boot,支持NAND启动
3.增加菜单update功能
4.增加MLC NAND支持
5.支持DM9000,网卡下载程序
6.修改环境变量以及mtdpart分区
7.u-boot裁剪及制作补丁

一、修改环境变量

根据u-boot启动界面输出的using default environment,找到common/enc_common.c,还可以通过save命令找到env_nand.c,就不进一步分析了,直接修改代码。修改smdk6410.h

#define CONFIG_SYS_MALLOC_LEN  (CONFIG_ENV_SIZE + 512*1024)

#define CONFIG_ENV_IS_IN_NAND
#define CONFIG_ENV_SIZE   0x80000//0x4000 /* Total Size of Environment Sector */
#define CONFIG_ENV_OFFSET  0x80000
#define CONFIG_ENV_RANGE  CONFIG_ENV_SIZE

接着编译测试

SMDK6410 # set bootdelay 5
SMDK6410 # save
Saving Environment to NAND...
Erasing Nand...

nand0: MTD Erase failure: -22

Writing to Nand... done
SMDK6410 # reset

重启发现没有保存,看来还有问题,根据提示继续修改

change@change:/si/OK6410/u-boot-2012.04.01$ grep "MTD Erase failure" * -nR
Binary file drivers/mtd/nand/libnand.o matches
drivers/mtd/nand/nand_util.c:149:                       printf("\n%s: MTD Erase failure: %d\n",

ok,去drivers/mtd/nand/nand_util.c:149

result = meminfo->erase(meminfo, &erase);
  if (result != 0) {
   printf("\n%s: MTD Erase failure: %d\n",
          mtd_device, result);
   continue;
  }

没看出啥问题,那还是从save命令分析saveenv()是在common/env_nand.c中实现的,进去看看,加了很多打印语句还是没找到。后来在头文件include/asm-generic/errno.h找到#define EINVAL  22 /* Invalid argument */原来failure: -22是参数问题。输的u-boot命令肯定没问题。没办法只好到配置文件smdk6410.h找问题。仔细看了一遍还真找到了,原来#define CONFIG_ENV_OFFSET  0x40000没有改成#define CONFIG_ENV_OFFSET  0x80000。因为K9GAG08U0D的BLOCK SIZE是512K。下面测试

SMDK6410 # set bootdelay 5
SMDK6410 # save
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x80000 -- 100% complete.
Writing to Nand... done
SMDK6410 # reset
resetting ...

U-Boot 2012.04.01 (Jul 09 2013 - 21:30:25) for SMDK6400

CPU:     S3C6400@532MHz
         Fclk = 532MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)
Board:   SMDK6400
DRAM:  128 MiB
WARNING: Caches not enabled
Flash: 0 KB
NAND:  select s3c_nand_oob_mlc_64
NAND_ECC_NONE selected by board driver. This is not recommended !!
2048 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0

##### Update menu for ok6410 #####
[g] get file, and write to nand flash 0 block
[b] Boot the system
[r] Reset the u-boot
[q] Quit from menu
Enter your selection: q
SMDK6410 #

重启发现bootdelay变为5,正常了。

二、修改mtdpart分区
这个比较简单,仿照别人做法,直接在配置文件smdk6410.h增加如下:

/*-----------------------------------------------------------------------
 * Dynamic MTD partition support
 */
#define CONFIG_CMD_MTDPARTS
#define CONFIG_MTD_DEVICE               /* needed for mtdparts commands */
//#define CONFIG_FLASH_CFI_MTD
#define MTDIDS_DEFAULT          "nand0=OK6410-0"

#define MTDPARTS_DEFAULT        "mtdparts=OK6410-0:512k(u-boot),"      \
                                                 "512k(params),"            \
                                                 "4M(kernel),"        \
                                                 "-(rootfs)"        
 添加后编译在测试

SMDK6410 # mtdparts default
SMDK6410 # mtdparts

device nand0 <OK6410-0>, # parts = 4
 #: name                size            offset          mask_flags
 0: u-boot              0x00080000      0x00000000      0
 1: params              0x00080000      0x00080000      0
 2: kernel              0x00400000      0x00100000      0
 3: rootfs              0x7fb00000      0x00500000      0

active partition: nand0,0 - (u-boot) 0x00080000 @ 0x00000000

defaults:
mtdids  : nand0=OK6410-0
mtdparts: mtdparts=OK6410-0:512k(u-boot),512k(params),4M(kernel),-(rootfs)
SMDK6410 #

测试基本正常。下面制作补丁。

三、整个移植代码修改量比较大,这里制作一个补丁文件,大家直接打个补丁就可以用了。

change@change:/si/OK6410/u-boot-2012.04.01$ make distclean
change@change:/si/OK6410/u-boot-2012.04.01$ cd ..
change@change:/si/OK6410$ mv u-boot-2012.04.01 u-boot-2012.04.01_ok
change@change:/si/OK6410$ tar xjf u-boot-2012.04.01.tar.bz2 
change@change:/si/OK6410$ diff -urN u-boot-2012.04.01 u-boot-2012.04.01_ok > u-boot-2012.04.01_ok6410.patch
change@change:/si/OK6410$

生成补丁文件u-boot-2012.04.01_ok6410.patch,不想做繁琐的修改,打个上面的补丁文件就OK了。打补丁方法如下:

change@change:/si/OK6410/u-boot-2012.04.01$ patch -p1 < ../u-boot-2012.04.01_ok6410.patch 
patching file arch/arm/config.mk
patching file arch/arm/cpu/arm1176/start.S
patching file arch/arm/include/asm/arch-s3c64xx/s3c6400.h
patching file arch/arm/lib/board.c
patching file board/samsung/smdk6410/config.mk
patching file board/samsung/smdk6410/.gitignore
patching file board/samsung/smdk6410/init.c
patching file board/samsung/smdk6410/lowlevel_init.S
patching file board/samsung/smdk6410/Makefile
patching file board/samsung/smdk6410/sdram.c
patching file board/samsung/smdk6410/smdk6400_nand_spl.c
patching file board/samsung/smdk6410/smdk6410.c
patching file board/samsung/smdk6410/u-boot-nand.lds
patching file common/cmd_menu.c
patching file common/env_nand.c
patching file common/main.c
patching file common/Makefile
patching file drivers/mtd/nand/nand_base.c
patching file drivers/mtd/nand/s3c64xx.c
patching file include/common.h
patching file include/configs/smdk6410.h
patching file include/linux/mtd/mtd-abi.h
patching file Makefile
change@change:/si/OK6410/u-boot-2012.04.01$ make
System not configured - see README
make: *** [all] Error 1
change@change:/si/OK6410/u-boot-2012.04.01$ make smdk6410_config

warning: Please migrate to boards.cfg.  Failure to do so will
         mean removal of your board in the next release.

Configuring for smdk6410 board...
change@change:/si/OK6410/u-boot-2012.04.01$ make

编译ok就可以用了。想偷懒可以这样做,最简单。但不建议,自己亲自移植一遍更能学到东西。至此ok6410 u-boot-2012.04.01移植部分告一段落,下一篇linux移植。