【uboot201607移植到FL2440】添加自己的板子并实现串口的打印

来源:互联网 发布:win7数据库安装失败 编辑:程序博客网 时间:2024/05/16 15:01

(1)开发环境

  • u-boot源码版本:2016.07
  • 用的交叉编译工具:arm-none-linux-gnueabi-
  • 交叉编译工具安装位置:/usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
  • 开发板:飞凌FL2440
  • 虚拟机:VMware® Workstation 10.0.1 build-1379776
  • Ubuntu 系统:Ubuntu 12.04 版

(2)添加交叉编译工具:

2.1 在uboot源码的根目录下面,打开Makefile文件

vim Makefile

搜索:CROSS_COMPILE 修改编译器。

# set default to nothing for native buildsifeq ($(HOSTARCH),$(ARCH))CROSS_COMPILE ?=elseCROSS_COMPILE ?=/usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-endif注意:(1)这个地方也可以不用绝对路径的,还可以写成这样:CROSS_COMPILE ?=arm-none-linux-gnueabi-(2)编译器名称(arm-none-linux-gnueabi-)后面,千万不能有其他字符和空格键,否则编译不过的。

2.2添加名叫 fl2440 的板子到 uboot 中:

更改的依据是 doc/READ.kconfig 的添加板子的小贴士部分:

Conversion from boards.cfg to Kconfig-------------------------------------Prior to Kconfig, boards.cfg was a primary database that contained Arch, CPU,SoC, etc. of all the supported boards.  It was deleted when switching toKconfig.  Each field of boards.cfg was converted as follows: Status      ->  "S:" entry of MAINTAINERS Arch        ->  CONFIG_SYS_ARCH defined by Kconfig CPU         ->  CONFIG_SYS_CPU defined by Kconfig SoC         ->  CONFIG_SYS_SOC defined by Kconfig Vendor      ->  CONFIG_SYS_VENDOR defined by Kconfig Board       ->  CONFIG_SYS_BOARD defined by Kconfig Target      ->  File name of defconfig (configs/<target>_defconfig) Options     ->  CONFIG_SYS_EXTRA_OPTIONS defined by Kconfig Maintainers ->  "M:" entry of MAINTAINERSTips to add/remove boards-------------------------When adding a new board, the following steps are generally needed: [1] Add a header file include/configs/<target>.h [2] Make sure to define necessary CONFIG_SYS_* in Kconfig:       Define CONFIG_SYS_CPU="cpu" to compile arch/<arch>/cpu/<cpu>       Define CONFIG_SYS_SOC="soc" to compile arch/<arch>/cpu/<cpu>/<soc>       Define CONFIG_SYS_VENDOR="vendor" to compile board/<vendor>/common/*         and board/<vendor>/<board>/*       Define CONFIG_SYS_BOARD="board" to compile board/<board>/*         (or board/<vendor>/<board>/* if CONFIG_SYS_VENDOR is defined)       Define CONFIG_SYS_CONFIG_NAME="target" to include         include/configs/<target>.h [3] Add a new entry to the board select menu in Kconfig.     The board select menu is located in arch/<arch>/Kconfig or     arch/<arch>/*/Kconfig. [4] Add a MAINTAINERS file     It is generally placed at board/<board>/MAINTAINERS or     board/<vendor>/<board>/MAINTAINERS [5] Add configs/<target>_defconfigWhen removing an obsolete board, the following steps are generally needed: [1] Remove configs/<target>_defconfig [2] Remove include/configs/<target>.h if it is not used by any other boards [3] Remove board/<vendor>/<board>/* or board/<board>/* if it is not used     by any other boards [4] Update MAINTAINERS if necessary [5] Remove the unused entry from the board select menu in Kconfig [6] Add an entry to doc/README.scrapyard

2.3 添加板子的头文件:

cp include/configs/smdk2410.h include/configs/fl2440.h

2.4 这部分更改完 Kconfig 之后,make fl2440_config 自动生成。
这里的目的是提示你自己在给板子取名的时候要和文件的名字对应起来。

2.5 添加一个 make menuconfig 的选项:
arch/arm/Kconfig

config TARGET_SMDK2410
bool “Support smdk2410”
select CPU_ARM920T
的下边并列的添加:
config TARGET_FL2440
bool “Support fl2440”
select CPU_ARM920T
相应的在
source “board/samsung/smdk2410/Kconfig”
下边并列的添加:
source “board/samsung/fl2440/Kconfig”
2.5 添加一个 MAINTAINERS
一看位置,
board//MAINTAINERS or board///MAINTAINERS,我们发现,没有建立板子的文件夹呢,建立板子的文件夹:

cp board/samsung/smdk2410 board/samsung/fl2440 -rf  mv board/samsung/fl2440/smdk2410.c board/samsung/fl2440/fl2440.c  vim board/samsung/fl2440/Makefile 

将:
obj-y := smdk2441.o
更改为:
obj-y := fl2440.o

vim board/samsung/lip2440/Kconfig 

将:
Kconfig 中的内容更改成
if TARGET_LIP2440

config SYS_BOARD
default “lip2440”

config SYS_VENDOR
default “samsung”

config SYS_SOC
default “s3c24x0”

config SYS_CONFIG_NAME
default “lip2440”

endif

将:
MAINTAINERS 中的内容更改成
FL2440 BOARD
M: lip ymlmail@163.com
S: Maintained
F: board/samsung/fl2440/
F: include/configs/fl2440.h
F: configs/fl2440_defconfig

2.7 添加configs/_defconfig:

cp configs/smdk2410_defconfig configs/fl2440_config_defconfig  vim configs/fl2440_defconfig  
CONFIG_ARM=yCONFIG_TARGET_FL2440=yCONFIG_SYS_PROMPT="Js2440 # "# CONFIG_CMD_SETEXPR is not set

至此,板子添加的工作就做完了,现在,你可以用 make fl2440_config / make fl2440_defconfig 来把板子的默认参数添加进 .config 文件,并用 make 来生成 板子配置相关的头文件了。

(3)实现串口打印:

3.1 几个文件路径的总结:
板子的头文件:include/configs/fl2440.h
板子的文件夹:board/samsung/fl2440/fl2440.c
_main 函数的入口放在: arch/arm/lib/crt0.S
对于串口直接操作底层进行输出的函数(比如putc,puts)处在:drivers/serial/serial_s3c24x0.c
对 get_ FCLK HCLK PCLK 的函数处在:arch/arm/cpu/arm920t/s3c24x0/speed.c
在 fl2440.c 中的 board_init() 函数中 gd->bd->bi_arch_number = MACH_TYPE_S3C2440,在 arch/arm/include/asm/mach-types.h 中定义 有 MACH_TYPE_S3C2440 362 ,这个值与
linux内核中的 arch/arm/tools/mach-types 中相对应

3.2更改配置的宏:

vim include/configs/fl2440.h

将注释中的所有 板子 SAMSUNG SMDK2410 更改为 FL2440
将代码中的 2410 字眼改成 2440 : 用全局替换 :%s/2410/2440/g
特殊的更改:

#define CONFIG_S3C24X0        /* This is a SAMSUNG S3C24x0-type SoC */#define CONFIG_S3C2440        /* specifically a SAMSUNG S3C2440 SoC */#define CONFIG_FL2440        /* on a FL2440 Board */

