移植U-Boot到开发板
U-Boot虽然支持众多处理器和开发板,但是嵌入式系统的硬件是千差万别的,在使用U-Boot的时候,仍然需要针对自己的开发板做适当的修改。幸好U-Boot是一个结构设计合理的软件,在移植过程中严格按照U-Boot的工程结构移植很容易就能取得成功。本节将介绍如何移植U-Boot程序到ARM开发板。
U-Boot移植的一般步骤
从14.2节对U-Boot代码的分析可以看出, U-Boot移植工作主要分成处理器相关部分和开发板相关部分。由于U-Boot已经支持目前绝大多数处理器,因此处理器移植的工作相对较少,主要是修改一些配置。对于开发板部分的移植,需要参考硬件线路的外围器件的手册。U-Boot移植大致可以分为下面的步骤:
1.检查U-Boot工程是否支持目标平台
主要检查U-Boot根目录下的Readme文件是否提到目标平台处理器,cpu目录下是否有目标平台的处理器目录,以及board目录下是否有目标平台类似的工程。如果U-Boot已经编写了与目标平台类似的工程文件,移植工作会大大减轻。
2.分析目标平台类似工程目录结构
如果U-Boot有与目标平台类似的工程,需要分析一下目标板工程目录的结构。不同的目标板可能差别很大,分析工程目录中有哪些文件可以被新的目标开发板利用。
3.分析目标平台代码
目标平台代码分析可以按照14.3.4节介绍的U-Boot启动流程分析,看哪些代码是额外的,是否需要去掉额外的代码。
4.建立新的开发板平台目录
在board目录下建立新的开发板平台目录,目录下的文件可以从现有类似的开发板平台目录下复制得到。
5.对照手册修改平台差异部分代码
对照硬件手册,按照U-Boot启动流程修改现有代码与新平台有差异的部分。
6.调试新代码
新修改的代码很可能启动不了,需要通过JTag调试器跟踪调试。找出原因修改后再调试,直到正确启动。
以上分析的6个步骤并非必须严格遵守,这里仅是提供一个一般的思路,读者在移植的时候需要结合自己的目标板情况来分析。
移植U-Boot到目标开发板
移植U-Boot到新的目标平台会有许多问题。为了减少出错和工作量,在建立一个新的目标平台的时候可以直接复制现有类似平台的代码目录,然后在现有基础上修改。如移植到mini2440开发板,可以按照下面的步骤操作:
1.建立新目标板工程目录
在board目录下建立一个mini2440目录,现有的smdk2410目录是类似的平台,可以复制smdk2410目录下的所有文件到mini2440目录。
2.向配置文件加入新开发板配置
在U-Boot代码根目录下,修改Makefile文件。在Makefile的合适位置加上下面两行代码:
mini2440_config : unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t mini2440 tekkamanninija s3c24x0
新增代码的作用是告诉U-Boot,mini2440开发板用到了arm目录、arm920t目录、mini2440目录以及s3c24x0目录下的文件。在编译的时候,U-Boot会从这些目录中寻找Makefile并且编译。
保存Makefile文件退出,在include/configs目录下,复制smdk2410.h到mini2440.h,该操作是防止编译mini2440开发板的时候出错。
3.预编译新开发板的代码
到目前为止可以先编译一下新开发板的代码,目的是为了验证工程文件配置是否正确。在U-Boot目录下执行:
$ make mini2440_config
Configuring for mini2440 board...
$ make
“make mini2440_config”会生成mini2440开发板配置,然后执行make开始编译。编译后生成目标文件u-boot,该文件可以下载到目标板执行。如果编译成功,说明新建立的目标板工程目录是可以使用的。
4.修改目标板配置
新的目标板配置主要存放在include/configs/mini2440.h文件中,该文件有几个宏需要修改添加和更改,下面是mini2440.h文件:
下面这个文件主要是参考了include/configs/smdk2410.h,然后根据自己开发板的情况作了一些修改
/*
* (C) Copyright 2002
* Sysgo Real-Time Solutions, GmbH <
* Marius Groeger
* Gary Jennejohn
* David Mueller
*
* Modified for the friendly-arm SBC-2410X by
* (C) Copyright 2005
* JinHua Luo, GuangDong Linux Center,
*
* Configuation settings for the friendly-arm SBC-2410X board.
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#ifndef __CONFIG_H
#define __CONFIG_H
/*
* If we are developing, we might want to start armboot from ram
* so we MUST NOT initialize critical regs like mem-timing ...
*/
#undef CONFIG_SKIP_LOWLEVEL_INIT /* undef for developing */
/*
* High Level Configuration Options
* (easy to change)
*/
#define CONFIG_ARM920T 1 /* This is an ARM920T Core */
//#define CONFIG_S3C2410 1 /* in a SAMSUNG S3C2410 SoC */
//#define CONFIG_SBC2410X 1 /* on a friendly-arm SBC-2410X Board */
#define CONFIG_S3C2440 1 /* in a SAMSUNG S3C2440 SoC */
#define CONFIG_MINI2440 1 /* on a friendly-arm MINI2440 Board */
#define CONFIG_MINI2440_LED 1
#define CONFIG_S3C2410_NAND_SKIP_BAD 1
/* input clock of PLL */
#define CONFIG_SYS_CLK_FREQ 12000000/* the SBC2410X has 12MHz input clock */
#使用MMU功能
#define USE_920T_MMU 1
//#undef CONFIG_USE_IRQ /* we don't need IRQ/FIQ stuff */
#使用USB功能
#define CONFIG_USB_DEVICE 1
#ifdef CONFIG_USB_DEVICE
#define CONFIG_USE_IRQ 1
#endif
/*
* Size of malloc() pool
*/
#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + 128*1024)
#define CONFIG_SYS_GBL_DATA_SIZE 128 /* size in bytes reserved for initial data */
/*
* Hardware drivers
*/
#if 0
#define CONFIG_NET_MULTI
#define CONFIG_CS8900 /* we have a CS8900 on-board */
#define CONFIG_CS8900_BASE 0x19000300
#define CONFIG_CS8900_BUS16 /* the Linux driver does accesses as shorts */
#endif
#使能网络功能,平且使用DM9000网卡,并且定义网络的一些基本参数
#define CONFIG_NET_MULTI 1
#define CONFIG_NET_RETRY_COUNT 20
#define CONFIG_DRIVER_DM9000 1
#define CONFIG_DM9000_BASE 0x20000300
#define DM9000_IO CONFIG_DM9000_BASE
#define DM9000_DATA (CONFIG_DM9000_BASE+4)
#define CONFIG_DM9000_USE_16BIT 1
#define CONFIG_DM9000_NO_SROM 1
#undef CONFIG_DM9000_DEBUG
/*
* select serial console configuration
*/
#define CONFIG_S3C24X0_SERIAL
#define CONFIG_SERIAL1 1 /* we use SERIAL 1 on SBC2410X */
/************************************************************
* RTC
************************************************************/
#define CONFIG_RTC_S3C24X0 1
/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE
#define CONFIG_BAUDRATE 115200
/*
* BOOTP options
*/
#define CONFIG_BOOTP_BOOTFILESIZE
#define CONFIG_BOOTP_BOOTPATH
#define CONFIG_BOOTP_GATEWAY
#define CONFIG_BOOTP_HOSTNAME
/*
* Command line configuration.
*/
#include <config_cmd_default.h>
#define CONFIG_CMD_ASKENV
#define CONFIG_CMD_CACHE
#define CONFIG_CMD_DATE
#define CONFIG_CMD_DHCP
#define CONFIG_CMD_ELF
//#define CONFIG_MTD_DEVICE
//#define CONFIG_CMD_MTDPARTS
#define CONFIG_CMD_PING
#define CONFIG_CMD_NAND
#define CONFIG_CMD_REGINFO
#define CONFIG_CMD_FAT
/* FAT support*/
//#define CONFIG_CMD_EXT2
#define CONFIG_CMD_JFFS2
/* JFFS2 Support*/
#define CONFIG_CMD_USB
/* USB Support*/
#定义与启动有关的参数,启动延迟时间以及传送到Linux内核的启动参数
#define CONFIG_BOOTDELAY 1
#define CONFIG_BOOTARGS "noinitrd root=/dev/nfs rw nfsroot=192.168.0.1:/home/tekkaman/working/nfs/rootfs ip=192.168.0.2:192.168.0.1::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M"
#定义网络配置,MAC,MASK,IP,SEVERIP,GETWAYIP
#define CONFIG_ETHADDR 08:08:11:18:12:27
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 192.168.0.2
#define CONFIG_SERVERIP 192.168.0.1
#define CONFIG_GATEWAYIP 192.168.0.1
#define CONFIG_OVERWRITE_ETHADDR_ONCE
/*#define CONFIG_BOOTFILE "elinos-lart" */
#define CONFIG_BOOTCOMMAND "nfs 0x30008000 192.168.0.1:/home/tekkaman/working/nfs/zImage.img;bootm"
#define CONFIG_EXTRA_ENV_SETTINGS \
"tekkaman=bmp d 70000\0 " \
"stdin=serial\0" \
"stdout=serial\0" \
"stderr=serial\0" \
""
#if defined(CONFIG_CMD_KGDB)
#define CONFIG_KGDB_BAUDRATE 115200 /* speed to run kgdb serial port */
/* what's this ? it's not used anywhere */
#define CONFIG_KGDB_SER_INDEX 1 /* which serial port to use */
#endif
/*
* Miscellaneous configurable options
*/
#define CONFIG_SYS_LONGHELP /* undef to save memory */
#define CONFIG_SYS_PROMPT "[u-boot@MINI2440]# " /* Monitor Command Prompt */
#define CONFIG_SYS_CBSIZE 256 /* Console I/O Buffer Size */
#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE+sizeof(CONFIG_SYS_PROMPT)+16) /* Print Buffer Size */
#define CONFIG_SYS_MAXARGS 16 /* max number of command args */
#define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE /* Boot Argument Buffer Size */
#define CONFIG_SYS_MEMTEST_START 0x30000000 /* memtest works on */
#define CONFIG_SYS_MEMTEST_END 0x33F00000 /* 63 MB in DRAM */
#define CONFIG_SYS_LOAD_ADDR 0x30008000 /* default load address */
#define CONFIG_SYS_HZ 1000
/* valid baudrates */
#define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200 }
/*-----------------------------------------------------------------------
* Stack sizes
*
* The stack sizes are set up in start.S using the settings below
*/
#define CONFIG_STACKSIZE (128*1024) /* regular stack */
#ifdef CONFIG_USE_IRQ
#define CONFIG_STACKSIZE_IRQ (4*1024) /* IRQ stack */
#define CONFIG_STACKSIZE_FIQ (4*1024) /* FIQ stack */
#endif
/*-----------------------------------------------------------------------
* Physical Memory Map
*/
#define CONFIG_NR_DRAM_BANKS 1 /* we have 1 bank of DRAM */
#define PHYS_SDRAM_1 0x30000000 /* SDRAM Bank #1 */
#define PHYS_SDRAM_1_SIZE 0x04000000 /* 64 MB */
#define PHYS_FLASH_1 0x00000000 /* Flash Bank #1 */
#define CONFIG_SYS_FLASH_BASE PHYS_FLASH_1
/*-----------------------------------------------------------------------
* FLASH and environment organization
*/
/* #define CONFIG_AMD_LV400 1 /\* uncomment this if you have a LV400 flash *\/ */
//#define CONFIG_AMD_LV800 1 /* uncomment this if you have a LV800 flash */
#define CONFIG_SST_VF1601 1 /* uncomment this if you have a Am29LV160DB flash */
#define CONFIG_SYS_MAX_FLASH_BANKS 1 /* max number of memory banks */
#ifdef CONFIG_AMD_LV800
#define PHYS_FLASH_SIZE 0x00100000 /* 1MB */
#define CONFIG_SYS_MAX_FLASH_SECT (19) /* max number of sectors on one chip */
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x0F0000) /* addr of environment */
#endif
#ifdef CONFIG_AMD_LV400
#define PHYS_FLASH_SIZE 0x00080000 /* 512KB */
#define CONFIG_SYS_MAX_FLASH_SECT (11) /* max number of sectors on one chip */
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000) /* addr of environment */
#endif
/* timeout values are in ticks */
#define CONFIG_SYS_FLASH_ERASE_TOUT (5*CONFIG_SYS_HZ) /* Timeout for Flash Erase */
#define CONFIG_SYS_FLASH_WRITE_TOUT (5*CONFIG_SYS_HZ) /* Timeout for Flash Write */
//#if 0
#define CONFIG_CMD_EEPROM
#define CONFIG_CMD_I2C
#define CONFIG_DRIVER_S3C24X0_I2C 1 /* we use the buildin I2C controller */
#define CONFIG_HARD_I2C 1 /* I2C with hardware support */
#define CONFIG_SYS_I2C_SPEED 100000 /* I2C speed and slave address */
#define CONFIG_SYS_I2C_SLAVE 0x7F
#define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 /* EEPROM at24c08 */
#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1 /* Bytes of address */
/* mask of address bits that overflow into the "EEPROM chip address" */
#define CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW 0x07
#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 4 /* The Catalyst CAT24WC08 has */
/* 16 byte page write mode using*/
/* last 4 bits of the address */
#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 10 /* and takes up to 10 msec */
#define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE
//#define CONFIG_ENV_IS_IN_EEPROM 1 /* use EEPROM for environment vars */
//#define CONFIG_ENV_OFFSET 0x000 /* environment starts at offset 0 */
//#define CONFIG_ENV_SIZE 0x400 /* 1KB */
//#else
#define CONFIG_ENV_IS_IN_NAND 1
//#define CONFIG_ENV_IS_IN_FLASH 1
#define CONFIG_ENV_OFFSET 0X60000
#define CONFIG_ENV_SIZE 0x20000 /* Total Size of Environment Sector */
//#endif
/* == LENGTH_UBOOT*/
#ifdef CONFIG_SST_VF1601
#define PHYS_FLASH_SIZE 0x00200000 /* 2MB */
#define CONFIG_SYS_MAX_FLASH_SECT (32) /* max number of sectors on one chip */
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET) /* addr of environment */
#endif
/*-----------------------------------------------------------------------
* NAND flash settings
*/
#if defined(CONFIG_CMD_NAND)
#define CONFIG_NAND_S3C2410
#define CONFIG_SYS_NAND_BASE 0x4E000000
#define CONFIG_SYS_MAX_NAND_DEVICE 1 /* Max number of NAND devices */
#define SECTORSIZE 512
#define SECTORSIZE_2K 2048
#define NAND_SECTOR_SIZE SECTORSIZE
#define NAND_SECTOR_SIZE_2K SECTORSIZE_2K
#define NAND_BLOCK_MASK 511
#define NAND_BLOCK_MASK_2K 2047
#define NAND_MAX_CHIPS 1
#define CONFIG_MTD_NAND_VERIFY_WRITE
#define CONFIG_SYS_64BIT_VSPRINTF /* needed for nand_util.c */
#endif /* CONFIG_CMD_NAND */
#define CONFIG_SETUP_MEMORY_TAGS
#define CONFIG_INITRD_TAG
#define CONFIG_CMDLINE_TAG
#define CONFIG_SYS_HUSH_PARSER
#define CONFIG_SYS_PROMPT_HUSH_PS2 "> "
#define CONFIG_CMDLINE_EDITING
//#ifdef CONFIG_CMDLINE_EDITING
//#undef CONFIG_AUTO_COMPLETE
//#else
#define CONFIG_AUTO_COMPLETE
//#endif
#if 1
#define CONFIG_USB_OHCI
#define CONFIG_USB_STORAGE
//#define CONFIG_KEYBOARD
//#define CONFIG_USB_KEYBOARD
#define CONFIG_DOS_PARTITION
#define CONFIG_SYS_DEVICE_DEREGISTER
#define CONFIG_SUPPORT_VFAT
#define LITTLEENDIAN
#endif
#define CONFIG_JFFS2_NAND 1
//#undef CONFIG_JFFS2_CMDLINE
#define CONFIG_JFFS2_DEV "nand0"
#define CONFIG_JFFS2_PART_SIZE 0x480000
#define CONFIG_JFFS2_PART_OFFSET 0x80000
#define CONFIG_JFFS2_CMDLINE 1
#define MTDIDS_DEFAULT "nand0=nandflash0"
#define MTDPARTS_DEFAULT "mtdparts=nandflash0:384k(bootloader)," \
"128k(params)," \
"5m(kernel)," \
"-(root)"
#define ENABLE_CMD_LOADB_X 1
#define ENABLE_CMD_NAND_YAFFS 1
#define ENABLE_CMD_NAND_YAFFS_SKIPFB 1
//#define CFG_NAND_YAFFS1_NEW_OOB_LAYOUT 1
#if 1
#define CONFIG_CMD_BMP
#define CONFIG_VIDEO
#define CONFIG_VIDEO_S3C2410
#define CONFIG_VIDEO_LOGO
#define VIDEO_FB_16BPP_PIXEL_SWAP
#define CONFIG_VIDEO_SW_CURSOR
#define CONFIG_VIDEO_BMP_LOGO
//#define CONFIG_CONSOLE_EXTRA_INFO
//#define CONFIG_CONSOLE_CURSOR
//#define CONFIG_CONSOLE_TIME
#define CONFIG_CFB_CONSOLE
#define CONFIG_SYS_CONSOLE_IS_IN_ENV
//#define CFG_CONSOLE_INFO_QUIET
//#define VIDEO_FB_LITTLE_ENDIAN
#define CONFIG_SPLASH_SCREEN
#define CONFIG_SYS_VIDEO_LOGO_MAX_SIZE (240*320+1024+100) /* 100 = slack */
#define CONFIG_VIDEO_BMP_GZIP
#define CONFIG_CMD_UNZIP
#define LCD_VIDEO_ADDR 0x33d00000
/*for PC-keyboard*/
#define VIDEO_KBD_INIT_FCT 0
#define VIDEO_TSTC_FCT serial_tstc
#define VIDEO_GETC_FCT serial_getc
#endif
/*for SD Card*/
#define CONFIG_CMD_MMC
#define CONFIG_MMC 1
#define CONFIG_MMC_S3C 1 /* Enabling the MMC driver */
#define CFG_MMC_BASE 0xff000000
#if 0
#define CONFIG_YAFFS2
//#undef CONFIG_YAFFS_YAFFS2
#undef CONFIG_YAFFS_NO_YAFFS1
#endif
#endif /* __CONFIG_H */
|
用户需要根据目标板的配置情况修改,在本例中需要修改Flash存储器大小,其他使用默认值。
在board/mini2440目录下,需要修改config.mk文件中TEXT_BASE宏的值为0x33f80000,该值是mini2440开发板加载Bootloader的地址。
5.编译新的配置并且下载执行
回到U-Boot代码根目录,重新执行make编译生成u-boot目标文件,然后通过Flash烧写工具烧写到mini2440开发板的NOR Flash存储器,然后上电启动。
14.4.3 移植U-Boot的常见问题
在移植U-Boot的过程中会遇到很多问题,最主要的是一开始无法启动U-Boot。代码中很多地方设置有误都会导致无法启动,对于Stage1的代码来说,系统的出错信息是无法打印到串口或者其他设备的,此时可以使用JTag调试器调试目标开发板。
对于汇编编写的代码,一般都与系统硬件息息相关,在编写的时候需要非常仔细。最好准备好ARM体系结构手册和S3C2440A芯片手册,并且认真阅读编程模型相关的章节,对硬件的初始化流程要细心分析。
此外建议尽可能地把目标板外围硬件设备的初始化工作放在Stage2阶段,最好能使用C语言编写,避免使用汇编调试周期长的问题,提高开发效率。
阅读(844) | 评论(0) | 转发(0) |