Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: Add i2c enabler to make-prep.sh #886

Merged
Merged
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
39 changes: 39 additions & 0 deletions image/make-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SCRIPT_NAME=$(basename $0)
SCRIPT_DIR=$(dirname $0)
VERBOSE=0
ENABLE_CONSOLE=1
ENABLE_I2C=1
ENABLE_WIFI=0
WIFI_SSID=
WIFI_PASSWORD=
Expand All @@ -39,6 +40,7 @@ where OPTION can be one of:
--ssid SSID Specify the SSID for Wifi access
--password PWD Specify the password for wifi access
--wifi-country CC Specify the WiFi country code to use (default: GB)
--no-i2c Disable I2C bus
--hostname NAME Specify the hostname
--dd DEV Issue a dd command to copy the image to an sdcard
--summary Print summary of changed files
Expand Down Expand Up @@ -82,6 +84,35 @@ END
fi
}

###########################################################################
#
# Enables the I2C bus
#
enable_i2c_bus() {
CONFIG="${BOOT_MOUNTPOINT}/config.txt"
local pattern="dtparam=i2c_arm=on"
if grep -q "$pattern" ${CONFIG} ; then
sudo sed -i "s/.*$pattern/$pattern/g" "${CONFIG}"
else
echo "Enabling I2C bus"
sudo sh -c "cat >> '${CONFIG}'" <<END

$pattern
END
fi

CONF="${ROOT_MOUNTPOINT}/etc/modules"
if sudo grep -q "i2c-dev" "${CONF}:"; then
sudo sed -i "s/.*i2c-dev/i2c-dev/g" "${CONF}"
else
sudo sh -c "cat >> '${CONF}'" <<END

i2c-dev
END
fi
}


###########################################################################
#
# Enables SSH
Expand Down Expand Up @@ -211,6 +242,9 @@ main() {
HOSTNAME="${!OPTIND}"
OPTIND=$(( OPTIND + 1 ))
;;
no-i2c)
ENABLE_I2C=0
;;
noconsole)
ENABLE_CONSOLE=0
;;
Expand Down Expand Up @@ -285,6 +319,7 @@ main() {
echo " IMG_FILENAME = ${IMG_FILENAME}"
echo " PREP_FILENAME = ${PREP_FILENAME}"
echo "ENABLE_CONSOLE = ${ENABLE_CONSOLE}"
echo " ENABLE_I2C = ${ENABLE_I2C}"
echo " ENABLE_WIFI = ${ENABLE_WIFI}"
echo " WIFI_SSID = ${WIFI_SSID}"
echo " WIFI_PASSWORD = ${WIFI_PASSWORD}"
Expand Down Expand Up @@ -375,6 +410,10 @@ main() {
enable_serial_console
fi

if [ "${ENABLE_I2C}" == 1 ]; then
enable_i2c_bus
fi

if [ "${ENABLE_WIFI}" == 1 ]; then
enable_wifi
fi
Expand Down