Skip to content

Commit

Permalink
meta-lxatac-software: tac-gadget: fix shellcheck warnings in helper s…
Browse files Browse the repository at this point in the history
…cripts

Signed-off-by: Leonard Göhrs <[email protected]>
  • Loading branch information
hnez committed Dec 15, 2023
1 parent a3e4cfd commit b7e16c6
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ set -e -u -o pipefail

source /usr/share/gadget/gadget-common

DEVDIR=$MAINDIR/gadget-audio
DEVDIR="${MAINDIR:?}/gadget-audio"

clear_gadget
setup_gadget

# Set up audio
mkdir $DEVDIR/functions/uac2.usb0
ln -s $DEVDIR/functions/uac2.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/uac2.usb0"
ln -s "${DEVDIR}/functions/uac2.usb0" "${DEVDIR}/configs/c.1"

start_gadget

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ PRODUCTNAME="LXATAC"
UDC_ADDR="49000000.usb-otg"

clear_gadget () {
if [ -s $DEVDIR/UDC ]; then
if [[ -s "${DEVDIR}/UDC" ]]; then
echo "USB Gadget is already set up."
exit 11
elif [ -s $MAINDIR/*/UDC ]; then
elif [[ -s "${MAINDIR}"/*/UDC ]]; then
echo "Remove existing USB Gadgets."
# when removing a gadget we have to reverse the init process
for dir in $MAINDIR/*/configs/*/strings/*; do
[ -d $dir ] && rmdir $dir
for dir in "${MAINDIR}"/*/configs/*/strings/*; do
test -d "${dir}" && rmdir "${dir}"
done
for func in $MAINDIR/*/configs/*.*/*.*; do
[ -e $func ] && rm $func
for func in "${MAINDIR}"/*/configs/*.*/*.*; do
test -e "${func}" && rm "${func}"
done
for conf in $MAINDIR/*/configs/*; do
[ -d $conf ] && rmdir $conf
for conf in "${MAINDIR}"/*/configs/*; do
test -d "${conf}" && rmdir "${conf}"
done
for func in $MAINDIR/*/functions/*.*; do
[ -d $func ] && rmdir $func
for func in "${MAINDIR}"/*/functions/*.*; do
test -d "${func}" && rmdir "${func}"
done
for str in $MAINDIR/*/strings/*; do
[ -d $str ] && rmdir $str
for str in "${MAINDIR}"/*/strings/*; do
test -d "${str}" && rmdir "${str}"
done
rmdir $MAINDIR/*
elif [ -n $DEVDIR ]; then
rmdir "${MAINDIR}"/*
elif [[ -n "${DEVDIR}" ]]; then
modprobe libcomposite
else
echo "Nothing to do here."
Expand All @@ -45,20 +45,20 @@ clear_gadget () {

setup_gadget () {
echo "Set up new USB Gadget."
mkdir $DEVDIR
echo $VENDOR > $DEVDIR/idVendor
echo $PRODUCT > $DEVDIR/idProduct
mkdir "${DEVDIR}"
echo "${VENDOR}" > "${DEVDIR}/idVendor"
echo "${PRODUCT}" > "${DEVDIR}/idProduct"

mkdir $DEVDIR/strings/0x409 # set language to EN-US
echo $SERIAL > $DEVDIR/strings/0x409/serialnumber
echo $VENDORNAME > $DEVDIR/strings/0x409/manufacturer
echo $PRODUCTNAME > $DEVDIR/strings/0x409/product
mkdir "${DEVDIR}/strings/0x409" # set language to EN-US
echo "${SERIAL:?}" > "${DEVDIR}/strings/0x409/serialnumber"
echo "${VENDORNAME}" > "${DEVDIR}/strings/0x409/manufacturer"
echo "${PRODUCTNAME}" > "${DEVDIR}/strings/0x409/product"

mkdir $DEVDIR/configs/c.1
mkdir $DEVDIR/configs/c.1/strings/0x409
echo Normal > $DEVDIR/configs/c.1/strings/0x409/configuration
mkdir "${DEVDIR}/configs/c.1"
mkdir "${DEVDIR}/configs/c.1/strings/0x409"
echo Normal > "${DEVDIR}/configs/c.1/strings/0x409/configuration"
}

start_gadget () {
echo $UDC_ADDR > $DEVDIR/UDC
echo "${UDC_ADDR}" > "${DEVDIR}/UDC"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ set -e -u -o pipefail

source /usr/share/gadget/gadget-common

DEVDIR=$MAINDIR/gadget-ethernet-serial
DEVDIR="${MAINDIR:?}/gadget-ethernet-serial"

clear_gadget
setup_gadget

# Set up ethernet
mkdir $DEVDIR/functions/ecm.usb0
echo $HOST_MAC > $DEVDIR/functions/ecm.usb0/host_addr
echo $DEV_MAC > $DEVDIR/functions/ecm.usb0/dev_addr
ln -s $DEVDIR/functions/ecm.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/ecm.usb0"
echo "${HOST_MAC:?}" > "${DEVDIR}/functions/ecm.usb0/host_addr"
echo "${DEV_MAC:?}" > "${DEVDIR}/functions/ecm.usb0/dev_addr"
ln -s "${DEVDIR}/functions/ecm.usb0" "${DEVDIR}/configs/c.1"

# Set up serial
mkdir $DEVDIR/functions/acm.usb0
ln -s $DEVDIR/functions/acm.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/acm.usb0"
ln -s "${DEVDIR}/functions/acm.usb0" "${DEVDIR}/configs/c.1"

start_gadget
exit 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
set -e -u -o pipefail

STORAGE=${1:-}
if [ -z $STORAGE ]; then
if [[ -z "${STORAGE}" ]]; then
echo "ERROR: No medium given. Start again with image location attached to command."
exit 1
fi

source /usr/share/gadget/gadget-common

DEVDIR=$MAINDIR/gadget-ethernet-storage
DEVDIR="${MAINDIR:?}/gadget-ethernet-storage"

clear_gadget
setup_gadget

# Set up ethernet
mkdir $DEVDIR/functions/ecm.usb0
echo $HOST_MAC > $DEVDIR/functions/ecm.usb0/host_addr
echo $DEV_MAC > $DEVDIR/functions/ecm.usb0/dev_addr
ln -s $DEVDIR/functions/ecm.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/ecm.usb0"
echo "${HOST_MAC:?} > ${DEVDIR}/functions/ecm.usb0/host_addr"
echo "${DEV_MAC:?} > ${DEVDIR}/functions/ecm.usb0/dev_addr"
ln -s "${DEVDIR}/functions/ecm.usb0" "${DEVDIR}/configs/c.1"

# Set up storage
mkdir $DEVDIR/functions/mass_storage.usb0
echo $STORAGE > $DEVDIR/functions/mass_storage.usb0/lun.0/file
ln -s $DEVDIR/functions/mass_storage.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/mass_storage.usb0"
echo "${STORAGE}" > "${DEVDIR}/functions/mass_storage.usb0/lun.0/file"
ln -s "${DEVDIR}/functions/mass_storage.usb0" "${DEVDIR}/configs/c.1"

start_gadget
exit 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ set -e -u -o pipefail

source /usr/share/gadget/gadget-common

DEVDIR=$MAINDIR/gadget-ethernet
DEVDIR="${MAINDIR:?}/gadget-ethernet"

clear_gadget
setup_gadget

# Set up ethernet
mkdir $DEVDIR/functions/ecm.usb0
echo $HOST_MAC > $DEVDIR/functions/ecm.usb0/host_addr
echo $DEV_MAC > $DEVDIR/functions/ecm.usb0/dev_addr
ln -s $DEVDIR/functions/ecm.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/ecm.usb0"
echo "${HOST_MAC:?}" > "${DEVDIR}/functions/ecm.usb0/host_addr"
echo "${DEV_MAC:?}" > "${DEVDIR}/functions/ecm.usb0/dev_addr"
ln -s "${DEVDIR}/functions/ecm.usb0" "${DEVDIR}/configs/c.1"

start_gadget

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
set -e -u -o pipefail

STORAGE=${1:-}
if [ -z $STORAGE ]; then
if [[ -z "${STORAGE}" ]]; then
echo "ERROR: No medium given. Start again with image location attached to command."
exit 1
fi

source /usr/share/gadget/gadget-common
source /usr/share/gadget/gadget-reports

DEVDIR=$MAINDIR/gadget-hid-storage
DEVDIR="${MAINDIR:?}/gadget-hid-storage"

clear_gadget
setup_gadget

# Set up mass storage
mkdir $DEVDIR/functions/mass_storage.usb0
echo $STORAGE > $DEVDIR/functions/mass_storage.usb0/lun.0/file
ln -s $DEVDIR/functions/mass_storage.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/mass_storage.usb0"
echo "${STORAGE}" > "${DEVDIR}/functions/mass_storage.usb0/lun.0/file"
ln -s "${DEVDIR}/functions/mass_storage.usb0" "${DEVDIR}/configs/c.1"

# Set up HID
mkdir $DEVDIR/functions/hid.usb0
echo 1 > $DEVDIR/functions/hid.usb0/protocol
echo 1 > $DEVDIR/functions/hid.usb0/subclass
echo 8 > $DEVDIR/functions/hid.usb0/report_length
report_keyboard > $DEVDIR/functions/hid.usb0/report_desc
ln -s $DEVDIR/functions/hid.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/hid.usb0"
echo 1 > "${DEVDIR}/functions/hid.usb0/protocol"
echo 1 > "${DEVDIR}/functions/hid.usb0/subclass"
echo 8 > "${DEVDIR}/functions/hid.usb0/report_length"
report_keyboard > "${DEVDIR}/functions/hid.usb0/report_desc"
ln -s "${DEVDIR}/functions/hid.usb0" "${DEVDIR}/configs/c.1"

start_gadget

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ set -e -u -o pipefail
source /usr/share/gadget/gadget-common
source /usr/share/gadget/gadget-reports

DEVDIR=$MAINDIR/gadget-hid
DEVDIR="${MAINDIR:?}/gadget-hid"

echo "Will export keyboard configuration."
clear_gadget
setup_gadget

# Set up HID
mkdir $DEVDIR/functions/hid.usb0
echo 1 > $DEVDIR/functions/hid.usb0/protocol
echo 1 > $DEVDIR/functions/hid.usb0/subclass
echo 8 > $DEVDIR/functions/hid.usb0/report_length
report_keyboard > $DEVDIR/functions/hid.usb0/report_desc
ln -s $DEVDIR/functions/hid.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/hid.usb0"
echo 1 > "${DEVDIR}/functions/hid.usb0/protocol"
echo 1 > "${DEVDIR}/functions/hid.usb0/subclass"
echo 8 > "${DEVDIR}/functions/hid.usb0/report_length"
report_keyboard > "${DEVDIR}/functions/hid.usb0/report_desc"
ln -s "${DEVDIR}/functions/hid.usb0" "${DEVDIR}/configs/c.1"

start_gadget

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

report_keyboard () {
# sample report descriptor, taken from Documentation/usb/gadget_hid.rst
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
set -e -u -o pipefail

STORAGE=${1:-}
if [ -z $STORAGE ]; then
if [[ -z "${STORAGE}" ]]; then
echo "ERROR: No medium given. Start again with image location attached to command."
exit 1
fi

source /usr/share/gadget/gadget-common

DEVDIR=$MAINDIR/gadget-serial-storage
DEVDIR="${MAINDIR:?}/gadget-serial-storage"

clear_gadget
setup_gadget

# Set up mass storage
mkdir $DEVDIR/functions/mass_storage.usb0
echo $STORAGE > $DEVDIR/functions/mass_storage.usb0/lun.0/file
ln -s $DEVDIR/functions/mass_storage.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/mass_storage.usb0"
echo "${STORAGE}" > "${DEVDIR}/functions/mass_storage.usb0/lun.0/file"
ln -s "${DEVDIR}/functions/mass_storage.usb0" "${DEVDIR}/configs/c.1"

# Set up serial
mkdir $DEVDIR/functions/acm.usb0
ln -s $DEVDIR/functions/acm.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/acm.usb0"
ln -s "${DEVDIR}/functions/acm.usb0" "${DEVDIR}/configs/c.1"

start_gadget

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ set -e -u -o pipefail

source /usr/share/gadget/gadget-common

DEVDIR=$MAINDIR/gadget-serial
DEVDIR="${MAINDIR:?}/gadget-serial"

clear_gadget
setup_gadget

# Set up serial
mkdir $DEVDIR/functions/acm.usb0
ln -s $DEVDIR/functions/acm.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/acm.usb0"
ln -s "${DEVDIR}/functions/acm.usb0" "${DEVDIR}/configs/c.1"

start_gadget

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
set -e -u -o pipefail

STORAGE=${1:-}
if [ -z $STORAGE ]; then
if [[ -z "${STORAGE}" ]]; then
echo "ERROR: No medium given. Start again with image location attached to command."
exit 1
fi

source /usr/share/gadget/gadget-common

DEVDIR=$MAINDIR/gadget-storage
DEVDIR="${MAINDIR:?}/gadget-storage"

clear_gadget
setup_gadget

# Set up storage
mkdir $DEVDIR/functions/mass_storage.usb0
echo $STORAGE > $DEVDIR/functions/mass_storage.usb0/lun.0/file
ln -s $DEVDIR/functions/mass_storage.usb0 $DEVDIR/configs/c.1
mkdir "${DEVDIR}/functions/mass_storage.usb0"
echo "${STORAGE}" > "${DEVDIR}/functions/mass_storage.usb0/lun.0/file"
ln -s "${DEVDIR}/functions/mass_storage.usb0" "${DEVDIR}/configs/c.1"

start_gadget

Expand Down

0 comments on commit b7e16c6

Please sign in to comment.