Remove sw-update recipe

This is an old useless recipe.

BugZID: 74466
This commit is contained in:
Alexandre Bard 2021-08-26 15:54:43 +02:00
parent fa238836ce
commit 62b15c5b53
3 changed files with 0 additions and 367 deletions

View File

@ -1,18 +0,0 @@
DESCRIPTION = "Software update script"
HOMEPAGE = "http://www.netmodule.com/"
LICENSE = "Proprietary"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Proprietary;md5=0557f9d92cf58f2ccdd50f62f8ac0b28"
RDEPENDS_${PN} = "e2fsprogs"
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}/${MACHINE}:"
PV = "1.0.1"
SRC_URI = " \
file://sw-update.sh \
file://sw_update_config"
do_install () {
install -D -m 0755 ${WORKDIR}/sw-update.sh ${D}/${bindir}/sw-update.sh
install -D -m 0666 ${WORKDIR}/sw_update_config ${D}/${sysconfdir}/default/sw_update_config
}

View File

@ -1,313 +0,0 @@
#!/bin/sh
# Software update script
# Local variables
IMAGE_LOCATION=""
IMAGE_FW_VERSION=""
IMAGE_HW_VERSION=""
IMAGE_PROD_COMPATIBILITY=""
IMAGE_MD5=""
TMP_RFS_MOUNT="/tmp/new_rfs"
# Load platform specific configuration
source /etc/default/sw_update_config
#-------------------------------------------------------------------------------
# Print log with level $1 and message $2
log() {
local level=${1?}
shift
local code=
local line="[$(date '+%F %T')] $level: $*"
if [ -t 2 ]
then
case "$level" in
INFO) code=36 ;;
DEBUG) code=32 ;;
WARN) code=33 ;;
ERROR) code=31 ;;
*) code=37 ;;
esac
echo -e "\e[${code}m${line}\e[0m"
else
echo "$line"
fi >&2
}
#-------------------------------------------------------------------------------
# Extract image header information and update local variables
extract_header_infos()
{
log INFO "Extracting firmware header information ... "
IMAGE_HEADER=$(head ${IMAGE_LOCATION} -n1 | sed 's/;bz2-image=.*//g')
log INFO "$IMAGE_HEADER"
oIFS=$IFS
IFS=";"
for field in "${FIELDS[@]}"
do
case "${field}" in
attocube-fw=*)
IMAGE_FW_VERSION=$(echo $field | cut -d= -f2)
;;
hwver=*)
IMAGE_HW_VERSION=$(echo $field | cut -d= -f2)
;;
prod_compatibility=*)
IMAGE_PROD_COMPATIBILITY=$(echo $field | cut -d= -f2)
;;
md5sum=*)
IMAGE_MD5=$(echo $field | cut -d= -f2)
;;
*)
log WARNING "Unknown header field ${field}"
;;
esac
done
IFS=$oIFS
}
#-------------------------------------------------------------------------------
# Check if the given image is compatible with the hardware
check_image_compatibility()
{
log INFO "Checking firmware compatibility ... "
# Prod variant
if [ "${PLATFORM_PROD_COMPATIBILITY}" != "${IMAGE_PROD_COMPATIBILITY}" ]
then
log ERROR "Incompatible product variant ${PLATFORM_PROD_COMPATIBILITY} != ${IMAGE_PROD_COMPATIBILITY}"
exit -1
fi
# HW version, the image can be for more than one HW
found=0
oIFS=$IFS
IFS='|'
for hw_vesion in $IMAGE_HW_VERSION
do
if [ "${hw_vesion}" = "${PLATFORM_HW_VERSION}" ]
then
found=1
break
fi
done
IFS=$oIFS
if [ "${found}" = "0" ]
then
log ERROR "Incompatible hardware version: ${PLATFORM_HW_VERSION} not in ${IMAGE_HW_VERSION}"
exit -1
fi
}
#-------------------------------------------------------------------------------
# Extract the image from the binary
extract_image()
{
EXTRACTED_IMAGE=$IMAGE_LOCATION.tmp
cat $IMAGE_LOCATION | sed '1{/.*bz2-image=/d}' > $EXTRACTED_IMAGE
}
#-------------------------------------------------------------------------------
# Check the md5sum of the firmware image
check_image_md5()
{
log INFO "Checking image MD5 ..."
COMPUTED_MD5=$(md5sum $EXTRACTED_IMAGE | awk '{print $1}')
if [ "${COMPUTED_MD5}" != "${IMAGE_MD5}" ]
then
log ERROR "MD5 mismatch ${COMPUTED_MD5} != ${IMAGE_MD5}"
exit -1
fi
}
#-------------------------------------------------------------------------------
# Flash the firmware on the inactive partition
flash_firmware()
{
if [ "${PLATFORM_ACTIVE_PARTITION}" == "1" ]
then
# the active partition is 1 so we have to flash 0
DEST_PARTITION=${PLATFORM_FIRST_PARTITION}
else
DEST_PARTITION=${PLATFORM_SECOND_PARTITION}
fi
log INFO "Formatting partition ${DEST_PARTITION} ..."
mkfs.ext4 ${DEST_PARTITION}
if [ "$?" != "0" ]
then
log ERROR "Formating parition ${DEST_PARTITION} failed"
exit -1
fi
log INFO "Extracting firmware ..."
mkdir -p ${TMP_RFS_MOUNT}
if [ ! -d ${TMP_RFS_MOUNT} ]
then
log ERROR "Couldn't create folder ${TMP_RFS_MOUNT}"
exit -1
fi
mount ${DEST_PARTITION} ${TMP_RFS_MOUNT}
if [ "$?" != "0" ]
then
log ERROR "Couldn't mount ${DEST_PARTITION} to ${TMP_RFS_MOUNT}"
exit -1
fi
export EXTRACT_UNSAFE_SYMLINKS=1
tar -xzf ${EXTRACTED_IMAGE} -C ${TMP_RFS_MOUNT}
if [ "$?" != "0" ]
then
log ERROR "Error extracting new firmware"
exit -1
fi
umount ${TMP_RFS_MOUNT}
if [ "${PLATFORM_ACTIVE_PARTITION}" == "1" ]
then
set_active_partition 0
else
set_active_partition 1
fi
}
cleanup()
{
log INFO "cleanup..."
rm $EXTRACTED_IMAGE
}
check_file()
{
if [ ! -e "$1" ]
then
log ERROR "Please provide a valid update image"
exit -1
else
IMAGE_LOCATION=$1
fi
}
get_bin()
{
echo $(dd if=$IMAGE_LOCATION bs=1 count=$2 skip=$1 2>/dev/null | hexdump -ve '1/1 "%.2x"')
}
update_linux()
{
log INFO "Starting linux update ..."
check_file $1
head=$(get_bin 0 2)
if [ "a$head" == "a1f8b" ]; then
log INFO "Found valid gzip archive"
# gzip header found, normal image
# Don't use the header stuff for now, move the file instead
EXTRACTED_IMAGE=$IMAGE_LOCATION
else
log INFO "Search gzip archive in image"
for i in $(seq 0 1024); do
head=$(get_bin $i 2)
if [ "a$head" == "a1f8b" ]; then
log INFO "Found gzip archive in image, extracting now"
EXTRACTED_IMAGE=$(mktemp)
dd if=$IMAGE_LOCATION bs=$i skip=1 of=$EXTRACTED_IMAGE 2>/dev/null
break
fi
done
test $i -eq 1024 && echo "Could not find a vaild gzip archive" && exit -1
fi
# This is not the original sw-update, we use plain tar.gz
# extract_header_infos
# check_image_compatibility
# extract_image
# Also don't check the md5 sum
# check_image_md5
log INFO "Installing linux update ..."
flash_firmware
cleanup
log INFO "Linux update succeed!"
}
update_uboot()
{
log INFO "Starting u-boot update ..."
check_file $1
head_should=$(echo -e "\x27\x05\x19\x56")
head_is=$(dd if=$1 bs=1 count=4 2>/dev/null)
if [ "$head_is" != "$head_should" ]; then
log ERROR "Header of the input image seems invalid, abort update"
return
fi
dd if=$1 of=$PLATFORM_MAIN_STORAGE bs=512 seek=768 &> /dev/null
if [ $? -ne 0 ]; then
log ERROR "Failed to write u-boot to mmcblk0"
return
fi
log INFO "u-boot update succeed!"
}
update_spl()
{
log INFO "Starting spl update ..."
check_file $1
head_should=$(echo -e "\x40\x00\x00\x00")
head_is=$(dd if=$1 bs=1 count=4 2>/dev/null)
if [ "$head_is" != "$head_should" ]; then
log ERROR "Header of the input image seems invalid, abort update"
return
fi
dd if=$1 of=$PLATFORM_MAIN_STORAGE bs=512 seek=256 &> /dev/null
if [ $? -ne 0 ]; then
log ERROR "Failed to write spl to $PLATFORM_MAIN_STORAGE"
return
fi
log INFO "spl update succeed!"
}
usage()
{
echo "Usage: $0 [ -l <linux-image>.tar.gz ] [ -u <u-boot>.img ] [ -s <spl>.img ] [ -h ]"
exit 2
}
############################ Start of script ###################################
if [ ! -b $PLATFORM_MAIN_STORAGE ]; then
log ERROR "Storage $PLATFORM_MAIN_STORAGE does not exist, please fix /etc/default/sw_update_config"
exit 1
fi
while getopts ":l:u:s:h" opt; do
case $opt in
l)
update_linux $OPTARG
;;
u)
update_uboot $OPTARG
;;
s)
update_spl $OPTARG
;;
h)
usage
;;
?)
log INFO "Invalid option: -$OPTARG"
usage
;;
esac
done
exit 0

View File

@ -1,36 +0,0 @@
PLATFORM_MAIN_STORAGE="/dev/mmcblk1"
PLATFORM_FIRST_PARTITION=$PLATFORM_MAIN_STORAGE"p1"
PLATFORM_SECOND_PARTITION=$PLATFORM_MAIN_STORAGE"p2"
PLATFORM_PROD_COMPATIBILITY=
PLATFORM_HW_VERSION=
get_active_partition()
{
boot_part=$(bd read boot_part)
if [ "$boot_part" == "None" ]; then
flag=$(bd read partition64.flags)
if [ $flag -ne 0 ]; then
boot_part=0
else
boot_part=1
fi
fi
echo $boot_part
}
PLATFORM_ACTIVE_PARTITION=$(get_active_partition)
set_active_partition()
{
boot_part=$(bd read boot_part)
if [ "$boot_part" == "None" ]; then
if [ $1 -eq 0 ]; then
bd write partition64.flags=128
bd write partition64_1.flags=0
else
bd write partition64_1.flags=128
bd write partition64.flags=0
fi
else
bd write boot_part=$1
fi
}