Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions board/opendingux/create-opk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ${HOST_DIR}/usr/bin/mksquashfs \
board/opendingux/opendingux_icon.png \
board/opendingux/opk_update_script.sh \
${TARGET_DIR}/usr/sbin/od-update \
${TARGET_DIR}/usr/bin/thisdevice \
${BINARIES_DIR}/${CONFIG}-update-${DATE}.opk \
-noappend -no-xattrs -all-root

Expand Down
115 changes: 105 additions & 10 deletions board/opendingux/opk_update_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,85 @@ cd `dirname $0`

DATE_FILE=./date.txt

export DIALOGOPTS="--colors --no-shadow"
if [ -f "$DATE_FILE" ] ; then
DATE="`cat $DATE_FILE`"
export DIALOGOPTS="$DIALOGOPTS --backtitle \"OpenDingux update $DATE\""
fi

echo "screen_color = (RED,RED,ON)" > /tmp/dialog_err.rc

# ----------
# 1. Select and confirm device
# ----------
THISDEVICE=./thisdevice
DEVICE=$($THISDEVICE --detect)
while true; do
if [ -n "$DEVICE" ]; then
eval $($THISDEVICE --device $DEVICE | grep DEVICE_NAME)
if [ -z "$DEVICE_NAME" ]; then
DEVICE=
continue
fi
DEVICE_LINE="
\Zb\Z3$DEVICE_NAME\Zn
"
if [ "$DEVICE_SELECTED" -eq 1 ]; then
TITLE="The selected device is"
else
TITLE="We detected this device as"
fi
DEVICE_CONFIRMATION="$TITLE:
$DEVICE_LINE
Flashing incorrect firmware will
likely make your device unbootable.

You can select your device from
manually from the list.

Proceed with the current device?"

dialog --yes-label 'Continue' --no-label 'Select' \
--yesno "$DEVICE_CONFIRMATION" 0 0
if [ $? -eq 0 ] ; then
break
fi
else
DEVICE_WARNING="\Zb\Z1We could not detect your device\Zn

Flashing incorrect firmware will
likely make your device unbootable.

Please CAREFULLY select your device
manually from the list."

dialog --defaultno --yes-label 'Select' --no-label 'Exit' \
--yesno "$DEVICE_WARNING" 0 0
if [ $? -ne 0 ] ; then
exit $?
fi
fi

exec 3>&1
NEW_DEVICE=$($THISDEVICE --devices $1 | while read i; do
echo $i | cut -d'-' -f1 | xargs
echo $i | cut -d'-' -f2- | xargs
done | tr \\n \\0 | xargs -0 \
dialog --menu "Select your device from the list" 0 0 3 \
2>&1 1>&3)
EXIT_STATUS=$?
exec 3>&-
if [ $EXIT_STATUS -ne 0 ] ; then
continue
fi

DEVICE=$NEW_DEVICE
DEVICE_SELECTED=1
done

# ----------
# 2. Final confirmation
# ----------
DISCLAIMER="\Zb\Z3NOTICE\Zn

While we carefully constructed this
Expand All @@ -16,30 +95,31 @@ you perform the update.

Do you want to update now?"

UP_TO_DATE=yes

if [ -f "$DATE_FILE" ] ; then
DATE="`cat $DATE_FILE`"
export DIALOGOPTS="--colors --no-shadow --backtitle \"OpenDingux update $DATE\""
fi

echo "screen_color = (RED,RED,ON)" > /tmp/dialog_err.rc

dialog --defaultno --yes-label 'Update' --no-label 'Cancel' --yesno "$DISCLAIMER" 0 0
if [ $? -ne 0 ] ; then
exit $?
fi

# ----------
# 3. Flashing
# ----------
clear
echo 'Update in progress - please be patient.'
echo

if [ "$(whoami)" = "root" -a ! -x /usr/sbin/od-update ]; then
./od-update $1
./od-update "$1" "$DEVICE"
else
# Old firmware's od-update requires equally one argument
# and ENV variables are restricted by sudo
# so the only way to pass the device is via a tmp file
echo "$DEVICE" > /tmp/_force_thisdevice
sudo od-update $1
fi

# ----------
# 4. Checking status
# ----------
ERR=$?
if [ $ERR -ne 0 ] ; then
case $ERR in
Expand Down Expand Up @@ -73,13 +153,28 @@ if [ $ERR -ne 0 ] ; then
11)
ERR_MSG="Updated bootloader is corrupted!\nPlease report this bug!"
;;
12)
ERR_MSG="Can't detect the device.\nPlease ensure that you are running a stock firmware"
;;
13)
ERR_MSG="Bootloader file $BOOTLOADER is missing\nPlease report this bug!"
;;
14)
ERR_MSG="Device tree file $DEVICETREE is missing\nPlease report this bug!"
;;
*)
ERR_MSG="Unexpected return code: $ERR\nPlease report this bug!"
;;
esac

export DIALOGRC="/tmp/dialog_err.rc"
dialog --msgbox "ERROR!\n\n${ERR_MSG}" 0 0
exit $ERR
fi

# ----------
# 5. Reboot
# ----------
case $1 in
rs90)
LAST_KERNEL=START
Expand Down
125 changes: 125 additions & 0 deletions board/opendingux/target_skeleton/usr/bin/thisdevice
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/sh

display_usage() {
cat <<-END
Usage $0 <command> [argument]:

Available commands are:
--families Show list of supported device families
--devices <family>
Show list of devices for the given family
--device <device>
Show device information, including bootloader and devicetree
--detect Try to detect the current device
--help, -h Show this message
END
}

