从头开始移植u-boot和linux kernel 到imx6ul之u-boot

soc的启动一般都有下面这几个阶段:
1.soc上电,执行IROM中的厂商固话的boot_strap 代码
2.IROM中的boot_strap 代码初始化IRAM
3.并把IROM中的boot_strap 代码拷贝到IRAM中
4.跳到IRAM中继续执行boot_strap 代码
5.在IRAM中的boot_strap 代码初始化外部RAM,也就是主memory,一般是某种DDR器件。
6.在IRAM中的boot_strap 代码根据硬件的启动模式配置从对应的启动介质中拷贝用户的启动代码到RAM中
7.执行RAM中的用户的启动代码
总之,就像滚雪球一样,从最初的IROM中往外开疆拓土,最后完成用户程序(比如操作系统)的运行。
正好手中有一块NXP 的imx6ul开发板,想做个u-boot的移植实验,看看能够跑起u-boot的最小配置是怎么样的。
首先,找一个u-boot版本入手
http://www.denx.de/wiki/U-Boot/SourceCode
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第1张图片
ftp://ftp.denx.de/pub/u-boot/
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第2张图片
心想既然要移植,那就找个最新的版本吧。但下载下来后提示我的交叉编译工具版本太老了,高版本的u-boot中已经需要v4.6版本以上的gcc交叉编译工具了,已经不支持我手上的v4.5版本交叉工具链了。
最终,找来找去,发现u-boot-2017.11这个版本是最后一个能支持我手上的交叉编译工具版本的,所以只能下这个版本的进行试验了。
2.source 一下交叉编译工具环境变量
1.解压u-boot源码压缩包到工作目录
2. make board_xxx_default_config
3.make menuconfig
make
然后发现生成了uboot-spl
而我的imx6ul一般使用uboot.imx格式的文件,这个是在u-boot.bin基础上做了些修改,能够被IROM中的boot_strap解析的uboot镜像格式,使用这种格式,就可以借助boot_strap代码帮助我们初始化DDR,有了DDR,其他什么都好办了。
1.添加一个board配置
在这里插入图片描述
配置文件my_imx6ul_defconfig 中为空
清理一下工作目录,确保旧的配置什么的都被清理干净
在这里插入图片描述
make 一下我们的配置
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第3张图片

root@ubuntu:~/my-imx6/02_source/u-boot-2017.11# ls configs/
mx6ul_14x14_evk_defconfig  my_imx6ul_defconfig
root@ubuntu:~/my-imx6/02_source/u-boot-2017.11# cat configs/my_imx6ul_defconfig 
root@ubuntu:~/my-imx6/02_source/u-boot-2017.11# make distclean
  CLEAN   scripts/basic
  CLEAN   scripts/kconfig
  CLEAN   .config
root@ubuntu:~/my-imx6/02_source/u-boot-2017.11# make my_imx6ul_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#

提示配置已经被写到了.config中,让我们看一下现在.config中是什么样的:

#
# Automatically generated file; DO NOT EDIT.
# U-Boot 2017.11 Configuration
#
# CONFIG_ARC is not set
# CONFIG_ARM is not set
# CONFIG_M68K is not set
# CONFIG_MICROBLAZE is not set
# CONFIG_MIPS is not set
# CONFIG_NDS32 is not set
# CONFIG_NIOS2 is not set
# CONFIG_PPC is not set
CONFIG_SANDBOX=y
# CONFIG_SH is not set
# CONFIG_X86 is not set
# CONFIG_XTENSA is not set

#
# General setup
#
CONFIG_LOCALVERSION=""
CONFIG_LOCALVERSION_AUTO=y
CONFIG_CC_OPTIMIZE_FOR_SIZE=y
# CONFIG_DISTRO_DEFAULTS is not set
CONFIG_SYS_MALLOC_F=y
CONFIG_SYS_MALLOC_F_LEN=0x400
CONFIG_SPL_SYS_MALLOC_F_LEN=0x400
CONFIG_TPL_SYS_MALLOC_F_LEN=0x400
CONFIG_EXPERT=y
CONFIG_SYS_MALLOC_CLEAR_ON_INIT=y
# CONFIG_TOOLS_DEBUG is not set
# CONFIG_PHYS_64BIT is not set

#
# Boot images
#
# CONFIG_ANDROID_BOOT_IMAGE is not set
# CONFIG_FIT is not set
CONFIG_SYS_EXTRA_OPTIONS=""
CONFIG_ARCH_FIXUP_FDT_MEMORY=y

#
# API
#
# CONFIG_API is not set

#
# Boot timing
#
# CONFIG_BOOTSTAGE is not set
CONFIG_BOOTSTAGE_RECORD_COUNT=30
CONFIG_SPL_BOOTSTAGE_RECORD_COUNT=5
CONFIG_BOOTSTAGE_STASH_ADDR=0
CONFIG_BOOTSTAGE_STASH_SIZE=0x1000

#
# Boot media
#
# CONFIG_NAND_BOOT is not set
# CONFIG_ONENAND_BOOT is not set
# CONFIG_QSPI_BOOT is not set
# CONFIG_SATA_BOOT is not set
# CONFIG_SD_BOOT is not set
# CONFIG_SPI_BOOT is not set
CONFIG_BOOTDELAY=2
# CONFIG_USE_BOOTARGS is not set

#
# Console
#
# CONFIG_CONSOLE_RECORD is not set
CONFIG_IDENT_STRING=""
CONFIG_LOGLEVEL=4
CONFIG_SPL_LOGLEVEL=4
# CONFIG_SILENT_CONSOLE is not set
# CONFIG_PRE_CONSOLE_BUFFER is not set
# CONFIG_CONSOLE_MUX is not set
# CONFIG_SYS_CONSOLE_IS_IN_ENV is not set
# CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE is not set
# CONFIG_SYS_CONSOLE_ENV_OVERWRITE is not set
# CONFIG_SYS_CONSOLE_INFO_QUIET is not set
# CONFIG_SYS_STDIO_DEREGISTER is not set
CONFIG_DEFAULT_FDT_FILE=""
# CONFIG_VERSION_VARIABLE is not set
CONFIG_BOARD_LATE_INIT=y
# CONFIG_DISPLAY_CPUINFO is not set
CONFIG_DISPLAY_BOARDINFO=y

#
# Start-up hooks
#
# CONFIG_ARCH_EARLY_INIT_R is not set
# CONFIG_ARCH_MISC_INIT is not set
# CONFIG_BOARD_EARLY_INIT_F is not set

#
# Security support
#
CONFIG_HASH=y

#
# SPL / TPL
#

#
# Command line interface
#
CONFIG_CMDLINE=y
# CONFIG_HUSH_PARSER is not set
CONFIG_SYS_PROMPT="=> "

#
# Autoboot options
#
CONFIG_AUTOBOOT=y
# CONFIG_AUTOBOOT_KEYED is not set

#
# FASTBOOT
#
CONFIG_BUILD_BIN2C=y

#
# Commands
#

