linux - 使用 initramfs 在启动时运行程序

标签 linux boot uclinux

我在 SmartFusion2 上运行 uClinux,作为构建小型立方体卫星的大学团队的一部分。但是,我在 Linux 内核方面不是很有经验,这个问题让我难过了几天。我试图让 SmartFusion 在启动时运行程序。目前,唯一执行此操作的 .uImage 是测试“hello”文件。我正在尝试为另一个程序重新创建流程,但遇到了一些困难。

在我的 hello 目录中,我有以下文件:hello.busybox、hello.kernel.M2S、help.txt、hello.uImage、Makefile、hello.initramfs、hello(目录)

在 hello 子目录 (projects/hello/hello) 中:

hello(可执行文件)、hello.c、hello.gdb、hello.h、hello.o、Makefile

为了尝试让 uImage 启动并运行不同的程序,我复制了我的 projects/hello/hello 目录并将其重命名为“goodbye”,对 .h 和 .c 文件进行了一些小改动测试目的。现在,我正在尝试让 projects/hello/goodbye 中的可执行文件“hello”在启动时运行。

我的 initramfs 文件原来是这样的:

# This is a very simple, default initramfs

dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1
nod /dev/tty 0666 0 0 c 5 0
nod /dev/null 0600 0 0 c 1 3
nod /dev/mem 0600 0 0 c 1 1
nod /dev/kmem 0600 0 0 c 1 2
nod /dev/zero 0600 0 0 c 1 5
nod /dev/random 0600 0 0 c 1 8
nod /dev/urandom 0600 0 0 c 1 9

dir /dev/pts 0755 0 0
nod /dev/ptmx 0666 0 0 c 5 2

nod /dev/ttyS0 0666 0 0 c 4 64
nod /dev/ttyS1 0666 0 0 c 4 65
nod /dev/ttyS2 0666 0 0 c 4 66
nod /dev/ttyS3 0666 0 0 c 4 67
nod /dev/ttyS4 0666 0 0 c 4 68
nod /dev/ttyS5 0666 0 0 c 4 69

dir /bin 755 0 0
dir /proc 755 0 0

file /bin/hello ${INSTALL_ROOT}/projects/${SAMPLE}/hello/hello 755 0 0
slink /bin/init hello 777 0 0
I changed the last two lines of the initramfs to read as follows:

file /bin/hello ${INSTALL_ROOT}/projects/${SAMPLE}/hello/goodbye 755 0 0
slink /bin/init hello 777 0 0

但是当我在重新制作 uImage 后尝试启动 SmartFusion2 时,我得到了这个,但底部有错误:

Starting kernel ...

Linux version 2.6.33-arm1 (ecenstudent@EE10308) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-189) ) #38 Thu May 25 09:09:08 MDT 2017
CPU: ARMv7-M Processor [412fc231] revision 1 (ARMv7M)
CPU: NO data cache, 8K instruction cache
Machine: Microsemi M2S
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: m2s_platform=m2s-fg484-som console=ttyS0,115200 panic=10 ip=10.2.118.102:10.2.118.101:192.168.0.1::m2s-fg484-som:eth0:off ethaddr=3C:FB:96:05:00:53
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 64408k/64408k available, 1128k reserved, 0K highmem
Virtual kernel memory layout:
    vector  : 0x00000000 - 0x00001000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    vmalloc : 0x00000000 - 0xffffffff   (4095 MB)
    lowmem  : 0xa0000000 - 0xa4000000   (  64 MB)
    modules : 0xa0000000 - 0x01000000   (1552 MB)
      .init : 0xa0008000 - 0xa0012000   (  40 kB)
      .text : 0xa0074bc0 - 0xa0083000   (  58 kB)
      .data : 0xa0084000 - 0xa008cce0   (  36 kB)
Hierarchical RCU implementation.
NR_IRQS:83
Calibrating delay loop... 132.30 BogoMIPS (lpj=661504)
Mount-cache hash table entries: 512
Switching to clocksource mss_timer2
Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
serial8250.0: ttyS0 at MMIO 0x40000000 (irq = 10) is a 16550A
console [ttyS0] enabled
serial8250.1: ttyS1 at MMIO 0x40010000 (irq = 11) is a 16550A
Freeing init memory: 40K
Kernel panic - not syncing: No init found.  Try passing init= option to kernel.
Backtrace: no frame pointer
Rebooting in 10 seconds..

有人可以帮助解释为什么会发生这种情况以及我需要对我的 initramfs 做些什么才能使其在启动时运行正确的程序吗?谢谢!!

最佳答案

事实证明,我对这两条线的工作方式感到困惑。当我终于弄清楚时,它们看起来像这样:

file /bin/hello ${INSTALL_ROOT}/projects/${SAMPLE}/goodbye/hello 755 0 0
slink /bin/init hello 777 0 0

然后它按预期工作,我能够将它实现到其他 uImages 中。

关于linux - 使用 initramfs 在启动时运行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44267711/

相关文章:

linux - 如何在 linux ubuntu 上安装 flatc 和 flatbuffers

linux - 新的自定义 centos 启动盘,参数来自官方谷歌云设置

c - 在同一线程中多次锁定互斥量

Java - 在 JVM 启动时加载附加类

ios - 如何在 iPhone 中创建应用即服务

c - 与sqlite3链接时,getaddrinfo永远卡住

linux - uclinux 和设备驱动程序的必要性

linux - 无缘无故“无规则制定目标”

java - 无法在使用 Java7u13 JFX2.2.5 的最新 Linux 和 Mac 上的浏览​​器中运行

c - linux自动删除文件