Merge pull request #174 from ThomasKaiser/master

Fix reboot issues with H3 devices
This commit is contained in:
Igor Pečovnik 2016-02-24 07:59:21 +01:00
commit c2482e019e
9 changed files with 191 additions and 80 deletions

View File

@ -21,4 +21,4 @@ bootz 0x48000000
#--------------------------------------------------------------------------------------------------------------------------------
fi
# Recompile with:
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr

View File

@ -1,5 +1,5 @@
# Wired adapter #1
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
# hwaddress ether # if you want to set MAC manually
# pre-up /sbin/ifconfig eth0 mtu 3838 # setting MTU for DHCP, static just: mtu 3838
@ -19,4 +19,4 @@ auto eth0
#
# Local loopback
auto lo
iface lo inet loopback
iface lo inet loopback

View File

@ -539,9 +539,6 @@ gmac_used = 2
;gmac_mdio = port:PD17<2><default><3><default>
gmac_power1 =
[gmac_phy_power]
gmac_phy_power_en = port:PL08<1><default><default><0>
;--------------------------------------------------------------------------------
;vip (video input port) configuration
;vip_used: 0:disable 1:enable

View File

@ -351,9 +351,6 @@ pwm_positive = port:PA05<3><0><default><default>
gmac_used = 2
gmac_power1 =
[gmac_phy_power]
gmac_phy_power_en = port:PL08<1><default><default><0>
[csi0]
vip_used = 1
vip_mode = 0

View File

@ -351,9 +351,6 @@ pwm_positive = port:PA05<3><0><default><default>
gmac_used = 2
gmac_power1 =
[gmac_phy_power]
gmac_phy_power_en = port:PL08<1><default><default><0>
[csi0]
vip_used = 1
vip_mode = 0

View File

@ -353,9 +353,6 @@ pwm_positive = port:PA05<3><0><default><default>
gmac_used = 2
gmac_power1 =
[gmac_phy_power]
gmac_phy_power_en = port:PL08<1><default><default><0>
[csi0]
vip_used = 1
vip_mode = 0

View File

@ -217,7 +217,7 @@
#build 3wip
LINUXFAMILY="sun8i"
BOOTCONFIG="orangepi_plus_defconfig"
MODULES="8189es gpio_sunxi w1-sunxi w1-gpio w1-therm"
MODULES="8189es"
MODULES_NEXT=""
CPUMIN="480000"
CPUMAX="1296000"
@ -229,7 +229,7 @@
#build 3wip
LINUXFAMILY="sun8i"
BOOTCONFIG="orangepi_pc_defconfig"
MODULES="8189es gpio_sunxi w1-sunxi w1-gpio w1-therm"
MODULES="8189es"
MODULES_NEXT=""
CPUMIN="480000"
CPUMAX="1296000"
@ -241,7 +241,7 @@
#build 3wip
LINUXFAMILY="sun8i"
BOOTCONFIG="orangepi_pc_defconfig"
MODULES="gpio_sunxi w1-sunxi w1-gpio w1-therm"
MODULES=""
MODULES_NEXT=""
CPUMIN="480000"
CPUMAX="1296000"
@ -253,7 +253,7 @@
#build 3wip
LINUXFAMILY="sun8i"
BOOTCONFIG="orangepi_one_defconfig"
MODULES="gpio_sunxi w1-sunxi w1-gpio w1-therm"
MODULES=""
MODULES_NEXT=""
CPUMIN="648000"
CPUMAX="1200000"
@ -265,7 +265,7 @@
#build 3wip
LINUXFAMILY="sun8i"
BOOTCONFIG="orangepi_pc_defconfig"
MODULES="8189es gpio_sunxi w1-sunxi w1-gpio w1-therm"
MODULES="8189es"
MODULES_NEXT=""
CPUMIN="648000"
CPUMAX="1200000"

View File

