嵌入式爱好者

嵌入式爱好者 门户 知识库 查看内容

emmc启动及操作

2017-11-23 17:25| 发布者: 冰斩Resona| 查看: 928| 评论: 0|来自: 自创

类目:  >  知识库     文档编号: 150


**************************************************************************************************************************
**************************************************************************************************************************

xx18的SD卡烧写与启动

 使用SD卡制作工具制作SD卡,SD卡制作之后有一个分区,其中文件为

 ubootp.bin
 boot.img
 root.img
 partmap.txt

 拨码开关到SD之后,上电,CPU到SD卡加载ubootp.bin,并启动uboot

 查看bootcmd命令

 mmc rescan;
 if test $bootdev = sd0;
  then mmc dev 0;
  if fatload mmc 0:1 48000000 partmap.txt;
   then update_sdcard mmc 0:1 48000000 partmap.txt;
  else
   ext4load mmc 2:1 0x48000000 uImage;
   ext4load mmc 2:1 0x49000000 root.img.gz;
   bootm 0x48000000;fi;
 else
  ext4load mmc 2:1 0x48000000 uImage;
  ext4load mmc 2:1 0x49000000 root.img.gz;
  bootm 0x48000000;fi;

 而bootdev在SD卡启动时为sd0,在mmc启动时为mmc

 所以最重要的是fatload mmc 0:1 48000000 partmap.txt;命令

**************************************************************************************************************************
**************************************************************************************************************************
update_mmc - update mmc data


Usage:
update_mmc
    - type :  2ndboot | boot | raw | part

update_mmc boot 'mem' 'addr' 'length' [load addr]
    - update  data 'length' add boot header(512) on 'mem' to device addr,
      and set jump addr with 'load addr'
      if no [load addr], set jump addr default u-boot _TEXT_BASE_

update_mmc raw 'mem' 'addr' 'length'
    - update data 'length' on 'mem' to device addr.

update_mmc part 'mem' 'part no' 'length'
    - update partition image 'length' on 'mem' to mmc 'part no'.

Note.
    - All numeric parameters are assumed to be hex.

——————————————————————————————————————————————————————————————
update_mmc命令:更新mmc数据

举例:
 update_mmc    2       2ndboot    0x48000000       0x200      0x78000
 update_mmc [设备号] [分区格式] [内存起始地址] [mmc起始地址] [长度大小]

含义:
 从内存的[内存起始地址]开始读取数据,将读取到的数据写入[设备号]的mmc的[mmc起始地址],写[长度大小]这么大!
——————————————————————————————————————————————————————————————

举例
 update_mmc     2    part     48000000      1       c920b8
 update_mmc [设备号] part [内存起始地址] [分区号] [长度大小]

含义:
 从内存的[内存起始地址]开始读取数据,将读取到的数据写入[设备号]的mmc的[分区号]的首地址,写[长度大小]这么大!

**************************************************************************************************************************
**************************************************************************************************************************

update_sdcard:- Image Update from SDCard

Usage:
update_sdcard update_sdcard []
  ex> update_sdcard mmc 0:1 48000000 partmap.txt
    - inte**ce : mmc
    - dev       : mmc channel
    - part      : partition number
    - addr      : image load address
    - filename  : partition map file
————————————————————————————————————————————————————————————
partmap.txt 文件格式

flash=mmc,2:uboot:2nd:0x200,0x78000:ubootp.bin;

flash=mmc,2:boot:ext4:0x00100000,0x04000000:boot.img;
flash=mmc,2:system:ext4:0x04100000,0x2F200000:root.img;

flash=mmc,2:data:ext4:0x33300000,0:data.img;


————————————————————————————————————————————————————————————
 


update_sdcard命令:从SDCard更新镜像

举例:
 flash=mmc,2   :uboot :2nd   :0x200       ,0x78000   :ubootp.bin;

 flash=mmc,[设备号]:[名称]:[格式]:[mmc起始地址],[长度大小]:[文件名称];
含义:
 将[文件名称]以[格式]烧写到[设备号]的mmc中,[mmc起始地址],大小为[长度大小]


**************************************************************************************************************************
**************************************************************************************************************************
SD卡烧写镜像步骤详解