#
# Info commands
#
CONFIG_CMD_BDI=y
CONFIG_CMD_CONFIG=y
CONFIG_CMD_CONSOLE=y
# CONFIG_CMD_CPU is not set
# CONFIG_CMD_LICENSE is not set

#
# Boot commands
#
CONFIG_CMD_BOOTD=y
CONFIG_CMD_BOOTM=y
# CONFIG_CMD_BOOTZ is not set
# CONFIG_CMD_BOOTMENU is not set
CONFIG_CMD_ELF=y
CONFIG_CMD_GO=y
CONFIG_CMD_RUN=y
CONFIG_CMD_IMI=y
# CONFIG_CMD_IMLS is not set
CONFIG_CMD_XIMG=y
# CONFIG_CMD_POWEROFF is not set
# CONFIG_CMD_THOR_DOWNLOAD is not set
# CONFIG_CMD_ZBOOT is not set

#
# Environment commands
#
# CONFIG_CMD_ASKENV is not set
CONFIG_CMD_EXPORTENV=y
CONFIG_CMD_IMPORTENV=y
CONFIG_CMD_EDITENV=y
# CONFIG_CMD_GREPENV is not set
CONFIG_CMD_SAVEENV=y
CONFIG_CMD_ENV_EXISTS=y
# CONFIG_CMD_ENV_CALLBACK is not set
# CONFIG_CMD_ENV_FLAGS is not set

#
# Memory commands
#
CONFIG_CMD_CRC32=y
CONFIG_CRC32_VERIFY=y
# CONFIG_CMD_EEPROM is not set
# CONFIG_LOOPW is not set
# CONFIG_CMD_MD5SUM is not set
# CONFIG_CMD_MEMINFO is not set
CONFIG_CMD_MEMORY=y
# CONFIG_CMD_MEMTEST is not set
# CONFIG_CMD_MX_CYCLIC is not set
# CONFIG_CMD_SHA1SUM is not set
# CONFIG_CMD_STRINGS is not set

#
# Compression commands
#
CONFIG_CMD_LZMADEC=y
# CONFIG_CMD_UNZIP is not set
# CONFIG_CMD_ZIP is not set

#
# Device access commands
#
# CONFIG_CMD_ARMFLASH is not set
# CONFIG_CMD_CLK is not set
# CONFIG_CMD_DEMO is not set
# CONFIG_CMD_DFU is not set
CONFIG_CMD_DM=y
# CONFIG_CMD_FDC is not set
CONFIG_CMD_FLASH=y
CONFIG_CMD_FPGA=y
# CONFIG_CMD_FPGA_LOADBP is not set
# CONFIG_CMD_FPGA_LOADFS is not set
# CONFIG_CMD_FPGA_LOADMK is not set
# CONFIG_CMD_FPGA_LOADP is not set
# CONFIG_CMD_FPGAD is not set
# CONFIG_CMD_FUSE is not set
# CONFIG_CMD_GPIO is not set
# CONFIG_CMD_GPT is not set
# CONFIG_RANDOM_UUID is not set
# CONFIG_CMD_IDE is not set
CONFIG_CMD_IO=y
CONFIG_CMD_IOTRACE=y
# CONFIG_CMD_I2C is not set
CONFIG_CMD_LOADB=y
CONFIG_CMD_LOADS=y
# CONFIG_CMD_MMC is not set
# CONFIG_CMD_NAND is not set
# CONFIG_CMD_MMC_SPI is not set
# CONFIG_CMD_ONENAND is not set
# CONFIG_CMD_PART is not set
# CONFIG_CMD_PCI is not set
# CONFIG_CMD_PCMCIA is not set
# CONFIG_CMD_READ is not set
CONFIG_CMD_SATA=y
# CONFIG_CMD_SAVES is not set
# CONFIG_CMD_SDRAM is not set
# CONFIG_CMD_SF is not set
CONFIG_CMD_SF_TEST=y
# CONFIG_CMD_SPI is not set
# CONFIG_CMD_TSI148 is not set
# CONFIG_CMD_UNIVERSE is not set
# CONFIG_CMD_USB is not set
# CONFIG_CMD_USB_SDP is not set
# CONFIG_CMD_USB_MASS_STORAGE is not set

#
# Shell scripting commands
#
CONFIG_CMD_ECHO=y
CONFIG_CMD_ITEST=y
CONFIG_CMD_SOURCE=y
CONFIG_CMD_SETEXPR=y

#
# Network commands
#
CONFIG_CMD_NET=y
# CONFIG_CMD_TFTPPUT is not set
# CONFIG_CMD_TFTPSRV is not set
# CONFIG_CMD_RARP is not set
# CONFIG_CMD_DHCP is not set
# CONFIG_CMD_PXE is not set
CONFIG_CMD_NFS=y
# CONFIG_CMD_MII is not set
# CONFIG_CMD_PING is not set
# CONFIG_CMD_CDP is not set
# CONFIG_CMD_SNTP is not set
# CONFIG_CMD_DNS is not set
# CONFIG_CMD_LINK_LOCAL is not set
# CONFIG_CMD_ETHSW is not set

#
# Misc commands
#
# CONFIG_CMD_BSP is not set
# CONFIG_CMD_CACHE is not set
# CONFIG_CMD_DISPLAY is not set
# CONFIG_CMD_LED is not set
# CONFIG_CMD_DATE is not set
# CONFIG_CMD_TIME is not set
CONFIG_CMD_GETTIME=y
CONFIG_CMD_MISC=y
# CONFIG_CMD_TIMER is not set
# CONFIG_CMD_QFW is not set
# CONFIG_CMD_TERMINAL is not set
# CONFIG_CMD_UUID is not set

#
# Power commands
#

#
# Security commands
#
# CONFIG_CMD_AES is not set
# CONFIG_CMD_BLOB is not set
CONFIG_CMD_HASH=y
CONFIG_HASH_VERIFY=y

#
# Firmware commands
#

#
# Filesystem commands
#
# CONFIG_CMD_BTRFS is not set
# CONFIG_CMD_EXT2 is not set
# CONFIG_CMD_EXT4 is not set
# CONFIG_CMD_FAT is not set
# CONFIG_CMD_FS_GENERIC is not set
# CONFIG_CMD_FS_UUID is not set
# CONFIG_CMD_JFFS2 is not set
# CONFIG_CMD_MTDPARTS is not set
CONFIG_MTDIDS_DEFAULT=""
CONFIG_MTDPARTS_DEFAULT=""
# CONFIG_CMD_REISER is not set
CONFIG_CMD_SCSI=y
# CONFIG_CMD_ZFS is not set

#
# Debug commands
#
# CONFIG_CMD_BEDBUG is not set
# CONFIG_CMD_DIAG is not set
# CONFIG_CMD_IRQ is not set
# CONFIG_CMD_KGDB is not set
# CONFIG_CMD_TRACE is not set
# CONFIG_CMD_UBI is not set

