linux下实现用户态烧写内核

还是拿TQ210的板子做例子吧

1.修改内核代码,增加一个USER1分区(),0x8000000就是128M的地址,待会准备在这个分区烧写一个linux 内核,实现从这个分区启动

static struct mtd_partition tq210_partition_info[] = {
 [0] = {
  .name  = "Bootloader",
  .offset  = 0,
  .size  = 0x200000,
  .mask_flags = MTD_CAP_NANDFLASH,
 },
/* [1] = {
  .name  = "Param",
  .offset  = 0x80000,
  .size  = 0x80000,
  .mask_flags = MTD_CAP_NANDFLASH,
 },*/
 [1] = {
  .name  = "LOGO",
  .offset  = 0x200000,
  .size  = 0x300000,
  .mask_flags = MTD_CAP_NANDFLASH,
 },
 [2] = {
  .name  = "Kernel",
  .offset  = 0x500000,
  .size  = 0x500000,
  .mask_flags = MTD_CAP_NANDFLASH,
 },
 [3] = {
  .name  = "ROOTFS",
  .offset  = 0xA00000,
  .size  = 0x6400000,
 },
[4] = {
  .name  = "USER1",
  .offset  = 0x8000000,
  .size  = MTDPART_SIZ_FULL,
 },
};

2.下载mtd-utils-1.5.1,编译,

下载地址:http://download.csdn.net/detail/xdshengk/8923849

   首先打开common.mk,增加CROSS=arm-linux-

  然后打开Makefile,将下面的参数打开,或者执行make  WITHOUT_XATTR=1

#ifeq ($(WITHOUT_XATTR), 1)
  CPPFLAGS += -DWITHOUT_XATTR
#endif

3.启动系统,格式化分区

[root@EmbedSky /]# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00200000 00020000 "Bootloader"
mtd1: 00300000 00020000 "LOGO"
mtd2: 00500000 00020000 "Kernel"
mtd3: 06400000 00020000 "ROOTFS"
mtd4: 18000000 00020000 "USER1"

确认分区为mtd4(字符型),mtdblock4为块设备

格式化6m空间,就够内核用了

首先看一下使用方法:

[root@EmbedSky arm-linux]# ./flash_erase --help
Usage: flash_erase [options] MTD_DEVICE <start offset> <block count>
Erase blocks of the specified MTD device.
Specify a count of 0 to erase to end of device.

  -j, --jffs2       format the device for jffs2
  -N, --noskipbad   don't skip bad blocks
  -u, --unlock      unlock sectors before erasing
  -q, --quiet       do not display progress messages
      --silent      same as --quiet
      --help        display this help and exit
      --version     output version information and exit

 

做个擦写测试:
[root@EmbedSky arm-linux]# ./flash_erase /dev/mtd4 0 1
Erasing 128 Kibyte @ 0 -- 100 % complete
[root@EmbedSky arm-linux]# ./flash_erase /dev/mtd4 0 2
Erasing 128 Kibyte @ 20000 -- 100 % complete
[root@EmbedSky arm-linux]# ./flash_erase /dev/mtd4 0 3
Erasing 128 Kibyte @ 40000 -- 100 % complete
[root@EmbedSky arm-linux]# ./flash_erase /dev/mtd4 0 4
Erasing 128 Kibyte @ 60000 -- 100 % complete

经过了测试,发现一个block为0x20000大小,也就是128k,所以擦写50个块,6.25m就够了

[root@EmbedSky arm-linux]# ./flash_erase /dev/mtd4 0 50
Erasing 128 Kibyte @ 620000 -- 100 % complete

然后烧写内核,-p是使页对齐

