目前较优秀的NandFlash文件系统为:UBI文件系统,但是,近两周来,移植UBI文件系统一直有问题,挂载总是失败!但是,经过不断的尝试与分析,不断的更换linux 内核,uboot启动参数,烧写方式,终于跑起来了。
硬件平台为:AT91sam9261EK的开发板,不过NandFlash为:128MB的,虽然256MB换成128MB应该也没有什么大的修改,但是在文件系统移植上,问题多出在128MB NandFlash上。使用Atmel SAM-BA 2.15下载文件系统,总是提示挂载失败!后来转为用Uboot tftp下载,终于成功。
Uboot 需要设置为支持UBI命令,方法是更改相应的开发板头文件:位置在include/configs/at91sam9261ek.h,不同的开发板或是自己的板子,需要更改相应的xxxx.h文件。
我这里使用的是:Uboot 2014.04,修改与添加如下:
一:网络支持部分:DM9000支持,用于tftp,设置好后,就不用在uboot命令行里设置了。
#define CONFIG_BOOTDELAY 2 //等待时间改为短点:2秒。
直接添加如下的网络参数:注意IP设置要与自己的PC主机在一个网段
#define CONFIG_ETHADDR 08:00:3e:26:0a:5b
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 192.168.9.210
#define CONFIG_SERVERIP 192.168.9.106
二:添加UBI工具命令的支持
/*
* Command for UBI.
*/
#define CONFIG_CMD_UBI /* UBI Support */
#define CONFIG_CMD_UBIFS /* UBIFS Support */
#define CONFIG_MTD_DEVICE
#define CONFIG_MTD_PARTITIONS
#define CONFIG_CMD_MTDPARTS
#define CONFIG_RBTREE
#define CONFIG_LZO
#define MTDPARTS_DEFAULT "mtdparts=nand0:2m(boot)," \
"6m(kernel)," \
"-(rootfs)"
#define MTD_ACTIVE_PART "nand0,2"
#define MTDIDS_DEFAULT "nand0=nand0"
注意:新点的版本,如Uboot 2014.04是支持UBI文件系统的相关命令的,但是,需要添加相关的宏才能打开这些命令,如上。注意Linux内核NandFlahs分区。我这里分了三个分区,2M boot 6M Kernel 余下的为:rootfs根文件系统。
三:Linux内核的启动传递参数设置:UBI根文件系统
#else /* CONFIG_SYS_USE_NANDFLASH */
/* bootstrap + u-boot + env + linux in nandflash */
#define CONFIG_ENV_IS_IN_NAND
#define CONFIG_ENV_OFFSET 0xc0000
#define CONFIG_ENV_OFFSET_REDUND 0x100000
#define CONFIG_ENV_SIZE 0x20000 /* 1 sector = 128 kB */
#define CONFIG_BOOTCOMMAND "nand read 0x22000000 0x200000 0x300000; bootm"
#define CONFIG_BOOTARGS \
"mem=64M console=ttyS0,115200 " \
"ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs init=/linuxrc "
#endif
以上为Uboot的主要修改,我这里使用的是NandFlash启动,虽然NandFlash存放启动文件与根文件系统,不太好,但是,一般boot kernel文件一旦烧写成功后,以后只是读,读NandFlash,对NandFlash没有太大的影响!!因此,在一起,更方便,省了其他的存储芯片。
我使用的是Linux 2.6.32的内核,感觉这个比较稳定一点吧,支持UBI文件系统(好像2.6.30之后的UBI都支持的不错了)。修改的主要位置为:linux-2.6.32.2/arch/arm/mach-at91/board-sam9261ek.c
修改NandFlash分区:这个需要与Uboot那边的对应起来,如下:
/*
* NAND flash
*/
static struct mtd_partition __initdata ek_nand_partition[] = {
{
.name = "boot",
.offset = 0,
.size = SZ_2M,
},
{
.name = "kernel",
.offset = 0x200000,
.size = SZ_4M+SZ_2M,
},
{
.name = "rootfs",
.offset = 0x800000,
.size = MTDPART_SIZ_FULL,
},
};
制作UBI根文件系统,这里有时间再整理一下,因为使用的NandFlash不一样(大小不一样,命令的参数不一样)。我这里的为:128MB的NandFlash,制作的命令如下:
mkfs.ubifs -r rootfs -m 2048 -e 126KiB -o ubifs.img -c 800
生成:ubifs.img文件(这个可以直接由uboot烧写,ubi write)。如果想直接nand write烧写,还需要ubinize再处理一下,因为ubinize处理后,烧写后总是挂载不成功,因此不走那条路,使用uboot tftp烧写,速度快,方便。
烧写的步骤如下:
uboot->mtdparts default
uboot->nand erase 0x800000 0x6400000 //格式化rootfs分区
uboot->ubi part rootfs //rootfs分区作为ubi文件系统,此步骤出错,需要重新擦除整个NandFlash
uboot->tftp 0x22000000 ubifs.img //0x22000000为内存的位置。ubifs.img 为mkfs.ubifs 生成的,而不是ubinize处理过的。
uboot->ubi create rootfs //创建UBI volume
uboot->ubi write 0x22000000 rootfs 0x7ff800 //后面的那个0x7ff800 为ubifs.img的实际大小,十六进制的。
uboot->reset //或是断电重上电,都可以重新运行整个系统了。
我的启动信息如下:
RomBOOT
AT91Bootstrap 3.8.2 (Tue Feb 23 22:43:35 CST 2016)
NAND: ONFI not supported
NAND: Manufacturer ID: 0xec Chip ID: 0xf1
WARNING: Fail to disable On-Die ECC
NAND: Using Software ECC
NAND: Image: Copy 0x80000 bytes from 0x40000 to 0x21f00000
NAND: Done to load image
U-Boot 2014.04 (Feb 28 2016 - 15:53:00)
CPU: AT91SAM9261
Crystal frequency: 18.432 MHz
CPU clock : 198.656 MHz
Master clock : 99.328 MHz
DRAM: 64 MiB
WARNING: Caches not enabled
NAND: 128 MiB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
NAND read: device 0 offset 0x200000, size 0x300000
3145728 bytes read: OK
## Booting kernel from Legacy Image at 22000000 ...
Image Name: Linux-2.6.32.2
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1644632 Bytes = 1.6 MiB
Load Address: 20008000
Entry Point: 20008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
Starting kernel ...
Uncompressing Linux....................................................................................................... done, booting the kernel.
Linux version 2.6.32.2 (root@zhangsz) (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29) ) #4 Sun Feb 28 15:50:52 CST 2016
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
CPU: VIVT data cache, VIVT instruction cache
Machine: Atmel AT91SAM9261-EK
Memory policy: ECC disabled, Data cache writeback
Clocks: CPU 198 MHz, master 99 MHz, main 18.432 MHz
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: mem=64M console=ttyS0,115200 ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs init=/linuxrc
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 61560KB available (2840K code, 247K data, 124K init, 0K highmem)
Hierarchical RCU implementation.
NR_IRQS:192
AT91: 96 gpio irqs in 3 banks
Console: colour dummy device 80x30
console [ttyS0] enabled
Calibrating delay loop... 99.12 BogoMIPS (lpj=495616)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
bio: create slab at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Switching to clocksource pit
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
NetWinder Floating Point Emulator V0.97 (double precision)
msgmni has been set to 120
io scheduler noop registered
io scheduler anticipatory registered (default)
atmel_lcdfb atmel_lcdfb.0: backlight control is not available
atmel_lcdfb atmel_lcdfb.0: 150KiB frame buffer at 23900000 (mapped at ffc00000)
Console: switching to colour frame buffer device 30x40
atmel_lcdfb atmel_lcdfb.0: fb0: Atmel LCDC at 0x00600000 (mapped at c4814000), irq 21
atmel_usart.0: ttyS0 at MMIO 0xfefff200 (irq = 1) is a ATMEL_SERIAL
brd: module loaded
ssc ssc.1: Atmel SSC device at 0xc4818000 (irq 15)
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 446 at 0x0000037c0000
Bad eraseblock 994 at 0x000007c40000
Creating 3 MTD partitions on "atmel_nand":
0x000000000000-0x000000200000 : "boot"
0x000000200000-0x000000800000 : "kernel"
0x000000800000-0x000008000000 : "rootfs"
UBI: attaching mtd2 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 129024 bytes
UBI: smallest flash I/O unit: 2048
UBI: sub-page size: 512
UBI: VID header offset: 512 (aligned 512)
UBI: data offset: 2048
UBI: attached mtd2 to ubi0
UBI: MTD device name: "rootfs"
UBI: MTD device size: 120 MiB
UBI: number of good PEBs: 958
UBI: number of bad PEBs: 2
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 1
UBI: available PEBs: 0
UBI: total number of reserved PEBs: 958
UBI: number of PEBs reserved for bad PEB handling: 9
UBI: max/mean erase counter: 4/1
UBI: image sequence number: 0
atmel_spi atmel_spi.0: Atmel SPI Controller at 0xfffc8000 (irq 12)
UBI: background thread "ubi_bgt0d" started, PID 779
dm9000 Ethernet Driver, V1.31
dm9000 dm9000.0: eth%d: Invalid ethernet MAC address. Please set using ifconfig
eth0: dm9000a at c4872000,c4876044 IRQ 107 MAC: 00:00:00:00:00:00 (chip)
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
at91_ohci at91_ohci: AT91 OHCI
at91_ohci at91_ohci: new USB bus registered, assigned bus number 1
at91_ohci at91_ohci: irq 20, io mem 0x00500000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
udc: at91_udc version 3 May 2006
mice: PS/2 mouse device common for all mice
input: gpio-keys as /devices/platform/gpio-keys/input/input0
ads7846 spi0.2: touchscreen, irq 29
input: ADS7843 Touchscreen as /devices/platform/atmel_spi.0/spi0.2/input/input1
rtc-at91sam9 at91_rtt.0: rtc core: registered at91_rtt as rtc0
IRQ 1/rtc0: IRQF_DISABLED is not guaranteed on shared IRQs
rtc-at91sam9 at91_rtt.0: rtc0: SET TIME!
i2c /dev entries driver
i2c-gpio i2c-gpio: using pins 39 (SDA) and 40 (SCL)
AT91SAM9 Watchdog: sorry, watchdog is disabled
at91_wdt: probe of at91_wdt failed with error -5
TCP cubic registered
NET: Registered protocol family 17
rtc-at91sam9 at91_rtt.0: hctosys: unable to read the hardware clock
UBIFS: recovery needed
UBIFS: recovery completed
UBIFS: mounted UBI device 0, volume 0, name "rootfs"
UBIFS: file system size: 101799936 bytes (99414 KiB, 97 MiB, 789 LEBs)
UBIFS: journal size: 9033728 bytes (8822 KiB, 8 MiB, 71 LEBs)
UBIFS: media format: w4/r0 (latest is w4/r0)
UBIFS: default compressor: lzo
UBIFS: reserved for root: 0 bytes (0 KiB)
VFS: Mounted root (ubifs filesystem) on device 0:13.
Freeing init memory: 124K
#-----Start /etc/init.d/rcS
------------*******AT91SAM9261EK-Linux 2016-02-26***********------------
ifconfig: SIOCSIFFLAGS: Cannot assign requested address
AT91 login: root
Password:
login[826]: root login on 'ttyS0'
[root@AT91 /]# ls
bin dev home linuxrc proc sbin tmp var
boot etc lib mnt root sys usr
[root@AT91 /]# cd home/
[root@AT91 /home]# sl
-sh: sl: not found
[root@AT91 /home]# ls
hello hello.txt
[root@AT91 /home]# cat hello.txt
移植ubi文件系统成功了!! 2016-02-28
[root@AT91 /home]# cd /
[root@AT91 /]# ls
bin dev home linuxrc proc sbin tmp var
boot etc lib mnt root sys usr
[root@AT91 /]#
如果进入控制台,说明UBI根文件系统已经跑起来了,建个文件夹,写个数据,断电,然后 上电,文件夹与数据不会丢失的!这就是可以写的文件系统,而不像cramfs文件系统,只能读。
移植总结:
(1)遇到文件系统挂载失败,原因很多,有可能是制作工具或是烧写的问题,或是内核配置的问题。
(2)制作好的文件系统(准备好相关的文件),可以使用cramfs挂一下试试能不能跑起来,排除文件系统制作问题。
(3)烧写ubi文件系统(如果硬件配置与atmel官方的不一样,可能官方的samba工具不好用),可以使用带ubi工具的uboot。
(4)遇到问题,多搜索,并不断的尝试与总结,相信,就会很快找到出路!!
文件系统的制作,有时间整理一下再发出来。
阅读(2466) | 评论(0) | 转发(0) |