im6q linux 瘦身计划-减少启动时间

3个方面:
1.uboot:
irom从inand拷贝uboot部分代码到iram时间
uboot从inand拷贝自身到ddr3时间
uboot初始化所用时间
uboot从inand拷贝内核到ddr3所用时间

2.kernel
内核解压缩所用时间
内核加载驱动之前的初始化所用时间
内核加载驱动所用时间
内核加载init程序所用时间

内核打印浪费的时间


3.文件系统
init初始化所用时间
准备执行目标程序


一、uboot部分

irom从inand拷贝uboot部分代码到iram时间
uboot从inand拷贝自身到ddr3时间
uboot初始化所用时间
uboot从inand拷贝内核到ddr3所用时间


二、kernel 部分


1.内核启动时的打印控制

kernel/printk.c
int console_printk[4] = {
	DEFAULT_CONSOLE_LOGLEVEL,	/* console_loglevel ,7,即所有级别高于此控制台打印级别的消息都会打印在控制台上*/
	DEFAULT_MESSAGE_LOGLEVEL,	/* default_message_loglevel ,1,即printk不加任何级别标志时的默认级别*/
	MINIMUM_CONSOLE_LOGLEVEL,	/* minimum_console_loglevel */
	DEFAULT_CONSOLE_LOGLEVEL,	/* default_console_loglevel */
};


inlcue/linux/printk.h
#define KERN_EMERG	"<0>"	/* system is unusable			*/
#define KERN_ALERT	"<1>"	/* action must be taken immediately	*/
#define KERN_CRIT	"<2>"	/* critical conditions			*/
#define KERN_ERR	"<3>"	/* error conditions			*/
#define KERN_WARNING	"<4>"	/* warning conditions			*/
#define KERN_NOTICE	"<5>"	/* normal but significant condition	*/
#define KERN_INFO	"<6>"	/* informational			*/
#define KERN_DEBUG	"<7>"	/* debug-level messages			*/

cat /proc/sys/kernel/printk,在内核启动时,所有优先级高于7的printk打印都会打印出来,即所有打印信息
7       1       1       7
分别表示
当前控制台日志级别
未明确指定日志级别的默认消息日志级别
最小(最高)允许设置的控制台日志级别
引导时默认的日志级别

在uboot参数中指定loglevel=2,在内核启动时,所有优先级高于2的printk打印都会打印出来
cat /proc/sys/kernel/printk
2       1       1       7

可以动态修改
echo 4 1 1 7 > /proc/sys/kernel/printk 

printk("<1>""hello");
printk(KERN_ALERT"hello");
2.

[    5.504872] =======================now will call :8002c3f0
[    5.515601] =======================now will call :8002c3f4
[    5.521142] =======================now will call :8002c3f8
[    5.526630] =======================now will call :8002c3fc
[    5.532609] Waiting for root device /dev/mmcblk1p1...
[    5.743856] mmc2: new high speed SDHC card at address 8ff2
[    5.749782] mmcblk1: mmc2:8ff2 SD04G 3.69 GiB 
[    5.755298]  mmcblk1: p1
[    6.995400] EXT4-fs (mmcblk1p1): warning: maximal mount count reached, running e2fsck is recommended
[    7.262931] EXT4-fs (mmcblk1p1): recovery complete
[    7.525682] EXT4-fs (mmcblk1p1): mounted filesystem with ordered data mode. Opts: (null)
[    7.533821] VFS: Mounted root (ext4 filesystem) on device 179:25.
[    7.539990] Freeing init memory: 188K
starting pid 1330, tty '': '/etc/rc.d/rcS'
Mounting /proc and /sys 

[    5.532609] Waiting for root device /dev/mmcblk1p1...
init/do_mounts.c
start_kernel->rest_init->kernel_init->prepare_namespace()


[    5.743856] mmc2: new high speed SDHC card at address 8ff2
drivers/mmc/core/bus.c
mmc_rescan->mmc_rescan_try_freq->mmc_attach_mmc->()mmc_add_card()


[    5.755298]  mmcblk1: p1
mmc_blk_probe->mmc_blk_alloc->mmc_blk_alloc_req->


[    6.995400] EXT4-fs (mmcblk1p1): warning: maximal mount count reached, running e2fsck is recommended
[    7.262931] EXT4-fs (mmcblk1p1): recovery complete
[    7.525682] EXT4-fs (mmcblk1p1): mounted filesystem with ordered data mode. Opts: (null)
fs/ext4/super.c
ext4_mount->ext4_fill_super->ext4_setup_super


[    7.533821] VFS: Mounted root (ext4 filesystem) on device 179:25.
init/do_mounts.c
start_kernel->rest_init->kernel_init->prepare_namespace->mount_block_root->do_mount_root()


[    7.523325] Freeing init memory: 188K
arch/arm/mm/init.c
start_kernel->rest_init->kernel_init->init_post->free_initmem->free_area


这个是内核最后的一个打印,之后内核会调用文件系统里如下程序,如果在uboot参数中指定了比如init=/init,那么会优先执行指定的程序/init
	if (execute_command) {
		run_init_process(execute_command);
		printk(KERN_WARNING "Failed to execute %s.  Attempting "
					"defaults...\n", execute_command);
	}
	run_init_process("/sbin/init");
	run_init_process("/etc/init");
	run_init_process("/bin/init");
	run_init_process("/bin/sh");