switch to partitions #0, OK      <----------------切换mmc设备,切换到emmc
mmc2(part 0) is current device
** Not find partition magic number **
Warn  : [uboot] make new partitions ....
fdisk 2 3: 0x100000:0x4000000 0x4100000:0x2f200000 0x33300000:0x0 <----------------为设备号为2的mmc设备重新分3个区,3个分区的起始地址:大小
fdisk : DONE
=============================================================《《------------------------从这里开始调用的update_sdcard命令来烧写,partmap.txt文件在0x48000000
304992 bytes read in 19 ms (15.3 MiB/s)
update_mmc 2 2ndboot 0x48000000 0x200 0x4a760    
switch to partitions #0, OK
mmc2(part 0) is current device
head boot dev  = 2
update mmc.2 type 2ndboot = 0x200(0x1) ~ 0x4a760(0x254): Done  <----------------注意:此地方的~后面的长度为烧写文件的实际大小,如ubootp.bin为297k,0x4a760也是297k
Flash : ubootp.bin - DONE
=============================================================
13181112 bytes read in 550 ms (22.9 MiB/s)
update_mmc 2 part 48000000 1 c920b8     <----------------从内存的0x48000000开始读取数据,将读取到的数据写入设备号为2的mmc的分区号为1的首地址,写[c920b8]这么大!
switch to partitions #0, OK
mmc2(part 0) is current device
update mmc.2 compressed ext4 = 0x100000(2048) ~ 0xc920b8(25745): Done <----------------注意:数量换算方法,13181112 bytes=0xc920b8<=25745*512
Flash : boot.img - DONE
=============================================================
302120864 bytes read in 12550 ms (23 MiB/s)
update_mmc 2 part 48000000 2 1201ffa0     <----------------从内存的0x48000000开始读取数据,将读取到的数据写入设备号为2的mmc的分区号为1的首地址,写[1201ffa0]这么大!
switch to partitions #0, OK
mmc2(part 0) is current device
update mmc.2 compressed ext4 = 0x4100000(133120) ~ 0x1201ffa0(590080): Done
Flash : root.img - DONE
=============================================================
update done...


**************************************************************************************************************************
**************************************************************************************************************************
针对早期的文件系统:是以Units和Blocks为大小计数单位的,Units单位为8225280 bytes,Blocks单位为1024 bytes

Disk /dev/mmcblk0: 7818 MB, 7818182656 bytes
255 heads, 63 sectors/track, 950 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

        Device Boot      Start         End      Blocks  Id System
/dev/mmcblk0p1               1           9       65536  83 Linux <----------------此地的Blocks为linux的块,单位为1k bytes,Start和END的单位是Units的大小,为8225280 bytes
Partition 1 has different physical/logical beginnings (non-Linux?): <----------------65536*1k=64M
     phys=(0, 1, 1) logical=(0, 32, 33)
Partition 1 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(8, 73, 1)
/dev/mmcblk0p2               9         105      772096  83 Linux
Partition 2 has different physical/logical beginnings (non-Linux?): <----------------772096*1k=754M
     phys=(0, 1, 1) logical=(8, 73, 2)
Partition 2 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(104, 103, 63)
/dev/mmcblk0p3             105         951     6796288  83 Linux
Partition 3 has different physical/logical beginnings (non-Linux?): <----------------6796288*1k=6637M
     phys=(0, 1, 1) logical=(104, 104, 1)
Partition 3 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(950, 129, 11)

Disk /dev/mmcblk0boot1: 4 MB, 4194304 bytes
4 heads, 16 sectors/track, 128 cylinders
Units = cylinders of 64 * 512 = 32768 bytes

Disk /dev/mmcblk0boot1 doesn't contain a valid partition table

Disk /dev/mmcblk0boot0: 4 MB, 4194304 bytes
4 heads, 16 sectors/track, 128 cylinders
Units = cylinders of 64 * 512 = 32768 bytes

Disk /dev/mmcblk0boot0 doesn't contain a valid partition table
—————————————————————————————————————————————————————————————
大小公式可以这样表示

(65536+772096+6796288)*1k bytes≈951*8225280 bytes≈7818182656 bytes
**************************************************************************************************************************
针对最新的文件系统:是以Units和Blocks为大小计数单位的,Units单位为8225280 bytes,Blocks单位为1024 bytes
【以下内容是经过修改之后的】

Disk /dev/mmcblk0: 7456 MB, 7818182656 bytes, 15269888 sectors
950 cylinders, 255 heads, 63 sectors/track
Units: cylinders of 16065 * 512 = 8225280 bytes

Device       Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size  Id Type
/dev/mmcblk0p1    0,1,1       1023,254,63       2048     133119     131072 64.0M  83 Linux  <----------------131072*512 bytes=65536k bytes=64M
Partition 1 has different physical/logical start (non-Linux?):
     phys=(0,1,1) logical=(0,32,33)
Partition 1 has different physical/logical end:
     phys=(1023,254,63) logical=(8,73,1)
