五、移植 JZ2440 開發板


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 到 下面的目錄中去

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

  修改文件:

  cd uboot/board/samsung/jz2440

  mv smdk2410.c jz2440.c

  修改 makefile:

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

  jz2440.c 文件修改:

  

  注意:這里之所以把arch number 改為 S3C2440,是因為在 arch/arm/include/asm/mach-types.h 中給我們定義了一個s3c2440 的通用宏,而且在此文件中,已經給我們設置好了:

  

 

 

   

  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

  當前目錄修改完畢

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 文件如下:

  

(2)arch/arm/Kconfig 中添加

  添加

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.

  

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 中指定一下交叉編譯 工具鏈:

  

 

 

   執行 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 后,查找此配置宏:

  

 

   依賴於 MTD_UBI,這個我們是沒有開的,這個宏的配置在 Device Drivers--> UBI support-->Enable UBI 下。Enable UBI 沒有配置。看看是否有其他地方宏配置了。

  include/configs/jz2440.h 中配置了UBI文件系統,我們將文件系統的配置全部刪除掉,保留 YAFFS2 即可。

  

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

 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

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中定義此變量

  文件頭加上如下代碼:

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>

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:

    

    在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 宏未定義,開宏即可

    

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:

    

    這里編譯進了 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 中下面幾句:

  

  clean 之后編譯。

  編譯完成,生成了 u-boot.bin.

  

   或者將這些內容直接加入到 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/

    

    修改完成,已經可以編譯出完整的 u-boot.bin 文件了。后續再做代碼分析和移植的時候,有些東西還需要修改

    當前的 .bin 文件是過大的,接近350K

    

 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)+16)
#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 */

 

    

      

  

  

  

  

 

 

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM