IMX6学习记录(3)-LINUX编译

上面是我创建的群聊,欢迎新朋友的加入。

目录

1.获取官方kernel

2.编译内核

3.内核烧录

4.调整uboot

5.卡分区


1.获取官方kernel


地址:http://git.freescale.com/git/cgit.cgi/imx/linux-imx.git/tag/?h=imx_4.1.15_2.0.0_ga&id=rel_imx_4.1.15_2.1.0_ga

拉到最后,先把源码搞下来

IMX6学习记录(3)-LINUX编译_第1张图片

 

2.编译内核

IMX6学习记录(3)-LINUX编译_第2张图片

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_v7_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j4

不知道怎么回事,上来编译就报错了

jun@ubuntu:~/i.mx6/source/linux$ make clean
./scripts/gcc-goto.sh: 行 4: $'\r': 未找到命令
./scripts/gcc-goto.sh: 行 21: 警告: 立即文档在第 5 行被文件结束符分隔 (需要 `END')
./scripts/gcc-version.sh: 行 11: $'\r': 未找到命令
./scripts/gcc-version.sh: 行 33: 语法错误: 未预期的文件结尾
/bin/sh: 1: [: -lt: unexpected operator
./scripts/gcc-version.sh: 行 11: $'\r': 未找到命令
./scripts/gcc-version.sh: 行 33: 语法错误: 未预期的文件结尾
/bin/sh: 1: [: -lt: unexpected operator
./scripts/link-vmlinux.sh: 行 27: $'\r': 未找到命令
: 无效选项link-vmlinux.sh: 第 29 行: set: -
set: 用法: set [--abefhkmnptuvxBCHP] [-o 选项名] [--] [参数 ...]
./scripts/link-vmlinux.sh: 行 30: $'\r': 未找到命令
./scripts/link-vmlinux.sh: 行 33: 未预期的符号 `$'\r'' 附近有语法错误
'/scripts/link-vmlinux.sh: 行 33: `info()
Makefile:1195: recipe for target 'vmlinuxclean' failed
make: *** [vmlinuxclean] Error 2
jun@ubuntu:~/i.mx6/source/linux$ ls -la

解决办法

sudo apt install dos2unix
dos2unix ./scripts/gcc-goto.sh
dos2unix ./scripts/gcc-version.sh
dos2unix ./scripts/link-vmlinux.sh

IMX6学习记录(3)-LINUX编译_第3张图片

3.内核烧录

找到编译出来的文件

IMX6学习记录(3)-LINUX编译_第4张图片

IMX6学习记录(3)-LINUX编译_第5张图片

其中zimage就是内核固件,烧录的就是它,一个6M的文件

按照官方指导,通过DD烧录到SD卡

IMX6学习记录(3)-LINUX编译_第6张图片

IMX6学习记录(3)-LINUX编译_第7张图片

搞完内核。还有一个设备树也要捎进去

4.调整uboot

IMX6学习记录(3)-LINUX编译_第8张图片

启动是启动了,但是这不是我刚刚编译出来的

将uboot的头文件按照烧录的地址设置启动位置

#define CONFIG_SYS_MMC_IMG_LOAD_PART	1

#ifdef CONFIG_SYS_BOOT_NAND
#define CONFIG_MFG_NAND_PARTITION "mtdparts=gpmi-nand:64m(boot),16m(kernel),16m(dtb),1m(misc),-(rootfs) "
#else
#define CONFIG_MFG_NAND_PARTITION ""
#endif

#define CONFIG_MFG_ENV_SETTINGS \
	"mfgtool_args=setenv bootargs console=${console},${baudrate} " \
	    CONFIG_BOOTARGS_CMA_SIZE \
		"rdinit=/linuxrc " \
		"g_mass_storage.stall=0 g_mass_storage.removable=1 " \
		"g_mass_storage.file=/fat g_mass_storage.ro=1 " \
		"g_mass_storage.idVendor=0x066F g_mass_storage.idProduct=0x37FF "\
		"g_mass_storage.iSerialNumber=\"\" "\
		CONFIG_MFG_NAND_PARTITION \
		"clk_ignore_unused "\
		"\0" \
	"initrd_addr=0x83800000\0" \
	"initrd_high=0xffffffff\0" \
	"bootcmd_mfg=run mfgtool_args;bootz ${loadaddr} ${initrd_addr} ${fdt_addr};\0" \

#if defined(CONFIG_SYS_BOOT_NAND)
#define CONFIG_EXTRA_ENV_SETTINGS \
	CONFIG_MFG_ENV_SETTINGS \
	"panel=TFT43AB\0" \
	"fdt_addr=0x83000000\0" \
	"fdt_high=0xffffffff\0"	  \
	"console=ttymxc0\0" \
	"bootargs=console=ttymxc0,115200 ubi.mtd=4 "  \
		"root=ubi0:rootfs rootfstype=ubifs "		     \
		CONFIG_BOOTARGS_CMA_SIZE \
		"mtdparts=gpmi-nand:64m(boot),16m(kernel),16m(dtb),1m(misc),-(rootfs)\0"\
	"bootcmd=nand read ${loadaddr} 0x4000000 0x800000;"\
		"nand read ${fdt_addr} 0x5000000 0x100000;"\
		"bootz ${loadaddr} - ${fdt_addr}\0"

#else
#define CONFIG_EXTRA_ENV_SETTINGS \
	CONFIG_MFG_ENV_SETTINGS \
	"script=boot.scr\0" \
	"image=zImage\0" \
	"console=ttymxc0\0" \
	"fdt_high=0xffffffff\0" \
	"initrd_high=0xffffffff\0" \
	"fdt_file=undefined\0" \
	"fdt_addr=0x83000000\0" \
	"boot_fdt=try\0" \
	"ip_dyn=yes\0" \
	"panel=TFT43AB\0" \
	"mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
	"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
	"mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
	"mmcautodetect=yes\0" \
	"mmcargs=setenv bootargs console=${console},${baudrate} " \
		CONFIG_BOOTARGS_CMA_SIZE \
		"root=${mmcroot}\0" \
	"loadbootscript=" \
		"fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};\0" \
	"bootscript=echo Running bootscript from mmc ...; " \
		"source\0" \
	"loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
	"loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
	"mmcboot=echo Booting from mmc ...; " \
		"run mmcargs; " \
		"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
			"if run loadfdt; then " \
				"bootz ${loadaddr} - ${fdt_addr}; " \
			"else " \
				"if test ${boot_fdt} = try; then " \
					"bootz; " \
				"else " \
					"echo WARN: Cannot load the DT; " \
				"fi; " \
			"fi; " \
		"else " \
			"bootz; " \
		"fi;\0" \
	"netargs=setenv bootargs console=${console},${baudrate} " \
		CONFIG_BOOTARGS_CMA_SIZE \
		"root=/dev/nfs " \
	"ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
		"netboot=echo Booting from net ...; " \
		"run netargs; " \
		"if test ${ip_dyn} = yes; then " \
			"setenv get_cmd dhcp; " \
		"else " \
			"setenv get_cmd tftp; " \
		"fi; " \
		"${get_cmd} ${image}; " \
		"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
			"if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
				"bootz ${loadaddr} - ${fdt_addr}; " \
			"else " \
				"if test ${boot_fdt} = try; then " \
					"bootz; " \
				"else " \
					"echo WARN: Cannot load the DT; " \
				"fi; " \
			"fi; " \
		"else " \
			"bootz; " \
		"fi;\0" \
		"findfdt="\
			"if test $fdt_file = undefined; then " \
				"if test $board_name = EVK && test $board_rev = 9X9; then " \
					"setenv fdt_file imx6ull-9x9-evk.dtb; fi; " \
				"if test $board_name = EVK && test $board_rev = 14X14; then " \
					"setenv fdt_file imx6ull-14x14-evk.dtb; fi; " \
				"if test $fdt_file = undefined; then " \
					"echo WARNING: Could not determine dtb to use; fi; " \
			"fi;\0" \

#define CONFIG_BOOTCOMMAND \
	   "run findfdt;" \
	   "mmc dev ${mmcdev};" \
	   "mmc dev ${mmcdev}; if mmc rescan; then " \
		   "if run loadbootscript; then " \
			   "run bootscript; " \
		   "else " \
			   "if run loadimage; then " \
				   "run mmcboot; " \
			   "else run netboot; " \
			   "fi; " \
		   "fi; " \
	   "else run netboot; fi"
#endif

IMX6学习记录(3)-LINUX编译_第9张图片

现在还是没跑起来

将之前yocto的镜像下载一遍,替换掉uboot、zimage和设备树

IMX6学习记录(3)-LINUX编译_第10张图片

现在是可以进linux的,但是没有正常跑起来,内核是今天编译出来的

5.卡分区

现在跑起来是因为我先下载了一个yocto出来的镜像,对卡进行了分区。

如果没得镜像,那这个uboot和kernel就不能正常用了

从SD卡读zimage和设备树是要文件系统的

尝试自行划分一个分区出来

首先对照官方出来的卡状态

IMX6学习记录(3)-LINUX编译_第11张图片98

IMX6学习记录(3)-LINUX编译_第12张图片

总共两分区,按理说只要和这个分区一样,uboot就可以找到内核镜像和设备树,以及文件系统了

首先格式化整个卡片

IMX6学习记录(3)-LINUX编译_第13张图片

开始分配第一个分区,最小是16M,分不出8M。

IMX6学习记录(3)-LINUX编译_第14张图片

第二个分区

IMX6学习记录(3)-LINUX编译_第15张图片

整个盘

IMX6学习记录(3)-LINUX编译_第16张图片

为了确定改动是有效的,将内核和uboot都全编译一次

时间戳

首先写入uboot

拷贝zimage和设备树进boot盘

IMX6学习记录(3)-LINUX编译_第17张图片

文件系统先空着不管他

查看终端打印信息

其中uboot是U-Boot 2016.03 (Oct 23 2019 - 15:52:59 +0800)

kernel是:Oct 23 15:56:44 CST 2019

说明是正常从uboot跳转到了kernel

U-Boot 2016.03 (Oct 23 2019 - 15:52:59 +0800)

CPU:   Freescale i.MX6ULL rev1.0 528 MHz (running at 396 MHz)
CPU:   Industrial temperature grade (-40C to 105C) at 31C
Reset cause: POR
Board: MX6ULL 14x14 EVK
I2C:   ready
DRAM:  512 MiB
NAND:  256 MiB
MMC:   FSL_SDHC: 0
*** Warning - bad CRC, using default environment

Display: TFT43AB (480x272)
Video: 480x272x24
In:    serial
Out:   serial
Err:   serial
Net:   FEC0 MXC: board_eth_init:failed
No ethernet found.
Normal Boot
Hit any key to stop autoboot:  0 
switch to partitions #0, OK
mmc0 is current device
switch to partitions #0, OK
mmc0 is current device
reading boot.scr
** Unable to read file boot.scr **
reading zImage
6680408 bytes read in 587 ms (10.9 MiB/s)
Booting from mmc ...
reading imx6ull-14x14-evk.dtb
35969 bytes read in 22 ms (1.6 MiB/s)
Kernel image @ 0x80800000 [ 0x000000 - 0x65ef58 ]
## Flattened Device Tree blob at 83000000
   Booting using the fdt blob at 0x83000000
   Using Device Tree in place at 83000000, end 8300bc80

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.1.15 (jun@ubuntu) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01) ) #2 SMP PREEMPT Wed Oct 23 15:56:44 CST 2019
CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c53c7d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
Machine model: Freescale i.MX6 ULL 14x14 EVK Board
Reserved memory: created CMA memory pool at 0x8c000000, size 320 MiB
Reserved memory: initialized node linux,cma, compatible id shared-dma-pool
Memory policy: Data cache writealloc
PERCPU: Embedded 12 pages/cpu @8bb32000 s16960 r8192 d24000 u49152
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: console=ttymxc0,115200 root=/dev/mmcblk0p2 rootwait rw
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)

 

你可能感兴趣的:(IMX6ULL)