I was able to follow the steps here to get the firmware analyzed using Ghidra: https://chdk.fandom.com/wiki/Firmware_analysis_with_Ghidra
Ultimately getting towards a buildable and testable package that I can install on a SD card and test out on my camera would be nice to get to this weekend.
Depending on your experience with these things, a usable build in one weekend might be a stretch, but blinking an LED should be within reach
I posted a somewhat recent overview here:
https://chdk.setepontos.com/index.php?topic=5592.msg144892#msg144892 (the mentions of
code-gen don't apply to Digic 6 though, you should generate the disassembly with capis instead)
It only worked when I added some additional params like this:
make PLATFORM=g1x2 PLATFORMSUB=120a \
TARGET_PRIMARY=/path/to/PRIMARY.BIN \
OPT_CAPSTONE_TOOLS=1 \
CAPSTONE_TOOLS_INC=-I/usr/include/capstone/ \
CAPSTONE_TOOLS_LINK=-lcapstone rebuild-stubs
You can put these settings in localbuildconf.inc. Copy buildconf.inc to localbuildconf.inc and edit to taste.
Which CHDK source branch are you using? I'd recommend using the trunk for a digic 6 port.
sudo apt install gcc-arm-none-eabi
sudo apt install libcapstone-dev
You should check that the arm gcc version is one of the supported versions (4, 5, 8, 9 or 10), otherwise you might end up with a build that doesn't work. The trunk makefiles should check this.
IIRC, the version supplied by ubuntu 20.04 is 6, which I think had problems (but I don't recall the details.)
edit: I remembered wrong, according to
https://launchpad.net/ubuntu/focal/+package/gcc-arm-none-eabi it's 9, which is supported.
The capstone version must be 4.x (or 3.x built from source with the patch from tools applied)
FWIW, you can get a native windows toolchain from
https://chdk.setepontos.com/index.php?topic=12752.0There is also a docker based toolchain
https://chdk.fandom.com/wiki/Compiling_CHDK_With_DockerOnce installing these packages I was able to get the make command working. Importing the resulting files into the Ghidra was pretty straightforward, although I don't fully understand all the finer details regarding what I was doing.
The CHDK scripts mainly set up the memory map (so various bits of code and data appear at their real addresses), and name the functions found by finsig_thumb2.
For porting, the Ghidra version tracking tool is quite useful
https://chdk.fandom.com/wiki/Ghidra_Version_Tracking_workflow_for_portingIf you want realtime advice, I'm sometimes in the #chdk IRC channel on freenode.