NUC970系列资料之NuWriter使用举例

一 烧写到Nand Flash

1.1 相关文件说明

l BSP版本:nuc970bsp-release-20150519.zip

l NuWriter版本:2015/04/28-V01,nuvoTon Nu-Writer V1.0

l 烧写文件:

u-boot-spl.bin:负责将u-boot.bin从Nand flash搬到DDR中执行。默认执行地址:0x200,可修改。

u-boot.bin:u-boot程序,默认执行地址:0xE00000,在nand flash中的烧写地址:0x100000。

env.txt:u-boot环境变量,在Nand Flash中的烧写地址:0x80000。

970image.ub:Linux kernel。加载地址:0x7fc0;执行地址:0x8000;烧写地址:0x200000,可变要与u-boot环境参数一致,bootcmd=nboot 0x7fc0 0 0x200000;bootm 0x7fc0。

1.2 烧写举例

1.烧写u-boot-spl.bin

clip_image002

Image Type:uBoot型

Image execute address: 0x200

2. 烧写 u-boot.bin

clip_image004

Image Type:Data型

Image start offset: 0x100000

3. 烧写U-Boot环境变量env.txt

clip_image006

Image Type:Environment型

Image start offset: 0x80000

4. 烧写kernel

clip_image008

Image Type:Data型

Image start offset: 0x200000

5.烧写yaffs2文件系统

1)制作yaffs2文件系统

mkyaffs2 -inband-tags -p 2048 rootfs rootfs_yaffs2.img

2)烧写yaffs2文件系统

clip_image010

3)内核配置

取消RAM文件系统设定

clip_image012

内核配置文件系统加载nand flash的yaffs2文件系统

Boot options —>

(noinitrd root=/dev/mtdblock2 rootfstype=yaffs2 rootflags=inband-tags console=ttyS0,115200n8 rdinit=/sbin/init mem=64M)) Default kernel command string

Kernel command line type (use bootloader arguments if available) —

配置yaffs2文件系统支持

clip_image014

clip_image016

Mtd nand flash设置

clip_image018

4)u-boot启动设置

set bootcmd nboot 0x7fc0 0 0x200000\;bootm 0x7fc0

6 ubi文件系统使用

1)制作ubi文件系统

mkfs.ubifs -F -x lzo -m 2048 -e 126976 -c 732 -o rootfs_ubifs.img -d ./rootfs

ubinize -o ubi.img -m 2048 -p 131072 -O 2048 -s 2048 rootfs_ubinize.cfg

rootfs_ubinize.cfg 內容如下:

[rootfs-volume]

mode=ubi

image=rootfs_ubifs.img

vol_id=0

vol_size=92946432

vol_type=dynamic

vol_name=system

vol_flags=autoresize

clip_image020

2) 配置linux内核

设置nand flash驱动

clip_image022

注意command line partition table parsing项:

如果选择该项,则启动参数中需设置mtdparts信息,如下:

noinitrd ubi.mtd=2 root=ubi0:system rw rootfstype=ubifs console=ttyS0,115200n8 rdinit=/sbin/init mem=64M mtdparts=nand0:0x200000@0x0(u-boot),0x1400000@0x200000(kernel),-(user)

如果没有选中该选项,则使用linux下nand flash驱动中的分区。开机文件系统参数可以不设置mtdparts信息,如下:

noinitrd ubi.mtd=2 root=ubi0:system rw rootfstype=ubifs console=ttyS0,115200n8 rdinit=/sbin/init mem=64M

取消RAM根文件系统设定

clip_image024

设置开机文件系统参数

开机文件系统参数的设置可以在u-boot的环境变量中设置bootargs变量,如下:

bootargs=noinitrd ubi.mtd=2 root=ubi0:system rw rootfstype=ubifs console=ttyS0,115200n8 rdinit=/sbin/init mem=64M mtdparts=nand0:0x200000@0x0(u-boot),0x1400000@0x200000(kernel),-(user)

也可以在linux在linux内核中配置,具体如下:

clip_image026

UBI文件系统设置:

clip_image028

3)烧写ubi文件系统到nand flash

Bsp中ubi默认放在nand的第三个分区,地址为0x1600000。镜像类型选择data型,如下图所示:

clip_image030

4)u-boot启动设置

set bootcmd nboot 0x7fc0 0 0x200000\;bootm 0x7fc0

4)ubi文件系统加载问题及原因:

问题1:打印如下错误信息

UBI error: ubi_init: UBI error: cannot initialize UBI, error -19

UBIFS error (pid 1): ubifs_mount: cannot open “ubi0.system”, error -22

原因:分区信息没有传递给内核。

解决方法:

方法1:启动的文件系统参数中加入mtd的分区信息,即加入mtdparts变量信息。

方法2:使用linuxi下nand flash驱动中的分区。

二 烧写到spi flash

2.1 说明

u-boot.bin:u-boot程序,默认执行地址:0xE00000,在spi flash中的烧写地址:0x0。

env.txt:u-boot环境变量,在spi Flash中的烧写地址:0x80000。

970image.ub:Linux kernel。加载地址:0x7fc0;执行地址:0x8000;烧写地址:0x100000,可变要与u-boot环境参数一致,

set bootcmd sf probe 0 18000000\;sf read 0x7fc0 0x100000 0x600000\;bootm 0x7fc0

