四、移植 JZ2440 开发板

4.1 移植第一步

  前面已经分析过了 .config 的过程,可以知道移植需要用到的文件:

  • .config 文件
  • arch/arm/cpu 下的文件
  • board 目录

    .config 文件是根据后面两个文件生成的,所以我们重点需要配置后面两个目录

4.1.2 移植 board 目录

  JZ2440 是基于 S3C2440 的,为三星架构,我们可以从其他支持 2440 的 uboot 版本中进行移植。

  u-boot自v2014.10版本开始引入KBuild系统,所以我们在 2014.10之后不久的版本中查询版本,这样尽量减少移植时候的差异性

  下载 u-boot 2015.01 版本代码:git clone git://git.denx.de/u-boot.git u-boot

  切换版本:

  git status

  git tag

  git checkout v2015.01

  git diff v2018.03(对比源码,可以不做)

  拷贝board/samsung/smdk2410 到 下面的目录中去

1 cp -R smdk2410/ ../../../../../uboot/u-boot-2018.03/board/samsung/jz2440

  修改文件:

  cd u-boot-2018.03/board/samsung/jz2440

  mv smdk2410.c jz2440.c

  修改 makefile:

1 obj-y    := jz2440.o
2 obj-y    += lowlevel_init.o

  jz2440.c 文件修改:

1     /* arch number of JZ2440-Board */
2     gd->bd->bi_arch_number = MACH_TYPE_JZ2440;

  注意:修改这里的类型还必须在另一个地方进行添加这个模块:

  

  直接将 SMDK2440 改为 JZ2440 即可

1 #define MACH_TYPE_SMDK2460             1007
2 #define MACH_TYPE_JZ2440               1008
3 #define MACH_TYPE_SMDK2412             1009

  Kconfig 修改:

 1 if TARGET_JZ2440
 2 
 3 config SYS_BOARD
 4     default "jz2440"
 5 
 6 config SYS_VENDOR
 7     default "samsung"
 8 
 9 config SYS_SOC
10     default "s3c24x0"
11 
12 config SYS_CONFIG_NAME
13     default "jz2440"
14 
15 endif

  当前目录修改完毕

4.1.3 arch/arm/cpu/arm920t 目录修改

  uboot2015.01/u-boot$ cd arch/arm/cpu/arm920t/

  u-boot/arch/arm/cpu/arm920t$ cp -R s3c24x0/ ../../../../../../../uboot/u-boot-2018.03/arch/arm/cpu/arm920t/

(1)u-boot-2018.03/arch/arm/cpu/arm920t/Makefile 修改

 1 extra-y    = start.o
 2 
 3 obj-y    += cpu.o
 4 
 5 obj-$(CONFIG_EP93XX) += ep93xx/
 6 obj-$(CONFIG_IMX) += imx/
 7 obj-$(CONFIG_S3C24X0) += s3c24x0/
 8 
 9 # some files can only build in ARM mode
10 
11 ifdef CONFIG_$(SPL_)SYS_THUMB_BUILD
12 CFLAGS_cpu.o := -marm
13 endif

(2)头文件添加

  查看 s3c24x0.h 文件,发现都包含了一个头文件: asm/arch/s3c24x0_cpu.h ,添加此头文件。

  在 uboot2015.01 根目录下找到此文件:find . -name s3c24x0_cpu.h

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

  由找到的结果可知,需要添加 arch-s3c24x0 目录

  cp -R arch/arm/include/asm/arch-s3c24x0/ ../../u-boot-2018.03/arch/arm/include/asm/

  添加进去就可以了 不需要做其他设置

(3)arch/arm/Kconfig 中添加

  第1323行添加

1 source "board/samsung/jz2440/Kconfig"

   在第 339 行,就是  menuconfig  中目标板的选择项,这这个选项中我们可以添加自己的板子,使其在 menuconfig 中可见

  

  569~573 行添加:

1 config TARGET_JZ2440
2     bool "Samsung S3C24X0"
3     select CPU_ARM920T
4     help
5         The S3C24X0 is deperated,but I want to use it.

4.2 生成 .config 文件

  我们通过 make menuconfig 进行配置我们的开发板。或者可以用 uboot 2015 版本中的 smdk2410_defconfig进行配置,可以拷贝进去。

  cp configs/smdk2410_defconfig ../../u-boot-2018.03/configs/jz2440_defconfig

  执行命令 make  jz2440_defconfig

  再执行 make menuconfig 查看配置。适量修改下,编译肯定会出错,出错后再进行修改。

4.3 编译

4.3.1 .config:138:warning: symbol value '' invalid for SYS_TEXT_BASE

  在 .config 中我们没有配置代码段的基地址。先找找这个在原先的 uboot 中配置在哪里。在 include/configs/smdk2410.h 中

  拷贝这个文件进入我们的工程中:cp include/configs/smdk2410.h ../../u-boot-2018.03/include/configs/jz2440.h

  查找下包含文件,进行修改,然后查看 include/configs/jz2440.h 文件,进行 make menuconfig  配置

  将 CONFIG_SYS_TEXT_BASE 在menuconfig  中修改为 0x0

4.3.2 include/configs/jz2440.h:78:32: fatal error: config_cmd_default.h: No such file or directory

  没有这个文件了。注释掉编译

4.3.3 重复定义项

  (1)include/configs/jz2440.h:84:0: warning: "CONFIG_CMD_ELF" redefined

  (2)include/configs/jz2440.h:91:0: warning: "CONFIG_CMDLINE_EDITING" redefined

  (3)include/configs/jz2440.h:110:0: warning: "CONFIG_SYS_LONGHELP" redefined

  (4)include/configs/jz2440.h:111:0: warning: "CONFIG_SYS_PROMPT" redefined

  (5)include/configs/jz2440.h:119:0: warning: "CONFIG_DISPLAY_CPUINFO" redefined

  (6)include/configs/jz2440.h:129:0: warning: "CONFIG_LZMA" redefined

  注释掉代码中的那几行即可

4.3.4 时钟函数未找到

  (1)arch/arm/cpu/arm920t/s3c24x0/cpu_info.c:15:2: error: ‘get_FCLK’ undeclared here (not in a function); did you mean ‘get_dacr’?   

  (2)arch/arm/cpu/arm920t/s3c24x0/cpu_info.c:16:2: error: ‘get_HCLK’ undeclared here (not in a function); did you mean ‘get_FCLK’?

  (3)arch/arm/cpu/arm920t/s3c24x0/cpu_info.c:17:2: error: ‘get_PCLK’ undeclared here (not in a function); did you mean ‘get_HCLK’?

  通过文件对比可以知道,这三个函数被定义在 arch/arm/cpu/arm920t/s3c24x0/speed.c 中,但是当前工程版本中未包含这几个函数,在头文件中进行申明添加。

  505-510 行加入

 1 /* $(CPU)/speed.c */
 2 int    get_clocks (void);
 3 ulong    get_bus_freq  (ulong);
 4 int get_serial_clock(void);
 5 #if defined(CONFIG_S3C24X0)
 6 ulong get_FCLK(void);
 7 ulong get_HCLK(void);
 8 ulong get_PCLK(void);
 9 ulong get_UCLK(void);
10 #endif

4.3.5 板子适配问题

  board/samsung/jz2440/jz2440.c:100:27: error: ‘MACH_TYPE_JZ2440’ undeclared (first use in this function)

  对比2015版本的代码可以知道是因为 machine_arch_type 没有定义,所以在arch/arm/include/asm/mach-types.h中定义此变量

  文件头加上如下代码:

1 #ifndef __ASSEMBLY__
2 extern unsigned int __machine_arch_type;
3 #endif

  文件尾加上如下代码:

 1 #ifdef CONFIG_ARCH_JZ2440
 2 # ifdef machine_arch_type
 3 # undef machine_arch_type
 4 # define machine_arch_type __machine_arch_type
 5 # else
 6 # define machine_arch_type MACH_TYPE_JZ2440
 7 # endif
 8 # define machine_is_jz2440()    (machine_arch_type == MACH_TYPE_JZ2440)
 9 #else
10 # define machine_is_jz2440()    (0)
11 #endif

  board/samsung/jz2440/jz2440.c 加上头文件:

#include <asm/mach-types.h>

4.3.6 无此文件和目录

  (1)cmd/reginfo.c:10:10: fatal error: asm/ppc.h: No such file or directory

    #include <asm/ppc.h>

    reginfo.c  是命令文件,打印寄存器的信息,可以在 menuconfig 中的 common line 选项中修改

    带源代码中查找 CONFIG_CMD_REGINFO:

    

    在menuconfig 中 CMD_REGINFO 依赖于 PPC=y,注释掉此项定义。

  (2)cmd/ubi.c: In function ‘display_ubi_info’:

      cmd/ubi.c:79:44: error: ‘CONFIG_MTD_UBI_WL_THRESHOLD’ undeclared (first use in this function)

      cmd/ubi.c:28:54: note: in definition of macro ‘ubi_msg’

      cmd/ubi.c:79:44: note: each undeclared identifier is reported only once for each function it appears in ubi_msg("wear-leveling threshold:    %d", CONFIG_MTD_UBI_WL_THRESHOLD);

      cmd/ubi.c:28:54: note: in definition of macro ‘ubi_msg’ #define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)

    

    README 中的解释,默认值是4096

    

    menuconfig 中没有开 MTD_UBI 则此模块可以注释掉。

    include/configs/jz2440.h 中

    

  (3)cmd/built-in.o: In function `do_fat_fsinfo':

    cmd/fat.c:85: undefined reference to `fat_set_blk_dev'

    cmd/fat.c:90: undefined reference to `file_fat_detectfs'

    追踪代码可以知道 fat_set_blk_dev 和 file_fat_detectfs 都定义在 Fat.c (fs\fat) 中,fat 文件系统我们并没有支持。在 include/configs/jz2440.h 中关闭掉这个命令宏。

    代码第 185 行注释

  (4)drivers/mtd/nand/built-in.o: In function `nand_init_chip':

    drivers/mtd/nand/nand.c:94: undefined reference to `board_nand_init'

    对比代码可以知道,drivers/mtd/nand/s3c2410_nand.c 这个文件在 2018.03 版本中没有,复制进工程中。

    drivers/mtd/nand$ cp s3c2410_nand.c ../../../../../u-boot-2018.03/drivers/mtd/nand/s3c2440_nand.c

    将 s3c2440_nand.c 中的2410 字符串改为 2440

    drivers/mtd/nand/Makefile 中59行添加:

1 obj-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o 

    drivers/mtd/nand/Kconfig 中添加:

1 config NAND_S3C2440
2     bool "Support for S3c2440 Nand Controller"
3     depends on TARGET_JZ2440
4     imply CMD_NAND
5     help 
6       This enables Nand driver support for Nand flash contoller
7       found on S3C2440 Soc.

    修改完成后 需要进入 menuconfig 中添加配置。

  (5)env/built-in.o: In function `env_flash_save':

    env/flash.c:268: undefined reference to `flash_sect_protect'

    env/flash.c:276: undefined reference to `flash_sect_erase'

    env/flash.c:280: undefined reference to `flash_write'

    env/flash.c:303: undefined reference to `flash_sect_protect'

    env/flash.c:298: undefined reference to `flash_perror'

    追踪代码可以知道 CONFIG_MTD_NOR_FLASH 宏未定义,开宏即可

    

4.3.7 规则问题

  (1)make[1]: *** No rule to make target 'arch/arm/dts/unset.dts', needed by 'arch/arm/dts/unset.dtb'. 

    Makefile:879: recipe for target 'dts/dt.dtb' failed

    看一下顶层的  Makefile:

    

    这里编译进了 dts ,dts  我们不支持得干掉

    make menuconfig 中,

    Device Tree Control  干掉

    Path to dtc binary for use within mkimage  的值设为空

4.3.8 宏定义问题   

    Error: You must add new CONFIG options using Kconfig
    The following new ad-hoc CONFIG options were detected:
    CONFIG_JZ2440
    CONFIG_NAND_S3C2410
    CONFIG_RTC_S3C24X0
    CONFIG_S3C2410
    CONFIG_S3C24X0
    CONFIG_S3C24X0_SERIAL
    CONFIG_SMDK2410
    CONFIG_SYS_HUSH_PARSER
    CONFIG_SYS_S3C2410_NAND_HWECC
    CONFIG_USB_OHCI_S3C24XX
    CONFIG_ZERO_BOOTDELAY_CHECK

  注释掉顶层  Makefile 中下面几句:

  

  clean 之后编译。

  编译完成,生成了 u-boot.bin.

  

4.3.8 驱动问题

  (1)cmd/date.c:52:12: warning: implicit declaration of function ‘I2C_GET_BUS’;

  (2)cmd/date.c:53:2: warning: implicit declaration of function ‘I2C_SET_BUS’; 

  (3)cmd/date.c:53:14: error: ‘CONFIG_SYS_RTC_BUS_NUM’ undeclared

   函数问题是因为 CONFIG_DM_I2C_COMPAT 未定义,即 I2C 模块未开启,若是开启了 CONFIG_SYS_I2C 或是 CONFIG_DM_RTC 则不会走那个分支

   我们直接关掉 CONFIG_DM_I2C 模块 

  (4)drivers/spi/built-in.o: In function `dev_read_u32_default'

    DM 模块问题,关掉 DM 模块。    

  (5)rivers/serial/serial.c:379: undefined reference to `default_serial_console'

    对比代码可以知道,缺少serial_s3c24x0.c文件,拷贝进去,并修改 Makefile

    drivers/serial$ cp serial_s3c24x0.c ../../../../u-boot-2018.03/drivers/serial/

    

    修改完成,已经可以编译出完整的 u-boot.bin 文件了。后续再做代码分析和移植的时候,有些东西还需要修改

    当前的 .bin 文件是过大的,接近350K

    

    

      

  

  

  

  

  

  

猜你喜欢

转载自www.cnblogs.com/kele-dad/p/8983109.html