`一)概念
ramdisk一般是指虚拟内存盘,即通过软件将一部分内存(RAM)模拟为硬盘来使用的一种技术。在 ARM linux领域里面ramdisk文件系统则是指通过ramdisk方式加载文件系统。
Linux文件系统中的文件是数据的集合,文件系统不仅包含着文件中的数据而且还有文件系统的结构,所有Linux 用户和程序看到的文件、目录、软连接及文件保护信息等都存储在其中。
linux根文件系统是内核启动时所mount的第一个文件系统,内核代码映像文件必须保存在根文件系统中,系统引导启动程序会在根文件系统挂载之后从中把一些基本的初始化脚本和服务等加载到内存中去运行。
那么根文件系统在系统启动中到底是什么时候挂载的呢?先将/dev/ram0挂载,而后执行/linuxrc.等其执行完后。切换根目录,再挂载具体的根文件系统.根文件系统执行完之后,也就是到了Start_kernel()函数的最后,执行init的进程,也就第一个用户进程。对系统进行各种初始化的操作。
PC上有ramdisk 和直接挂载HD(Harddisk,硬盘)上两种根文件系统;嵌入式中一般是从Flash启动,最简单的方法是将文件系统加载到RAM的RAMDisk,
稍复杂的方式是直接从Flash 读取Cramfs文件系统,更复杂的方式是在Flash上分区,并构建JFFS2等文件系统。
RAMDisk文件系统将制作好的文件系统压缩后写入Flash,启动的时候由Bootloader load到RAM,解压缩,然后挂载到 /。
ramdisk就是用内存空间来模拟出硬盘分区,ramdisk通常使用磁盘文件系统的压缩存放在flash中,在系统初始化时,解压缩到SDRAM并挂载根文件系统,
在linux系统中,ramdisk有二种,一种就是可以格式化并加载,在linux内核2.0/2.2就已经支持,其不足之处是大小固定;
另一种是 2.4的内核才支持,通过,ramfs来实现,他不能被格式化,但用起来方便,其大小随所需要的空间增加或减少,是目前linux常用的ramdisk技术。
初始RAM磁盘(initrd)是在实际根文件系统可用之前挂载到系统中的一个初始根文件系统。initrd与内核绑定在一起,并作为内核引导过程的一部分进行加载。内核然后会将这个 initrd文件作为其两阶段引导过程的一部分来加载模块,这样才能稍后使用真正的文件系统,并挂载实际的根文件系统。
initrd 中包含了实现这个目标所需要的目录和可执行程序的最小集合,例如将内核模块加载到内核中所使用的 insmod 工具。
Matrix文件系统,它是 ti公司自己单独维护的一个具有GUI的Linux文件系统,我们可以安装ti的Sitara Software Development Kit (SDK)后,就可以很方便的开发一些应用程序。
二)ramdisk文件系统实现
1.文件系统实现
1.1 下载busybox源代码,下载地址为:https://busybox.net/downloads/busybox-1.25.0.tar.bz2
1.2 解压,编译busybox,并通过tftp和nfs方式测试此文件系统。
1.3 在etc/profile文件中修改如下测试代码:
echo "Done 20161128"
通过下面的kernel log我们可以确定下面几点:
a.我们编译的kernel被加载到系统中;
b.我们修改的profile被加载到系统中;
- Starting kernel ...
- Booting Linux on physical CPU 0x0
- Linux version 3.12.10 (root@pc) (gcc version 4.7.3 20130226 (prerelease) (crosstool-NG linaro-1.13.1-4.7-2013.03-20130313 - Linaro GCC 2013.03) ) #4 Thu Nov 24 17:25:29 CST 2016
- CPU: ARMv7 Processor [412fc09a] revision 10 (ARMv7), cr=10c53c7d
- CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
- Machine: Generic AM43 (Flattened Device Tree), model: MYIR Rico Board
- cma: CMA: reserved 24 MiB at 9e000000
- Memory policy: ECC disabled, Data cache writeback
- CPU: All CPU(s) started in SVC mode.
- AM437x ES1.0 (sgx neon )
- Built 1 zonelists in Zone order, mobility grouping on. Total pages: 129280
- Kernel command line: console=ttyO0,115200n8 omapdss.def_disp=display1 omapfb.mode=display1:1024x768MR-24@60 root=/dev/nfs nfsroot=192.168.9.217:/opt/nfs_dir,nolock rw ip=dhcp
- PID hash table entries: 2048 (order: 1, 8192 bytes)
- Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
- Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
- Memory: 483248K/521216K available (5591K kernel code, 561K rwdata, 1904K rodata, 346K init, 225K bss, 37968K reserved, 0K highmem)
- Virtual kernel memory layout:
- vector : 0xffff0000 - 0xffff1000 ( 4 kB)
- fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
- vmalloc : 0xe0800000 - 0xff000000 ( 488 MB)
- lowmem : 0xc0000000 - 0xe0000000 ( 512 MB)
- pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB)
- modules : 0xbf000000 - 0xbfe00000 ( 14 MB)
- .text : 0xc0008000 - 0xc075a08c (7497 kB)
- .init : 0xc075b000 - 0xc07b1848 ( 347 kB)
- .data : 0xc07b2000 - 0xc083e478 ( 562 kB)
- .bss : 0xc083e478 - 0xc0876a80 ( 226 kB)
- NR_IRQS:16 nr_irqs:16 16
- GIC CPU mask not found - kernel will fail to boot.
- GIC CPU mask not found - kernel will fail to boot.
- OMAP clockevent source: timer2 at 24000000 Hz
- sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 178956ms
- OMAP clocksource: timer1 at 24000000 Hz
- Console: colour dummy device 80x30
- Calibrating delay loop... 597.60 BogoMIPS (lpj=2988032)
- pid_max: default: 32768 minimum: 301
- Security Framework initialized
- Mount-cache hash table entries: 512
- CPU: Testing write buffer coherency: ok
- Setting up static identity map for 0xc057b8e8 - 0xc057b958
- L310 cache controller enabled
- l2x0: 16 ways, CACHE_ID 0x410000c9, AUX_CTRL 0x7e030000, Cache size: 256 kB
- devtmpfs: initialized
- VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
- omap_hwmod: dss_dispc: cannot be enabled for reset (3)
- omap_hwmod: dss_rfbi: cannot be enabled for reset (3)
- pinctrl core: initialized pinctrl subsystem
- regulator-dummy: no parameters
- NET: Registered protocol family 16
- DMA: preallocated 256 KiB pool for atomic coherent allocations
- spi_init
- cpuidle: using governor ladder
- cpuidle: using governor menu
- platform 49000000.edma: FIXME: clock-name 'fck' DOES NOT exist in dt!
- platform 44e3e000.rtc: Cannot lookup hwmod 'rtc'
- OMAP GPIO hardware version 0.1
- platform 56000000.sgx: FIXME: clock-name 'fck' DOES NOT exist in dt!
- platform ocp2scp.0: FIXME: clock-name 'fck' DOES NOT exist in dt!
- platform ocp2scp.1: FIXME: clock-name 'fck' DOES NOT exist in dt!
- platform 48380000.omap_dwc3_1: FIXME: clock-name 'fck' DOES NOT exist in dt!
- platform 483c0000.omap_dwc3_2: FIXME: clock-name 'fck' DOES NOT exist in dt!
- platform 4832a000.dss: FIXME: clock-name 'fck' DOES NOT exist in dt!
- platform 4832a400.dispc: FIXME: clock-name 'fck' DOES NOT exist in dt!
- platform 4832a800.rfbi: FIXME: clock-name 'fck' DOES NOT exist in dt!
- No ATAGs?
- hw-breakpoint: found 5 (+1 reserved) breakpoint and 1 watchpoint registers.
- hw-breakpoint: maximum watchpoint size is 4 bytes.
- bio: create slab at 0
- edma-dma-engine edma-dma-engine.0: TI EDMA DMA engine driver
- vmmcsd_fixed: 3300 mV
- evm_v3p3: 3300 mV
- vgaarb: loaded
- SCSI subsystem initialized
- u***core: registered new interface driver u***fs
- u***core: registered new interface driver hub
- u***core: registered new device driver u***
- omap_i2c 44e0b000.i2c: could not find pctldev for node /pinmux@44e10800/pinmux_i2c0_pins, deferring probe
- platform 44e0b000.i2c: Driver omap_i2c requests probe deferral
- omap_i2c 4802a000.i2c: could not find pctldev for node /pinmux@44e10800/i2c1_pins, deferring probe
- platform 4802a000.i2c: Driver omap_i2c requests probe deferral
- media: Linux media interface: v0.10
- Linux video capture interface: v2.00
- pps_core: LinuxPPS API ver. 1 registered
- pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti
- PTP clock support registered
- Switched to clocksource timer1
- NET: Registered protocol family 2
- TCP established hash table entries: 4096 (order: 3, 32768 bytes)
- TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
- TCP: Hash tables configured (established 4096 bind 4096)
- TCP: reno registered
- UDP hash table entries: 256 (order: 0, 4096 bytes)
- UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
- NET: Registered protocol family 1
- RPC: Registered named UNIX socket transport module.
- 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)
- PM: Loading am335x-pm-firmware.bin
- VFS: Disk quotas dquot_6.5.2
- Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
- NFS: Registering the id_resolver key type
- Key type id_resolver registered
- Key type id_legacy registered
- jffs2: version 2.2. (NAND) (SUMMARY) ? 2001-2006 Red Hat, Inc.
- msgmni has been set to 991
- NET: Registered protocol family 38
- io scheduler noop registered
- io scheduler deadline registered
- io scheduler cfq registered (default)
- omap-ocp2scp ocp2scp.0: invalid resource
- omap-ocp2scp: probe of ocp2scp.0 failed with error -22
- omap-ocp2scp ocp2scp.1: invalid resource
- omap-ocp2scp: probe of ocp2scp.1 failed with error -22
- pinctrl-single 44e10800.pinmux: 199 pins at pa f9e10800 size 796
- OMAP DSS rev 2.0
- connector-hdmi connector.6: failed to find video source
- platform connector.6: Driver connector-hdmi requests probe deferral
- omapfb omapfb: failed to find default display
- omapfb omapfb: failed to setup omapfb
- platform omapfb: Driver omapfb requests probe deferral
- Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
- omap_uart 44e09000.serial: No clock speed specified: using default:48000000
- 44e09000.serial: ttyO0 at MMIO 0x44e09000 (irq = 104, base_baud = 3000000) is a OMAP UART0
- console [ttyO0] enabled
- omap_rng 48310000.rng: OMAP Random Number Generator ver. 20
- brd: module loaded
- loop: module loaded
- mtdoops: mtd device (mtddev=name/number) must be supplied
- spidev_init
- =1=spi_gpio_probe
- =1=spi_gpio_probe_dt pdata->sck=0xa4
- =1=spi_gpio_probe_dt pdata->miso=0xa5
- =1=spi_gpio_probe_dt pdata->mosi=0xa6
- =1=spi_gpio_probe_dt pdata->num_chipselect=0x4
- =2=spi_gpio_probe
- =21=spi_gpio_probe
- =22=spi_gpio_probe
- =3=spi_gpio_probe
- =4=spi_gpio_probe
- =5=spi_gpio_probe
- =6=spi_gpio_probe
- =7=spi_gpio_probe
- =8=spi_gpio_probe
- =1=spi_register_master
- =1=of_spi_register_master master->num_chipselect=4 nb=1
- =2=of_spi_register_master master->num_chipselect=4
- =2=spi_register_master master->num_chipselect=4
- =3=spi_register_master master->bus_num=32766
- =4=spi_register_master
- =6=spi_register_master
- =1=spi_add_device
- =2=spi_add_device
- =3=spi_add_device
- =1=spi_gpio_setup spi->chip_select=0
- =1=spi_gpio_setup cs=0xa7
- =2=spi_gpio_setup
- =21=spi_gpio_setup
- =22=spi_gpio_setup
- =23=spi_gpio_setup
- =31=spi_gpio_setup
- =32=spi_gpio_setup
- =4=spi_add_device
- =5=spi_add_device
- =7=spi_register_master
- =9=spi_gpio_probe
- ti_qspi_probe
- =1=spi_register_master
- =1=of_spi_register_master master->num_chipselect=4 nb=-2
- =2=of_spi_register_master master->num_chipselect=4
- =2=spi_register_master master->num_chipselect=4
- =3=spi_register_master master->bus_num=32765
- =4=spi_register_master
- =6=spi_register_master
- =1=spi_add_device
- =2=spi_add_device
- =3=spi_add_device
- =4=spi_add_device
- spi_init
- m25p80 spi32765.0: s25fl128s (16384 Kbytes)
- 7 ofpart partitions found on MTD device spi32765.0
- Creating 7 MTD partitions on "spi32765.0":
- 0x000000000000-0x000000080000 : "QSPI.U_BOOT"
- 0x000000080000-0x000000100000 : "QSPI.U_BOOT.backup"
- 0x000000100000-0x000000120000 : "QSPI.U_BOOT_ENV"
- 0x000000120000-0x000000140000 : "QSPI.U-BOOT-ENV.backup"
- 0x000000140000-0x000000150000 : "QSPI.U-BOOT-DEVICETREE"
- 0x000000150000-0x000000650000 : "QSPI.KERNEL"
- 0x000000650000-0x000001000000 : "QSPI.FILESYSTEM"
- =5=spi_add_device
- =7=spi_register_master
- u***core: registered new interface driver asix
- u***core: registered new interface driver ax88179_178a
- u***core: registered new interface driver cdc_ether
- u***core: registered new interface driver r815x
- u***core: registered new interface driver smsc95xx
- u***core: registered new interface driver net1080
- u***core: registered new interface driver cdc_subset
- u***core: registered new interface driver zaurus
- u***core: registered new interface driver cdc_ncm
- ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
- ehci-pci: EHCI PCI platform driver
- ehci-omap: OMAP-EHCI Host Controller driver
- xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
- xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 1
- xhci-hcd xhci-hcd.0.auto: irq 206, io mem 0x483d0000
- u*** u***1: New USB device found, idVendor=1d6b, idProduct=0002
- u*** u***1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
- u*** u***1: Product: xHCI Host Controller
- u*** u***1: Manufacturer: Linux 3.12.10 xhci-hcd
- u*** u***1: SerialNumber: xhci-hcd.0.auto
- hub 1-0:1.0: USB hub found
- hub 1-0:1.0: 1 port detected
- xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
- xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 2
- u*** u***2: New USB device found, idVendor=1d6b, idProduct=0003
- u*** u***2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
- u*** u***2: Product: xHCI Host Controller
- u*** u***2: Manufacturer: Linux 3.12.10 xhci-hcd
- u*** u***2: SerialNumber: xhci-hcd.0.auto
- hub 2-0:1.0: USB hub found
- hub 2-0:1.0: 1 port detected
- u***core: registered new interface driver cdc_wdm
- u***core: registered new interface driver u***-storage
- mousedev: PS/2 mouse device common for all mice
- omap_rtc 44e3e000.rtc: rtc core: registered 44e3e000.rtc as rtc0
- 44e3e000.rtc: already running
- i2c /dev entries driver
- vpfe-capture 48326000.vpfe: v4l2 device registered
- vpfe-capture 48326000.vpfe: Asynchronous subdevice registration
- vpfe-capture 48326000.vpfe: AM437x ISIF is registered with vpfe.
- vpfe-capture 48328000.vpfe: v4l2 device registered
- vpfe-capture 48328000.vpfe: Asynchronous subdevice registration
- vpfe-capture 48328000.vpfe: AM437x ISIF is registered with vpfe.
- Driver for 1-wire Dallas network protocol.
- omap_wdt: OMAP Watchdog Timer Rev 0x01: initial timeout 60 sec
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:3
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:2
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:25
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:24
- ledtrig-cpu: registered to indicate activity on CPUs
- mmc0: BKOPS_EN bit is not set
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:36
- omap-sham 53100000.sham: hw accel on OMAP rev 0.0
- omap-aes 53501000.aes: OMAP AES hw accel rev: 0.1
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:5
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:6
- omap-des 53701000.des: OMAP DES hw accel rev: 0.33
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:33
- mmc0: new high speed MMC card at address 0001
- edma-dma-engine edma-dma-engine.0: allocated channel for 0:34
- mmcblk0: mmc0:0001 P1XXXX 3.60 GiB
- mmcblk0boot0: mmc0:0001 P1XXXX partition 1 2.00 MiB
- mmcblk0boot1: mmc0:0001 P1XXXX partition 2 2.00 MiB
- mmcblk0: p1 p2 p3
- u***core: registered new interface driver u***hid
- u***hid: USB HID core driver
- mmcblk0boot1: unknown partition table
- oprofile: no performance counters
- oprofile: using timer interrupt.
- mmcblk0boot0: unknown partition table
- TCP: cubic registered
- Initializing XFRM netlink socket
- NET: Registered protocol family 17
- NET: Registered protocol family 15
- 8021q: 802.1Q VLAN Support v1.8
- Key type dns_resolver registered
- cpu cpu0: cpu0 regulator not ready, retry
- platform cpufreq-cpu0.0: Driver cpufreq-cpu0 requests probe deferral
- PM: CM3 Firmware Version = 0x186
- ThumbEE CPU extension supported.
- vdd_core: 920 <--> 1140 mV at 1100 mV
- vdd_mpu: 920 <--> 1375 mV at 950 mV
- DCDC3: at 1500 mV
- LDO1: 1800 mV
- vdd_vbus0: no parameters
- vdd_vbus1: no parameters
- ov2659 0-0030: ov2659_probe: debug: 0
- mmc1: host does not support reading read-only switch. assuming write-enable.
- ov2659 0-0030: Sensor detection failed (3030, 0)
- mmc1: new high speed SDHC card at address aaaa
- omap_i2c 44e0b000.i2c: bus 0 rev0.12 at 100 kHz
- mmcblk1: mmc1:aaaa SU04G 3.69 GiB
- sii9022 1-003b: sil9022 HDMI Chip version = b0
- mmcblk1: p1
- ov2659 1-0030: ov2659_probe: debug: 0
- ov2659 1-0030: Sensor detection failed (3030, 0)
- omap_i2c 4802a000.i2c: bus 1 rev0.12 at 100 kHz
- sii9022 1-003b: CONNECT
- omapdss APPLY error: manager lcd is already connected to an output
- fbcvt: 1024x768@60: CVT Name - .786M3-R
- Console: switching to colour frame buffer device 128x48
- sii9022 1-003b: ENABLE
- sii9022 1-003b: HW_ENABLE -> Timings
- pixel_clk = 56000
- horizontal res = 1024
- vertical res = 768
- sii9022 1-003b: hdmi enabled
- davinci_mdio 4a101000.mdio: davinci mdio revision 1.6
- davinci_mdio 4a101000.mdio: detected phy mask fffffffe
- libphy: 4a101000.mdio: probed
- davinci_mdio 4a101000.mdio: phy[0]: device 4a101000.mdio:00, driver unknown
- Detected MACID = c4:be:84:cd:b1:ea
- input: gpio_keys.9 as /devices/gpio_keys.9/input/input0
- omap_rtc 44e3e000.rtc: setting system clock to 2000-01-01 00:57:52 UTC (946688272)
- net eth0: initializing cpsw version 1.15 (0)
- net eth0: phy found : id is : 0x221622
- 8021q: adding VLAN 0 to HW filter on device eth0
- libphy: 4a101000.mdio:00 - Link is Up - 100/Full
- Sending DHCP requests ., OK
- IP-Config: Got DHCP answer from 192.168.9.1, my address is 192.168.9.166
- IP-Config: Complete:
- device=eth0, hwaddr=c4:be:84:cd:b1:ea, ipaddr=192.168.9.166, mask=255.255.255.0, gw=192.168.9.1
- host=192.168.9.166, domain=, nis-domain=(none)
- bootserver=0.0.0.0, rootserver=192.168.9.217, rootpath=
- nameserver0=202.106.46.151, nameserver1=202.106.196.115
- VFS: Mounted root (nfs filesystem) on device 0:13.
- devtmpfs: mounted
- Freeing unused kernel memory: 344K (c075b000 - c07b1000)
- Processing /etc/profile... Done 20161128
复制代码
2.uboot和kernel设置
kernel设置如下:
uboot命令行设置:
- Kernel command line: console=ttyO0,115200n8 omapdss.def_disp=display1 omapfb.mode=display1:1024x768MR-24@60 root=/dev/ram0 rw ramdisk_size=131072 initrd=0x81000000,64M rootfstype=ext2
复制代码
3.ramdisk.gz制作,加载。
3.1 下载genext2fs源代码,下载地址:http://jaist.dl.sourceforge.net/project/genext2fs/genext2fs/1.4.1/genext2fs-1.4.1.tar.gz
./configure&&make &&make install
3.2 使用下面的命令将准备好的文件系统制作成ramdisk,并拷贝到TF卡中
genext2fs -b 32768 -d /opt/RicoBoard/02-Images/20161128/_install ramdisk
测试的kernel启动log如下:
通过Hdmi显示的linux系统启动画面如下:
三)总结
1. ramdisk,initrd和init以及linux根文件系统流程;
2. 通过busybox源代码制作linux文件系统;
3. ramdisk文件系统的制作,启动。
`
0
|
|
|
|