分类: LINUX
2008-09-09 23:14:00
Linux2.6.11.12 with YAFFS NAND flash filesystem porting
Author:Dujiang
Email:
Preparing works:
Our board is smdk2410. You can read the board’s specification document from the hycose.com
These are some predefined terms.
$kernel_root: It is the root directory of the kernel source files
#: It is a Linux shell console sign.
Now ,lets start the porting works.
1:Downloading the Linux kernel source files and its patch file from the ftp site.If you are a CERNET user, you can obtain it from the Linux kernel mirror site Linux kernel files are released by the .
2:Downloading the cross-compile tools. We need download it from the or the . It usually named arm-linux- or linux-elf- etc. In our project, we got the arm-linux-gcc-3.4.1.tar.bz2 as the cross-compiler.
3:Obtain the YAFFS source filesVisiting the
website,you can get a YAFFS source file.
4:Loging in the Linux as root in your host computer, extracting all the compressed file.We must follow the instructions as below.
4.1 Decompressing these files, and patch them. And we assume that all these files were stored in /home/yourname/
#cd /home/yourname
#tar –zxvf linux-2.6.11.12.tar.gz
#cp –a ./linux-2.6.11.12 /usr/src
#cp patch-2.6.11.12.tar.gz /usr/src/
#mkdir /usr/local/arm/
#tar –jxvf arm-linux-gcc-3.4.1.tar.bz2
#cp –a ./3.4.1 /usr/local/arm/
#tar –zxvf yaffs.tar.gz
#cp –a ./yaffs /usr/src/linux-2.6.11.12/fs/yaffs
#cd /usr/src/linux-2.6.11.12/
#zcat ../patch-2.6.11.12.tar.gz | patch –p1 –f
Now,we got a patched kernel source and the YAFFS filesystem was added into the kernel source.
5:In this step,we should hack the system follow the instructions as below
Get into the Linux2.6.11.12 root directory, then modifying the kernel source files.
#cd usr/src/linux-2.6.11.12/arch/arm/mach-s3c2410/
#vi devs.c
5.1 add your nand flash partition information modify the
arch/arm/mach-3c2410/devs.c file
/***********add here*************/
#include
#include
#include
/***********end add*************/
/**********************add here*********************/
static struct mtd_partition partition_info[] ={
{
.name = "vivi",
.size = 0x00030000,
.offset = 0,
}, {
.name = "param",
.size = 0x00150000,
.offset = 0x00030000,
}, {
.name = "kernel",
.size = 0x00180000,
.offset = 0x00180000,
}, {
.name = "root",
.size = 0x01e00000,
.offset = 0x00300000,
/*mask_flags: MTD_WRITEABLE,*/
}, {
.name = "user",
.size = 0x01f00000,
.offset = 0x02100000,
}
};
struct s3c2410_nand_set nandset ={
.nr_partitions = 5 ,
.partitions = partition_info ,
};
struct s3c2410_platform_nand superlpplatform={
.tacls =0,
.twrph0 =30,
.twrph1 =0,
.sets = &nandset,
.nr_sets = 1,
};
/***********************end add*************************/
struct platform_device s3c_device_nand = {
.name = "s3c2410-nand",
.id = 0xec,
.num_resources = ARRAY_SIZE(s3c_nand_resource),
.resource = s3c_nand_resource,
.dev = {
.platform_data = &superlpplatform //***********add here*****
}
};
5.2 add "&s3c_device_nand" to the __initdata in the
arch/arm/mach-s3c2410/mach-smdk2410.c
5.3 disable the ecc modify the drivers/mtd/nand/s3c2410.c
for example:
/**** chip->eccmode = NAND_ECC_SOFT; **/
chip->eccmode = NAND_ECC_NONE;
5.4 Add the yaffs/ to the /fs/Makefile
Insert this line "obj-$(CONFIG_YAFFS_FS) += yaffs/" to the Makefile.
6 In the step, we will modify the YAFFS source files.
#cd /usr/src/linux-2.6.11.12/fs/yaffs/linux-kernel/
# ./patch-ker.sh
#cd ./fs/yaffs
#cp ./* /usr/src/linux-2.6.11.12/fs/yaffs/
6.1 adding “#include
and yaffs_fs.c
7 config the kernel
7.1 modify the MakeFile
#cd /usr/src/linux-2.6.11.12/
#vi Makefile
We must modify the “ARCH=” and “CROSS-COMPILE=” as follow:
We should annotate these lines like this.
***********************changes start*******************************
##SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
## -e s/arm.*/arm/ -e s/sa110/arm/ \
## -e s/s390x/s390/ -e s/parisc64/parisc/ )
**********************changes end********************************
And change the “SUBARCH” like this.
SUBARCH :=arm
then change the “CROSS_COMPILE” like this
##CROSS_COMPILE ?=
CROSS_COMPILE ?=/toolchain/bin/arm-linux- ##according to your situation
7.2 configure the kernel
if you started a xwindow ,you can use the GUI configuration, the command as below
#make xconfig
You also can use the text mode configuration without a xwindow,the command as below
#make menuconfig
Generally,as we are the beginner ,using the def-configs is a wise choice.All the def-configs are available in the
directory /usr/src/linux-2.6.11.12/arch/arm/configs
the following is my configuration
#define AUTOCONF_INCLUDED
#define CONFIG_ARM 1
#define CONFIG_MMU 1
#define CONFIG_UID16 1
#define CONFIG_RWSEM_GENERIC_SPINLOCK 1
#define CONFIG_GENERIC_CALIBRATE_DELAY 1
#define CONFIG_GENERIC_IOMAP 1
/*
* Code maturity level options
*/
#define CONFIG_EXPERIMENTAL 1
#define CONFIG_CLEAN_COMPILE 1
#define CONFIG_BROKEN_ON_SMP 1
/*
* General setup
*/
#define CONFIG_LOCALVERSION "Nankai_Robot"
#define CONFIG_SWAP 1
#define CONFIG_SYSVIPC 1
#undef CONFIG_POSIX_MQUEUE
#undef CONFIG_BSD_PROCESS_ACCT
#define CONFIG_SYSCTL 1
#undef CONFIG_AUDIT
#define CONFIG_LOG_BUF_SHIFT 14
#undef CONFIG_HOTPLUG
#define CONFIG_KOBJECT_UEVENT 1
#undef CONFIG_IKCONFIG
#undef CONFIG_EMBEDDED
#define CONFIG_KALLSYMS 1
#undef CONFIG_KALLSYMS_ALL
#undef CONFIG_KALLSYMS_EXTRA_PASS
#define CONFIG_FUTEX 1
#define CONFIG_EPOLL 1
#define CONFIG_CC_OPTIMIZE_FOR_SIZE 1
#define CONFIG_SHMEM 1
#define CONFIG_CC_ALIGN_FUNCTIONS 0
#define CONFIG_CC_ALIGN_LABELS 0
#define CONFIG_CC_ALIGN_LOOPS 0
#define CONFIG_CC_ALIGN_JUMPS 0
#undef CONFIG_TINY_SHMEM
/*
* Loadable module support
*/
#define CONFIG_MODULES 1
#define CONFIG_MODULE_UNLOAD 1
#define CONFIG_MODULE_FORCE_UNLOAD 1
#define CONFIG_OBSOLETE_MODPARM 1
#undef CONFIG_MODVERSIONS
#undef CONFIG_MODULE_SRCVERSION_ALL
#undef CONFIG_KMOD
/*
* System Type
*/
#undef CONFIG_ARCH_CLPS7500
#undef CONFIG_ARCH_CLPS711X
#undef CONFIG_ARCH_CO285
#undef CONFIG_ARCH_EBSA110
#undef CONFIG_ARCH_CAMELOT
#undef CONFIG_ARCH_FOOTBRIDGE
#undef CONFIG_ARCH_INTEGRATOR
#undef CONFIG_ARCH_IOP3XX
#undef CONFIG_ARCH_IXP4XX
#undef CONFIG_ARCH_IXP2000
#undef CONFIG_ARCH_L7200
#undef CONFIG_ARCH_PXA
#undef CONFIG_ARCH_RPC
#undef CONFIG_ARCH_SA1100
#define CONFIG_ARCH_S3C2410 1
#undef CONFIG_ARCH_SHARK
#undef CONFIG_ARCH_LH7A40X
#undef CONFIG_ARCH_OMAP
#undef CONFIG_ARCH_VERSATILE
#undef CONFIG_ARCH_IMX
#undef CONFIG_ARCH_H720X
/*
* S3C24XX Implementations
*/
#undef CONFIG_ARCH_BAST
#undef CONFIG_ARCH_H1940
#define CONFIG_ARCH_SMDK2410 1
#undef CONFIG_MACH_VR1000
#undef CONFIG_MACH_RX3715
#define CONFIG_CPU_S3C2410 1
/*
* S3C2410 Setup
*/
#define CONFIG_S3C2410_DMA 1
#undef CONFIG_S3C2410_DMA_DEBUG
#undef CONFIG_S3C2410_PM_DEBUG
#undef CONFIG_S3C2410_PM_CHECK
#define CONFIG_S3C2410_LOWLEVEL_UART_PORT 0
/*
* Processor Type
*/
#define CONFIG_CPU_32 1
#define CONFIG_CPU_ARM920T 1
#define CONFIG_CPU_32v4 1
#define CONFIG_CPU_ABRT_EV4T 1
#define CONFIG_CPU_CACHE_V4WT 1
#define CONFIG_CPU_CACHE_VIVT 1
#define CONFIG_CPU_COPY_V4WB 1
#define CONFIG_CPU_TLB_V4WBI 1
/*
* Processor Features
*/
#define CONFIG_ARM_THUMB 1
#undef CONFIG_CPU_ICACHE_DISABLE
#undef CONFIG_CPU_DCACHE_DISABLE
#undef CONFIG_CPU_DCACHE_WRITETHROUGH
/*
* General setup
*/
#define CONFIG_ZBOOT_ROM_TEXT 0x0
#define CONFIG_ZBOOT_ROM_BSS 0x0
#undef CONFIG_XIP_KERNEL
/*
* PCCARD (PCMCIA/CardBus) support
*/
#undef CONFIG_PCCARD
/*
* PC-card bridges
*/
/*
* At least one math emulation must be selected
*/
#define CONFIG_FPE_NWFPE 1
#undef CONFIG_FPE_NWFPE_XP
#undef CONFIG_FPE_FASTFPE
#define CONFIG_BINFMT_ELF 1
#define CONFIG_BINFMT_AOUT 1
#undef CONFIG_BINFMT_MISC
/*
* Generic Driver Options
*/
#define CONFIG_STANDALONE 1
#define CONFIG_PREVENT_FIRMWARE_BUILD 1
#undef CONFIG_FW_LOADER
#undef CONFIG_DEBUG_DRIVER
#define CONFIG_PM 1
#undef CONFIG_PREEMPT
#undef CONFIG_APM
#undef CONFIG_ARTHUR
#define CONFIG_CMDLINE "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200 mem=64M"
#define CONFIG_ALIGNMENT_TRAP 1
/*
* Parallel port support
*/
8 compile kernel
#make zImage
If there is no error in the compiling process,you can get a zImage file in the /usr/src/linux-2.6.11.12/arch/arm/boot/.It is the kernel image which will be writed to the NAND flash.
9 make vivi bootloader In our board,we need a bootloader to initialize the S3C2410A and its memory or flash,then boot the kernel image from the NAND flash.
We used the vivi-bootloader developed by Mizi Co. Ltd.
9.1 get a vivi source file from our ftp which was described in the begin part of this document. Assumed to put the
vivi source file in /home/yourname/
#cd vivi
#vi Makefile
9.1.1 Modifying the “LINUX-INCLUDE-DIR =” to “LINUX-INCLUDE-DIR = [your cross-compiler’s include directory path]”
For instance in our project, it was changed like this:
“LINUX-INCLUDE-DIR = /usr/local/arm/2.95.3/include”
2.95.3 is a pre-version cross-compiler,you can get it in .
9.1.2 change the “CROSS-COMPILE=” path, for example:
“CROSS-COMPILE = /usr/local/arm/2.95.3/bin/arm-linux-”
9.1.3 we must modify the cmd line to transporting the init parameters when the kernel booting.
Open the “/home/yourname/vivi/arch/s3c2410/smdk.c”
Add these code in it,
****************************add start********************************
#ifdef CONFIG_S3C2410_NAND_BOOT
mtd_partition_t default_mtd_partitions[] = {
{
name: "vivi",
offset: 0,
size: 0x00030000,
flag: 0
}, {
name: "param",
offset: 0x00030000,
size: 0x00150000,
flag: 0
}, {
name: "kernel",
offset: 0x00180000,
size: 0x00180000,
flag: 0
}, {
name: "root",
offset: 0x00300000,
size: 0x01e00000,
flag: 0
//flag: MF_BONFS
}, {
name: "user",
offset: 0x02100000,
size: 0x01f00000,
flag: 0
}
};
#endif
****************************add end*********************************
And modify the cmd_line as below
“char linux_cmd[] = "noinitrd root=/dev/mtdblock/3 init=/linuxrc console=ttySAC0,115200 mem=64M";”
9.2 return to the vivi root directory,configure the vivi
#make menuconfig
My configuration is printed as below:
/*
* Automatically generated by make menuconfig: don't edit
*/
#define AUTOCONF_INCLUDED
/*
* System Type
*/
#undef CONFIG_ARCH_SA1100
#undef CONFIG_ARCH_PXA250
#undef CONFIG_ARCH_S3C2400
#define CONFIG_ARCH_S3C2410 1
/*
* Implementations
*/
#define CONFIG_S3C2410_SMDK 1
#undef CONFIG_S3C2410_MPORT3
#undef CONFIG_S3C2410_MPORT1
#define CONFIG_S3C2410_NAND_BOOT 1
#undef CONFIG_S3C2410_AMD_BOOT
#undef CONFIG_BOOTUP_MEMTEST
/*
* General setup
*/
#undef CONFIG_VIVI_ADDR
#define CONFIG_VIVI_TEXTADDR 0x0
#undef CONFIG_RESET_HANDLING
#undef CONFIG_CPU_D_CACHE_ON
#undef CONFIG_CPU_I_CACHE_ON
#define CONFIG_PM 1
#undef CONFIG_MSG_PROGRESS
#undef CONFIG_MD5
/*
* Private Data
*/
#define CONFIG_PRIV 1
#define CONFIG_PARSE_PRIV_DATA 1
#define CONFIG_USE_PARAM_BLK 1
#undef CONFIG_DEBUG_VIVI_PRIV
/*
* Serial Port
*/
#define CONFIG_SERIAL 1
#define CONFIG_SERIAL_TERM 1
#undef CONFIG_SERIAL_GETCMD_STD
#define CONFIG_SERIAL_GETCMD_EXT 1
#define CONFIG_SERIAL_TERM_PROMPT "vivi"
#define CONFIG_SERIAL_UART0 1
#undef CONFIG_SERIAL_UART1
#undef CONFIG_SERIAL_UART2
#undef CONFIG_SERIAL_UART3
#define CONFIG_SERIAL_XMODEM 1
#undef CONFIG_SERIAL_YMODEM
#undef CONFIG_SERIAL_ZMODEM
/*
* Memory Technology Devices (MTD)
*/
#define CONFIG_MTD 1
#undef CONFIG_MTD_DEBUG
/*
* NOR Flash chip drivers
*/
#undef CONFIG_MTD_NOR
#undef CONFIG_MTD_CFI
#undef CONFIG_MTD_GEN_PROBE
#undef CONFIG_MTD_CFI_INTELEXT
#undef CONFIG_MTD_OBSOLETE_CHIPS
#undef CONFIG_MTD_AMDSTD
/*
* Mapping drivers for chip access
*/
#undef CONFIG_MTD_SA1100
#undef CONFIG_MTD_S3C2400
#define CONFIG_MTD_S3C2410 1
#undef CONFIG_MTD_PXA250
/*
* NAND Flash Device Drivers
*/
#define CONFIG_MTD_NAND 1
#undef CONFIG_MTD_NAND_ECC
#undef CONFIG_MTD_NAND_VERIFY_WRITE
#undef CONFIG_MTD_SMC
#undef CONFIG_MTD_BONFS
#undef CONFIG_MTD_NANDY
/*
* Add Built-in Commands
*/
#define CONFIG_CMD_MEM 1
#undef CONFIG_MEMORY_RAM_TEST
#define CONFIG_CMD_PARAM 1
#define CONFIG_CMD_PART 1
#undef CONFIG_CMD_BONFS
#undef CONFIG_CMD_SLEEP
#undef CONFIG_CMD_PROMPT
#undef CONFIG_TEST
#undef CONFIG_CMD_AMD_FLASH
/*
* System hacking
*/
#undef CONFIG_TEST_MODE
#undef CONFIG_DEBUG
/*
* Debugging messages
*/
#undef CONFIG_DEBUG_LL
#undef CONFIG_DEBUG_CFI
9.3 compile the vivi
#make vivi
If everything is all right ,you can find the vivi file in the vivi source root directory.
This vivi image will burn at address 0 in the NAND flash.
10 make a cramfs root filesystem.
We can use the cramfs image made by the hycose Co. Ltd, download it from the ftp.
11 GOOD LUCK