DEVICES=$(cat <<-END
gcw0 ;gcw,zero ;GCW-Zero;v20_mddr_512mb;gcw0;
gcw0 ;gcw,zero_proto ;GCW-Zero Prototype (256 MiB);v11_ddr2_256mb;gcw0_proto;
gcw0 ;ylm,rg350 ;Anbernic RG-350 / RG-350P;rg350;rg350;
gcw0 ;ylm,rg350m ;Anbernic RG-350M (metal cover, 640x480 IPS screen);rg350;rg350m;
gcw0 ;ylm,rg280v ;Anbernic RG-280V;rg350;rg280v;
gcw0 ;ylm,rg280m ;Anbernic RG-280M;rg350;rg280m;
gcw0 ;wolsen,playgo ;PlayGo or PocketGo 2 second gen (v2, with a reset button);rg350;playgo;
gcw0 ;wolsen,pocketgo2;PocketGo 2 or PlayGo first gen (v1, without a reset button);v20_mddr_512mb;pocketgo2;
rs90 ;ylm,rs90v21 ;Anbernic RS-90 v2.1;v21;rs90;nand
rs90 ;ylm,rs90v30 ;Anbernic RS-90 v3.0;v30;rs90;nand
rs90 ;ylm,rg99 ;Anbernic RG-99;v21;rg99;nand
lepus;ylm,rs97 ;Anbernic RS-97 v2.0;lepus;rs97
lepus;ylm,rg300 ;Anbernic RG-300 non-IPS;lepus;rg300
lepus;wolsen,ldkv ;LDK (vertical);lepus;ldkv;
lepus;wolsen,ldkh ;LDK (horizontal);lepus;ldkh;
END
)

if [ $# -le 0 ]; then
display_usage
exit 1
fi

if [ $1 = "--help" ] || [ $1 = "-h" ]; then
display_usage
exit 0
fi

detect_device() {
HWVARIANT_CMDLINE="$(sed -n 's/.*hwvariant=\([[:alnum:]_]\+\).*/\1/p' /proc/cmdline)"
DEVICE=
if [ -e /sys/firmware/devicetree/base/compatible ] ; then
DEVICE=$(sed -n 's/\(.*\)ingenic.*/\1/p' /sys/firmware/devicetree/base/compatible)
# two versions of rs90 use the same devicetree
[ "$DEVICE" = ylm,rs90 ] && DEVICE="$DEVICE$HWVARIANT_CMDLINE"
elif [ "$HWVARIANT_CMDLINE" = "rg350" ] ; then
if [ -r /sys/devices/platform/jz-lcd.0/graphics/fb0/modes -a \
"$(grep '640x480' /sys/devices/platform/jz-lcd.0/graphics/fb0/modes)" ] ; then
DEVICE=ylm,rg350m
elif [ "$(uname -v)" = "#128 Fri May 29 11:19:07 CST 2020" ] ; then
DEVICE=ylm,rg280m
elif [ "$(uname -v)" = "#171 Tue Jun 30 18:36:05 CST 2020" ] ; then
DEVICE=ylm,rg280v
elif [ "$(uname -v)" = "#2 Sat Mar 28 16:19:20 CST 2020" ] ; then
DEVICE=wolsen,playgo
else
DEVICE=ylm,rg350
fi
else
case "$HWVARIANT_CMDLINE" in
"GCW Zero"|v20_mddr_512mb)
DEVICE=gcw,zero
;;
v11_ddr2_256mb)
DEVICE=gcw,zero_proto
;;
*)
echo "Unknown device." 1>&2
exit 1
;;
esac
fi
echo $DEVICE
}

case $1 in
--families)
echo "$DEVICES" | cut -d';' -f1 | uniq
;;
--devices)
FAMILY=$2
if ! echo "$DEVICES" | cut -d';' -f1 | grep -qe "^$FAMILY[[:space:]]*$"; then
echo "unknown family $FAMILY (--families will show all families)" 1>&2
exit 1
fi

echo "$DEVICES" | grep -e "^$FAMILY" | while read i; do
echo "$(echo "$i" | cut -d';' -f2)" - $(echo $i | cut -d';' -f3)
done
;;
--device)
DEVICE=$2
if ! echo "$DEVICES" | grep -qe ";$DEVICE[[:space:]]*;"; then
echo "unknown device $DEVICE (--devices will show all devices)" 1>&2
exit 1
fi

LINE=$(echo "$DEVICES" | grep -e ";$DEVICE" | head -n1)
STORAGE=$(echo "$LINE" | cut -d';' -f6)
if [ -z "$STORAGE" ]; then
STORAGE=mmc
fi
echo 'DEVICE_FAMILY="'$(echo "$LINE" | cut -d';' -f1 | xargs)'"'
echo 'DEVICE_CODE="'$(echo "$LINE" | cut -d';' -f2 | xargs)'"'
echo 'DEVICE_NAME="'$(echo "$LINE" | cut -d';' -f3 | xargs)'"'
echo 'DEVICE_BOOTLOADER="'$(echo "$LINE" | cut -d';' -f4)'"'
echo 'DEVICE_DEVICETREE="'$(echo "$LINE" | cut -d';' -f5)'"'
echo 'DEVICE_STORAGE="'$STORAGE'"'
;;
--detect)
detect_device
;;
*)
echo "invalid command $1 (-h will show valid options)" 1>&2
exit 1
;;
esac
Loading