Skip to content

Instantly share code, notes, and snippets.

@wido
Last active October 11, 2024 19:28
Show Gist options
  • Save wido/e0883399e8c9146fe873a9483874511a to your computer and use it in GitHub Desktop.
Save wido/e0883399e8c9146fe873a9483874511a to your computer and use it in GitHub Desktop.
Tesla Model S/X MCU1 eMMC image creator
#!/bin/bash
#
# Create a 8GB eMMC image for Tesla Model S/X MCU1
#
# Example usage: ./mkteslaemmcimg.sh ./vinXXXXX.img ./develop-2019.20.2.1-16-5659e07dfd.img
#
set -e
FIRMWARE=$2
IMAGE=$1
SIZE=7818182656
INDEX=$((10 + RANDOM % 100))
LOOP="loop${INDEX}"
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <image file> <firmware file>"
exit 255
fi
if [ -e "${IMAGE}" ]; then
echo "Error: ${IMAGE} already exists"
exit 1
fi
if [ ! -f "${FIRMWARE}" ]; then
echo "Error: ${FIRMWARE} does not exist"
exit 2
fi
echo "Info: Writing empty image file=${IMAGE} size=${SIZE}"
dd if=/dev/zero of=${IMAGE} bs=1024 count=7634944
echo "Info: Creating partitions on ${IMAGE}"
parted -s ${IMAGE} mklabel msdos
parted -s ${IMAGE} mkpart primary 4096s 2101247s
parted -s ${IMAGE} mkpart primary 2101248s 4198399s
parted -s ${IMAGE} mkpart primary 4198400s 4460543s
parted -s ${IMAGE} mkpart primary 4460544s 15269887s
echo "Info: Setting up loop device ${LOOP}"
sudo losetup -P ${LOOP} ${IMAGE}
echo "Info: Writing ${FIRMWARE} to partitions 1 and 2"
sudo dd if=${FIRMWARE} of=/dev/${LOOP}p1
sudo dd if=${FIRMWARE} of=/dev/${LOOP}p2
echo "Info: Creating empty ext3 filesystem on partitions 3 and 4"
sudo mkfs.ext3 /dev/${LOOP}p3
sudo mkfs.ext3 /dev/${LOOP}p4
echo "Info: Cleaning up loop device ${LOOP}"
sudo losetup -d /dev/${LOOP}
@wido
Copy link
Author

wido commented Feb 3, 2020

Where do we get a firmware file from?

They are not freely available. You will need to have your sources on there to get the firmware.

@manfredasbaksys
Copy link

Is it possible to edit /vinXXXXX.img and change vin? or its encrypted?

@wido
Copy link
Author

wido commented May 19, 2020

Is it possible to edit /vinXXXXX.img and change vin? or its encrypted?

vinXXXXX.img is the output file. You can name it whatever you like.

@incccs
Copy link

incccs commented Aug 14, 2020

What i missing when i write got fw.img does not exist???
./mkteslaemmcimg.sh --vin.img --fw.img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment