首页 技术 正文
技术 2022年11月23日
0 收藏 604 点赞 2,875 浏览 11985 个字

5.1 移植第一步

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

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

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

5.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 v2017.01(对比源码,可以不做)

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

 cp -R smdk2410/ ./uboot/board/samsung/jz2440

  修改文件:

  cd uboot/board/samsung/jz2440

  mv smdk2410.c jz2440.c

  修改 makefile:

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

  jz2440.c 文件修改:

  四、移植 JZ2440 开发板

  注意:这里之所以把arch number 改为 S3C2440,是因为在 arch/arm/include/asm/mach-types.h 中给我们定义了一个s3c2440 的通用宏,而且在此文件中,已经给我们设置好了:

  四、移植 JZ2440 开发板

  四、移植 JZ2440 开发板

  Kconfig 修改:

 if TARGET_JZ2440 config SYS_BOARD
default "jz2440" config SYS_VENDOR
default "samsung" config SYS_SOC
default "s3c24x0" config SYS_CONFIG_NAME
default "jz2440" endif

  当前目录修改完毕

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

(1)头文件

  ./arch/arm/include/asm/arch-s3c24x0/s3c24x0.h 这个文件是 s3c24x0 芯片的寄存器的 的定义

  ./arch/arm/include/asm/arch-s3c24x0:CPU的一些操作和定义

  jz2440.h 头文件:cp smdk2410.h ../../../uboot/include/configs/jz2440.h

  修改 jz2440.h 文件如下:

  四、移植 JZ2440 开发板

(2)arch/arm/Kconfig 中添加

  添加

 source "board/samsung/jz2440/Kconfig"

  四、移植 JZ2440 开发板

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

  四、移植 JZ2440 开发板

  569~573 行添加:

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

  四、移植 JZ2440 开发板

5.2 生成 .config 文件

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

  cp smdk2410_defconfig ../../uboot/configs/jz2440_defconfig

  执行命令 make  jz2440_defconfig

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

  • ARM architecture:

    • ARM64 system support AArch32 execution state:此选项去掉
    • Use PSCI for reset and shutdown:此选项去掉
    • Target select:目标选择,选择我们定义的开发板 Samsung S3C24X0
  • General setup:
    • 64bit physical address support:去掉此选项
  • delay in seconds before automatically booting:设置为5
  • Device Tree Control:
    • Run-time configuration via Device Tree:关闭掉此项

  主Makefile 中指定一下交叉编译 工具链:

  四、移植 JZ2440 开发板

  执行 make  编译。

5.3 编译

5.3.1 .config:138:warning: symbol value ” invalid for SYS_TEXT_BASE

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

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

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

  将 CONFIG_SYS_TEXT_BASE 在menuconfig  中修改为 0x0

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

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

5.3.3 cmd/ubi.c:79:44: error: ‘CONFIG_MTD_UBI_WL_THRESHOLD’ undeclared (first use in this function); did you mean ‘CONFIG_MTD_UBI_BEB_RESERVE’?

  make menuconfig 后,查找此配置宏:

  四、移植 JZ2440 开发板

  依赖于 MTD_UBI,这个我们是没有开的,这个宏的配置在 Device Drivers–> UBI support–>Enable UBI 下。Enable UBI 没有配置。看看是否有其他地方宏配置了。

  include/configs/jz2440.h 中配置了UBI文件系统,我们将文件系统的配置全部删除掉,保留 YAFFS2 即可。

  四、移植 JZ2440 开发板

5.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

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

  不止这几项重复,所有的重复项定义都可以在 include/configs/jz2440.h 中删除,在执行 make menuconfig 的时候,其实都可以配置。

5.3.4 dts/Makefile:27: recipe for target ‘arch/arm/dts/unset.dtb’ failed

  未配置 DTS,所以是include/configs/jz2440.h 中添加的定义,删除掉

5.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 行加入

 /* $(CPU)/speed.c */
int get_clocks (void);
ulong get_bus_freq (ulong);
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

5.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中定义此变量

  文件头加上如下代码:

 #ifndef __ASSEMBLY__
extern unsigned int __machine_arch_type;
#endif

  文件尾加上如下代码:

 #ifdef CONFIG_ARCH_JZ2440
# ifdef machine_arch_type
# undef machine_arch_type
# define machine_arch_type __machine_arch_type
# else
# define machine_arch_type MACH_TYPE_JZ2440
# endif
# define machine_is_jz2440() (machine_arch_type == MACH_TYPE_JZ2440)
#else
# define machine_is_jz2440() ()
#endif

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

#include <asm/mach-types.h>

5.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:

    四、移植 JZ2440 开发板

    在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__)

    四、移植 JZ2440 开发板

    README 中的解释,默认值是4096

    四、移植 JZ2440 开发板

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

    include/configs/jz2440.h 中

    四、移植 JZ2440 开发板

  (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行添加:

 obj-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o 

    drivers/mtd/nand/Kconfig 中添加:

 config NAND_S3C2440
bool "Support for S3c2440 Nand Controller"
depends on TARGET_JZ2440
imply CMD_NAND
help
This enables Nand driver support for Nand flash contoller
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 宏未定义,开宏即可

    四、移植 JZ2440 开发板

5.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:

    四、移植 JZ2440 开发板

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

    make menuconfig 中,

    Device Tree Control  干掉

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

5.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 中下面几句:

  四、移植 JZ2440 开发板

  clean 之后编译。

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

  四、移植 JZ2440 开发板

  或者将这些内容直接加入到 scripts/config_whitelist.txt  当中。

  

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

    四、移植 JZ2440 开发板

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

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

    四、移植 JZ2440 开发板

6. 第一次裁剪后的 jz2440.h 文件

/*
* (C) Copyright 2002
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
* Marius Groeger <mgroeger@sysgo.de>
* Gary Jennejohn <garyj@denx.de>
* David Mueller <d.mueller@elsoft.ch>
*
* Configuation settings for the SAMSUNG SMDK2410 board.
*
* SPDX-License-Identifier: GPL-2.0+
*/#ifndef __CONFIG_H
#define __CONFIG_H/*
* High Level Configuration Options
* (easy to change)
*/
#define CONFIG_S3C24X0 /* This is a SAMSUNG S3C24x0-type SoC */
#define CONFIG_S3C2440#define CONFIG_SYS_TEXT_BASE 0x0#define CONFIG_SYS_ARM_CACHE_WRITETHROUGH/* input clock of PLL (the SMDK2410 has 12MHz input clock) */
#define CONFIG_SYS_CLK_FREQ 12000000#define CONFIG_CMDLINE_TAG /* enable passing of ATAGs */
#define CONFIG_SETUP_MEMORY_TAGS
#define CONFIG_INITRD_TAG/*
* Hardware drivers
*/
#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 *//*
* select serial console configuration
*/
#if 0
#define CONFIG_S3C24X0_SERIAL
#endif
#define CONFIG_SERIAL1 1 /* we use SERIAL 1 on SMDK2410 *//************************************************************
* USB support (currently only works with D-cache off)
************************************************************/
#define CONFIG_USB_OHCI/************************************************************
* RTC
************************************************************/#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.
*/#define CONFIG_CMD_BSP
#define CONFIG_CMD_CACHE
#define CONFIG_CMD_DHCP
#define CONFIG_CMD_PING
#define CONFIG_CMD_REGINFO
#define CONFIG_CMDLINE_EDITING/* autoboot */
#define CONFIG_BOOT_RETRY_TIME -1
#define CONFIG_RESET_TO_RETRY
#if 0
#define CONFIG_ZERO_BOOTDELAY_CHECK
#endif#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 10.0.0.110
#define CONFIG_SERVERIP 10.0.0.1#if defined(CONFIG_CMD_KGDB)
#define CONFIG_KGDB_BAUDRATE 115200 /* speed to run kgdb serial port */
#endif/*
* Miscellaneous configurable options
*/
#define CONFIG_SYS_LONGHELP /* undef to save memory */
#define CONFIG_SYS_CBSIZE 256
/* Print Buffer Size */
#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \
sizeof(CONFIG_SYS_PROMPT)+)
#define CONFIG_SYS_MAXARGS 16
#define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE#define CONFIG_SYS_MEMTEST_START 0x30000000 /* memtest works on */
#define CONFIG_SYS_MEMTEST_END 0x33F00000 /* 63 MB in DRAM */#define CONFIG_SYS_LOAD_ADDR 0x30800000/* support additional compression methods */
#define CONFIG_BZIP2
#define CONFIG_LZO
#define CONFIG_LZMA/*-----------------------------------------------------------------------
* 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 #0 */#define CONFIG_SYS_FLASH_BASE PHYS_FLASH_1/*-----------------------------------------------------------------------
* FLASH and environment organization
*/#define CONFIG_SYS_FLASH_CFI
#define CONFIG_FLASH_CFI_DRIVER
#define CONFIG_FLASH_CFI_LEGACY
#define CONFIG_SYS_FLASH_LEGACY_512Kx16
#define CONFIG_FLASH_SHOW_PROGRESS 45#define CONFIG_SYS_MAX_FLASH_BANKS 1
#define CONFIG_SYS_FLASH_BANKS_LIST { CONFIG_SYS_FLASH_BASE }
#define CONFIG_SYS_MAX_FLASH_SECT (19)#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)
#define CONFIG_ENV_IS_IN_FLASH
#define CONFIG_ENV_SIZE 0x10000
/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE/*
* Size of malloc() pool
* BZIP2 / LZO / LZMA need a lot of RAM
*/
#define CONFIG_SYS_MALLOC_LEN (4 * 1024 * 1024)#define CONFIG_SYS_MONITOR_LEN (448 * 1024)
#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_FLASH_BASE/*
* NAND configuration
*//*
* File system
*/
#if 0
#define CONFIG_YAFFS2
#endif/* additions for new relocation code, must be added to all boards */
#define CONFIG_SYS_SDRAM_BASE PHYS_SDRAM_1
#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x1000 - \
GENERATED_GBL_DATA_SIZE)#define CONFIG_BOARD_EARLY_INIT_F#endif /* __CONFIG_H */

    

      

  

  

  

  

  

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,903
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,429
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,245
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,057
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,689
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,726