2.2 烧写举例

1.烧写 u-boot.bin

clip_image032

Image Type:uBoot型

Image execute address: 0xE00000

2. 烧写U-Boot环境变量env.txt

clip_image034

Image Type:Environment型

Image start offset: 0x80000

3. 烧写kernel

clip_image036

Image Type:Data型

Image start offset: 0x100000

4. 烧写jffs2文件系统

1)制作jffs2文件

mkfs.jffs2 -e 0x10000 -p 0x400000 -l -d rootfs -o rootfs.jffs2

烧写文件系统到相应的地址

clip_image038

烧写地址由mtd分区决定

2)修改mtd分区

arch/arm/mach-nuc970/dev.c

static struct mtd_partition nuc970_spi0_flash_partitions[] = {

{

.name = “u-boot”,

.size = 512 * 1024,

.offset = 0,

},

{

.name = “u-boot env”,

.size = 512 * 1024,

.offset = MTDPART_OFS_APPEND,

},

{

.name = “kernel”,

.size = 4 * 1024 * 1024,

.offset = MTDPART_OFS_APPEND,

},

{

.name = “rootfs”,

.offset = MTDPART_OFS_APPEND,

.size = MTDPART_SIZ_FULL,

},

};

3). 修改内核配置

取消RAM根文件系统设定

clip_image040

设置kernel boot command

Boot option–>

(root=/dev/mtdblock3 rw rootfstype=jffs2 console=ttyS0,115200n8 rdinit=/sbin/init mem=64M) Defaut

Kernel command line type (Use bootloader kernel arguments if available) —>

Enable mtd及jffs2文件系统

clip_image042

clip_image044

clip_image046

4)设置u-boot启动参数

set bootcmd sf probe 0 18000000\;sf read 0x7fc0 0x100000 0x200000\;bootm 0x7fc0

sa

遇到的问题及解决方法:

1.使用en25qh256时,不能挂载成功,出现如下打印信息:

jffs2: Further such events for this erase block will not be printed

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae0000: 0xe807 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae0004: 0xe2bb instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae0008: 0x0013 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae000c: 0xe1fc instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae0010: 0xffff instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae0014: 0xe000 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae0018: 0x2fff instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae001c: 0x2d40 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae0020: 0x9f00 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01ae0024: 0xff94 instead

jffs2: Further such events for this erase block will not be printed

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af0000: 0x8330 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af0004: 0xd420 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af0008: 0x8330 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af000c: 0xd420 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af0010: 0x8330 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af0014: 0xd420 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af0018: 0x9320 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af001c: 0xa000 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af0020: 0xa000 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x01af0024: 0xbd80 instead

jffs2: Further such events for this erase block will not be printed

jffs2: Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes

jffs2: empty_blocks 0, bad_blocks 0, c->nr_blocks 432

mount: mounting /dev/mtdblock3 on /mnt failed: Input/output error

这个是因为flash 大小大于16MB需要切换到4-byte address mode,但set_4byte函数没有切换.修改下面代码:

/*

* Enable/disable 4-byte addressing mode.

*/

static inline int set_4byte(struct m25p *flash, u32 jedec_id, int enable)

{

switch (JEDEC_MFR(jedec_id)) {

case CFI_MFR_MACRONIX:

case 0xEF /* winbond */:

flash->command[0] = enable ? OPCODE_EN4B : OPCODE_EX4B;

return spi_write(flash->spi, flash->command, 1);

default:

/* Spansion style */

flash->command[0] = OPCODE_BRWR;

flash->command[1] = enable << 7;

return spi_write(flash->spi, flash->command, 2);

}

}

增加case CFI_MFR_EON: /* cFeon */,这样就可以支持cFeon的flash了。修改后的代码如下:

/*

* Enable/disable 4-byte addressing mode.

*/

static inline int set_4byte(struct m25p *flash, u32 jedec_id, int enable)

{

switch (JEDEC_MFR(jedec_id)) {

case CFI_MFR_MACRONIX:

case 0xEF /* winbond */:

case CFI_MFR_EON: /* cFeon */

flash->command[0] = enable ? OPCODE_EN4B : OPCODE_EX4B;

return spi_write(flash->spi, flash->command, 1);

default:

/* Spansion style */

flash->command[0] = OPCODE_BRWR;

flash->command[1] = enable << 7;

return spi_write(flash->spi, flash->command, 2);

}

}

2.能够挂载成功,但出现如下打印信息:

jffs2: Node at 0x00211fac with length 0x0000008b would run over the end of the erase block

jffs2: Perhaps the file system was created with the wrong erase size?

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00212000: 0x6565 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00212004: 0x7420 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00212008: 0x6562 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x0021200c: 0x736e instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00212010: 0x6c6c instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00212014: 0x6920 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00212018: 0x6c0a instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x0021201c: 0x6964 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00212020: 0x2f27 instead

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00212024: 0x2f63 instead

jffs2: Further such events for this erase block will not be printed

修改spi flash属性

{ “en25qh256”, INFO(0x1c7019, 0, 64 * 1024, 512, SECT_4K) },

=>

{ “en25qh256”, INFO(0x1c7019, 0, 64 * 1024, 512, 0) },