Cloning, Integrated¶
See also
In Cloning, manual I show how to clone a working Mecrisp-Stellaris MCU using 8 manual steps, which is easy enough, but required a Serial Terminal with logging and so on. Boring, slow, and error prone.
Cloning, A New Method¶
In this article I will show a much easier single step method.
There is also a YouTube Video at: https://www.youtube.com/watch?v=od4pkkT9sS8
Included is a cloned kernel image of my default development kernel for a STM32F051, used in the STM32F0 Discovery Board. It contains a number of development aids, see the kernel README.txt for the contents and notes.
Note
This, like all my Forth apps, is designed for Unix, developed on FreeBSD, and should run on Linux, OpenBsd etc. The usual default Unix utils are used and most should already be present on your Unix system.
Dependencies¶
Gnu Screen
DD
arm-none-eabi-objcopy
st-flash
MD5 of some kind if you want to fingerprint the Kernel Image
clone.sh
f051-clone.fs
Operation¶
Install “clone.sh” in your path
Install “f051-clone.fs” in your path
Have a OPEN Interactive GnuScreen session to the development board/chip
Execute “clone.sh” … done.
Note
Clone will produce a binary named after the MD5sum, which is symlinked to ‘clone.bin’
Downloads¶
Download clone.sh
Download f051-clone.fs
Download f0-disco-48mhz.fs
Download Kernel ea85d79924b9c367f125f4fa12a6c6e3.bin
64KB
Download Wordlist ea85d79924b9c367f125f4fa12a6c6e3.words.txt
57KB
Download README ea85d79924b9c367f125f4fa12a6c6e3.README.txt
3.5KB
clone.sh¶
#!/bin/sh
# Program Name: clone.fs
# Date: Sat 5 Jan 2019 03:01:34 AEDT
# Copyright 2018 t.porter <terry@tjporter.com.au>, licensed under the GPL
# For Mecrisp-Stellaris by Matthias Koch.
# https://sourceforge.net/projects/mecrisp/
# Dependencies
# ------------
# * Gnu Screen
# * DD
# * arm-none-eabi-objcopy
# * st-flash
# * MD5 of some kind if you want to fingerprint the Kernel Image
#
# Operation
# ---------
#
# 1) Install "clone.sh" in your path
# 2) Have a OPEN Interactive GnuScreen session to the development board/chip
# xterm -title 'GnuScreen@cuaU0:460800 bps | CTRL A :quit | ' -e screen -t SCREEN1 -S SCREEN1 dev/cuaU0 460800,crtscts &
# 3) Execute "clone.sh" ... done.
AUTHOR="terry porter" # <--- CHANGE ME TO YOUR NAME !!!
SCREENAME="SCREEN1"
PROJECT=`basename $PWD`
LIBRARY=/home/tp/projects/programming-languages/forth/mecrisp-stellaris/library
FILE_NAME_1=f051-clone.fs
LOGFILE="screenlog.0"
HEXFILE=$PROJECT.hex
BINARYFILE=$PROJECT.bin
LEADING_BYTES_TO_REMOVE=8
TRAILING_BYTES_TO_REMOVE=8
FINGERPRINT_APPLICATION="md5"
# ............................................. #
screen -p $SCREENAME -X stuff 'compiletoram\n'
screen -p $SCREENAME -X stuff 'reset\n'
screen -p $SCREENAME -X stuff 'f0-disco-48mhz\n'
screen -p $SCREENAME -X readreg x $LIBRARY/$FILE_NAME_1
screen -p $SCREENAME -X paste x
screen -p $SCREENAME -X logtstamp off
screen -p $SCREENAME -X log on
screen -p $SCREENAME -X stuff 'clone\n'
# sleep while logging the memory dump or screen will cut it off while incomplete
sleep 10
screen -p $SCREENAME -X log off
BYTES=$(cat screenlog.0 | wc -c)
X=$((BYTES-LEADING_BYTES_TO_REMOVE))
Y=$((X-TRAILING_BYTES_TO_REMOVE))
dd if=$LOGFILE of=$HEXFILE bs=1 skip=$LEADING_BYTES_TO_REMOVE count=$Y
arm-none-eabi-objcopy -I ihex -O binary $HEXFILE $BINARYFILE
$FINGERPRINT_APPLICATION $BINARYFILE > $BINARYFILE.md5sum
rm $LOGFILE $HEXFILE
md5name=$(md5 -q $BINARYFILE)
screen -p $SCREENAME -X log on
screen -p $SCREENAME -X stuff 'words\n'
sleep 10
screen -p $SCREENAME -X log off
mv screenlog.0 $md5name.words.txt
mv $BINARYFILE $md5name.bin
ln -s $md5name.bin clone.bin
touch $md5name.README.txt
echo $md5name.README: Specific Notes regarding Mecrisp-Stellaris >$md5name.README.txt
echo Kernel $md5name.bin >>$md5name.README.txt
echo Created `date +%Y%m%d-%H%M` by $AUTHOR >> $md5name.README.txt
echo ----------------------------------------------------------------------------------- >> $md5name.README.txt
echo >> $md5name.README.txt
echo All Finished!
# Flash the binary:
# st-flash erase
# st-flash write $BINARYFILE 0x08000000