移植linux4.7.2与ubifs到jz2440

前言

整个暑假跟着韦东山的视频和书籍移植了linux2.3.6到jz2440,现在自己尝试移植linux4.7.2到板子上,并使用ubifs文件系统代替旧的jffs2文件系统。


下载交叉编译工具链

工具链我使用的是friendlyARM提供的工具链,因为韦东山教程提供的工具链比较旧不能编译较新的linux内核,也可以自己使用crosstool-ng构建。
ARM-Linux GCC 4.4.3

下载源码

下载linux4.7.2的源码
Linux4.7.2

修改编译烧写uboot

uboot还是使用了有韦东山提供的uboot1.1.6,这里我修改了一下uboot的分区
打开打好韦东山提供的uboot补丁的uboot目录。打开/include/configs/100ask24x0.h,修改代码57行如下:

#define MTDPARTS_DEFAULT "mtdparts=nandflash0:256k@0(bootloader)," \
			    "128k(params)," \
                "8m(kernel)," \
                "-(rootfs)"

这里把nandflash分成4个分区,kernel存放系统内核uImage,rootfs存放ubifs文件系统。最后make生成u-boot.bin,烧写进norflash里。

注意:这里的uboot是1.1.6比较旧所以不可以使用arm-linux-gcc4.4.3来编译,所以我这里换成使用韦东山提供的工具中的3.4.5来编译

修改编译烧写内核

解压linux4.7.2.tar.xz并进入目录

make s3c2410_defconfig
make menuconfig
进入【Device Drivers】--->
		Memory Technology Device (MTD) support --->
			<*>Enable UBI
进入 【File System】--->
		Miscellaneous filesustems --->
			<*>UBIFS file system
进入	【Kernel Features】--->
     [*] Use the ARM EABI to compile the kernel
     [*]   Allow old ABI binaries to run with this kernel (EXPERIMENTAL)

修改./arch/arm/mach-s3c24xx/common-smdk.c中的smdk_default_nand_part[]结构体数组

static struct mtd_partition smdk_default_nand_part[] = {
	[0] = {
		.name	= "bootloader",
		.size	= SZ_256K,
		.offset	= 0,
	},
	[1] = {
		.name	= "params",
		.offset = MTDPART_OFS_APPEND,
		.size	= SZ_128K,
	},
	[2] = {
		.name	= "kernel",
		.offset = MTDPART_OFS_APPEND,
		.size	= SZ_8M,
	},
	[3] = {
		.name	= "rootfs",
		.offset = MTDPART_OFS_APPEND,
		.size	= MTDPART_SIZ_FULL,
	}
};

修改./arch/arm/mach-s3c24xx/mach-smdk2440.c中的smdk2440_init_time(void)函数

static void __init smdk2440_init_time(void)
{
	s3c2440_init_clocks(12000000);//板子的晶振是12M
	samsung_timer_init();
}

修改makeflie的第255和256行

ARCH		?= arm
CROSS_COMPILE	?= arm-linux-
最后make uImage,在/arch/arm/boot下生成uImage
启动jz2440,进入uboot
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
set bootcmd 'nboot 0x32000000 kernel; bootm 0x32000000'
set ipaddr 192.168.199.148		#根据自己修改
set serverip 192.168.199.146	#根据自己修改
save
tftp 0x30000000 uImage
nand erase
nand write.jffs2 0x30000000 kernel $(filesize)
reset

如果系统启动成功则会最后显示类似end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-bl,则证明系统启动成功,下面就是制作根文件系统了。

制作根文件系统

这里我采用ubifs文件系统,具体优缺点自己google
首先下载busybox,我这里用的版本是1.20.0

cd busybox1.20.0
make menconfig
Busybox Settings -->
	Build options -->
		Cross Compiler prefix
		填arm-linux-
Build Options --->
	[*]Build BusyBox as a static binary (no shared libs)

make
make CONFIG_PREFIX=~/2440/ubifs install
cd '/home/zzm/arm/opt/FriendlyARM/toolschain/4.4.3/lib'
cp *.so.* ~/2440/ubifs/lib -d
cd ~/2440/ubifs
cp -r ~/2440/busybox-1.20.0/examples/bootfloppy/etc ./ 
vim inittab

内容如下:

::sysinit:/etc/init.d/rcS
console::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
::shutdown:/bin/umount -a -r
vim fstab

内容如下:

proc        /proc   proc    defaults    0   0
tmpfs       /tmp    tmpfs   defaults    0   0
sysfs       /sys    sysfs   defaults    0   0
tmpfs       /dev    tmpfs   defaults    0   0
vim init.d/rcS

内容如下:

#! /bin/sh
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
cd ~/2440/ubifs
mkdir dev
cd dev
sudo mknod null c 1 3
sudo mknod console c 5 1
cd ..
mkdir proc mnt tmp sys root home
cd ..
mkfs.ubifs -r ubifs -m 2048 -e 129024 -c 105 -o fs_jz2440.img#129024*105=13MB
vim ubinize.cfg
[ubifs]
mode=ubi
image=fs_jz2440.img
vol_id=0
vol_size=13MiB 
vol_type=dynamic
vol_name=root
vol_flags=autoresize

ubinize -o ubi.img -m 2048 -p 128KiB -s 512 ubinize.cfg
生成ubi.img

最后烧写

tftp 0x30000000 ubi.img
nand erase root
nand write.i 0x30000000 root $(filesize)
bootargs=console=ttySAC0,115200 ubi.mtd=3 root=ubi0:root rootfstype=ubifs
set bootcmd 'nboot 0x32000000 kernel; bootm 0x32000000'
save
reset
posted @ 2016-09-06 00:22  zzmx  阅读(934)  评论(0编辑  收藏  举报