使用的是讯为的IMX6Q开发板
ubuntu18.04系统
升级ddr内存2G
文章目录
- 前言
- 一、下载源码
- 二、编译源码
- 三、解决报错
- 1.PMIC问题
- 2.SD卡问题
- 3.DDR内存问题
- 4.网络问题
- 总结
前言
本文主要学习在NXP官网下载uboot移植,官方uboot默认的是1G的DDR内存,需要修改内存为2G,另外需要修改SD卡的DC引脚和网口驱动
一、下载源码
在官网下载源码
git clone https://source.codeaurora.org/external/imx/uboot-imx -b nxp/imx_v2016.03_4.1.15_2.0.0_ga --depth=1
编写脚本来编译uboot
#!/bin/bash
export PATH=$PATH:/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mx6qsabresd_defconfig
make V=1 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8
二、编译源码
输入./uboot.sh编译uboot源码,然后使用SD启动方式将u-boot.imx下载到SD卡中,开发板设置SD卡启动模式,SD卡下载脚本如下,因为我是用的512M的SD卡,所以修改了讯为官方的下载脚本,新建脚本mksdcard-android_512M.sh,内容如下
#!/bin/bash
# partition size in MB
BOOTLOAD_RESERVE=8
BOOT_ROM_SIZE=8
SYSTEM_ROM_SIZE=64
CACHE_SIZE=16
RECOVERY_ROM_SIZE=8
VENDER_SIZE=8
MISC_SIZE=8
help() {
bn=`basename $0`
cat << EOF
usage $bn <option> device_nodeoptions:-h displays this help message-s only get partition size-np not partition.-f flash android image.
EOF
}
# check the if root?
userid=`id -u`
if [ $userid -ne "0" ]; thenecho "you're not root?"exit
fi
# parse command line
moreoptions=1
node="na"
cal_only=0
flash_images=0
not_partition=0
not_format_fs=0
while [ "$moreoptions" = 1 -a $# -gt 0 ]; docase $1 in-h) help; exit ;;-s) cal_only=1 ;;-f) flash_images=1 ;;-np) not_partition=1 ;;-nf) not_format_fs=1 ;;*) moreoptions=0; node=$1 ;;esac[ "$moreoptions" = 0 ] && [ $# -gt 1 ] && help && exit[ "$moreoptions" = 1 ] && shift
done
if [ ! -e ${node} ]; thenhelpexit
fi
# call sfdisk to create partition table
# get total card size
seprate=10
total_size=`sfdisk -s ${node}`
total_size=`expr ${total_size} / 1024`
boot_rom_sizeb=`expr ${BOOT_ROM_SIZE} + ${BOOTLOAD_RESERVE}`
extend_size=`expr ${SYSTEM_ROM_SIZE} + ${CACHE_SIZE} + ${VENDER_SIZE} + ${MISC_SIZE} + ${seprate}`
data_size=`expr ${total_size} - ${boot_rom_sizeb} - ${RECOVERY_ROM_SIZE} - ${extend_size} + ${seprate}`
# create partitions
if [ "${cal_only}" -eq "1" ]; then
cat << EOF
BOOT : ${boot_rom_sizeb}MB
RECOVERY: ${RECOVERY_ROM_SIZE}MB
SYSTEM : ${SYSTEM_ROM_SIZE}MB
CACHE : ${CACHE_SIZE}MB
DATA : ${data_size}MB
MISC : ${MISC_SIZE}MB
EOF
exit
fi
# destroy the partition table
dd if=/dev/zero of=${node} bs=1024 count=1
sfdisk --force ${node} << EOF
,${boot_rom_sizeb}M,83
,${RECOVERY_ROM_SIZE}M,83
,${extend_size}M,5
,${data_size}M,83
,${SYSTEM_ROM_SIZE}M,83
EOF
# adjust the partition reserve for bootloader.
# if you don't put the uboot on same device, you can remove the BOOTLOADER_ERSERVE
# to have 8M space.
# the minimal sylinder for some card is 4M, maybe some was 8M
# just 8M for some big eMMC 's sylinder
sfdisk --force ${node} -N1 << EOF
${BOOTLOAD_RESERVE}M,${BOOT_ROM_SIZE}M,83
EOF
df=/dev/zero of=${node} bs=1k seek=384 conv=fsync count=129
dd if=u-boot.imx of=${node} bs=512 seek=2
mkfs.fat ${node}4
mkfs.ext4 ${node}5
然后插入SD卡到ubuntu系统中,执行命令./mksdcard-android_512M.sh /dev/sdb等待下载完成,然后启动开发板,打印日志如下:
U-Boot 2016.03-ga57b13b (Mar 14 2022 - 18:26:31 +0800)CPU: Freescale i.MX6Q rev1.5 996 MHz (running at 792 MHz)
CPU: Extended Commercial temperature grade (-20C to 105C) at 28C
Reset cause: POR
Board: MX6-SabreSD
I2C: ready
DRAM: 1 GiB
Can't find PMIC:PFUZE100
initcall sequence 4ff96d3c failed at call 17804258 (err=-19)
### ERROR ### Please RESET the board ###
三、解决报错
1.PMIC问题
因为讯为的开发板没有使用PMIC芯片,所以直接在uboot中把相关代码屏蔽即可,首先修改宏定义,在uboot-imx/include/configs/mx6_common.h
文件中修改
#define CONFIG_LDO_BYPASS_CHECK
#undef CONFIG_LDO_BYPASS_CHECK
然后在uboot-imx/board/freescale/mx6sabresd/mx6sabresd.c
文件中直接屏蔽power_init_board函数代码
#if 0
int power_init_board(void)
{struct pmic *pfuze;unsigned int reg;int ret;pfuze = pfuze_common_init(I2C_PMIC);if (!pfuze)return -ENODEV;
然后编译下载打印日志如下
U-Boot 2016.03-ga57b13b-dirty (Mar 14 2022 - 18:46:42 +0800)CPU: Freescale i.MX6Q rev1.5 996 MHz (running at 792 MHz)
CPU: Extended Commercial temperature grade (-20C to 105C) at 28C
Reset cause: POR
Board: MX6-SabreSD
I2C: ready
DRAM: 1 GiB
MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
MMC: no card present
*** Warning - MMC init failed, using default environmentNo panel detected: default to Hannstar-XGA
Display: Hannstar-XGA (1024x768)
In: serial
Out: serial
Err: serial
MMC: no card present
Net: Board Net Initialization Failed
No ethernet found.
Normal Boot
Hit any key to stop autoboot: 0
此时PMIC没有报错了,但是SD卡读取不到
2.SD卡问题
SD卡读取失败一般是由于CD引脚错误,查看原理图CD引脚为MX6_PAD_GPIO_4__GPIO1_IO04
于是修改uboot-imx/board/freescale/mx6sabresd/mx6sabresd.c
文件
static iomux_v3_cfg_t const usdhc2_pads[] = {MX6_PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_NANDF_D4__SD2_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_NANDF_D5__SD2_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_NANDF_D6__SD2_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),MX6_PAD_NANDF_D7__SD2_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
// MX6_PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */MX6_PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
};
#define USDHC2_CD_GPIO IMX_GPIO_NR(1, 4)
然后重新编译下载打印日志
U-Boot 2016.03-ga57b13b-dirty (Mar 15 2022 - 09:06:17 +0800)CPU: Freescale i.MX6Q rev1.5 996 MHz (running at 792 MHz)
CPU: Extended Commercial temperature grade (-20C to 105C) at 25C
Reset cause: POR
Board: MX6-SabreSD
I2C: ready
DRAM: 1 GiB
MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
*** Warning - bad CRC, using default environmentNo panel detected: default to Hannstar-XGA
Display: Hannstar-XGA (1024x768)
In: serial
Out: serial
Err: serial
switch to partitions #0, OK
mmc0 is current device
Net: Board Net Initialization Failed
No ethernet found.
Normal Boot
Hit any key to stop autoboot: 0
现在剩下网络和DDR问题了,先解决DDR问题吧
3.DDR内存问题
开发板的DDR是2G的,uboot中DDR默认是1G的,需要修改以下几个文件
uboot-imx/include/configs/mx6sabresd.h
uboot-imx/board/freescale/mx6sabresd/mx6q_4x_mt41j128.cfg
首先修改uboot-imx/include/configs/mx6sabresd.h
文件
#define PHYS_SDRAM_SIZE (2u * 1024 * 1024 * 1024)
#if 0
#if defined(CONFIG_MX6QP)
#define PHYS_SDRAM_SIZE (1u * 1024 * 1024 * 1024)
#elif defined(CONFIG_MX6Q)
#define PHYS_SDRAM_SIZE (2u * 1024 * 1024 * 1024)
#elif defined(CONFIG_MX6DL)
#define PHYS_SDRAM_SIZE (1u * 1024 * 1024 * 1024)
#elif defined(CONFIG_MX6SOLO)
#define PHYS_SDRAM_SIZE (512u * 1024 * 1024)
#endif
#endif
这里直接将内存改为2G
然后修改uboot-imx/board/freescale/mx6sabresd/mx6q_4x_mt41j128.cfg
文件
修改这个文件需要用到NXP官网的DDR测试工具ddr_stress_tester_v3.00,根据MX6X_DDR3_调校_应用手册_V4_20150730.pdf
和飞思卡尔i.MX6平台DRAM接口高阶应用指导-DDR3篇.pdf
文档来操作
首先在官网下载 ddr_stress_tester_v3.00_setup.exe.zip工具安装
还有下载I.MX6DQP_DDR3_Script_Aid_V0.01.xlsx表格来配置
表格配置内容是根据MX6X_DDR3_调校_应用手册_V4_20150730.pdf
来配置的如下
然后把表格生成的文件保存成MX6Q_SabreSD_DDR3_2GB_64bit.inc
文件,使用DDR_Tester.exe软件下载,这里需要把开发板设置成usb启动方式,然后上电点击Download下载
下载完后开始校准Calibration,最后把校准好的值写进MX6Q_SabreSD_DDR3_2GB_64bit.inc
文件里。主要就是以下几个值
接下来照着这几个值的地址修改uboot-imx/board/freescale/mx6sabresd/mx6q_4x_mt41j128.cfg
文件中对应地址的值,这时候修改的只是校准部分的值,接下来还需要修改//MMDC init部分的寄存器值
对应寄存器的值修改,没有的就不管他。接下来编译代码并重新下载查看日志
U-Boot 2016.03-ga57b13b-dirty (Mar 15 2022 - 12:51:10 +0800)CPU: Freescale i.MX6Q rev1.5 996 MHz (running at 792 MHz)
CPU: Extended Commercial temperature grade (-20C to 105C) at 29C
Reset cause: POR
Board: MX6-SabreSD
I2C: ready
DRAM: 2 GiB
MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
No panel detected: default to Hannstar-XGA
Display: Hannstar-XGA (1024x768)
In: serial
Out: serial
Err: serial
switch to partitions #0, OK
mmc0 is current device
Net: Board Net Initialization Failed
No ethernet found.
Normal Boot
Hit any key to stop autoboot: 0
现在DDR读取是2G了,最后开始修改网络问题,另外我把DDR测试工具和文档上传到了CSDN上,大家可以下载https://download.csdn.net/download/u012988644/84960092
4.网络问题
在include/mx6sabre_common.h文件中修改宏定义
#define CONFIG_PHYLIB
/*#define CONFIG_PHY_ATHEROS*/
#define CONFIG_PHY_REALTEK
重新编译烧录发现网络没找到,引脚定义一样,宏定义也修改了网络还是有问题,可能就是驱动文件有差异了,于是对比了一下drivers/net/phy文件夹下的文件,主要编译了phy.c和realtek.c两个文件,索性直接将两个文件替换掉,重新编译报错
drivers/net/phy/phy.c: 在文件作用域:
drivers/net/phy/phy.c:585:1: 错误: 对‘get_phy_id’的静态声明出现在非静态声明之后{^
In file included from include/miiphy.h:22:0,from drivers/net/phy/phy.c:17:
include/phy.h:269:5: 附注: ‘get_phy_id’的上一个声明在此int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id);^
make[1]: *** [drivers/net/phy/phy.o] 错误 1
make: *** [drivers/net/phy] 错误 2
make: *** 正在等待未完成的任务....
根据报错修改
//static int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
去掉static重新编译ok,然后烧录重启,网络重启成功
接下来配置网络参数和启动参数
setenv bootcmd 'tftp 12000000 zImage; tftp 18000000 imx6q.dtb; bootz 12000000 - 18000000'
setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs nfsroot=192.168.1.74:/home/ubuntu/topeet/nfs/rootfs,proto=tcp rw ip=192.168.1.55:192.168.1.74:192.168.1.1:255.255.255.0::eth0:off'
setenv ipaddr 192.168.1.55
setenv ethaddr b8:ae:1d:01:00:00
setenv gatewayip 192.168.1.1
setenv netmask 255.255.255.0
setenv serverip 192.168.1.74
saveenv
重新上电启动
U-Boot 2016.03-ga57b13b-dirty (Mar 22 2022 - 10:12:40 +0800)CPU: Freescale i.MX6Q rev1.5 996 MHz (running at 792 MHz)
CPU: Extended Commercial temperature grade (-20C to 105C) at 30C
Reset cause: POR
Board: MX6-SabreSD
I2C: ready
DRAM: 2 GiB
MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
No panel detected: default to Hannstar-XGA
Display: Hannstar-XGA (1024x768)
In: serial
Out: serial
Err: serial
switch to partitions #0, OK
mmc0 is current device
Net: FEC [PRIME]
Normal Boot
Hit any key to stop autoboot: 0
接下来输入boot可以正常tftp下载内核和设备树并挂载文件系统
总结
好了,成功移植了uboot