norflash 使用的是 cfi 的 flash,因此删除 #define CONFIG_FLASH_CFI_LEGACY
更改 sdram 的扇区数量 #define CONFIG_SYS_MAX_FLASH_SECT (35)
更改不是可能不全,自己好好查查就行。

注意,这个地方如果采用 “//#define CONFIG_FLASH_CFI_LEGACY”在编译后,连接会报错。而且会把这一行直接添加到连接文件“uboot.lds”的开头部分:
正常的应该是这样:
这里写图片描述
错误的会变成这样:
这里写图片描述
而这多的一行,就会导致链接有问题。。。网上有解决办法,比如:
~
但是我按照他们的改了,不凑效。
换一种方式:既然不能用//xxxx来注释,那么我们就不用得了,改为:

/*#define CONFIG_FLASH_CFI_LEGACY*/

这样就没有问题,据说这是2013版本后都会有这个问题。如果你注意观察,文件:include/configs/fl2440.h 中的所有注释都是用
/*
xxxxxxx
*/
来实现的,没有出现”//xxxxx”。
3.3 更改 FCLK HCLK PCLK :
FCLK : HCLK : PCLK => 400 : 100 : 50
屏蔽中断和分频比例:

vi arch/arm/cpu/arm920t/start.S  

@@ -74,16 +74,16 @@ copyex:
mov r1, #0xffffffff
ldr r0, =INTMSK
str r1, [r0]
-# if defined(CONFIG_S3C2410)
- ldr r1, =0x3ff
+# if defined(CONFIG_S3C2440)
+ ldr r1, =0x7fff
ldr r0, =INTSUBMSK
str r1, [r0]
# endif

  • /* FCLK:HCLK:PCLK = 1:2:4 */
  • /* default FCLK is 120 MHz ! */
  • /* FCLK:HCLK:PCLK = 1:4:8 */
  • /* 400 MHz:100 MHz:50 MHz */
    ldr r0, =CLKDIVN
  • mov r1, #3
  • mov r1, #5
    str r1, [r0]
    #endif /* CONFIG_S3C24X0 */