[root@EmbedSky arm-linux]# ./nandwrite -p /dev/mtd4 /home/zImage
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
Writing data to block 4 at offset 0x80000
Writing data to block 5 at offset 0xa0000
Writing data to block 6 at offset 0xc0000
Writing data to block 7 at offset 0xe0000
Writing data to block 8 at offset 0x100000
Writing data to block 9 at offset 0x120000
Writing data to block 10 at offset 0x140000
Writing data to block 11 at offset 0x160000
Writing data to block 12 at offset 0x180000
Writing data to block 13 at offset 0x1a0000
Writing data to block 14 at offset 0x1c0000
Writing data to block 15 at offset 0x1e0000
Writing data to block 16 at offset 0x200000
Writing data to block 17 at offset 0x220000
Writing data to block 18 at offset 0x240000
Writing data to block 19 at offset 0x260000
Writing data to block 20 at offset 0x280000
Writing data to block 21 at offset 0x2a0000
Writing data to block 22 at offset 0x2c0000
Writing data to block 23 at offset 0x2e0000
Writing data to block 24 at offset 0x300000
Writing data to block 25 at offset 0x320000
Writing data to block 26 at offset 0x340000
Writing data to block 27 at offset 0x360000
Writing data to block 28 at offset 0x380000
Writing data to block 29 at offset 0x3a0000
Writing data to block 30 at offset 0x3c0000
Writing data to block 31 at offset 0x3e0000
Writing data to block 32 at offset 0x400000
Writing data to block 33 at offset 0x420000
Writing data to block 34 at offset 0x440000
Writing data to block 35 at offset 0x460000
Writing data to block 36 at offset 0x480000
Writing data to block 37 at offset 0x4a0000
Writing data to block 38 at offset 0x4c0000
[root@EmbedSky arm-linux]#

4,修改启动参数,让uboot从128M的地方启动内核


netmask=255.255.255.0
lcdtype=X800Y480
bootargs_defaults=setenv bootargs ${bootargs} lcd=${lcdtype}
bootloaderimgname=u-boot.bin
logoimgname=logo.bin
nkimgname=NK.bin
kernelimgname=zImage.bin
rootimgname=root.bin
mtdids=nand0=s5pv210-nand
mtdparts=mtdparts=s5pv210-nand:1m@0(bios),1m(params),3m(logo),5m(kernel),-(root)
nfsserverip=192.168.1.8
nfsipaddr=192.168.1.5
nfsnetmask=255.255.255.0
nfs_dir=/dirnfs
bootargs=noinitrd init=/init console=ttySAC0 root=/dev/nfs rootwait=1 nfsroot=192.168.1.8:/dirnfs ip=192.168.1.5:192.168.1.8:192.168.1.5:255.255.255.0:www.embedsky.com:eth0:off
stdin=serial
stdout=serial
stderr=serial
partition=nand0,0
mtddevnum=0
mtddevname=bios

Environment size: 846/16380 bytes

##### Parameter Menu #####
[1] Set NFS boot parameter
[2] Set Yaffs boot parameter for Android or Standard Linux
[3] Set UBIfs boot parameter for Android or Standard Linux
[4] Set parameter
[5] View the parameters
[c] Choice lcd type.
[d] Delete parameter
[i] Display nand flash infomation.
[s] Save the parameters to Nand Flash
[q] Return main Menu
Enter your selection: 4
Name: *mtdparts
Value: *mtdparts=s5pv210-nand:1m@0(bios),1m(params),126m(logo),5m(kernel),-(root)

保存,启动成功

[u] Download bootloader to SD Card
Enter your selection: 8
Start Linux ...

NAND read: device 0 offset 0x8000000, size 0x500000


 5242880 bytes read: OK
Boot with zImage

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Initializing cgroup subsys cpu
Linux version 3.0.8-EmbedSky (root@ubuntu) (gcc version 4.4.6 (for TQ210 EmbedSky Tech) ) #17 PREEMPT Tue Jul 21 20:04:41 PDT 2015
CPU: ARMv7 Processor [412fc082] revision 2 (ARMv7), cr=10c53c7f
CPU: VIPT nonaliasing data cache, VIPT aliasing instruction cache
Machine: TQ210
Truncating RAM at 40000000-5fffffff to -54ffffff (vmalloc region overlap).
Memory policy: ECC disabled, Data cache writeback
bootargs no set lcd type! using default a70.
CPU S5PV210/S5PC110 (id 0x43110220)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
S5PV210: PLL settings, A=1000000000, M=667000000, E=80000000 V=54000000
S5PV210: ARMCLK=1000000000, HCLKM=200000000, HCLKD=166750000

 

 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值