Skip to content

Instantly share code, notes, and snippets.

@dopsi
Last active July 25, 2022 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dopsi/b043efafcae9424f06b8634e3d9afb8c to your computer and use it in GitHub Desktop.
Save dopsi/b043efafcae9424f06b8634e3d9afb8c to your computer and use it in GitHub Desktop.
Example script to flash the eMMC memory of the STM32MP157C Odyssey SoM
#! /bin/sh
set -eu
# Config
IMAGES_DIR=/mnt/images # this is the images directory as spit out by buildroot
EMMC_BLK=mmcblk1
# Check if mounted and attempt to mount
if [ ! -d "${IMAGES_DIR}" ] ; then
echo "warn: ${IMAGES_DIR} not found, attempting to mount /dev/sda1 ..."
mount /dev/sda1 /mnt
fi
# Check required elements
echo "=> Checking if required elements are found ..."
if [ ! -f "${IMAGES_DIR}/u-boot-spl.stm32" ] ; then
echo "error: missing '${IMAGES_DIR}/u-boot-spl.stm32'"
exit 1
fi
if [ ! -f "${IMAGES_DIR}/sdcard.img" ] ; then
echo "error: missing '${IMAGES_DIR}/sdcard.img'"
exit 1
fi
if [ ! -e "/dev/${EMMC_BLK}boot0" ] ; then
echo "error: missing '/dev/${EMMC_BLK}boot0'"
exit 1
fi
if [ ! -e "/dev/${EMMC_BLK}boot1" ] ; then
echo "error: missing '/dev/${EMMC_BLK}boot1'"
exit 1
fi
if [ ! -e "/dev/${EMMC_BLK}" ] ; then
echo "error: missing '/dev/${EMMC_BLK}'"
exit 1
fi
if grep -q ${EMMC_BLK} /proc/cmdline ; then
echo "error: booted from ${EMMC_BLK}, cannot flash it"
exit 1
fi
# Mark eMMC boot partitions as writable
echo "=> Making boot partition writable ..."
echo 0 > /sys/block/${EMMC_BLK}boot0/force_ro
# Write partition data
echo "=> Write boot partition ..."
dd if=${IMAGES_DIR}/u-boot-spl.stm32 of=/dev/${EMMC_BLK}boot0
echo "=> Write user partition ..."
dd if=${IMAGES_DIR}/sdcard.img of=/dev/${EMMC_BLK}
echo "=> Syncing ..."
sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment