I have received a Pine Time dev-kit this week and I would like
to provide some information to fellow hobbyist developers on
how I got some things done.
The hard part is starting your development environment. I have
worked on another embedded project but we already had a bootloader
present on the SOC which implemented a Bluetooth DFU.
This time instead my developer environment has to grow to include
some physical stuff. Namely a Jlink programmer/debugger and some
more wiring.
On the Pine Time wiki page there is the pinout for the SWD
pins but not much more information on how to get things done. This is
my take.
I will be using OpenOCD and this is my configuration
to talk to the dev-kit.
The physical connection should not be much trouble but then you
may get some interesting warnings from openocd.
What does this mean? What is a MEM-AP? Should I send the damn thing back?
This is perfectly normal in embedded development, you are required to
read the damn manual and figure out where the information is. Most
likely in a 400 page PDF. Love the PDF, you may not now but you will.
But what if you are a student trying to take over the world with
your new smartwatch firmware and only have the weekends to sleep and
do embedded development? Then you are in the right place!
SWD is a protocol to read and write data from/to the SOC so you
could actually read the whole firmware and reverse it along with
most likely proprietary parts such as the Nordic soft device or
some other drivers that only ships in binary blobs. To prevent your
users to tamper with the firmware you can set up a protection
system directly in the silicon and the SOC will refuse to let the
user read whatever it wants.
We can check if the firmware is protected by poking the register
APPROTECTSTATUS (0x0C) and reading the value in there. If it’s a
zero then the whole chip will deny tampering.
Turns out that you can turn this off if you are willing to have the
SOC erase both the FLASH and the RAM. Good enough for us.
So create a new configuration file and now you can poke at anti
tampering and even reset the whole watch to go on with your
project of taking over the world.
A happy openocd ready to do stuff.
and the companion of a happy GDB complaining that there
is no firmware on the SOC anymore!