Initial commit
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
define_default_set_state() {
|
||||
. /etc/diag.sh
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main define_default_set_state
|
||||
10
package/base-files/files/lib/preinit/02_sysinfo
Normal file
10
package/base-files/files/lib/preinit/02_sysinfo
Normal file
@@ -0,0 +1,10 @@
|
||||
do_sysinfo_generic() {
|
||||
[ -d /proc/device-tree ] || return
|
||||
mkdir -p /tmp/sysinfo
|
||||
[ -e /tmp/sysinfo/board_name ] || \
|
||||
echo "$(strings /proc/device-tree/compatible | head -1)" > /tmp/sysinfo/board_name
|
||||
[ ! -e /tmp/sysinfo/model -a -e /proc/device-tree/model ] && \
|
||||
echo "$(cat /proc/device-tree/model)" > /tmp/sysinfo/model
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main do_sysinfo_generic
|
||||
17
package/base-files/files/lib/preinit/10_indicate_failsafe
Normal file
17
package/base-files/files/lib/preinit/10_indicate_failsafe
Normal file
@@ -0,0 +1,17 @@
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
# commands for emitting messages to network in failsafe mode
|
||||
|
||||
indicate_failsafe_led () {
|
||||
set_state failsafe
|
||||
}
|
||||
|
||||
indicate_failsafe() {
|
||||
[ "$pi_preinit_no_failsafe" = "y" ] && return
|
||||
echo "- failsafe -"
|
||||
preinit_net_echo "Entering Failsafe!\n"
|
||||
indicate_failsafe_led
|
||||
}
|
||||
|
||||
boot_hook_add failsafe indicate_failsafe
|
||||
207
package/base-files/files/lib/preinit/10_indicate_preinit
Normal file
207
package/base-files/files/lib/preinit/10_indicate_preinit
Normal file
@@ -0,0 +1,207 @@
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
preinit_ip_config() {
|
||||
local netdev vid
|
||||
|
||||
netdev=${1%\.*}
|
||||
vid=${1#*\.}
|
||||
|
||||
if [ "$vid" = "$netdev" ]; then
|
||||
vid=
|
||||
fi
|
||||
|
||||
grep -q "$netdev" /proc/net/dev || return
|
||||
|
||||
if [ -n "$vid" ]; then
|
||||
ip link add link $netdev name $1 type vlan id $vid
|
||||
fi
|
||||
|
||||
ip link set dev $netdev up
|
||||
if [ -n "$vid" ]; then
|
||||
ip link set dev $1 up
|
||||
fi
|
||||
ip -4 address add $pi_ip/$pi_netmask broadcast $pi_broadcast dev $1
|
||||
}
|
||||
|
||||
preinit_config_switch() {
|
||||
local role roles ports device enable reset
|
||||
|
||||
local name=$1
|
||||
local lan_if=$2
|
||||
|
||||
json_select switch
|
||||
json_select $name
|
||||
|
||||
json_get_vars enable reset
|
||||
|
||||
if [ "$reset" -eq "1" ]; then
|
||||
swconfig dev $name set reset
|
||||
fi
|
||||
swconfig dev $name set enable_vlan $enable
|
||||
|
||||
if json_is_a roles array; then
|
||||
json_get_keys roles roles
|
||||
json_select roles
|
||||
|
||||
for role in $roles; do
|
||||
json_select "$role"
|
||||
json_get_vars ports device
|
||||
json_select ..
|
||||
|
||||
if [ "$device" = "$lan_if" ]; then
|
||||
swconfig dev $name vlan $role set ports "$ports"
|
||||
fi
|
||||
done
|
||||
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
swconfig dev $name set apply
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
preinit_config_port() {
|
||||
local original
|
||||
|
||||
local netdev="$1"
|
||||
local path="$2"
|
||||
|
||||
[ -d "/sys/devices/$path/net" ] || return
|
||||
original="$(ls "/sys/devices/$path/net" | head -1)"
|
||||
|
||||
[ "$netdev" = "$original" ] && return
|
||||
|
||||
ip link set "$original" name "$netdev"
|
||||
}
|
||||
|
||||
preinit_config_board() {
|
||||
/bin/board_detect /tmp/board.json
|
||||
|
||||
[ -f "/tmp/board.json" ] || return
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
json_init
|
||||
json_load "$(cat /tmp/board.json)"
|
||||
|
||||
# Find the current highest eth*
|
||||
max_eth=$(grep -o '^ *eth[0-9]*:' /proc/net/dev | tr -dc '[0-9]\n' | sort -n | tail -1)
|
||||
# Find and move netdevs using eth*s we are configuring
|
||||
json_get_keys keys "network_device"
|
||||
for netdev in $keys; do
|
||||
json_select "network_device"
|
||||
json_select "$netdev"
|
||||
json_get_vars path path
|
||||
if [ -n "$path" -a -h "/sys/class/net/$netdev" ]; then
|
||||
ip link set "$netdev" down
|
||||
ip link set "$netdev" name eth$((++max_eth))
|
||||
fi
|
||||
json_select ..
|
||||
json_select ..
|
||||
done
|
||||
|
||||
# Move interfaces by path to their netdev name
|
||||
json_get_keys keys "network_device"
|
||||
for netdev in $keys; do
|
||||
json_select "network_device"
|
||||
json_select "$netdev"
|
||||
json_get_vars path path
|
||||
[ -n "$path" ] && preinit_config_port "$netdev" "$path"
|
||||
json_select ..
|
||||
json_select ..
|
||||
done
|
||||
|
||||
json_select network
|
||||
json_select "lan"
|
||||
json_get_vars device
|
||||
json_get_values ports ports
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
[ -n "$device" -o -n "$ports" ] || return
|
||||
|
||||
# swconfig uses $device and DSA uses ports
|
||||
[ -z "$ports" ] && {
|
||||
ports="$device"
|
||||
}
|
||||
|
||||
# only use the first one
|
||||
ifname=${ports%% *}
|
||||
|
||||
if [ -x /sbin/swconfig ]; then
|
||||
# configure the switch, if present
|
||||
|
||||
json_get_keys keys switch
|
||||
for key in $keys; do
|
||||
preinit_config_switch $key $ifname
|
||||
done
|
||||
else
|
||||
# trim any vlan ids
|
||||
ifname=${ifname%\.*}
|
||||
# trim any vlan modifiers like :t
|
||||
ifname=${ifname%\:*}
|
||||
fi
|
||||
|
||||
pi_ifname=$ifname
|
||||
|
||||
preinit_ip_config $pi_ifname
|
||||
}
|
||||
|
||||
preinit_ip() {
|
||||
[ "$pi_preinit_no_failsafe" = "y" ] && return
|
||||
|
||||
# if the preinit interface isn't specified and ifname is set in
|
||||
# preinit.arch use that interface
|
||||
if [ -z "$pi_ifname" ]; then
|
||||
pi_ifname=$ifname
|
||||
fi
|
||||
|
||||
if [ -n "$pi_ifname" ]; then
|
||||
preinit_ip_config $pi_ifname
|
||||
elif [ -d "/etc/board.d/" ]; then
|
||||
preinit_config_board
|
||||
fi
|
||||
|
||||
preinit_net_echo "Doing OpenWrt Preinit\n"
|
||||
}
|
||||
|
||||
preinit_ip_deconfig() {
|
||||
[ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && {
|
||||
local netdev vid
|
||||
|
||||
netdev=${pi_ifname%\.*}
|
||||
vid=${pi_ifname#*\.}
|
||||
|
||||
if [ "$vid" = "$netdev" ]; then
|
||||
vid=
|
||||
fi
|
||||
|
||||
ip -4 address flush dev $pi_ifname
|
||||
ip link set dev $netdev down
|
||||
|
||||
if [ -n "$vid" ]; then
|
||||
ip link delete $pi_ifname
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
preinit_net_echo() {
|
||||
[ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && {
|
||||
{
|
||||
[ "$pi_preinit_net_messages" = "y" ] || {
|
||||
[ "$pi_failsafe_net_message" = "true" ] &&
|
||||
[ "$pi_preinit_no_failsafe_netmsg" != "y" ]
|
||||
}
|
||||
} && netmsg $pi_broadcast "$1"
|
||||
}
|
||||
}
|
||||
|
||||
pi_indicate_preinit() {
|
||||
set_state preinit
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main preinit_ip
|
||||
boot_hook_add preinit_main pi_indicate_preinit
|
||||
102
package/base-files/files/lib/preinit/30_failsafe_wait
Normal file
102
package/base-files/files/lib/preinit/30_failsafe_wait
Normal file
@@ -0,0 +1,102 @@
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
fs_wait_for_key () {
|
||||
local timeout=$3
|
||||
local timer
|
||||
local do_keypress
|
||||
local keypress_true="$(mktemp)"
|
||||
local keypress_wait="$(mktemp)"
|
||||
local keypress_sec="$(mktemp)"
|
||||
if [ -z "$keypress_wait" ]; then
|
||||
keypress_wait=/tmp/.keypress_wait
|
||||
touch $keypress_wait
|
||||
fi
|
||||
if [ -z "$keypress_true" ]; then
|
||||
keypress_true=/tmp/.keypress_true
|
||||
touch $keypress_true
|
||||
fi
|
||||
if [ -z "$keypress_sec" ]; then
|
||||
keypress_sec=/tmp/.keypress_sec
|
||||
touch $keypress_sec
|
||||
fi
|
||||
|
||||
trap "echo 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" INT
|
||||
trap "echo 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" USR1
|
||||
|
||||
[ -n "$timeout" ] || timeout=1
|
||||
[ $timeout -ge 1 ] || timeout=1
|
||||
timer=$timeout
|
||||
lock $keypress_wait
|
||||
{
|
||||
while [ $timer -gt 0 ]; do
|
||||
pi_failsafe_net_message=true \
|
||||
preinit_net_echo "Please press button now to enter failsafe"
|
||||
echo "$timer" >$keypress_sec
|
||||
timer=$(($timer - 1))
|
||||
sleep 1
|
||||
done
|
||||
lock -u $keypress_wait
|
||||
rm -f $keypress_wait
|
||||
} &
|
||||
|
||||
local consoles="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | sed -e 's/^console=//' -e 's/,.*//')"
|
||||
[ -n "$consoles" ] || consoles=console
|
||||
for console in $consoles; do
|
||||
[ -c "/dev/$console" ] || continue
|
||||
[ "$pi_preinit_no_failsafe" != "y" ] && echo "Press the [$1] key and hit [enter] $2" > "/dev/$console"
|
||||
echo "Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level" > "/dev/$console"
|
||||
{
|
||||
while [ -r $keypress_wait ]; do
|
||||
timer="$(cat $keypress_sec)"
|
||||
|
||||
[ -n "$timer" ] || timer=1
|
||||
timer="${timer%%\ *}"
|
||||
[ $timer -ge 1 ] || timer=1
|
||||
do_keypress=""
|
||||
{
|
||||
read -t "$timer" do_keypress < "/dev/$console"
|
||||
case "$do_keypress" in
|
||||
$1)
|
||||
echo "true" >$keypress_true
|
||||
;;
|
||||
1 | 2 | 3 | 4)
|
||||
echo "$do_keypress" >/tmp/debug_level
|
||||
;;
|
||||
*)
|
||||
continue;
|
||||
;;
|
||||
esac
|
||||
lock -u $keypress_wait
|
||||
rm -f $keypress_wait
|
||||
}
|
||||
done
|
||||
} &
|
||||
done
|
||||
lock -w $keypress_wait
|
||||
|
||||
keypressed=1
|
||||
[ "$(cat $keypress_true)" = "true" ] && keypressed=0
|
||||
|
||||
rm -f $keypress_true
|
||||
rm -f $keypress_wait
|
||||
rm -f $keypress_sec
|
||||
|
||||
return $keypressed
|
||||
}
|
||||
|
||||
failsafe_wait() {
|
||||
FAILSAFE=
|
||||
[ "$pi_preinit_no_failsafe" = "y" ] && {
|
||||
fs_wait_for_key "" "" $fs_failsafe_wait_timeout
|
||||
return
|
||||
}
|
||||
grep -q 'failsafe=' /proc/cmdline && FAILSAFE=true && export FAILSAFE
|
||||
if [ "$FAILSAFE" != "true" ]; then
|
||||
fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true
|
||||
[ -f "/tmp/failsafe_button" ] && FAILSAFE=true && echo "- failsafe button "$(cat /tmp/failsafe_button)" was pressed -"
|
||||
[ "$FAILSAFE" = "true" ] && export FAILSAFE && touch /tmp/failsafe
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main failsafe_wait
|
||||
16
package/base-files/files/lib/preinit/40_run_failsafe_hook
Normal file
16
package/base-files/files/lib/preinit/40_run_failsafe_hook
Normal file
@@ -0,0 +1,16 @@
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
run_failsafe_hook() {
|
||||
[ "$pi_preinit_no_failsafe" = "y" ] && return
|
||||
if [ "$FAILSAFE" = "true" ]; then
|
||||
lock /tmp/.failsafe
|
||||
boot_run_hook failsafe
|
||||
while [ ! -e /tmp/sysupgrade ]; do
|
||||
lock -w /tmp/.failsafe
|
||||
done
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main run_failsafe_hook
|
||||
@@ -0,0 +1,9 @@
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
indicate_regular_preinit() {
|
||||
preinit_net_echo "Continuing with Regular Preinit\n"
|
||||
set_state preinit_regular
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main indicate_regular_preinit
|
||||
12
package/base-files/files/lib/preinit/70_initramfs_test
Normal file
12
package/base-files/files/lib/preinit/70_initramfs_test
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
initramfs_test() {
|
||||
if [ -n "$INITRAMFS" ]; then
|
||||
boot_run_hook initramfs
|
||||
preinit_ip_deconfig
|
||||
break
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main initramfs_test
|
||||
54
package/base-files/files/lib/preinit/80_mount_root
Normal file
54
package/base-files/files/lib/preinit/80_mount_root
Normal file
@@ -0,0 +1,54 @@
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
missing_lines() {
|
||||
local file1 file2 line
|
||||
file1="$1"
|
||||
file2="$2"
|
||||
oIFS="$IFS"
|
||||
IFS=":"
|
||||
while read line; do
|
||||
set -- $line
|
||||
grep -q "^$1:" "$file2" || echo "$*"
|
||||
done < "$file1"
|
||||
IFS="$oIFS"
|
||||
}
|
||||
|
||||
# Rootfs mount options can be passed by declaring in the kernel
|
||||
# cmdline as much options as needed prefixed with "rootfs_mount_options."
|
||||
#
|
||||
# Example:
|
||||
# rootfs_mount_options.compress_algorithm=zstd rootfs_mount_options.noinline_data
|
||||
#
|
||||
compose_rootfs_mount_options() {
|
||||
local mount_options
|
||||
local cmdlinevar
|
||||
|
||||
for cmdlinevar in $(cat /proc/cmdline); do
|
||||
if [ "$cmdlinevar" != "${cmdlinevar#rootfs_mount_options\.}" ]; then
|
||||
append mount_options "${cmdlinevar#rootfs_mount_options\.}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo $mount_options
|
||||
}
|
||||
|
||||
do_mount_root() {
|
||||
mount_root start "$(compose_rootfs_mount_options)"
|
||||
boot_run_hook preinit_mount_root
|
||||
[ -f /sysupgrade.tgz -o -f /tmp/sysupgrade.tar ] && {
|
||||
echo "- config restore -"
|
||||
cp /etc/passwd /etc/group /etc/shadow /tmp
|
||||
cd /
|
||||
[ -f /sysupgrade.tgz ] && tar xzf /sysupgrade.tgz
|
||||
[ -f /tmp/sysupgrade.tar ] && tar xf /tmp/sysupgrade.tar
|
||||
missing_lines /tmp/passwd /etc/passwd >> /etc/passwd
|
||||
missing_lines /tmp/group /etc/group >> /etc/group
|
||||
missing_lines /tmp/shadow /etc/shadow >> /etc/shadow
|
||||
rm /tmp/passwd /tmp/group /tmp/shadow
|
||||
# Prevent configuration corruption on a power loss
|
||||
sync
|
||||
}
|
||||
}
|
||||
|
||||
[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root
|
||||
15
package/base-files/files/lib/preinit/99_10_failsafe_login
Normal file
15
package/base-files/files/lib/preinit/99_10_failsafe_login
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2006-2015 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
failsafe_shell() {
|
||||
local consoles="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | sed -e 's/^console=//' -e 's/,.*//')"
|
||||
[ -n "$consoles" ] || consoles=console
|
||||
for console in $consoles; do
|
||||
[ -c "/dev/$console" ] && while true; do
|
||||
ash --login <"/dev/$console" >"/dev/$console" 2>"/dev/$console"
|
||||
sleep 1
|
||||
done &
|
||||
done
|
||||
}
|
||||
|
||||
boot_hook_add failsafe failsafe_shell
|
||||
8
package/base-files/files/lib/preinit/99_10_run_init
Normal file
8
package/base-files/files/lib/preinit/99_10_run_init
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
run_init() {
|
||||
preinit_ip_deconfig
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main run_init
|
||||
Reference in New Issue
Block a user