vi board/samsung/fl2440/fl2440.c
#elif (FCLK_SPEED == 1)        /* Fout = 48MHz */#define M_MDIV    92#define M_PDIV    1#define M_SDIV    1#endif#elif (USB_CLOCK == 1)#define U_M_MDIV    56#define U_M_PDIV    2#define U_M_SDIV    2#endif修改 SDRAM  的时序:#define B1_BWSCON        (DW16)#define B2_BWSCON        (DW16)#define B3_BWSCON        (DW16)#define B4_BWSCON        (DW32)#define B5_BWSCON        (DW16)#define B6_BWSCON        (DW32)#define B7_BWSCON        (DW32)/* BANK0CON */#define B0_Tacs            0x3    /*  0clk */#define B0_Tcos            0x3    /*  0clk */#define B0_Tacc            0x7    /* 14clk */#define B0_Tcoh            0x3    /*  0clk */#define B0_Tah            0x3    /*  0clk */#define B0_Tacp            0x1#define B0_PMC            0x0    /* normal *//* BANK1CON */#define B1_Tacs            0x1    /*  0clk */#define B1_Tcos            0x1    /*  0clk */#define B1_Tacc            0x6    /* 14clk */#define B1_Tcoh            0x1    /*  0clk */#define B1_Tah            0x1    /*  0clk */#define B1_Tacp            0x0#define B1_PMC            0x0#define B2_Tacs            0x1#define B2_Tcos            0x1#define B2_Tacc            0x6#define B2_Tcoh            0x1#define B2_Tah            0x1#define B2_Tacp            0x0#define B2_PMC            0x0#define B3_Tacs            0x1    /*  0clk */#define B3_Tcos            0x1    /*  4clk */#define B3_Tacc            0x6    /* 14clk */#define B3_Tcoh            0x1    /*  1clk */#define B3_Tah            0x1    /*  0clk */#define B3_Tacp            0x0 /*  6clk */#define B3_PMC            0x0    /* normal */#define B4_Tacs            0x1    /*  0clk */#define B4_Tcos            0x1    /*  0clk */#define B4_Tacc            0x6    /* 14clk */#define B4_Tcoh            0x1    /*  0clk */#define B4_Tah            0x1    /*  0clk */#define B4_Tacp            0x0#define B4_PMC            0x0    /* normal */#define B5_Tacs            0x1    /*  0clk */#define B5_Tcos            0x1    /*  0clk */#define B5_Tacc            0x6    /* 14clk */#define B5_Tcoh            0x1    /*  0clk */#define B5_Tah            0x1    /*  0clk */#define B5_Tacp            0x0#define B5_PMC            0x0    /* normal *//* REFRESH parameter */#define REFEN            0x1    /* Refresh enable */#define TREFMD            0x0    /* CBR(CAS before RAS)/Auto refresh */#define Trp            0x1    /* 2clk */#define Trc            0x1    /* 7clk */#define Tchr            0x2    /* 3clk */#define REFCNT            1268   

3.4 添加nandflash 相关的驱动:

cp drivers/mtd/nand/s3c2410_nand.c drivers/mtd/nand/s3c2440_nand.c  
> 进入 s3c2440_nand.c 将所有 2410 改成 2440%s/2410/2440/g更改 Makefile 的支持:在obj-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o    //这一行可以删除掉的。下边添加:obj-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o

(4)现在,你可以编译你的工程了:

make distclean
make lip2440_config
make all

(5)用jlink下载到板子上的 norflash 后串口输出结果是:

U-Boot 2016.09-rc1-00212-g00f4d16-dirty (Aug 04 2016 - 18:20:41 +0900)CPUID: 32440001
FCLK: 400 MHz
HCLK: 100 MHz
PCLK: 50 MHz
DRAM: 64 MiB
WARNING: Caches not enabled
Flash: 4 MiB
NAND: 0 MiB
* Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Net: CS8900-0
Error: CS8900-0 address not set.
Js2440 #

如何下载uboot到fl2440请参考我的另外一篇博客

(6) 补充:(待确认)

在后期调试的过程中发现了一个bug,用 print 打印环境量:
LIP2440 # print
baudrate=115200
bootdelay=6
ethact=CS8900-0
ipaddr=10.0.0.110
netmask=255.255.255.0
serverip=10.0.0.1
stderr=serial
stdin=serial
stdout=serial
更改其中的 bootdelay :setenv bootdelay 6 ,然后 saveenv,reset
LIP2440 # save
Saving Environment to Flash…
Un-Protected 1 sectors
Erasing Flash…
. done
Erased 1 sectors
Writing to Flash… 9….8….7….6….5….4….3….2….1….done
Protected 1 sectors
LIP2440 # reset
resetting …
板子重启不了
在做完 u-boot移植2 后 查看 u-boot.bin 的大小,发现为 513164
跟这个相关的宏是: CONFIG_ENV_ADDR
修改方法是:
-#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)
+#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x100000)

删除的这一句目的是 为 uboot 程序留出了 0x070000 (448k) 大小的空间,明显,程序要大于此,因此,当你保存环境变量的时候,覆盖了源代码,导致下次启动不起来,新加的这行 为 uboot 程序留出了 1M 大小的空间,我们的 norflash 的大小是 2M 还是能满足的。

参考博客:
老鹏 写得非常棒!!!

0 0
原创粉丝点击