linux启动流程./run-helloworld.sh

老生长谈的内容了,就是自己编译内核,然后制作initramfs,在用qemu跑
起来。不过在这之前先跑个helloworld玩玩

编译内核

#    建一个目录
$    mkdir build
#    首先當然是去下一個linux內核,地址,  我这里选的版本是3.10.104
$    wget https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.10.104.tar.xz
#    解压$    tar xvf linux-3.10.104.tar.xz
$    cd linux-3.10.104
$    make menuconfig

进行内核选项配置

#    -j8的选项是为了让编译更快点,一般这数字选择为cpu核数*2
$    make -j8
#    ls -la  linux-3.10.104/arch/x86_64/boot/bzImage
lrwxrwxrwx 1 seijia seijia 22 12月 17 23:52 linux-3.10.104/arch/x86_64/boot/bzImage -> ../../x86/boot/bzImage
$    cp linux-3.10.104/arch/x86_64/boot/bzImage  ..
#    安装qemu,可以自己去下源码安装,我比较懒直接用apt-get安装了
$    sudo apt-get install qemu

制作initramfs

vim /home/baohua/develop/linux/extra/hello.c

// hello.c
#include 
void main(){
    printf("Hello World\n");
    printf("Hello World\n");
    printf("Hello World\n");
    fflush(stdout);
    while(1);
}

vim /home/baohua/develop/linux/extra/run-helloworld.sh

qemu-system-arm \
-M vexpress-a9 \
-dtb vexpress-v2p-ca9.dtb \
-kernel ./zImage \
-initrd ./rootfs \
-append "root=/dev/ram rdinit=/helloworld"

运行

$    cd /home/baohua/develop/linux/extra
$    arm-linux-gnueabi-gcc -static -o helloworld hello.c
$    echo helloworld | cpio -o --format=newc > rootfs
$    ls -la rootfs
$    ./run-helloworld.sh

运行后文件调用关系

./drivers/tty/serial/amba-pl011.c: 向系统注册串口驱动 (dev_info(uap->port.dev, "no DMA platform data\n");)

./drivers/mtd/chips/cfi_probe.c: nor flash驱动探测芯片信息 (printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank. Manufacturer ID %#08x Chip ID %#08)

./drivers/mtd/chips/cfi_util.c: cfi_read_pri函数 (printk(KERN_INFO "%s Extended Query Table at 0x%4.4X\n", name, adr))

./drivers/mtd/chips/cfi_cmdset_0001.c: 初始化了mtd_info的read、write、erease等flash芯片的具体操作函数 (KERN_INFO "Using buffer write method\n")

./drivers/mtd/mtdconcat.c: MTD架构 (Concatenating MTD devices:\n)

./drivers/net/phy/mdio_bus.c: 以太网总线 (pr_info("%s: probed\n", bus->name);)

./drivers/net/ethernet/broadcom/sb1250-mac.c: 以太网驱动 (%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n)

./drivers/net/ethernet/neterion/s2io.c: 以太网驱动 ("%s: MAC Address: %pM\n", dev->name, dev->dev_addr)

./drivers/usb/core/driver.c: USB hub驱动 (%s: registered new interface driver %s\n)

./drivers/input/mousedev.c: 鼠标驱动 (mouse device common)

./drivers/rtc/class.c: RTC实时时钟构架 (rtc core: registered )

./drivers/base/driver.c: 就开始调用driver_register注册对应的驱动 (needs updating - please use)

./drivers/mmc/core/host.c: 为底层host controller driver实现mmc host的申请以及注册的API等等,以及host相关属性的实现 (Got CD GPIO)

./drivers/mmc/core/host.c: 为底层host controller driver实现mmc host的申请以及注册的API等等,以及host相关属性的实现 (Got WP GPIO)

./drivers/mmc/core/core.c: mmc core初始化,包括注册mmc bus、mm host class等等 (No vqmmc regulator found)

./drivers/mmc/host/mmci.c: 有一个mmci的probe函数 (%s: PL%03x manf %x rev%u at 0x%08llx irq %d,%d)

./drivers/mmc/host/mmci.c: 有一个mmci的probe函数 (DMA channels RX %s, TX %s\n)

./drivers/leds/trigger/ledtrig-cpu.c: led的cpu注册 (ledtrig-cpu: registered to indicate activity on CPUs)

./drivers/usb/core/driver.c: USB hub驱动 (%s: registered new interface driver %s\n)

./drivers/hid/usbhid/hid-core.c: USBHID驱动同时包含USB总线设备驱动和HID总线设备驱动 (USB HID core driver)

./net/socket.c: socket层 (NET: Registered protocol family %d\n)

./net/9p/mod.c: mod求余计算 (Installing 9P2000 support\n)

./arch/arm/kernel/swp_emulate.c: emulate计算 (Registering SWP/SWPB emulation handler\n)

./drivers/rtc/hctosys.c: RTC相关函数 (setting system clock to)

./sound/last.c: alsa声音架构 (ALSA device list:\n)

./hello.c: 自己写的文件 (Hello World\nHello World\nHello World\n)

./drivers/char/random.c: 随机线程池(pr_notice("random: %s pool is initialized\n", r->name);)

你可能感兴趣的:(operating,system)