/dev/mmcblk0p2    0,1,1       1023,254,63     133120   15269887   15136768 7391M  83 Linux  <----------------15136768*512 bytes=7750025216k bytes=7391M
Partition 2 has different physical/logical start (non-Linux?):
     phys=(0,1,1) logical=(8,73,2)
Partition 2 has different physical/logical end:
     phys=(1023,254,63) logical=(950,129,11)
Disk /dev/mmcblk0boot1: 4 MB, 4194304 bytes, 8192 sectors
128 cylinders, 4 heads, 16 sectors/track
Units: cylinders of 64 * 512 = 32768 bytes

Disk /dev/mmcblk0boot1 doesn't contain a valid partition table
Disk /dev/mmcblk0boot0: 4 MB, 4194304 bytes, 8192 sectors
128 cylinders, 4 heads, 16 sectors/track
Units: cylinders of 64 * 512 = 32768 bytes

Disk /dev/mmcblk0boot0 doesn't contain a valid partition table
Disk /dev/mmcblk1: 7580 MB, 7948206080 bytes, 15523840 sectors
1021 cylinders, 245 heads, 62 sectors/track
Units: cylinders of 15190 * 512 = 7777280 bytes


**************************************************************************************************************************
**************************************************************************************************************************

s5p4418# mmc part

Partition Map for MMC device 2  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     2048            131072          00000000-01     83 <----------------131072*512 bytes=65536k bytes=64M
  2     133120          1544192         00000000-02     83 <----------------1544192*512 bytes=772096k bytes=754M
  3     1677312         13592576        00000000-03     83 <----------------13592576*512 bytes=6796288k bytes=6637M

**************************************************************************************************************************
**************************************************************************************************************************
**************************************************************************************************************************
**************************************************************************************************************************
**************************************************************************************************************************
**************************************************************************************************************************

Filesystem           Type            Size      Used Available Use% Mounted on
/dev/root            ext4          742.1M    286.7M    455.5M  39% /
devtmpfs             devtmpfs      376.2M         0    376.2M   0% /dev
tmpfs                tmpfs         376.3M         0    376.3M   0% /dev/shm
tmpfs                tmpfs         376.3M    104.0K    376.2M   0% /tmp
tmpfs                tmpfs         376.3M     24.0K    376.3M   0% /run

关于为嵌入式Linux拓展文件系统大小的方法

首先确保
  root.img所在分区够大
其次
  root.img中解压之后所占空间要大

关于第一个问题:

修改partmap.txt,适用于制作SD镜像烧写卡

flash=mmc,2:uboot:2nd:0x200,0x78000:ubootp.bin;

flash=mmc,2:boot:ext4:0x00100000,0x04000000:boot.img;
flash=mmc,2:system:ext4:0x04100000,0x0:root.img;


用此烧写卡,会执行以下分区命令

fdisk 2 3: 0x100000:0x4000000 0x4100000:0x2f200000 0x33300000:0x0 <----------------为设备号为2的mmc设备重新分3个区,3个分区的起始地址:大小

关于第二个问题:

在生成root.img的脚本中修改

./make_ext4fs -s -T -I -l 5368709120 root.img ./tmproot/rootfs
    |
    |______此数字为文件系统所占空间大小,单位是Bytes,5*1024*1024*1024

此时再进入文件系统可以看到

# df -Th
Filesystem           Type            Size      Used Available Use% Mounted on
/dev/root            ext4            4.9G    286.3M      4.6G   6% /
devtmpfs             devtmpfs      376.2M         0    376.2M   0% /dev
tmpfs                tmpfs         376.3M         0    376.3M   0% /dev/shm
tmpfs                tmpfs         376.3M     56.0K    376.2M   0% /tmp
tmpfs                tmpfs         376.3M     20.0K    376.3M   0% /run


**************************************************************************************************************************
**************************************************************************************************************************
**************************************************************************************************************************
**************************************************************************************************************************
**************************************************************************************************************************
**************************************************************************************************************************

需要澄清的是,从厂家出来的eMMC 主要由这几个部分组成:

1.    BOOT Area Partition 1
2.    BOOT Area Partition 2
3.    RPMB
4.    User Data Area
5.    Vender private area

飞凌4418只是划分了三个分区
1.    BOOT Area Partition 1
2.    BOOT Area Partition 2
3.    User Data Area

但是只是使用了User Data Area分区:

uboodp.bin 使用了0x200(地址),0x78000(大小) emmc物理块(0x01)

boot.img 使用了0x00100000,0x04000000  emmc物理块(2048)

root.img 使用了0x04100000,0x0   emmc物理块(133120)



已解决

未解决

只是看看

最新评论

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2025-5-4 19:14

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部