CHDK Wiki
Advertisement
Notice

CHDK-PT tool offers a basic ARM dissassembler that works well with Canon camera ROM dumps, interprets CHDK stub_entry.S files, producing output as gcc compatible C files, and will convert stubs files and source code between firmware versions with a only little effort from the developer.


[ Modified from : new firmware version]

Porting CHDK to a new camera for the first time is really hard and very time consuming. Porting to a different firwmare version of the same camera is much easier. With the introduction on CHDK-PT tool, it has become even easier. At least that's the hope.

Prerequisites:

  • the CHDK-PT porting tool CHDK-PT (stub for now)
    File:CHDK-PT screenshot.png

    CHDK-PT Dissassembler Mode

  • a working CHDK build environment like CHDK-Shell
  • a good text editor, preferrably with a built-in diff function like Notepad++
  • a basic knowledge of software, although you will not really be writing code, just changing existing code to reflect difference between firmware versions of the same camera.
  • a little knowledge of CHDK software development - check out the links in the "Common Articles" section of For_Developers
  • the firmware dump (primary.bin) file from a working port of a different firmware version of your camera
  • the camera specific files (boot.c, capt_seq.c, lib.c, movie_rec.c etc) from that same working port
  • for the new firmware version you are trying to support, a firmware dump (primary.bin). If you don't have this, a good place to start is Firmware Dumping

Steps:

1) Intial Setup

  • Locate your camera model in the CHDK trunk directory
  • Create a new trunk/platform/<camera>/sub/<firmware> directory for your camera where <firmware> is your firmware version
  • Copy all files from the numerically closest version subdirectory to the new subdirectory (e.g. trunk/platform/ixus120_sd940/sub/103c -> trunk/platform/ixus120_sd940/sub/103d )
  • Find and move the firmware dump file (primary.bin) for your camera into your new subdirectory, naming it primary.bin.

2) Testing the initial configuration

  • Now you are ready to start updating files. I suggest keeping notes of which files you change and what ever else you do - things get confused fast so its nice to have a record.
  • To start, you need to edit the Makefile and makefile.inc in the trunk/trunknnnn directories to include your firmware version - search the files for the existing references to your camera and duplicate the lines you find, changing as necessary to point to your new firmware version. You will need to make one change in makefile.inc and and six in Makefile.
  • Build the new firmware version with the PRIMARY.BIN file in place and OPT_GEN_SIGS & OPT_GEN_STUBS selected (CHDK-shell). This will obviously not be a working port, you just want to generate stubs_entry.S and make sure that you have set things up correctly.
  • Use notepad++ to diff the newly generated stubs_entry.S and the one for the already supported firmware. While many of the addresses will have changed, you are looking to see if the same stubs were found with the same percentage of success. You will need to later update stubs_entry_2.S to cover any differences.

3) Converting stubs_entry_2.S

  • Use the CHDK-PT Convert Stubs function to create a new stubs_entry_2.S file for your new port. The tool will let you select the ROM image file and stubs_entry_2.S file for the reference port and the ROM image file for the new camera. Once you have selected those, it will generate a new stubs_entry_2.S file for your new camera based on finding the approriate code in your new ROM image using information about what that code looked like in the reference ROM image
  • Use CHDK-PT Stubs File function to dissassemble and create C file version of the stubs_entry_2.S files for the existing port and for your new port. Use the diff function in Notepad++ to compare the two resulting files. Where the routines match, your are done. If they don't match then you need to go searching for a better match with Local mode

4) Convering the C language CHDK task files

  • Use the CHDK-PT Convert C Files function to create a new C code task files for your new port. The tool will let you select the ROM image file and and address file pointing to the location of task information in the reference port and the ROM image file for the new camera. Once you have selected those, it will generate a new C code file for your new camera based on finding the approriate code in your new ROM image using information about what that code looked like in the reference ROM image

<<<edit stopped here for now... more work needed ...>>>

  • Open boot.c, find boot(), and compare the values there with the loops in the firmware dump. Update the code corresponding to the loops above. The start of initialized data has probably moved. If the sizes of the data and BSS have not changed, it's a good indication that the addresses of variables used by CHDK have not changed.
  • Now scan through the assembler in boot.c, and the corresponding code in IDA. You don't really have to really examine every line, you are mostly looking for calls to functions that have an address higher than highest unchanged address noted above. If you find one, compare it with what's in IDA, and update as needed. Also keep an eye out for variables that might have moved.
  • Follow the same procedure for the capt_seq.c and movie_rec.c

5) Converting lib.c and stubs_min.S

  • lib.c: If no variables have moved, you probably don't have to do anything here. You can sanity check by searching for the constants in both dumps, and making sure they are referenced by identical code (use "search for a sequence of bytes"). Hardware addresses are unlikely to have changed.
  • stubs_min.S: pretty much the same as lib.c, except FlashParamsTable which will probably have moved by the same amount as the canon data.

6) Warnings

  • makefile.inc: MEMISOSTART will need updating if the size of canon DATA + BSS has changed. Hopefully that will not be the case across different version of firmware on the same camera
  • some of the assumptions above (like variables not moving) are just educated guesses. Canon could have changed the order of variables or functions but had them come out the same size.

7) Cleaning up

  • That's it, you are done. Build it (from scratch with clean !) and find someone to try it it out...
  • OK, you weren't actually quite done yet. Assuming it works, update the toplevel makefile to include your new sub, and commit or submit a patch.
Advertisement