Android系统启动阶段多种快速重启系统方法试验记录
笔者的系统是android4.2 A20平台,平台使用的是ext4文件系统。按我以前的经验对于nand来说yaffs对系统突然断电重启会好很多。笔者一个应用需求就是,系统启动到kernel,但是还没到应用能处理倒车事件的时候,笔者需要快速重启,让系统进入boot来完成倒车功能,这也是为了快速响应倒车影像。笔者使用了好几种重启系统的方法,都有一些问题,有的系统虽然能重启,但是因为文件系统由于突然掉电可能导致一些cash页没写成功,在boot阶段加载nand驱动的时候会去做repair,这个过程大概需要2秒多一点,对我们来说不大可靠。虽然笔者后续产品可能会使用inand来替代,但是还是把以前做过的一点事情分享给大家,大家有什么好的方法可以分享一下。有7种方法如下:
/*****************************************************************************************************/
声明:本博内容均由http://blog.csdn.net/edsam49原创,转载请注明出处,谢谢!
/*****************************************************************************************************/
一、使用emergency_restart();
二、handle_sysrq('u');//mountro
handle_sysrq('b');//reboot
三、sys_sync();
sys_restart_syscall();
四、sys_sync();
kernel_restart(NULL);//LINUX_REBOOT_CMD_RESTART
五、sys_sync();
sys_reboot(0xfee1dead, 0x28121969, 0x1234567,NULL);
六、sys_reboot(0xfee1dead,0x28121969, 0x1234567, NULL);
加载内核过程中执行得话,系统crash;
七、直接写watchdog的寄存器搞定,这样会使得在重启的时候boot阶段会做repair,会要耽误2秒钟左右,这也是比较难接受的。
下面是各种方法的相应打印信息,对应如下:
1、 使用emergency_restart();
/*
* Emergency restart, callable from aninterrupt handler.
*/
[ 208.862932] BUG: using smp_processor_id() inpreemptible [00000000] code: sh/2667
[ 208.871614] caller is smp_send_stop+0x1c/0xe0
[ 208.876582] [
[ 208.887427] [
[ 208.898092] [
[ 208.907925] [
[ 208.918773] [
[ 208.929731] [
[ 208.939805] [
[ 208.949372] [
[ 208.958465] [
[ 208.968017] CPU0: stopping
[ 208.971127] [
[ 208.980867] [
[ 208.990505] [
[ 208.999916] Exception stack(0xc06c5cf0 to0xc06c5d38)
[ 209.005626] 5ce0: 0000040000000000 0fdcb000 c06c3140
[ 209.014866] 5d00: df82d640 00000000 00000000df807a80 00000000 00000000 c06d4480 00000001
[ 209.024100] 5d20: 00000000 c06c5d38 c0078ea8c00769c8 60000113 ffffffff
[ 209.031592] [
[ 209.040751] [
[ 209.050979] [
[ 209.061396] [
[ 209.071620] [
[ 209.082726] [
[ 209.093340] [
[ 209.102585] [
[ 209.111639] [
[ 209.121277] [
[ 209.130691] Exception stack(0xc06c5f68 to0xc06c5fb0)
[ 209.136407] 5f60: 00000003 01000000 0000000000000000 c06c4000 c070ba88
[ 209.145647] 5f80: c04ad9b8 c06dbfd0 4000406a 410fc07400000000 00000000 00000000 c06c5fb0
[ 209.154878] 5fa0: c000ea90 c000ea94 60000013ffffffff
[ 209.160614] [
[ 209.169866] [
[ 209.179025] [
[ 209.188350] [hotplug]: try to kill cpu:0failed!
[ 209.193552]
[ 209.195251] Restarting Linux version 3.4.39+(desheng@jeavox-server) (gcc version 4.6.3 20120201 (prerelease) (crosstool-NGlinaro-1.13.1-2012.02-20120222 - Linaro GCC 2012.02) ) #288 SMP PREEMPT Wed Dec11 11:39:14 HKT 2013
[ 209.195302]
[ 209.219501]sun7i_restart: to check
2、handle_sysrq('u');//mountro
handle_sysrq('b');//reboot
[ 66.797544] SysRq : Emergency Remount R/O
[ 66.808076] SysRq : Resetting
[ 66.811477] CPU0: stopping
[ 66.814617] [
[ 66.824341] [
[ 66.833966] [
[ 66.843365] Exception stack(0xd358be90 to0xd358bed8)
[ 66.849058] be80: df4e1b70 0000000000000000 df4e1c1c
[ 66.858295] bea0: de986878 df4e1b70 df4c8620df4e1bb0 df4e1c40 dfa6cfc4 dfa6cfc0 00000000
[ 66.867514] bec0: 00000000 d358bed8 c00e9c38c00e107c 20000013 ffffffff
[ 66.875006] [
[ 66.883559] [
[ 66.892706] [
[ 66.903042] [
[ 66.913251] [
[ 66.923765] [
[ 66.934668] [
[ 66.945094] [
[ 66.954422] [
[ 66.963835] [hotplug]: try to kill cpu:0failed!
[ 66.969061]
[ 66.970759] Restarting Linux version 3.4.39+(desheng@jeavox-server) (gcc version 4.6.3 20120201 (prerelease) (crosstool-NGlinaro-1.13.1-2012.02-20120222 - Linaro GCC 2012.02) ) #284 SMP PREEMPT Tue Dec10 17:32:11 HKT 2013
[ 66.970810]
[ 66.994836] sun7i_restart: to check
3、 sys_sync();
sys_restart_syscall();
重启不了
4、sys_sync();
kernel_restart(NULL);//LINUX_REBOOT_CMD_RESTART
重启的时候太慢,有异常,卡了几秒钟,太慢了。
126.005206]drivers/cpufreq/cpufreq.c:reboot_notifier_call: stop none boot cpus
[ 126.016497] CPU1: shutdown
[ 126.019916] [hotplug]: cpu(0) try to killcpu(1)
[ 126.026327] [hotplug]: cpu1 is killed!
[ 126.038924]drivers/cpufreq/cpufreq.c:reboot_notifier_call: stop none boot cpus done
[ 126.168999] codec active: 0
[ 126.172113] rest looping: 100
[ 126.788816] sunxi_rtc_setaie(222): para 0
[ 126.793314] WRN:L573(drivers/usb/host/ehci_sun7i.c):ERR:sw_ehci is disable, need not shutdown
[ 126.802944] [sw-ohci1]: ohci shutdown start
[ 126.807616] [sw-ohci1]: close clock
[ 126.811521] [sw-ohci1]: ohci shutdown end
[ 126.815988] [sw-ehci1]: ehci shutdown start
[ 126.821212] [sw-ehci1]: Set USB Power OFF
[ 126.825691] __set_vbus
[ 126.828320] [sw-ehci1]: close clock
[ 126.832266] [sw-ehci1]: ehci shutdown end
[ 126.836801] wrn: hcd is disable, need notshutdown
[ 126.842942] pmu_shutdown_chgcur = 1000000
[ 126.848055] [NAND]shutdown
[ 131.948829] nand try to shutdown 10 time
[ 131.995235] Nand flash shutdown ok!
[ 131.999177] devices shutdown time: 5948ms
[ 132.003641] Disabling non-boot CPUs ...
[ 132.007910] Restarting system.
[ 132.011326]
[ 132.012987] Restarting Linux version 3.4.39+(desheng@jeavox-server) (gcc version 4.6.3 20120201 (prerelease) (crosstool-NGlinaro-1.13.1-2012.02-20120222 - Linaro GCC 2012.02) ) #290 SMP PREEMPT Wed Dec11 17:03:17 HKT 2013
[ 132.013004]
[ 132.036965] sun7i_restart: to check
在启动过程中,IRQ中断handler里面执行得好,系统会crash。
6.537818] WARNING: at kernel/softirq.c:159local_bh_enable_ip+0x4c/0xcc()
[ 6.537827] Modules linked in: mali(O) lcddisp nand(O)
[ 6.537874] [
[ 6.537898] [
[ 6.537919] [
[ 6.537942] [
[ 6.537965] [
[ 6.537988] [
[ 6.538014] [
[ 6.538039] [
[ 6.538062] [
[ 6.538084] [
[ 6.538105] [
[ 6.538127] [
[ 6.538150] [
[ 6.538170] [
[ 6.538189] [
[ 6.538202] Exception stack(0xc06c5f68 to0xc06c5fb0)
[ 6.538216] 5f60: 00000003 01000000 0000000000000000 c06c4000 c070ba88
[ 6.538233] 5f80: c04ad9b8 c06dbfd0 4000406a410fc074 00000000 00000000 00000000 c06c5fb0
[ 6.538247] 5fa0: c000ea90 c000ea94 60000013ffffffff
[ 6.538265] [
[ 6.538285] [
[ 6.538312] [
[ 6.538324] ---[ end trace 12bae582f8d57edc]---
[ 6.538373] BUG: scheduling while atomic:swapper/0/0/0x00010002
[ 6.538381] Modules linked in: mali(O) lcddisp nand(O)
[ 6.538409] [
[ 6.538431] [
[ 6.538452] [
[ 6.538473] [
[ 6.538494] [
[ 6.538520] [
[ 6.538542] [
[ 6.538561] [
[ 6.538582] [
[ 6.538603] [
[ 6.538624] [
[ 6.538644] [
[ 6.538665] [
[ 6.538685] [
[ 6.538705] [
[ 6.538725] [
[ 6.538743] [
5、 sys_sync();
sys_reboot(0xfee1dead, 0x28121969, 0x1234567,NULL);
[ 3.874315] BUG: scheduling while atomic:swapper/0/0/0x00010002
[ 3.881006] Modules linked in:
[ 3.884451] [
[ 3.894063] [
[ 3.903869] [
[ 3.914149] [
[ 3.924923] [
[ 3.937152] [
[ 3.949082] [
[ 3.959178] [
[ 3.968395] [
[ 3.977234] [
[ 3.987022] [
[ 3.997877] [
[ 4.009705] [
[ 4.022407] [
[ 4.034335] [
[ 4.044814] [
[ 4.054329] [
[ 4.064906] [
[ 4.075481] [
[ 4.086059] [
[ 4.097016] [
[ 4.107486] [
[ 4.118154] [
[ 4.127950] [
[ 4.137353] [
[ 4.146655] Exception stack(0xc06c5f68 to0xc06c5fb0)
[ 4.152283] 5f60: 00000003 01000000 0000000000000000 c06c4000 c070ba88
[ 4.161400] 5f80: c04ad9b8 c06dbfd0 4000406a410fc074 00000000 00000000 00000000 c06c5fb0
[ 4.170518] 5fa0: c000ea90 c000ea94 60000013ffffffff
[ 4.176155] [
[ 4.185267] [
[ 4.194295] [
[ 4.203514] [
[ 4.211947] bad: scheduling from the idlethread!
[ 4.217192] [
[ 4.227381] [
[ 4.237272] [
[ 4.246589] [
[ 4.256390] [
[ 4.266676] [
[ 4.277444] [
[ 4.289662] [
[ 4.301587] [
[ 4.311680] [
[ 4.320901] [
[ 4.329726] [
[ 4.339522] [
[ 4.350392] [
[ 4.362228] [
[ 4.374932] [
[ 4.386869] [
[ 4.397347] [
6、 sys_reboot(0xfee1dead, 0x28121969, 0x1234567,NULL);
加载内核过程中执行得话,系统crash;
70.309402] SYSCALL_DEFINE4: rebootmagic1=0xfee1dead, magic2=0x28121969, cmd=0x1234567
[ 70.318745]drivers/cpufreq/cpufreq.c:reboot_notifier_call: stop none boot cpus
[ 70.339919] CPU1: shutdown
[ 70.343016] [hotplug]: cpu(0) try to killcpu(1)
[ 70.349214] [hotplug]: cpu1 is killed!
[ 70.353905]drivers/cpufreq/cpufreq.c:reboot_notifier_call: stop none boot cpus done
[ 70.479995] codec active: 0
[ 70.483109] rest looping: 100
[ 71.100040] sunxi_rtc_setaie(222): para 0
[ 71.104541] WRN:L573(drivers/usb/host/ehci_sun7i.c):ERR:sw_ehci is disable, need not shutdown
[ 71.114179] [sw-ohci1]: ohci shutdown start
[ 71.118851] [sw-ohci1]: close clock
[ 71.122756] [sw-ohci1]: ohci shutdown end
[ 71.127226] [sw-ehci1]: ehci shutdown start
[ 71.132254] [sw-ehci1]: Set USB Power OFF
[ 71.136716] __set_vbus
[ 71.139340] [sw-ehci1]: close clock
[ 71.143240] [sw-ehci1]: ehci shutdown end
[ 71.147775] wrn: hcd is disable, need notshutdown
[ 71.153941] pmu_shutdown_chgcur = 1000000
[ 71.159055] [NAND]shutdown
[ 76.259791] nand try to shutdown 10 time
[ 76.302211] Nand flash shutdown ok!
[ 76.306122] devices shutdown time: 5937ms
[ 76.310613] Disabling non-boot CPUs ...
[ 76.315034] Restarting system.
[ 76.318435]
[ 76.320121] Restarting Linux version 3.4.39+(desheng@jeavox-server) (gcc version 4.6.3 20120201 (prerelease) (crosstool-NGlinaro-1.13.1-2012.02-20120222 - Linaro GCC 2012.02) ) #292 SMP PREEMPT Wed Dec11 17:38:15 HKT 2013
[ 76.320138]
[ 76.343958] sun7i_restart: to check
8.891894] WARNING: at fs/sysfs/dir.c:508sysfs_add_one+0x78/0x98()
[ 8.899237] sysfs: cannot create duplicatefilename '/class/custom_design'
[ 8.907153] Modules linked in:custom_design_drv(+) sunxi_csi0 ov7725 camera videobuf_dma_contig videobuf_coresecurity_system ektf2k mali(O) lcd disp nand(O)
[ 8.923458] [
[ 8.934210] [
[ 8.950510] [
[ 8.960708] [
[ 8.974839] [
[ 8.984705] [
[ 8.998438] [
[ 9.010851] [
[ 9.021160] [
[ 9.031540] [
[ 9.044078] [
[ 9.056658] [
[ 9.067287] [
[ 9.082747] ---[ end trace a90fd0205139c366]---
[ 9.087932] ------------[ cut here]------------
[ 9.098729] WARNING: at lib/kobject.c:198kobject_add_internal+0x150/0x1c8()
[ 9.106623] kobject_add_internal failed forcustom_design with -EEXIST, don't try to register things with the same name inthe same directory.
[ 9.132884] Modules linked in:custom_design_drv(+) sunxi_csi0 ov7725 camera videobuf_dma_contig videobuf_coresecurity_system
[ 9.145147] ###########close all layers 0,hdl 103
[ 9.151230] ektf2k mali(O) lcd disp nand(O)
[ 9.161724] [
[ 9.172531] [
[ 9.183407] [
[ 9.194411] [
[ 9.205060] [
[ 9.215317] [
[ 9.225671] [
[ 9.238418] [
[ 9.255590] [
[ 9.270886] [
[ 9.286004] ---[ end trace a90fd0205139c367]---
[ 9.291276] class_create() failed 0
[ 9.295263] init: command 'insmod' r=0
[ 9.304720] init: starting 'reversemonitor'
[ 9.352176] [TVD_INF]V4L2 device registeredas video1
[ 9.358686] init: command 'insmod' r=0
[ 9.386257] init: command 'insmod' r=0
[ 9.428488] usbcore: registered new interfacedriver asix
[ 9.434609] init: command 'insmod' r=0
[ 9.463388] usbcore: registered new interfacedriver qf9700
[ 9.469848] init: command 'insmod' r=0
[ 9.497221] usbcore: registered new interfacedriver MOSCHIP usb-ethernet driver
[ 9.505800] init: command 'insmod' r=0
[ 9.529954] usbcore: registered new interfacedriver cdc_ether
[ 9.536568] init: command 'insmod' r=0
[ 9.545432] init: processing action 0x381d0(queue_property_triggers)
[ 9.552936] init: command'queue_property_triggers' r=0
[ 9.559380] init: processing action 0x30678 (property:ro.debuggable=1)
[ 9.566925] init: starting 'console'
[ 9.571673] init: command 'start' r=0
7、直接写watchdog的寄存器搞定,这样会使得在重启的时候boot阶段会做repair,会要耽误2秒钟左右,这也是比较难接受的。