前言:我在JZ2440烧写linux内核镜像(uImage)之后,内核可以正常启动,但是我烧写玩Yaffs2格式的根文件系统之后,内核启动不了,根据我以往的学习和工作经验,可能是nand flash出现了坏块,(nand flash是比较容易出现坏块的),下面是我的解决办法。
CPU : jz2440
u-boot: u-boot-1.1.6
kernel: linux-4.19-rc3
root :fs_mini_mdev_new
1. 我在烧写是通过串口打印,可以看出uImage大小、起始地址、结束地址、根据uImage烧写的结束地址,设置根文件系统的起始地址(即使uImage的结束地址)
2. 通过串口打印我知道我的uImage烧写成功的地址在0xlde0000地址处,我在这里偷懒了,我在u-boot里面直接给kernel分配了32M的空间,如下图所示:
3. 烧写经过修改的uboot,然后重新烧写kernel、根文件系统烧写然后进行重启,会打印出下面的错误信息,大概的意思
就是根文件系统在nand flash读取失败。
print_req_error: I/O error, dev mtdblock4, sector 0
FAT-fs (mtdblock4): unable to read boot sector
VFS: Cannot open root device "mtdblock4" or unknown-block(31,4): error -5
Please append a correct "root=" boot option; here are the available partitions:
0100 65536 ram0
(driver?)
0101 65536 ram1
(driver?)
0102 65536 ram2
(driver?)
0103 65536 ram3
(driver?)
0104 65536 ram4
(driver?)
0105 65536 ram5
(driver?)
0106 65536 ram6
(driver?)
0107 65536 ram7
(driver?)
0108 65536 ram8
(driver?)
0109 65536 ram9
(driver?)
010a 65536 ram10
(driver?)
010b 65536 ram11
(driver?)
010c 65536 ram12
(driver?)
010d 65536 ram13
(driver?)
010e 65536 ram14
(driver?)
010f 65536 ram15
(driver?)
1f00 256 mtdblock0
(driver?)
1f01 128 mtdblock1
(driver?)
1f02 128 mtdblock2
(driver?)
1f03 4096 mtdblock3
(driver?)
1f04 257536 mtdblock4
(driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,4)
CPU: 0 PID: 1 Comm: swapper Not tainted 4.19.0-rc3 #1
Hardware name: SMDK2440
[<c00106d4>] (unwind_backtrace) from [<c000dca0>] (show_stack+0x10/0x18)
[<c000dca0>] (show_stack) from [<c04dfdfc>] (dump_stack+0x18/0x24)
[<c04dfdfc>] (dump_stack) from [<c0019ce4>] (panic+0xc0/0x25c)
[<c0019ce4>] (panic) from [<c0633274>] (mount_block_root+0x1b4/0x2ac)
[<c0633274>] (mount_block_root) from [<c06335d0>] (mount_root+0x114/0x158)
[<c06335d0>] (mount_root) from [<c0633774>] (prepare_namespace+0x160/0x1b8)
[<c0633774>] (prepare_namespace) from [<c0632ec0>] (kernel_init_freeable+0x180/0x1cc)
[<c0632ec0>] (kernel_init_freeable) from [<c04f4d08>] (kernel_init+0x8/0xf8)
[<c04f4d08>] (kernel_init) from [<c00090e0>] (ret_from_fork+0x14/0x34)
Exception stack(0xc3833fb0 to 0xc3833ff8)
3fa0: 00000000 00000000 00000000 00000000
3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
3fe0: 00000000 00000000 00000000 00000000 00000013 00000000
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,4) ]---
random: crng init done
了解uboot、kernel、根文件系统它们之间的关系可以知道,uboot负责启动kernel,根文件系统的启动是kernel负责的,所以我们需要修改kernel,所以在内核中需要修改各个部分分区的大小,打开linux-4.19-rc3/arch/arm/mach-s3c24xx/common-smdk.c文件,把kernel分区的大小由4M改为32M即可(分配的空间大小要和uboot里面大小和位置保持一致)
kernel修改完成之后,重启启动发现kernel、根文件系统都可以正常启动了