#
# Partition Types
#
CONFIG_PARTITIONS=y
# CONFIG_MAC_PARTITION is not set
# CONFIG_DOS_PARTITION is not set
# CONFIG_ISO_PARTITION is not set
# CONFIG_AMIGA_PARTITION is not set
# CONFIG_EFI_PARTITION is not set
# CONFIG_PARTITION_UUIDS is not set
CONFIG_SUPPORT_OF_CONTROL=y

#
# Device Tree Control
#
# CONFIG_OF_CONTROL is not set
# CONFIG_OF_BOARD_FIXUP is not set
# CONFIG_MULTI_DTB_FIT is not set
CONFIG_MKIMAGE_DTC_PATH="dtc"

#
# Environment
#
CONFIG_ENV_IS_NOWHERE=y
# CONFIG_ENV_IS_IN_EEPROM is not set
# CONFIG_ENV_IS_IN_FAT is not set
# CONFIG_ENV_IS_IN_FLASH is not set
# CONFIG_ENV_IS_IN_MMC is not set
# CONFIG_ENV_IS_IN_NAND is not set
# CONFIG_ENV_IS_IN_NVRAM is not set
# CONFIG_ENV_IS_IN_ONENAND is not set
# CONFIG_ENV_IS_IN_REMOTE is not set
# CONFIG_ENV_IS_IN_SPI_FLASH is not set
# CONFIG_ENV_IS_IN_UBI is not set
# CONFIG_ENV_AES is not set
CONFIG_NET=y
# CONFIG_NET_RANDOM_ETHADDR is not set
# CONFIG_NETCONSOLE is not set
CONFIG_NET_TFTP_VARS=y
CONFIG_BOOTP_VCI_STRING="U-Boot"

#
# Device Drivers
#

#
# Generic Driver Options
#
CONFIG_DM=y
CONFIG_DM_WARN=y
# CONFIG_DM_DEBUG is not set
CONFIG_DM_DEVICE_REMOVE=y
CONFIG_DM_STDIO=y
CONFIG_DM_SEQ_ALIAS=y
# CONFIG_SPL_DM_SEQ_ALIAS is not set
# CONFIG_REGMAP is not set
# CONFIG_DEVRES is not set
CONFIG_DM_DEV_READ_INLINE=y
# CONFIG_ADC is not set
# CONFIG_ADC_EXYNOS is not set
# CONFIG_ADC_SANDBOX is not set
# CONFIG_SARADC_ROCKCHIP is not set
# CONFIG_AHCI is not set
CONFIG_SATA=y

#
# SATA/SCSI device support
#
CONFIG_BLK=y
# CONFIG_BLOCK_CACHE is not set
# CONFIG_IDE is not set

#
# Clock
#
# CONFIG_CLK is not set
# CONFIG_CPU is not set

#
# Hardware crypto devices
#
# CONFIG_FSL_CAAM is not set
# CONFIG_SYS_FSL_SEC_BE is not set
# CONFIG_SYS_FSL_SEC_LE is not set

#
# Demo for driver model
#
# CONFIG_DM_DEMO is not set

#
# DFU support
#

#
# DMA Support
#
# CONFIG_DMA is not set
# CONFIG_TI_EDMA3 is not set

#
# FPGA support
#
# CONFIG_FPGA_ALTERA is not set
# CONFIG_FPGA_SOCFPGA is not set
# CONFIG_FPGA_XILINX is not set

#
# GPIO Support
#
CONFIG_DM_GPIO=y
# CONFIG_ALTERA_PIO is not set
# CONFIG_DWAPB_GPIO is not set
# CONFIG_AT91_GPIO is not set
# CONFIG_ATMEL_PIO4 is not set
# CONFIG_INTEL_BROADWELL_GPIO is not set
# CONFIG_INTEL_ICH6_GPIO is not set
# CONFIG_IMX_RGPIO2P is not set
# CONFIG_LPC32XX_GPIO is not set
# CONFIG_MSM_GPIO is not set
# CONFIG_CMD_PCA953X is not set
# CONFIG_PCF8575_GPIO is not set
# CONFIG_ROCKCHIP_GPIO is not set
# CONFIG_SANDBOX_GPIO is not set
# CONFIG_CMD_TCA642X is not set
# CONFIG_TEGRA_GPIO is not set
# CONFIG_TEGRA186_GPIO is not set
# CONFIG_VYBRID_GPIO is not set
# CONFIG_DM_74X164 is not set
# CONFIG_DM_PCA953X is not set
# CONFIG_MPC85XX_GPIO is not set

#
# I2C support
#
CONFIG_DM_I2C=y
# CONFIG_DM_I2C_COMPAT is not set
# CONFIG_I2C_SET_DEFAULT_BUS_NUM is not set
# CONFIG_DM_I2C_GPIO is not set
# CONFIG_SYS_I2C_FSL is not set
# CONFIG_SYS_I2C_DW is not set
# CONFIG_SYS_I2C_INTEL is not set
# CONFIG_SYS_I2C_IMX_LPI2C is not set
# CONFIG_SYS_I2C_ROCKCHIP is not set
# CONFIG_SYS_I2C_SANDBOX is not set
# CONFIG_SYS_I2C_MVTWSI is not set
# CONFIG_I2C_MUX is not set
CONFIG_DM_KEYBOARD=y
# CONFIG_CROS_EC_KEYB is not set
# CONFIG_I8042_KEYB is not set

#
# LED Support
#
# CONFIG_LED is not set
# CONFIG_LED_STATUS is not set

#
# Mailbox Controller Support
#

#
# Memory Controller drivers
#

#
# Multifunction device drivers
#
# CONFIG_MISC is not set
# CONFIG_CROS_EC is not set
# CONFIG_DS4510 is not set
# CONFIG_FSL_SEC_MON is not set
# CONFIG_MXC_OCOTP is not set
# CONFIG_NUVOTON_NCT6102D is not set
# CONFIG_PWRSEQ is not set
# CONFIG_PCA9551_LED is not set
# CONFIG_WINBOND_W83627 is not set

#
# MMC Host controller Support
#
CONFIG_MMC=y
CONFIG_DM_MMC=y
# CONFIG_SPL_MMC_TINY is not set
# CONFIG_MMC_DW is not set
# CONFIG_MMC_MXC is not set
# CONFIG_MMC_MXS is not set
# CONFIG_MMC_PCI is not set
# CONFIG_MMC_OMAP_HS is not set
# CONFIG_MMC_SDHCI is not set

#
# MTD Support
#
# CONFIG_MTD is not set
# CONFIG_MTD_NOR_FLASH is not set
# CONFIG_NAND is not set

#
# SPI Flash Support
#
CONFIG_DM_SPI_FLASH=y
# CONFIG_SPI_FLASH_SANDBOX is not set
# CONFIG_SPI_FLASH is not set

#
# UBI support
#
# CONFIG_MTD_UBI is not set
# CONFIG_BITBANGMII is not set
# CONFIG_MV88E6352_SWITCH is not set
# CONFIG_PHYLIB is not set
# CONFIG_DM_ETH is not set
# CONFIG_NETDEVICES is not set
# CONFIG_PCI is not set

