设置reboot_mode变量,在uboot和kernel见传递,实现linux下自动重启,用于老化板子使用
uboot
定义变量值
- 文件路径
arch/arm/include/asm/reboot.h
1
| $ vim path/to/u-boot/arch/arm/include/asm/reboot.h
|
定义新的变量值
1
| #define {board-name}_AUTO_REBOOT 15
|
修改重启命令
1
| $ vim path/to/u-boot/common/cmd_reboot.c
|
- 添加设置环境变量进函数
do_get_rebootmode
1
2
3
4
5
6
7
|
case AMLOGIC_AUTO_REBOOT:
{
setenv("reboot_mode","auto_reboot");
break;
}
|
- 在
do_reboot
函数设置获取kernel重启时传递的值
1
2
| else if (strcmp(mode, "auto_reboot") == 0)
reboot_mode_val = AMLOGIC_AUTO_REBOOT;
|
- 在
U_BOOT_CMD
中加入auto_reboot
添加reboot_mode
到storeargs
- 文件路径
path/to/u-boot/board/{chip-board}/configs/{board-name}.h
1
| reboot_mode=${reboot_mode}
|
kernel
定义变量值
1
| $ vim `path/to/kernel/include/linux/{chip-board}/reboot.h
|
添加自动重启变量定义
1
| #define MESON_AUTO_REBOOT 15
|
修改驱动
1
| $ vim path/to/kernel/drivers/{chip-board}/reboot/reboot.c
|
添加代码到parse_reason
函数
1
2
| else if (strcmp(cmd, "auto_reboot") == 0)
reboot_reason = MESON_AUTO_REBOOT;
|
ubuntu
修改cmdline
1
| setenv rebootmode "reboot_mode=${reboot_mode}"
|
重启脚本文件
1
| $ vim usr/local/bin/auto-reboot-handle.sh
|
1
2
3
4
5
6
| #!/bin/bash
sleep 15
sync
reboot -f auto_reboot
|
autoreboot服务
- 系统服务文件路径
/lib/systemd/system
1
| $ sudo vim lib/systemd/system/auto-reboot.service
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| # This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=auto reboot service
#After=systemd-update-utmp-runlevel.service
[Service]
ExecStart=/usr/local/bin/auto-reboot-handle.sh
[Install]
WantedBy=multi-user.target
|
修改rc.local
1
| $ sudo vim etc/rc.local
|
1
2
3
4
5
6
| # Reboot test handle
if cat /proc/cmdline | grep -q auto_reboot > /dev/null; then
if ! systemctl is-active auto-reboot | grep "^active$" > /dev/null; then
systemctl start auto-reboot
fi
fi
|
重启命令
1
| $ sudo reboot -f auto_reboot
|
buildroot
开机运行脚本
1
| $ vim /etc/init.d/S98autoreboot
|
1
2
3
4
5
6
7
| #!/bin/bash
if cat /proc/cmdline | grep -q auto_reboot > /dev/null; then
sleep 15
sync
reboot -f -t
fi
|
修改busybox重启命令
1
| $ vim path/to/busybox/init/halt.c
|
1
| flags = getopt32(argv, "d:+nfwit", &delay); --> flags = getopt32(argv, "d:+nfwit", &delay);
|
1
2
3
4
5
6
7
| delect:
rc = reboot(magic[which]);
add:
if (reboot_test)
rc = reboot(0xA1B2C3D4, 537993216, 0xA1B2C3D4, "reboot_test");
else
rc = reboot(0xA1B2C3D4, 537993216, 0xA1B2C3D4, "");
|
修改busybox头文件
1
| $ vim path/to/busybox/init/reboot.h
|
1
2
| +//#include <sys/reboot.h>
#include <linux/reboot.h>
|
重启命令
1
| root@root# reboot -f -t
|
使用-t
进入自动重启模式
Source code
https://github.com/yan-wyb/source/tree/master/c/embedded/combine/auto-reboot
issues
如果有疑惑或错误,请提issues –> Issues