三、文件系统部分

init程序会读取/etc/inittab来获取初始化列表
root@freescale ~$ cat /etc/inittab 
# see busybox-1.00rc2/examples/inittab for more examples
::sysinit:/etc/rc.d/rcS
::respawn:/etc/rc.d/rc_mxc.S
::sysinit:/etc/rc.d/rc_gpu.S
::ctrlaltdel:/sbin/reboot
::shutdown:/etc/rc.d/rcS stop
::restart:/sbin/init

root@freescale ~$ cat /etc/rc.d/rcS 
#!/bin/sh

# minimal startup script, will work with msh (this is best available in
# MMUless format).

# load the configuration information
. /etc/rc.d/rc.conf
mode=${1:-start}
if [ $mode = "start" ]
then
    services=$cfg_services
else
    services=$cfg_services_r
fi
cfg_services=${2:-$services}

# run the configured sequence
for i in $cfg_services
do
    if [ -x /etc/rc.d/init.d/$i ]
    then                                                                        
        /etc/rc.d/init.d/$i $mode
        echo $i > /dev/ttymxc0
        cat /proc/uptime   > /dev/ttymxc0
    fi                                                                          
done

if [ $# -ge 2 ]
then 
    exit 0
fi
# show all kernel log messages
#echo 8 >  /proc/sys/kernel/printk

# run rc.local if present and executable
if [ -x /etc/rc.d/rc.local ]
then 
    /etc/rc.d/rc.local $mode
fi


im6q linux 瘦身计划-减少启动时间_第1张图片



附imx6q启动策略:

1.
BOOT_MODE[1:0]决定启动模式
每一个BOOT_ MODE都关联到由一个特定的gpio脚
BOOT_MODE[1:0] Boot Type

00 Boot From Fuses

01 Serial Downloader

10 Internal Boot

11 Reserved

当从Fuses启动时, BT_FUSE_SEL的状态是从BT_FUSE_SEL脚读取,
If BT_FUSE_SEL = 0, indicating that the boot device (for example, Flash, SD/

MMC) has not yet been programmed, the bootflow jumps directly to the Serial

Downloader. If BT_FUSE_SEL = 1, the normalboot flow is followed, where the ROM

attempts to boot from the selected bootdevice.

BT_FUSE_SEL = 0,bootdevice 没准备好

BT_FUSE_SEL = 1,从efuse选择的启动设备启动(efuse需要实现烧写,比如通过uboot的命令)

 

当是下载模式时,
In this mode the ROM programs WDOG-1 for a 32-second time-out if WDOG_ENABLE

eFuse is 1, and then continuously polls forUSB connection. If no activity is found on

USB OTG1 and the watchdog timer expires,the ARM core is reset.

 

当从Internal启动时

BT_FUSE_SEL = 0,根据efuse选择的启动设备启动

BT_FUSE_SEL = 1,优先根据gpio设置的启动设备启动

 

一般会把板子设置为Internal Boot,这个就优先从gpio选择的设备启动了,如果启动失败就自动进入下载模式。

 

 

2.
共有BOOT_CFG1到BOOT_CFG4共计28个BOOT_CFG

BOOT_CFG1[7:4]决定从哪个设备启动

其他BOOT_CFG选项则是启动设备的一些参数的设定

每一个BOOT_CFG都关联到由一个特定的gpio脚。

 

BOOT_CFG1[7:4] Boot Device

0000 NOR/OneNAND (EIM)

0001 Reserved

0010 SSD/Hard Disk

(SATA)

0011 Serial ROM (I2C/SPI)

010x SD/eSD/SDXC

011x MMC/eMMC

1xxx Raw NAND


3.

从sd或inand启动时,

Boot rom 会拷贝sd或inand的前4kB的数据(uboot)到内部ram,然后跳到内部ram执行

MMC/SD/eSD/SDXC/eMMC can be connected toany of USDHC-1,2,3,4 blocks and can

be booted by copying 4Kbyte of data fromMMC/SD/eSD/eMMC device to internal

RAM. After checking the Image Vector Tableheader value (0xD1) from Program Image,

the ROM code performs a DCD check. Aftersuccessful DCD extraction, the ROM code

extracts from Boot Data Structure thedestination pointer and length of image to be

copied to RAM device from where codeexecution occurs.

The maximum image size to load in SD/MMCboot is 32MB. This is due to the limited

number of uSDHC ADMA Buffer Descriptorsallocated by ROM.

NOTE

The Initial 4Kbyte of Program Image mustcontain the IVT,

DCD and the Boot Data structures.

另外,有自己的地址线和数据线的存储器,cpu可以采用随机访问方式而访问之。比如cpu可以从nor flash,iram,irom上直接取代码运行。
现代的cpu的启动策略一般如上(如imx6q),可以描述为
有一段内部rom和内部ram.内部rom地址会被映射为0. 内部rom代码根据外部gpio的配置来决定从哪个介质上启动。比如如果从a介质的话,rom代码会拷贝a介质的前nkB数据到内部ram,然后跳转到内部ram执行。

 


你可能感兴趣的:(cpu-a9-mx6)