#
# PHY Subsystem
#
# CONFIG_PHY is not set
# CONFIG_SPL_PHY is not set
# CONFIG_MVEBU_COMPHY_SUPPORT is not set

#
# Pin controllers
#
# CONFIG_PINCTRL is not set

#
# Power
#

#
# Power Domain Support
#
# CONFIG_DM_PMIC is not set
# CONFIG_PMIC_AS3722 is not set
# CONFIG_POWER_MC34VR500 is not set
# CONFIG_DM_REGULATOR is not set
# CONFIG_DM_PWM is not set
# CONFIG_PWM_SANDBOX is not set
# CONFIG_RAM is not set

#
# Remote Processor drivers
#
# CONFIG_REMOTEPROC_SANDBOX is not set

#
# Reset Controller Support
#

#
# Real Time Clock
#
# CONFIG_DM_RTC is not set
CONFIG_SCSI=y
# CONFIG_DM_SCSI is not set

#
# Serial drivers
#
CONFIG_BAUDRATE=115200
CONFIG_REQUIRE_SERIAL_CONSOLE=y
CONFIG_SERIAL_PRESENT=y
CONFIG_SPL_SERIAL_PRESENT=y
CONFIG_DM_SERIAL=y
# CONFIG_SERIAL_RX_BUFFER is not set
# CONFIG_SPL_DM_SERIAL is not set
# CONFIG_TPL_DM_SERIAL is not set
# CONFIG_DEBUG_UART is not set
# CONFIG_DEBUG_UART_SKIP_INIT is not set
# CONFIG_ALTERA_JTAG_UART is not set
# CONFIG_ALTERA_UART is not set
# CONFIG_ATMEL_USART is not set
# CONFIG_FSL_LPUART is not set
# CONFIG_MVEBU_A3700_UART is not set
# CONFIG_NULLDEV_SERIAL is not set
# CONFIG_SYS_NS16550 is not set
# CONFIG_SANDBOX_SERIAL is not set
# CONFIG_MSM_SERIAL is not set
# CONFIG_PXA_SERIAL is not set

#
# Sound support
#
# CONFIG_SOUND is not set

#
# SPI Support
#
CONFIG_DM_SPI=y
# CONFIG_ALTERA_SPI is not set
# CONFIG_CADENCE_QSPI is not set
# CONFIG_DESIGNWARE_SPI is not set
# CONFIG_EXYNOS_SPI is not set
# CONFIG_FSL_DSPI is not set
# CONFIG_ICH_SPI is not set
# CONFIG_MVEBU_A3700_SPI is not set
# CONFIG_ROCKCHIP_SPI is not set
# CONFIG_SANDBOX_SPI is not set
# CONFIG_TEGRA114_SPI is not set
# CONFIG_TEGRA20_SFLASH is not set
# CONFIG_TEGRA20_SLINK is not set
# CONFIG_TEGRA210_QSPI is not set
# CONFIG_XILINX_SPI is not set
# CONFIG_SOFT_SPI is not set
# CONFIG_FSL_ESPI is not set
# CONFIG_FSL_QSPI is not set
# CONFIG_NDS_AE3XX_SPI is not set
# CONFIG_TI_QSPI is not set
# CONFIG_OMAP3_SPI is not set

#
# SPMI support
#
# CONFIG_SPMI is not set

#
# System reset device drivers
#
# CONFIG_SYSRESET is not set
# CONFIG_SYSRESET_SYSCON is not set
# CONFIG_SYSRESET_WATCHDOG is not set
# CONFIG_DM_THERMAL is not set

#
# Timer Support
#
# CONFIG_TIMER is not set

#
# TPM support
#
# CONFIG_TPM_TIS_SANDBOX is not set
# CONFIG_USB is not set

#
# Graphics support
#
# CONFIG_DM_VIDEO is not set
# CONFIG_SYS_WHITE_ON_BLACK is not set
# CONFIG_NO_FB_CLEAR is not set

#
# TrueType Fonts
#
# CONFIG_VIDEO_VESA is not set
# CONFIG_VIDEO_LCD_ANX9804 is not set
# CONFIG_VIDEO_LCD_SSD2828 is not set
# CONFIG_VIDEO_MVEBU is not set
# CONFIG_I2C_EDID is not set
# CONFIG_DISPLAY is not set
# CONFIG_VIDEO_SANDBOX_SDL is not set
# CONFIG_VIDEO_BRIDGE is not set
# CONFIG_VIDEO is not set
# CONFIG_LCD is not set
# CONFIG_VIDEO_SIMPLE is not set
# CONFIG_VIDEO_DT_SIMPLEFB is not set

#
# Watchdog Timer Support
#
# CONFIG_BCM2835_WDT is not set
# CONFIG_ULP_WATCHDOG is not set
# CONFIG_WDT is not set
# CONFIG_PHYS_TO_BUS is not set

#
# File systems
#
# CONFIG_FS_BTRFS is not set
# CONFIG_FS_CBFS is not set
# CONFIG_FS_FAT is not set
# CONFIG_FS_JFFS2 is not set
# CONFIG_FS_CRAMFS is not set
# CONFIG_YAFFS2 is not set

#
# Library routines
#
# CONFIG_BCH is not set
# CONFIG_CC_OPTIMIZE_LIBS_FOR_SPEED is not set
CONFIG_SYS_HZ=1000
# CONFIG_USE_TINY_PRINTF is not set
CONFIG_REGEX=y
# CONFIG_LIB_RAND is not set
# CONFIG_SPL_TINY_MEMSET is not set
# CONFIG_TPL_TINY_MEMSET is not set
# CONFIG_CMD_DHRYSTONE is not set

#
# Security support
#
# CONFIG_AES is not set
# CONFIG_RSA is not set
# CONFIG_TPM is not set

#
# Hashing Support
#
# CONFIG_SHA1 is not set
# CONFIG_SHA256 is not set
# CONFIG_SHA_HW_ACCEL is not set

#
# Compression Support
#
# CONFIG_LZ4 is not set
CONFIG_LZMA=y
CONFIG_LZO=y
# CONFIG_SPL_LZO is not set
# CONFIG_SPL_GZIP is not set
# CONFIG_ERRNO_STR is not set
# CONFIG_OF_LIBFDT is not set
# CONFIG_OF_LIBFDT_OVERLAY is not set
# CONFIG_SPL_OF_LIBFDT is not set

#
# System tables
#
# CONFIG_UNIT_TEST is not set

这就是我们什么都没有配置时得到的kconfig中的默认配置,让我们把哪些用#注释掉的配置项都清理掉,看看默认配置都有哪些东西。

