u-boot移植1:添加自己的板子并实现串口的打印

来源:互联网 发布:无锡华云数据技术服务 编辑:程序博客网 时间:2024/06/06 00:28
u-boot 版本:2016.03
用的交叉编译工具:arm-none-linux-gnueabi-
git仓库:http://git.oschina.net/qqliyunpeng/ubootv2016_03forjz2440

1. 添加交叉编译工具


vi Makefile

ifeq ($(HOSTARCH),$(ARCH))
CROSS_COMPILE ?=
else 
CROSS_COMPILE =arm-none-linux-gnueabi-
endif

2. 添加名叫 lip2440 的板子到 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 to
Kconfig.  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 MAINTAINERS


Tips 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>_defconfig

2.1 添加板子的头文件

cp include/configs/smdk2410.h include/configs/lip2440.h

2.2 [2]这部分更改完 Kconfig 之后,make lip2440_config 自动生成

这里的目的是提示你自己在给板子取名的时候要和文件的名字对应起来。

2.3 添加一个 make menuconfig 的选项

arch/arm/Kconfig
config TARGET_SMDK2410
    bool "Support smdk2410"
    select CPU_ARM920T
的下边并列的添加:
config TARGET_LIP2440
    bool "Support lip2440"
    select CPU_ARM920T
相应的在
source "board/samsung/smdk2410/Kconfig"
下边并列的添加:
source "board/samsung/lip2440/Kconfig"

2.4 添加一个 MAINTAINERS 

一看位置,
board/<board>/MAINTAINERS or board/<vendor>/<board>/MAINTAINERS,我们发现,没有建立板子的文件夹呢,建立板子的文件夹:

cp board/samsung/smdk2410 board/samsung/lip2440 -rfmv board/samsung/lip2440/smdk2410.c board/samsung/lip2440/lip2440.cvi board/samsung/lip2440/Makefile

将:
obj-y    := smdk2441.o
更改为:
obj-y    := lip2440.o
vi 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 中的内容更改成
LIP2440 BOARD
M:    lip <qqliyunpeng@sina.cn>
S:    Maintained
F:    board/samsung/lip2440/
F:    include/configs/lip2440.h
F:    configs/lip2440_defconfig

2.5 添加configs/<target>_defconfig:

cp configs/smdk2410_defconfig configs/lip2440_config_defconfigvi configs/lip2440_defconfig

CONFIG_ARM=y
CONFIG_TARGET_LIP2440=y
CONFIG_SYS_PROMPT="LIP2440 # "
# CONFIG_CMD_SETEXPR is not set

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

3. 实现串口打印


3.1 几个文件路径的总结:

  • 板子的头文件:include/configs/lip2440.h
  • 板子的文件夹:board/samsung/lip2440/lip2440.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 
  • 在 lip2440.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更改配置的宏:

vi include/configs/lip2440.h

将注释中的所有 板子 SAMSUNG SMDK2410 更改为 LIP2440 
将代码中的 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_LIP2440        /* on a LIP2440 Board */

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

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/lip2440/lip2440.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

用jlink下载到板子上的 norflash 后串口输出结果是:
U-Boot 2016.03-00001-g79e6686 (May 04 2016 - 15:06:58 +0800)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 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.

LIP2440 # 

5. 补充:


在后期调试的过程中发现了一个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 还是能满足的。

参考博客


        赵春江的专栏
        jetli
2 0
原创粉丝点击