1.效果

IMX6学习记录(7)-编译脚本_IMX6ULL

这几天搞这个东西,会有一大堆的命令行操作

很多重复的内容

现在做一个简单的脚本,方便自己平时的开发工作

2.脚本内容
#!/bin/bash

#uboot编译
function mk_uboot()
{
	cd /home/jun/i.mx6/source/uboot-imx-rel_imx_4.1.15_2.1.0_ga/
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mx6ull_14x14_evk_defconfig
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4
	cd /home/jun/i.mx6/image/
}

#kernel编译
function mk_kernel()
{
	cd /home/jun/i.mx6/source/linux-imx-rel_imx_4.1.15_2.1.0_ga/
	make clean
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j4
	cd /home/jun/i.mx6/image/
}

#rootfs编译
function mk_rootfs()
{
	cd /home/jun/i.mx6/source/busybox-1.29.0/
	make clean
	make menuconfig
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
	make install busybox
	cd /home/jun/i.mx6/image/
}

#编译全部
function mk_all()
{
	mk_uboot
	mk_kernel
	mk_rootfs
}

#uboot拷贝
function cp_uboot()
{
	cd /home/jun/i.mx6/image/
	sudo rm -rf u-boot.imx
	sudo cp /home/jun/i.mx6/source/uboot-imx-rel_imx_4.1.15_2.1.0_ga/u-boot.imx /home/jun/i.mx6/image/
}

#kernel拷贝
function cp_kernel()
{
	cd /home/jun/i.mx6/image/
	sudo rm -rf zImage
	sudo cp /home/jun/i.mx6/source/linux-imx-rel_imx_4.1.15_2.1.0_ga/arch/arm/boot/zImage /home/jun/i.mx6/image/
	sudo rm -rf imx6ull-14x14-evk.dtb
	sudo cp /home/jun/i.mx6/source/linux-imx-rel_imx_4.1.15_2.1.0_ga/arch/arm/boot/dts/imx6ull-14x14-evk.dtb /home/jun/i.mx6/image/
}

#rootfs拷贝
function cp_rootfs()
{
	cd /home/jun/i.mx6/image/
	sudo cp -R ../source/busybox-1.29.0/_install/* rootfs/
	cd /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc//lib/
	cp *so* *.a /home/jun/i.mx6/image/rootfs/lib/ -d

	cd /home/jun/i.mx6/image/
	genext2fs -b 131072 -d rootfs/ ramdisk
	gzip -9 –f ramdisk
	mkimage -A arm -O linux -T ramdisk -C none -a 0x81800000 -n "ramdisk" -d ramdisk.gz ramdisk.img
}

#拷贝全部
function cp_all()
{
	cp_uboot
	cp_kernel
	cp_rootfs
}

#uboot更新
function up_uboot()
{
	sudo dd if=u-boot.imx of=/dev/sdb bs=1k seek=1 conv=fsync
}

#kernel更新
function up_kernel()
{
	sudo rm -rf /media/jun/BOOT1/*
	sudo cp /home/jun/i.mx6/image/zImage /media/jun/BOOT1/
	sudo cp /home/jun/i.mx6/image/imx6ull-14x14-evk.dtb /media/jun/BOOT1/
}

#rootfs更新
function up_rootfs()
{
	mkimage -A arm -O linux -T ramdisk -C none -a 0x81800000 -n "ramdisk" -d ramdisk.gz ramdisk.img
	sudo cp /home/jun/i.mx6/image/ramdisk.img /media/jun/BOOT1/
}

#更新全部
function up_all()
{
	up_uboot
	up_kernel
	up_rootfs
}

#更新SD卡
function up_sd()
{
	up_kernel
	up_rootfs
}

function menu()
{
	echo  "                欢迎使用IMX6ULL开发工具--jun     "
	echo -e "\e[1;33m------------------------------------------------------\e[0m"
	echo "  "
	echo "      1)uboot编译"
	echo "      2)kernel编译"
	echo "      3)rootfs编译"
	echo "      4)编译所有--会清除所有设置,恢复默认状态"
	echo "  "
	echo "      5)uboot拷贝"
	echo "      6)kernel拷贝"
	echo "      7)rootfs拷贝"
	echo "      8)拷贝所有"
	echo "  "
	echo "      9)uboot更新"
	echo "      10)kernel更新"
	echo "      11)rootfs更新"
	echo "      12)更新SD内容"
	echo "      13)更新所有"
	echo "  "
	echo "      14)退出"
	echo -e "\e[1;33m------------------------------------------------------\e[0m"
}

function usage()
{
    read -p "please input your choice: " choice
    case $choice in
        1)
            mk_uboot
            ;;
        2)
            mk_kernel
            ;;
        3)
            mk_rootfs
            ;;
        4)
            mk_all
            ;;
		5)
            cp_uboot
            ;;
		6)
            cp_kernel
            ;;
		7)
            cp_rootfs
            ;;
		8)
            cp_all
            ;;
		9)
            up_uboot
            ;;
		10)
            up_kernel
            ;;
		11)
            up_rootfs
            ;;
		12)
            up_sd
            ;;
		13)
            up_all
            ;;
        14)
            exit 0
            ;;
 
    esac
}

function  main()
{
    while true
    do
        menu
        usage
    done
}

main
3.测试

不跑编译了,就更新一下SD卡吧

然后让他运行起来,看芯片能不能正常工作就行了

首先准备一个空卡

IMX6学习记录(7)-编译脚本_IMX6ULL_02

准备一个文件夹用于存储镜像文件,现在里面没有镜像文件

IMX6学习记录(7)-编译脚本_IMX6ULL_03

脚本工具输入8

拷贝所有镜像文件

IMX6学习记录(7)-编译脚本_IMX6ULL_04

脚本工具输入13,更新SD卡内容

IMX6学习记录(7)-编译脚本_IMX6ULL_05

测试一下。

一切正常

IMX6学习记录(7)-编译脚本_IMX6ULL_06

启动时间好慢,将近一分钟,后面再裁剪一下