# Automatically generated file; DO NOT EDIT.
# U-Boot 2017.11 Configuration
CONFIG_SANDBOX=y
# General setup
CONFIG_LOCALVERSION=""
CONFIG_LOCALVERSION_AUTO=y
CONFIG_CC_OPTIMIZE_FOR_SIZE=y
CONFIG_SYS_MALLOC_F=y
CONFIG_SYS_MALLOC_F_LEN=0x400
CONFIG_SPL_SYS_MALLOC_F_LEN=0x400
CONFIG_TPL_SYS_MALLOC_F_LEN=0x400
CONFIG_EXPERT=y
CONFIG_SYS_MALLOC_CLEAR_ON_INIT=y
# Boot images
CONFIG_SYS_EXTRA_OPTIONS=""
CONFIG_ARCH_FIXUP_FDT_MEMORY=y
# Boot timing
CONFIG_BOOTSTAGE_RECORD_COUNT=30
CONFIG_SPL_BOOTSTAGE_RECORD_COUNT=5
CONFIG_BOOTSTAGE_STASH_ADDR=0
CONFIG_BOOTSTAGE_STASH_SIZE=0x1000
# Boot media
CONFIG_BOOTDELAY=2
# Console
CONFIG_IDENT_STRING=""
CONFIG_LOGLEVEL=4
CONFIG_SPL_LOGLEVEL=4
CONFIG_DEFAULT_FDT_FILE=""
CONFIG_BOARD_LATE_INIT=y
CONFIG_DISPLAY_BOARDINFO=y
# Security support
CONFIG_HASH=y
# Command line interface
CONFIG_CMDLINE=y
CONFIG_SYS_PROMPT="=> "
# Autoboot options
CONFIG_AUTOBOOT=y
# FASTBOOT
CONFIG_BUILD_BIN2C=y
# Info commands
CONFIG_CMD_BDI=y
CONFIG_CMD_CONFIG=y
CONFIG_CMD_CONSOLE=y
# Boot commands
CONFIG_CMD_BOOTD=y
CONFIG_CMD_BOOTM=y
CONFIG_CMD_ELF=y
CONFIG_CMD_GO=y
CONFIG_CMD_RUN=y
CONFIG_CMD_IMI=y
CONFIG_CMD_XIMG=y
# Environment commands
CONFIG_CMD_EXPORTENV=y
CONFIG_CMD_IMPORTENV=y
CONFIG_CMD_EDITENV=y
CONFIG_CMD_SAVEENV=y
CONFIG_CMD_ENV_EXISTS=y
# Memory commands
CONFIG_CMD_CRC32=y
CONFIG_CRC32_VERIFY=y
CONFIG_CMD_MEMORY=y
# Compression commands
CONFIG_CMD_LZMADEC=y
# Device access commands
CONFIG_CMD_DM=y
CONFIG_CMD_FLASH=y
CONFIG_CMD_FPGA=y
CONFIG_CMD_IO=y
CONFIG_CMD_IOTRACE=y
CONFIG_CMD_LOADB=y
CONFIG_CMD_LOADS=y
CONFIG_CMD_SATA=y
CONFIG_CMD_SF_TEST=y
# Shell scripting commands
CONFIG_CMD_ECHO=y
CONFIG_CMD_ITEST=y
CONFIG_CMD_SOURCE=y
CONFIG_CMD_SETEXPR=y
# Network commands
CONFIG_CMD_NET=y
CONFIG_CMD_NFS=y
# Misc commands
CONFIG_CMD_GETTIME=y
CONFIG_CMD_MISC=y
# Security commands
CONFIG_CMD_HASH=y
CONFIG_HASH_VERIFY=y
# Filesystem commands
CONFIG_MTDIDS_DEFAULT=""
CONFIG_MTDPARTS_DEFAULT=""
CONFIG_CMD_SCSI=y
# Partition Types
CONFIG_PARTITIONS=y
CONFIG_SUPPORT_OF_CONTROL=y
# Device Tree Control
CONFIG_MKIMAGE_DTC_PATH="dtc"
# Environment
CONFIG_ENV_IS_NOWHERE=y
CONFIG_NET=y
CONFIG_NET_TFTP_VARS=y
CONFIG_BOOTP_VCI_STRING="U-Boot"
# Generic Driver Options
CONFIG_DM=y
CONFIG_DM_WARN=y
CONFIG_DM_DEVICE_REMOVE=y
CONFIG_DM_STDIO=y
CONFIG_DM_SEQ_ALIAS=y
CONFIG_DM_DEV_READ_INLINE=y
CONFIG_SATA=y
# SATA/SCSI device support
CONFIG_BLK=y
# GPIO Support
CONFIG_DM_GPIO=y
# I2C support
CONFIG_DM_I2C=y
CONFIG_DM_KEYBOARD=y
# MMC Host controller Support
CONFIG_MMC=y
CONFIG_DM_MMC=y
# SPI Flash Support
CONFIG_DM_SPI_FLASH=y
# Real Time Clock
CONFIG_SCSI=y
# Serial drivers
CONFIG_BAUDRATE=115200
CONFIG_REQUIRE_SERIAL_CONSOLE=y
CONFIG_SERIAL_PRESENT=y
CONFIG_SPL_SERIAL_PRESENT=y
CONFIG_DM_SERIAL=y
# SPI Support
CONFIG_DM_SPI=y
# Library routines
CONFIG_SYS_HZ=1000
CONFIG_REGEX=y
# Compression Support
CONFIG_LZMA=y
CONFIG_LZO=y

现在我们从头进行配置,这里我们使用make menuconfig工具,而避免手动往my_imx6ul_defconfig里一个一个添加CONFIG_XXX宏,原因是有的配置间是有依赖或绑定关系的,这些依赖关系是编码在kconfig中的,手动配置不容易搞对各配置间的依赖关系。
首先是ARCH级的配置,选择为ARM
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第4张图片
确定ARCH的类型后,具体的ARCH相关细化的配置项才会继续展开让我们继续往下配置,配置arm 架构相关的细化选项,我们的不是ARM64类型,所以不要选中该选项,有些选项是kconfig的默认选项,并不一定是我们想要的。
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第5张图片
其次是machine级的配置,选择为imx6
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第6张图片
target确定后,arch级下的目录又会继续暂开更多新的更次级的选项(末尾带(NEW)的那些选项)让我们配置,这个就到的board级别了,我们选择MX6 board
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第7张图片
最后是board级的配置,这里本来应该选择为我们自己的board配置,但我们还没有添加board板级的支持文件,所以现在先选择一个其他的试试,比如官方的board
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第8张图片
下面应该就可以进行编译试试了
make -j8
很快就报错了
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第9张图片
看错误提示是sata驱动报的,而我们并不需要sata驱动,看来应该是kconfig的关于硬盘的配置默认是配置成sata的,让我们改一下硬盘相关的配置。
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第10张图片
居然是配置死的?说明这个配置是和其他什么配置绑定的,而那个配置被默认配置上后就必须select这个配置,而我们知道配置之间的依赖和绑定关系都被描述在kconfig中,所以我们搜索一下SATA的配置,发现是和cmd配置中的sata工具命令配置绑定的,让我们取消这个sata工具命令的选择。
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第11张图片
现在我们在回过头去看看SATA的驱动配置能不能取消了,发现现在可以取消选择该选项了
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第12张图片
继续尝试编译
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第13张图片
又有编译错误,没事,让我们按照刚才的套路操作一波。首先取消出错的驱动选项。
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第14张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第15张图片
fat.c报的错,查一下其所在目录的makefile:

