1.一、將內核讀入內存1.二、保存內核啓動參數到指定位置,內核啓動時去這個位置解析參數1.三、啓動內核、傳入機器ID
1.檢查CPU和機器類型2.進行堆棧、MMU等其餘程序運行關鍵的東西進行初始化3.打印內核信息4.執行各類模塊的初始化5.掛接根文件系統6.啓動第一個init進程
ENTRY(stext) THUMB( adr r9, BSYM(1f) ) @ Kernel is always entered in ARM. THUMB( bx r9 ) @ If this is a Thumb-2 kernel, THUMB( .thumb ) @ switch to Thumb now. THUMB(1: ) setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode @ and irqs disabled mrc p15, 0, r9, c0, c0 @ get processor id bl __lookup_processor_type @ r5=procinfo r9=cpuid movs r10, r5 @ invalid processor (r5=0)? THUMB( it eq ) @ force fixup-able long branch encoding beq __error_p @ yes, error 'p' #ifdef CONFIG_ARM_LPAE mrc p15, 0, r3, c0, c1, 4 @ read ID_MMFR0 and r3, r3, #0xf @ extract VMSA support cmp r3, #5 @ long-descriptor translation table format? THUMB( it lo ) @ force fixup-able long branch encoding blo __error_p @ only classic page table format #endif
MACHINE_START(S3C2440, "SMDK2440") /* Maintainer: Ben Dooks <ben-linux@fluff.org> */ .atag_offset = 0x100, .init_irq = s3c24xx_init_irq, .map_io = smdk2440_map_io, .init_machine = smdk2440_machine_init, .timer = &s3c24xx_timer, .restart = s3c244x_restart, MACHINE_END
MACHINE_START和 MACHINE_END實際上被展開成一個結構體node
#defineMACHINE_START(_type,_name) \ staticconst struct machine_desc __mach_desc_##_type \ __used \ __attribute__((__section__(".arch.info.init")))= { \ .nr =MACH_TYPE_##_type, \ .name =_name, #defineMACHINE_END \ };
因而上面的數據結構就被展開爲linux
staticconst struct machine_desc __mach_desc_S3C2440 \ __used \ __attribute__((__section__(".arch.info.init")))= { \ .nr =MACH_TYPE_S3C2440, \ .name =」SMDK2440」,}; .phys_io = S3C2410_PA_UART, .io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc, .boot_params = S3C2410_SDRAM_PA + 0x100, .init_irq =s3c24xx_init_irq, .map_io =smdk2440_map_io, .init_machine = smdk2440_machine_init, .timer =&s3c24xx_timer, }
/* * The following fragment of code is executed with the MMU on in MMU mode, * and uses absolute addresses; this is not position independent. * * r0 = cp#15 control register * r1 = machine ID * r2 = atags/dtb pointer * r9 = processor ID */ __INIT __mmap_switched: adr r3, __mmap_switched_data ldmia r3!, {r4, r5, r6, r7} cmp r4, r5 @ Copy data segment if needed 1: cmpne r5, r6 ldrne fp, [r4], #4 strne fp, [r5], #4 bne 1b mov fp, #0 @ Clear BSS (and zero fp) 1: cmp r6, r7 strcc fp, [r6],#4 bcc 1b ARM( ldmia r3, {r4, r5, r6, r7, sp}) THUMB( ldmia r3, {r4, r5, r6, r7} ) THUMB( ldr sp, [r3, #16] ) str r9, [r4] @ Save processor ID str r1, [r5] @ Save machine type str r2, [r6] @ Save atags pointer bic r4, r0, #CR_A @ Clear 'A' bit stmia r7, {r0, r4} @ Save control register values b start_kernel ENDPROC(__mmap_switched) .align 2 .type __mmap_switched_data, %object __mmap_switched_data: .long __data_loc @ r4 .long _sdata @ r5 .long __bss_start @ r6 .long _end @ r7 .long processor_id @ r4 .long __machine_arch_type @ r5 .long __atags_pointer @ r6 .long cr_alignment @ r7 .long init_thread_union + THREAD_START_SP @ sp .size __mmap_switched_data, . - __mmap_switched_data
asmlinkage void __init start_kernel(void)
static noinline void __init_refok rest_init(void)
他啓動了kernel_init這個函數,再來看kerne_init函數vim
static int __init kernel_init(void * unused) { /* * Wait until kthreadd is all set-up. */ wait_for_completion(&kthreadd_done); /* Now the scheduler is fully set up and can do blocking allocations */ gfp_allowed_mask = __GFP_BITS_MASK; /* * init can allocate pages on any node */ set_mems_allowed(node_states[N_HIGH_MEMORY]); /* * init can run on any cpu. */ set_cpus_allowed_ptr(current, cpu_all_mask); cad_pid = task_pid(current); smp_prepare_cpus(setup_max_cpus); do_pre_smp_initcalls(); lockup_detector_init(); smp_init(); sched_init_smp(); do_basic_setup(); /* Open the /dev/console on the rootfs, this should never fail */ if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) printk(KERN_WARNING "Warning: unable to open an initial console.\n"); (void) sys_dup(0); (void) sys_dup(0); /* * check if there is an early userspace init. If yes, let it do all * the work */ if (!ramdisk_execute_command) ramdisk_execute_command = "/init"; if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) { ramdisk_execute_command = NULL; prepare_namespace(); } /* * Ok, we have completed the initial bootup, and * we're essentially up and running. Get rid of the * initmem segments and start the user-mode stuff.. */ init_post(); return 0; }
vim Makefile |
ARCH=arm
CROSS_COMPILE=arm-linux-
三、選擇默認配置數據結構
find -name"*defconfig"
四、在解壓後文件目錄下,配置,生成.config文件架構
make s3c2410_defconfig
五、查看支持的單板ide
vim .config
六、編譯函數
make uImage
七、u-boot2012裏默認的是193機器ID,設置機器ID爲362使用SMDK2440,在uboot中設置機器IDpost
set machid 16a save
八、在uboot中設置啓動行參數並修改smdk2440單板的晶振信息12Mui
bootargs noinitrd root=/dev/nfs nfsroot=192.168.1.112:/opt/filesystem ip=192.168.1.130:192.168.1.112:192.168.1.1:255,255,255,0::eth0:off init=/linuxrc console=ttySAC0,115200
修改文件mach-smdk2440.c的晶振信息12Mthis
static void __init smdk2440_map_io(void) { s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc)); s3c24xx_init_clocks(12000000); s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs)); }
Creating 4 MTD partitions on "NAND": 0x000000000000-0x000000040000 : "bootloader" 0x000000040000-0x000000060000 : "params" 0x000000060000-0x000000460000 : "kernel" 0x000000460000-0x000010000000 : "rootfs"
這些分區是經過在文件linux-2.6.22.6\arch\arm\plat-s3c24xx/Common-smdk.c設置的
/* NAND parititon from 2.4.18-swl5 */ static struct mtd_partition smdk_default_nand_part[] = { [0] = { .name = "bootloader", .size = SZ_256K, .offset = 0, }, [1] = { .name = "params", .offset = MTDPART_OFS_APPEND, .size = SZ_128K, }, [2] = { .name = "kernel", .offset = MTDPART_OFS_APPEND, .size = SZ_4M, }, [3] = { .name = "rootfs", .offset = MTDPART_OFS_APPEND, .size = MTDPART_SIZ_FULL, }, };
#define MACH_SMDK2440_DM9K_BASE (S3C2410_CS4 + 0x300)
3 添加資源和設備
/* DM9000AEP 10/100 ethernet controller */ static struct resource smdk2440_dm9k_resource[] = { [0] = { .start = MACH_SMDK2440_DM9K_BASE, .end = MACH_SMDK2440_DM9K_BASE + 3, .flags = IORESOURCE_MEM }, [1] = { .start = MACH_SMDK2440_DM9K_BASE + 4, .end = MACH_SMDK2440_DM9K_BASE + 7, .flags = IORESOURCE_MEM }, [2] = { .start = IRQ_EINT7, .end = IRQ_EINT7, .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE, } }; /* * The DM9000 has no eeprom, and it's MAC address is set by * the bootloader before starting the kernel. */ static struct dm9000_plat_data smdk2440_dm9k_pdata = { .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM), }; static struct platform_device smdk2440_device_eth = { .name = "dm9000", .id = -1, .num_resources = ARRAY_SIZE(smdk2440_dm9k_resource), .resource = smdk2440_dm9k_resource, .dev = { .platform_data = &smdk2440_dm9k_pdata, }, }; static struct platform_device *smdk2440_devices[] __initdata = { &s3c_device_ohci, &s3c_device_lcd, &s3c_device_wdt, &s3c_device_i2c0, &s3c_device_iis, &smdk2440_device_eth, };
綜上,make uImage 完成Linux3.4.2的移植,並添加了網卡驅動。