@ -15,6 +15,15 @@
#
# Create this file to speed up boot process
#
# Immediately exit if not called correctly
if [ "X$1" != "Xstart" ]; then
exit 1
fi
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# create helper script to set swap settings
cat > /tmp/create_swap.sh <<EOT
#!/bin/bash
#
@ -56,28 +65,24 @@ if [ -f "/var/run/reboot" ]; then reboot; fi
rm -f /tmp/create_swap.sh
EOT
chmod +x /tmp/create_swap.sh
#
#
#
collect_informations() {
# get some info about the board
CURKERNE=$(uname -r | sed 's/\([0-9]\+\.[0-9]\+\)\..*/\1/')
DISTRIBUTION=$(lsb_release -cs)
HARDWARE=$(awk '/Hardware/ {print $3}' </proc/cpuinfo)
#
#
# get some info about the board
CURKERNE=$(uname -r | sed 's/\([0-9]\+\.[0-9]\+\)\..*/\1/')
DISTRIBUTION=$(lsb_release -cs)
HARDWARE=$(awk '/Hardware/ {print $3}' </proc/cpuinfo)
root_device=$(mountpoint -d /)
for file in /dev/* ; do
CURRENT_DEVICE=$(printf "%d:%d" $(stat --printf="0x%t 0x%T" $file))
if [ $CURRENT_DEVICE = $root_device ]; then
root_partition=$file
break;
fi
done
rootfstype=$(blkid -s TYPE -o value $root_partition)
set -e
root_device=$(mountpoint -d /)
for file in /dev/* ; do
CURRENT_DEVICE=$(printf "%d:%d" $(stat --printf="0x%t 0x%T" $file))
if [ $CURRENT_DEVICE = $root_device ]; then
root_partition=$file
break;
fi
done
rootfstype=$(blkid -s TYPE -o value $root_partition)
set -e
} # collect_informations
display_alert() {
if [ "$DISTRIBUTION" == "wheezy" ]; then
@ -88,15 +93,16 @@ display_alert() {
}
autodetect_h3() {
# This function adjusts script.bin and cpufreq settings based on /run/machine.id so
# that a single OS image built for Orange Pi Plus can be shipped.
# This function adjusts script.bin, hostname and cpufreq settings based on
# /run/machine.id so that two OS images (one built for Orange Pi Plus and one
# for the other H3 devices using the internal Ethernet PHY) can be shipped.
# wait for armhwinfo
sleep 3
read MACHINE </run/machine.id
case ${MACHINE} in
"Orange Pi+"*)
:
ln -sf /boot/bin/orangepiplus.bin /boot/script.bin
;;
"Orange Pi 2"*)
ln -sf /boot/bin/orangepi2.bin /boot/script.bin
@ -120,10 +126,6 @@ autodetect_h3() {
touch /var/run/reboot
} # autodetect_h3
#if [ "X${HARDWARE}" = "Xsun8i" ]; then
# autodetect_h3
#fi
do_expand_rootfs() {
device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0)
PARTITIONS=$(($(fdisk -l $device | grep $device | wc -l)-1))
@ -142,29 +144,32 @@ do_expand_rootfs() {
display_alert "Automatic reboot is needed. Please wait"
update-rc.d resize2fs defaults >/dev/null 2>&1
fi
return 0
return 0
}
case "$1" in
start)
display_alert "Force password change upon first login"
chage -d 0 root
if [[ "$rootfstype" == "ext4" && ! -f "/root/.no_rootfs_resize" ]]; then
display_alert "Expand ext4 root filesystem"
do_expand_rootfs
fi
display_alert "Creating 128Mb emergency swap area"
display_alert "SSH keys recreation. One moment please"
display_alert "Updating packages"
#resize2fs $root_partition
/tmp/create_swap.sh &
update-rc.d -f firstrun remove >/dev/null 2>&1
;;
*)
exit 1
;;
esac
main() {
collect_informations
display_alert "Force password change upon first login"
chage -d 0 root
if [[ "$rootfstype" == "ext4" && ! -f "/root/.no_rootfs_resize" ]]; then
display_alert "Expand ext4 root filesystem"
do_expand_rootfs
fi
display_alert "Creating 128Mb emergency swap area"
display_alert "SSH keys recreation. One moment please"
display_alert "Updating packages"
/tmp/create_swap.sh &
if [ "X${HARDWARE}" = "Xsun8i" ]; then
autodetect_h3
fi
update-rc.d -f firstrun remove >/dev/null 2>&1
sed -i 's/allow-hotplug\ eth0/auto eth0/' /etc/network/interfaces.default
} # main
main
exit 0

View File

@ -14,6 +14,8 @@
#
# Purpose of this script is to display the available reasonable settings and
# let the user choose from them to adjust fex file accordingly afterwards.
# In the meantime it's also possible to specify available resolutions on the
# command line. To display possible values use the -h switch.
#
# If HDMI-to-DVI adapters are used another fix has to be applied to the fex
# file: http://linux-sunxi.org/Orange_Pi_One#HDMI_to_DVI_converters -- so ask
@ -23,6 +25,11 @@
#
# CHANGES:
#
# v0.2: Added non-interactive mode. You can provide one or two arguments on
# the command line, eg. 'h3disp -m 1080p60 -d' (1920x1080@60Hz DVI) or
# 'h3disp -m 720i' (1280x720@30Hz HDMI). Complete list of modes via
# 'h3disp -h'
#
# v0.1: Initial release to adjust display settings in script.bin on commonly
# used Debian based OS images for H3 devices running Linux.
#
@ -52,22 +59,134 @@ Main() {
exit 1
fi
# Provide a list with possible HDMI display settings and store the chosen
# one in the HDMIMode variable
:
# ask the user whether he uses a HDMI-to-DVI converter and if true then
# set DVIUsed=TRUE
:
HDMIMode=4
DVIUsed=TRUE
# interactive mode if no arguments are provided -- currently not implemented
# otherwise we try to parse the command line arguments and use these
if [ $# -eq 0 ]; then
DisplayUsage ; exit 0
# Provide a list with possible HDMI display settings and store the chosen
# one in the HDMIMode variable
:
# ask the user whether he uses a HDMI-to-DVI converter and if true then
# set DVIUsed=TRUE
:
else
ParseOptions "$@"
case ${VideoMode} in
0|480i) # res
HDMIMode=0
;;
1|576i) # res
HDMIMode=1
;;
2|480p) # res
HDMIMode=2
;;
3|576p) # res
HDMIMode=3
;;
4|720p50|1280x720p50) # res
HDMIMode=4
;;
5|720p60|720p|1280x720p60) # res
HDMIMode=5
;;
6|1080i50|1920x1080i50) # res
HDMIMode=6
;;
7|1080i60|1080i|1920x1080i60) # res
HDMIMode=7
;;
8|1080p24|1920x1080p24) # res
HDMIMode=8
;;
9|1080p50|1920x1080p50) # res
HDMIMode=9
;;
10|1080p60|1080p|1920x1080p60) # res
HDMIMode=10
;;
*)
if [ "X${VideoMode}" = "X" ]; then
echo -e "$0: missing video mode. Try one of the following:\n"
else
echo -e "$0: illegal video mode \"-m ${VideoMode}\". Try one of the following:\n"
fi
ShowVideoModes
exit 0
;;
esac
fi
echo -e "Now trying to patch script.bin with your settings. \c"
PatchScriptBin ${HDMIMode} ${DVIUsed}
echo "Successfully finished. Please reboot for changes to take effect"
# Let's see whether we have to collect debug output
case ${Debug} in
TRUE)
which curl >/dev/null 2>&1 || apt-get -f -qq -y install curl
echo -e "\nDebug output has been collected at the following URL: \c"
(cat "${DebugOutput}"; echo -e "\n\n\nfex contents:\n" ; cat "${MyTmpFile}") \
| curl -F 'sprunge=<-' http://sprunge.us
;;
esac
} # Main
ParseOptions() {
while getopts 'hvVdDm:M:' c ; do
case ${c} in
h)
DisplayUsage
exit 0
;;
v|V)
# Increase verbosity. Will try to upload debug output from script
# to ease reporting of bugs or strange behaviour. Use only when
# asked for.
export Debug=TRUE
DebugOutput="$(mktemp /tmp/${0##*/}.XXXXXX)"
trap "rm \"${DebugOutput}\" ; exit 0" 0 1 2 3 15
set -x
exec 2>"${DebugOutput}"
;;
d|D)
# use HDMI-to-DVI converter
export DVIUsed=TRUE
;;
m|M)
# The HDMI mode in question
export VideoMode=${OPTARG}
;;
esac
done
} # ParseOptions
DisplayUsage() {
echo -e "Usage: ${0##*/} -m [video mode] [-d]\n"
echo -e "############################################################################\n"
echo "Detailed Description:"
grep "^#" "$0" | grep -v "^#\!/bin/bash" | sed 's/^#//'
echo -e "\n Short summary: This is a tool to set the display resolution of your Orange"
echo -e " Pi by patching script.bin.\n\n In case you use an HDMI-to-DVI converter\c"
echo -e " please use the -d switch.\n\n The resolution can be set using the -m switch.\c"
echo -e " The following resolutions\n are currently supported:\n"
ShowVideoModes
echo -e "############################################################################\n"
} # DisplayUsage
ShowVideoModes() {
OIFS=${IFS}
IFS="|"
awk -F" " '/ # res/ {print $1}' <"${0}" | tr -d ')' | grep -v 'awk' | while read ; do
set ${REPLY}
echo -e " ${2}\tuse \"-m ${2}\" or \"-m ${1}\""
done
IFS=${OIFS}
echo -e "\n Two examples:\n\n ${0##*/} -m 1080p60 -d' (1920x1080@60Hz DVI)"
echo -e " ${0##*/} -m 720i' (1280x720@30Hz HDMI)\n"
} # ShowVideoModes
PatchScriptBin() {
# This function will be called with 2 arguments:
# $1 HDMI mode to set
@ -96,7 +215,6 @@ PatchScriptBin() {
# create temp file
MyTmpFile="$(mktemp /tmp/${0##*/}.XXXXXX)"
# trap "rm \"${MyTmpFile}\" ; exit 0" 0 1 2 3 15
# convert script.bin to temporary fex file
bin2fex <"${ScriptBin}" 2>/dev/null | grep -v "^screen0_output" \
@ -137,4 +255,4 @@ InstallSunxiTools() {
make install
} # InstallSunxiTools
Main
Main "$@"