从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第16张图片
是需要定义了CONFIG_CMD_FAT宏的值为y后,fat.c才会被编译的。我们现在看一下当前的.config 文件内容 :
在这里插入图片描述
这个配置是没有开的,但fat.c确实被编译了,说明有其他地方定义了CONFIG_CMD_FAT宏。因为我们之前选择了官方已经支持的开发板,编译时会包含以下头文件:
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第17张图片
我们看到其中确实有CONFIG_CMD_FAT宏,而且还有其他许多的宏。这也引申出一个点,一些强制性的配置是可以通过自己硬编码宏定义进行控制的,不一定都放到kconfig中管理,其实kconfig最终也是需要生成一个头文件的,因为宏配置不仅是给Makefile中用于控制文件编译开关,在文件中也会作为代码块的编译开关。
既然这样,为了纯粹起见,我们还是不要偷懒而去编译官方board了,老老实实自定义一个board吧。

从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第18张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第19张图片
所以怎么让我们新建的这个Kconfig文件能够纳入到menuconfig中呢,必须得有其他上层的Kconfig来source我们这个Kconfig呀,关键这个上层Kconfig是哪个呢?首先有个逆向思维的方法,找一个其他的board的Kconfig,里面一般也有TARGET_XXX这个宏开关,看看其他哪个Kconfig使用了这个宏开关就可以大致找到了,还有一个比较正向思维的方法,我们再menuconfig中发现,一般是选择ARCH 在继续展开让我们选board,所以board的Kconfig极有可能是被ARCH下的某个Kconfig给source到menuconfig系统中的。最终我们定位到这个Kconfig是
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第20张图片
好吧,让我们把刚才的Kconfig接入到配置系统中
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第21张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第22张图片
现在使用make menuconfig重新配置一下板卡:
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第23张图片
make 的时候报错了,表示找不到configs/my_mx6ul.h
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第24张图片
看来新建一块板卡的时候,编译系统就会自动到include/configs/下找与board同名的头文件,这个文件我们没有创建过,现在创建一个吧。
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第25张图片
我们创建了一个空的board头文件,再make一次看看有什么其他新的编译错误。从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第26张图片
缺了一个宏,怎么办呢,目前我们对于宏有两种引入方法,一个是通过Kconfig中,一个是通过我们刚才创建的my_imx6ul.h文件硬编码写死。
这两种途径该选择哪个呢?
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第27张图片
根据:
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第28张图片
说明有几个宏是需要我们自己进行给出定义的,所以在我们的board头文件中加上吧
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第29张图片
继续编译:
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第30张图片
bootm 命令相关文件报的,先不配置这个命令吧
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第31张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第32张图片
还是报同样的错误,说明是一个必须的配置项,让我们找一下相关代码段的宏开关是什么
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第33张图片
然我们找一下CONFIG_NR_DRAM_BANKS这个宏开关是在哪里配置的
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第34张图片
并没有出现在任何Kconfig中,说明是需要我们自己进行定义的,在board头文件中加上吧
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第35张图片
继续编译
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第36张图片
搜一下在哪里定义的
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第37张图片
那让我们包含一下imx-regs.h这个头文件
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第38张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第39张图片
这个是因为我们在Kconfig中把board的名字写错了
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第40张图片
而且我们发现,虽然board名字写错了,但编译系统居然为我们以这个错误的board名创建了文件夹:
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第41张图片
让我们改一下
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第42张图片
我们的board头文件名也要进行更改了
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第43张图片
继续编译
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第44张图片
这回报错的路径对了,让我们加个Makefile吧
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第45张图片
继续编译
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第46张图片
搜一下
在这里插入图片描述
所以这个宏也不是Kconfig配置的,需要自己进行定义,其实有些这些常用的宏在产商的公共头文件中是有的,我们直接包含进来
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第47张图片
继续编译
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第48张图片
搜一下
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第49张图片
所以也是在头文件中定义的

继续编译
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第50张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第51张图片
看来就差一点了,让我们在board下面创建一个文件编译一下,让uboot镜像能够最终生成
在这里插入图片描述
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第52张图片
看来还有许多路要走…

root@ubuntu:~/my-imx6/02_source/u-boot-2017.11# make 
*** Your GCC is older than 6.0 and will not be supported starting in v2018.01.
  CHK     include/config/uboot.release
  CHK     include/generated/version_autogenerated.h
  CHK     include/generated/timestamp_autogenerated.h
  UPD     include/generated/timestamp_autogenerated.h
  CHK     include/generated/generic-asm-offsets.h
  CHK     include/generated/asm-offsets.h
  HOSTCC  tools/mkenvimage.o
  HOSTLD  tools/mkenvimage
  HOSTCC  tools/fit_image.o
  HOSTCC  tools/image-host.o
  HOSTCC  tools/dumpimage.o
  HOSTLD  tools/dumpimage
  HOSTCC  tools/mkimage.o
  HOSTLD  tools/mkimage
  CC      board/freescale/my_imx6ul/my_imx6ul.o
  LD      board/freescale/my_imx6ul/built-in.o
  CC      cmd/version.o
  CHK     cmd/config_data_gz.h
  CHK     cmd/config_data_size.h
  LD      cmd/built-in.o
  CC      common/main.o
  LD      common/built-in.o
  CC      lib/display_options.o
  LD      lib/built-in.o
  LD      u-boot
