所以我们添加一个可以操作宿主机的新外设romfs,基地址为0x10000000,其实际操作读写都使用c库访问真实的文件系统。
{内核配置:
.mask = ~(MAX_FS_SIZE-1), //25bit
.prefix = 0x10000000,
.reg_base = &peripheral_reg_base.fs,
.reset = fs_reset,
.read = fs_read,
.write = fs_write,
},
内核需要开启CONFIG_MTD,CONFIG_MTD_PHRAM,CONFIG_MTD_BLOCK等支持。
同时添加启动参数到设备树:
console=ttyS0 rootwait phram.phram=rootfs,0x10000000,32Mi root=/dev/mtdblock0 rw rootfstype=ext2 init=/linuxrc earlyprintk即可使用该外设。
https://github.com/hxdyxd/arm-emulator-linux/commit/0a00b2bb87d250a7d3bc9376b8cafc49f6e8d6fd
文件系统buildroot配置:
添加 ext2 文件系统生成
运行:
arm_emulator -m linux -f output/images/zImage.arm-emulator -r output/images/rootfs.ext2
[0]Peripheral register at 0x00000000, size 33554432 [1]Peripheral register at 0x10000000, size 33554432 Open output/images/rootfs.ext2: ok [2]Peripheral register at 0x4001f040, size 8 [3]Peripheral register at 0x4001f020, size 8 [4]Peripheral register at 0x40020000, size 256 load mem base 0x8000, size 1996348 Uncompressing Linux... done, booting the kernel. [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 5.1.15 (hxdyxd@DESKTOP-ROJM0AH) (gcc version 8.3.0 (Buildroot 2020.02-g84a0769-dirty)) #1 Mon Mar 16 20:47:20 CST 2020 [ 0.000000] CPU: ARM920T [41029205] revision 5 (ARMv4T), cr=00006133 [ 0.000000] CPU: VIVT data cache, VIVT instruction cache [ 0.000000] OF: fdt: Machine model: hxdyxd,armemulator [ 0.000000] printk: bootconsole [earlycon0] enabled [ 0.000000] Memory policy: Data cache buffered [ 0.000000] random: get_random_bytes called from 0xc0500900 with crng_init=0 [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 8128 [ 0.000000] Kernel command line: console=ttyS0 rootwait phram.phram=rootfs,0x10000000,32Mi root=/dev/mtdblock0 rw rootfstype=ext2 init=/linuxrc earlyprintk [ 0.000000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes) [ 0.000000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes) [ 0.000000] Memory: 26948K/32768K available (3154K kernel code, 143K rwdata, 284K rodata, 1024K init, 190K bss, 5820K reserved, 0K cma-reserved) [ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16 [ 0.000000] armemulator-ic base address = 0xc2800040 [ 0.000000] armemulator-timer base address = 0xc2802020 [ 0.000000] sched_clock: 32 bits at 1kHz, resolution 1000000ns, wraps every 2147483647500000ns [ 0.000000] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns [ 0.000000] set periodic to 240000 [ 0.015000] Console: colour dummy device 80x30 [ 0.015000] Calibrating delay loop... 18.63 BogoMIPS (lpj=93184) [ 0.250000] pid_max: default: 4096 minimum: 301 [ 0.250000] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.250000] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.265000] CPU: Testing write buffer coherency: ok [ 0.265000] Setting up static identity map for 0x100000 - 0x10003c [ 0.312000] devtmpfs: initialized [ 0.343000] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.359000] NET: Registered protocol family 16 [ 0.375000] DMA: preallocated 256 KiB pool for atomic coherent allocations [ 0.765000] clocksource: Switched to clocksource timer [ 1.140000] NET: Registered protocol family 2 [ 1.171000] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes) [ 1.171000] TCP established hash table entries: 1024 (order: 0, 4096 bytes) [ 1.187000] TCP bind hash table entries: 1024 (order: 0, 4096 bytes) [ 1.187000] TCP: Hash tables configured (established 1024 bind 1024) [ 1.187000] UDP hash table entries: 256 (order: 0, 4096 bytes) [ 1.203000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes) [ 1.203000] NET: Registered protocol family 1 [ 1.218000] NetWinder Floating Point Emulator V0.97 (extended precision) [ 1.250000] workingset: timestamp_bits=30 max_order=13 bucket_order=0 [ 1.281000] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254) [ 1.281000] io scheduler mq-deadline registered [ 1.281000] io scheduler kyber registered [ 4.734000] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled [ 4.906000] printk: console [ttyS0] disabled [ 4.906000] 40020000.serial: ttyS0 at MMIO 0x40020000 (irq = 17, base_baud = 230400) is a 8250 [ 4.921000] printk: console [ttyS0] enabled [ 4.921000] printk: console [ttyS0] enabled [ 4.921000] printk: bootconsole [earlycon0] disabled [ 4.921000] printk: bootconsole [earlycon0] disabled [ 5.093000] brd: module loaded [ 5.796000] loop: module loaded [ 5.921000] null: module loaded [ 6.109000] phram: rootfs device: 0x2000000 at 0x10000000 [ 6.140000] NET: Registered protocol family 10 [ 6.203000] Segment Routing with IPv6 [ 6.218000] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver [ 6.296000] random: fast init done [ 6.453000] EXT2-fs (mtdblock0): warning: mounting unchecked fs, running e2fsck is recommended [ 6.484000] VFS: Mounted root (ext2 filesystem) on device 31:0. [ 6.484000] devtmpfs: mounted [ 6.640000] Freeing unused kernel memory: 1024K [ 6.656000] Run /linuxrc as init process Starting syslogd: OK Starting klogd: OK Running sysctl: OK Initializing random number generator: OK Saving random seed: [ 13.515000] random: dd: uninitialized urandom read (512 bytes read) OK Starting network: OK Welcome to ARM Emulator armemulator login: root
Todo:
1.添加网络支持****
2.优化代码性能*****
3.添加声音支持**
4.添加图形支持*
没有评论:
发表评论