arch/arm/lib/built-in.o: In function `here':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/arch/arm/lib/crt0.S:76: undefined reference to `CONFIG_SYS_INIT_SP_ADDR'
arch/arm/cpu/armv7/built-in.o: In function `lowlevel_init':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/arch/arm/cpu/armv7/lowlevel_init.S:32: undefined reference to `CONFIG_SYS_INIT_SP_ADDR'
cmd/built-in.o: In function `do_print_stats':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/iotrace.c:15: undefined reference to `iotrace_get_enabled'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/iotrace.c:16: undefined reference to `iotrace_get_buffer'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/iotrace.c:22: undefined reference to `iotrace_get_checksum'
cmd/built-in.o: In function `do_set_buffer':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/iotrace.c:36: undefined reference to `iotrace_set_buffer'
cmd/built-in.o: In function `do_iotrace':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/iotrace.c:54: undefined reference to `iotrace_set_enabled'
cmd/built-in.o: In function `do_io_iod':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/io.c:38: undefined reference to `inl'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/io.c:40: undefined reference to `inw'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/io.c:42: undefined reference to `inb'
cmd/built-in.o: In function `do_io_iow':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/io.c:63: undefined reference to `outl'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/io.c:65: undefined reference to `outw'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/cmd/io.c:67: undefined reference to `outb'
common/built-in.o:(.rodata.init_sequence_f+0x4c): undefined reference to `dram_init'
common/built-in.o:(.data.init_sequence_r+0x28): undefined reference to `board_init'
common/built-in.o:(.data.init_sequence_r+0x60): undefined reference to `board_late_init'
drivers/built-in.o: In function `dev_read_alias_seq':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:541: undefined reference to `fdtdec_get_alias_seq'
drivers/built-in.o: In function `dev_read_u32_default':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:418: undefined reference to `ofnode_read_u32_default'
drivers/built-in.o: In function `dev_read_bool':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:429: undefined reference to `ofnode_read_bool'
drivers/gpio/built-in.o: In function `gpio_request_tail':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/drivers/gpio/gpio-uclass.c:666: undefined reference to `ofnode_get_name'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/drivers/gpio/gpio-uclass.c:681: undefined reference to `ofnode_get_name'
drivers/gpio/built-in.o: In function `dev_read_phandle_with_args':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:494: undefined reference to `ofnode_parse_phandle_with_args'
drivers/spi/built-in.o: In function `dev_read_u32_default':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:418: undefined reference to `ofnode_read_u32_default'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:418: undefined reference to `ofnode_read_u32_default'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:418: undefined reference to `ofnode_read_u32_default'
drivers/spi/built-in.o: In function `dev_read_bool':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:429: undefined reference to `ofnode_read_bool'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:429: undefined reference to `ofnode_read_bool'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:429: undefined reference to `ofnode_read_bool'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:429: undefined reference to `ofnode_read_bool'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:429: undefined reference to `ofnode_read_bool'
drivers/spi/built-in.o: In function `dev_read_u32_default':
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:418: undefined reference to `ofnode_read_u32_default'
/home/huangwu/my-imx6/02_source/u-boot-2017.11/include/dm/read.h:418: undefined reference to `ofnode_read_u32_default'
drivers/spi/built-in.o:(.u_boot_list_2_uclass_2_spi+0x8): undefined reference to `dm_scan_fdt_dev'
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: BFD (GNU Binutils) 2.24 assertion fail /home/ybx/fsl-release-bsp/build-x11/tmp/work/x86_64-nativesdk-pokysdk-linux/binutils-cross-canadian-arm/2.24-r0/binutils-2.24/bfd/elf32-arm.c:7696
arm-poky-linux-gnueabi-ld.bfd: error: required section '.rel.plt' not found in the linker script
arm-poky-linux-gnueabi-ld.bfd: final link failed: Invalid operation
make: *** [u-boot] Error 1
root@ubuntu:~/my-imx6/02_source/u-boot-2017.11# 

取消iotrace相关的配置选项

把存储相关的配置都加到board的头文件中:

#ifndef __MY_MX6UL_H
#define __MY_MX6UL_H
#include 
#include 
#include "mx6_common.h"
/* environment organization */
#define CONFIG_ENV_SIZE			SZ_8K
#define CONFIG_ENV_OFFSET		(8 * SZ_64K)
#define CONFIG_SYS_MMC_ENV_DEV		1   /* USDHC2 */
#define CONFIG_SYS_MMC_ENV_PART		0	/* user area */
#define CONFIG_MMCROOT			"/dev/mmcblk1p2"  /* USDHC2 */

/* Physical Memory Map */
#define CONFIG_NR_DRAM_BANKS		1
#define PHYS_SDRAM			MMDC0_ARB_BASE_ADDR

#define CONFIG_SYS_SDRAM_BASE		PHYS_SDRAM
#define CONFIG_SYS_INIT_RAM_ADDR	IRAM_BASE_ADDR
#define CONFIG_SYS_INIT_RAM_SIZE	IRAM_SIZE

#define CONFIG_SYS_INIT_SP_OFFSET \
	(CONFIG_SYS_INIT_RAM_SIZE - GENERATED_GBL_DATA_SIZE)
#define CONFIG_SYS_INIT_SP_ADDR \
	(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET)

#define CONFIG_SYS_MALLOC_LEN		(16 * SZ_1M)

#endif

从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第53张图片

从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第54张图片

从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第55张图片

从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第56张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第57张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第58张图片

从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第59张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第60张图片
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第61张图片
烧到板卡中试试:
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第62张图片
当然什么现象都没有,怎么知道uboot到底有没有成功执行起来呢?首先看一下map文件的链接地址对不对。
从头开始移植u-boot和linux kernel 到imx6ul之u-boot_第63张图片
我们看到链接地址是正确的,(_start 入口也处于向量表中,向量表的概念是用来解决如何告诉CPU在什么特定硬件条件下到哪个入口执行特定代码的问题,_start是正常情况下的执行入口,其他向量是“非正常”情况下的执行入口)。让我们在_start开始的地方点个LED灯试试。
u-boot-2017.11/arch/arm/lib/vectors.S:

/*
 *  vectors - Generic ARM exception table code
 *
 *  Copyright (c) 1998	Dan Malek 
 *  Copyright (c) 1999	Magnus Damm 
 *  Copyright (c) 2000	Wolfgang Denk 
 *  Copyright (c) 2001	Alex Züpke 
 *  Copyright (c) 2001	Marius Gröger 
 *  Copyright (c) 2002	Alex Züpke 
 *  Copyright (c) 2002	Gary Jennejohn 
 *  Copyright (c) 2002	Kyle Harris 
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include 

/*
 *************************************************************************
 *
 * Symbol _start is referenced elsewhere, so make it global
 *
 *************************************************************************
 */

.globl _start

/*
 *************************************************************************
 *
 * Vectors have their own section so linker script can map them easily
 *
 *************************************************************************
 */

	.section ".vectors", "ax"

/*
 *************************************************************************
 *
 * Exception vectors as described in ARM reference manuals
 *
 * Uses indirect branch to allow reaching handlers anywhere in memory.
 *
 *************************************************************************
 */

_start:

#ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
	.word	CONFIG_SYS_DV_NOR_BOOT_CFG
#endif
	b	run_my_led
	b	reset
	ldr	pc, _undefined_instruction
	ldr	pc, _software_interrupt
	ldr	pc, _prefetch_abort
	ldr	pc, _data_abort
	ldr	pc, _not_used
	ldr	pc, _irq
	ldr	pc, _fiq

#ifdef CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK
/*
 * Various SoCs need something special and SoC-specific up front in
 * order to boot, allow them to set that in their boot0.h file and then
 * use it here.
 */
#include 
#endif

/*
 *************************************************************************
 *
 * Indirect vectors table
 *
 * Symbols referenced here must be defined somewhere else
 *
 *************************************************************************
 */

	.globl	_undefined_instruction
	.globl	_software_interrupt
	.globl	_prefetch_abort
	.globl	_data_abort
	.globl	_not_used
	.globl	_irq
	.globl	_fiq

_undefined_instruction:	.word undefined_instruction
_software_interrupt:	.word software_interrupt
_prefetch_abort:	.word prefetch_abort
_data_abort:		.word data_abort
_not_used:		.word not_used
_irq:			.word irq
_fiq:			.word fiq

	.balignl 16,0xdeadbeef

/*
 *************************************************************************
 *
 * Interrupt handling
 *
 *************************************************************************
 */

/* SPL interrupt handling: just hang */

#ifdef CONFIG_SPL_BUILD

	.align	5
undefined_instruction:
software_interrupt:
prefetch_abort:
data_abort:
not_used:
irq:
fiq:
1:
	bl	1b			/* hang and never return */

#else	/* !CONFIG_SPL_BUILD */

/* IRQ stack memory (calculated at run-time) + 8 bytes */
.globl IRQ_STACK_START_IN
IRQ_STACK_START_IN:
#ifdef IRAM_BASE_ADDR
	.word   IRAM_BASE_ADDR + 0x20
#else
	.word	0x0badc0de
#endif

@
@ IRQ stack frame.
@
#define S_FRAME_SIZE	72

#define S_OLD_R0	68
#define S_PSR		64
#define S_PC		60
#define S_LR		56
#define S_SP		52

#define S_IP		48
#define S_FP		44
#define S_R10		40
#define S_R9		36
#define S_R8		32
#define S_R7		28
#define S_R6		24
#define S_R5		20
#define S_R4		16
#define S_R3		12
#define S_R2		8
#define S_R1		4
#define S_R0		0

#define MODE_SVC 0x13
#define I_BIT	 0x80

/*
 * use bad_save_user_regs for abort/prefetch/undef/swi ...
 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
 */

	.macro	bad_save_user_regs
	@ carve out a frame on current user stack
	sub	sp, sp, #S_FRAME_SIZE
	stmia	sp, {r0 - r12}	@ Save user registers (now in svc mode) r0-r12
	ldr	r2, IRQ_STACK_START_IN
	@ get values for "aborted" pc and cpsr (into parm regs)
	ldmia	r2, {r2 - r3}
	add	r0, sp, #S_FRAME_SIZE		@ grab pointer to old stack
	add	r5, sp, #S_SP
	mov	r1, lr
	stmia	r5, {r0 - r3}	@ save sp_SVC, lr_SVC, pc, cpsr
	mov	r0, sp		@ save current stack into r0 (param register)
	.endm

	.macro	irq_save_user_regs
	sub	sp, sp, #S_FRAME_SIZE
	stmia	sp, {r0 - r12}			@ Calling r0-r12
	@ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
	add	r8, sp, #S_PC
	stmdb	r8, {sp, lr}^		@ Calling SP, LR
	str	lr, [r8, #0]		@ Save calling PC
	mrs	r6, spsr
	str	r6, [r8, #4]		@ Save CPSR
	str	r0, [r8, #8]		@ Save OLD_R0
	mov	r0, sp
	.endm

	.macro	irq_restore_user_regs
	ldmia	sp, {r0 - lr}^			@ Calling r0 - lr
	mov	r0, r0
	ldr	lr, [sp, #S_PC]			@ Get PC
	add	sp, sp, #S_FRAME_SIZE
	subs	pc, lr, #4		@ return & move spsr_svc into cpsr
	.endm

	.macro get_bad_stack
	ldr	r13, IRQ_STACK_START_IN		@ setup our mode stack

	str	lr, [r13]	@ save caller lr in position 0 of saved stack
	mrs	lr, spsr	@ get the spsr
	str	lr, [r13, #4]	@ save spsr in position 1 of saved stack
	mov	r13, #MODE_SVC	@ prepare SVC-Mode
	@ msr	spsr_c, r13
	msr	spsr, r13	@ switch modes, make sure moves will execute
	mov	lr, pc		@ capture return pc
	movs	pc, lr		@ jump to next instruction & switch modes.
	.endm

	.macro get_irq_stack			@ setup IRQ stack
	ldr	sp, IRQ_STACK_START
	.endm

	.macro get_fiq_stack			@ setup FIQ stack
	ldr	sp, FIQ_STACK_START
	.endm

/*
 * exception handlers
 */

	.align  5
undefined_instruction:
	get_bad_stack
	bad_save_user_regs
	bl	do_undefined_instruction

	.align	5
software_interrupt:
	get_bad_stack
	bad_save_user_regs
	bl	do_software_interrupt

	.align	5
prefetch_abort:
	get_bad_stack
	bad_save_user_regs
	bl	do_prefetch_abort

	.align	5
data_abort:
	get_bad_stack
	bad_save_user_regs
	bl	do_data_abort

	.align	5
not_used:
	get_bad_stack
	bad_save_user_regs
	bl	do_not_used


	.align	5
irq:
	get_bad_stack
	bad_save_user_regs
	bl	do_irq

	.align	5
fiq:
	get_bad_stack
	bad_save_user_regs
	bl	do_fiq

run_my_led:
	ldr	r0, = 0x20ac000        @GPIO5_DR基地址
	mov r1, # 0x10              @io4
	str	r1, [r0, # 0x04]        @io4配置为输出
led_loop:
	bl	_gpio5_4_set	
	bl	delay
	bl	_gpio5_4_reset	
	bl	delay
	b	led_loop                @跳回IO开	

_gpio5_4_set:  
	mov r1, # 0x10              @io4
	str r1, [r0]                @io4开
	mov pc,lr 		@返回
	
_gpio5_4_reset:                        @io4关
	mov r1, # 0                @0关
	str r1, [r0]                @写入GPIO5_DR io关
	mov pc,lr 		@返回
	
delay:
	ldr r2, = 0x1fffff        @延时数	
delay_loop:                @io4开延时
	subs r2, r2, # 1        @延时数减1
	bne delay_loop        @没减到0就循环减
	mov pc,lr 			@返回
#endif	/* CONFIG_SPL_BUILD */

LED已经闪烁,至少说明程序是正确进入了入口的。
首先,需要承认的是,按照之前这么粗糙的移植步骤,程序肯定是不能完全跑起来的,但我们还是想看看在我们没什么作为的情况下,u-boot能走刀哪一步
我采取了led点灯跟踪法,之前已经写了汇编的点灯代码,后来我又写了C语言的点灯代码。
我在s_init中用C语言写了段跑马灯代码,发现时可以执行的,所以从汇编跳到执行C语言没有问题,这说明栈的设置是没啥问题的。经过几轮点灯,最后发现在执行board_init_f期间,板卡又执行了s_init中的跑马灯,说明板子复位了(难道是看门狗干的?感觉不是,之前使用过死循环,板子也没有被复位,应该是执行过程中出现什么异常导致板卡复位了),在正常uboot中,board_init_f现在都是使用的通用的实现,应该只有board_init_f中调用的初始化队列中需要board级自己实现的初始化方法会引入错误,重点关注这些方法就好,这次定位到时timer_init导致的复位。

但是点灯总不是个办法,u-boot到底是个裸机程序,用jlink进行调试将会事半功倍。接下来我们看看如何搭建u-boot调试环境。

你可能感兴趣的:(linux-驱动)