CHDK Wiki
m (updated info box)
Tag: Visual edit
 
(35 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{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.}}
 
{{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.}}
  +
{| align="right" style="border-collapse:collapse; font-size: x-small;"
  +
| __TOC__
  +
|}
   
 
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.
'''''[ Modified from : [http://chdk.wikia.com/wiki/Adding_support_of_a_new_firmware_version new firmware version]]'''''
 
   
  +
link to : [http://chdk.setepontos.com/index.php?topic=6367 CHDK Forum Thread for CHDK-PT]
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 [http://www.box.net/shared/38etrnb3yu <s>CHDK-PT</s>][[File:CHDK-PT_screenshot_1.0.jpg|thumb|CHDK-PT main window]][http://www.softpedia.com/get/Programming/Debuggers-Decompilers-Dissasemblers/CHDK-PT.shtml CHDK-PT Mirror]
'''Prerequisites:'''
 
*the CHDK-PT porting tool [http://www.box.net/shared/5xvdixognb CHDK-PT (stub for now)][[File:CHDK-PT_screenshot.png|thumb|250px|CHDK-PT Dissassembler Mode]]
 
 
*a working CHDK build environment like [http://chdk.wikia.com/wiki/CHDK-Shell CHDK-Shell]
 
*a working CHDK build environment like [http://chdk.wikia.com/wiki/CHDK-Shell CHDK-Shell]
 
*a good text editor, preferrably with a built-in diff function like [http://notepad-plus-plus.org/ Notepad++]
 
*a good text editor, preferrably with a built-in diff function like [http://notepad-plus-plus.org/ 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 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 [http://chdk.wikia.com/wiki/For_Developers For_Developers]
+
*a little knowledge of CHDK software development - check out the links in the "Common Articles" section of [http://chdk.wikia.com/wiki/For_Developers For_Developers] but don't spend too much time getting lost over there.
 
*the firmware dump (primary.bin) file from a working port of a different firmware version of your camera
 
*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
 
*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 [http://chdk.wikia.com/wiki/Canon_Basic/Scripts/Dumper Firmware Dumping]
 
*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 [http://chdk.wikia.com/wiki/Canon_Basic/Scripts/Dumper Firmware Dumping]
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; font-style: inherit; font-weight: inherit; margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline;">'''Steps:'''</p>
 
   
  +
==Steps==
<p style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13px; font-style: inherit; font-weight: inherit; margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline;">'''1) Intial Setup'''</p>
 
  +
  +
===Intial Setup===
 
*Locate your camera model in the CHDK trunk directory
 
*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
 
*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'' )
 
*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''.
 
*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'''
+
===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.
 
*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''.
+
*To start, you need to add your camera model to the build. In newer source trees, add your camera name to the camera_list.csv file located in the current trunk directory. For older source trees, 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.
*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.
 
 
*Build the new firmware version with the PRIMARY.BIN file in place and OPT_GEN_STUBS is 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.
'''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 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.
*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 '''
 
 
===Converting stubs_entry_2.S===
*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
 
  +
*The CHDK build process tries to find addresses in the camera ROM for CHDK code to connect with. This information is stored automatically in a file called stubs_entry.s by the build process. When the build process cannot fnd a good link, you must manually add it to the file stubs_entry_2.S. When porting different firmware versions across the same camera, CHKD-PT can convert the stubs_entry_2.S file from your existing reference port to a new version of stubs_entry_2.S for your new port.
'''<<<edit stopped here for now... more work needed ...>>>'''
 
 
*Use the CHDK-PT '''Convert : Stubs '''button 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 camera port and the ROM image file for the new camera. Once you have selected those, it will generate a new stubs_entry_2.S type 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 the Save button to create the new stubs_entry_2.S file if you are happy with what you see in CHDK-PT's text box.
*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.
 
 
*Next use CHDK-PT '''Analyze : Stubs '''function to dissassemble and create C file versions of the stubs_entry_2.S files for the existing port and for your new port (the file you just saved in the step above). Use the '''diff '''function in Notepad++ to compare the two resulting files. When the routines match, your are done! If they don't match then you need to go searching for a better match with '''Dissassemble '''mode in CHDK-PT.
*Follow the same procedure for the capt_seq.c and movie_rec.c
 
  +
'''5) Converting lib.c and stubs_min.S'''
 
 
===Converting the C language CHDK task files===
*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'''
 
  +
*In the previous step of these instructions, where you copied files into trunk/platform/<camera>/sub/<firmware>, you will have created (amongst other things) three C language files - boot.c, movie_rec.c and capt_set.c. These files contain ARM assembler code written in a format that the gcc compiler can compile. Each of these files contains small programs that are actually copies of some of the tasks in the original camera. What happens with CHDK is that these copied tasks are slightly modified to support the additional functionality that CHDK provides and are then compiled as part of the CHDK executable code. When you copied the files, you got code suitable for use with your reference camera, so you need to create new files suitable for your new target camera.
  +
*The easiest way to create these three files is to use CHDK-PT. But first you need to figure out where the original code was taken from in the original camera port. You can then let CHDK-PT produce code for the new versions of boot.c, movie_rec.c and capt_set.c that matches your new camera. You need to create an ''address.txt'' file by looking at the original tasks, where labels and maybe comments provide clues as to where the code was taken from. You can also use the dissassembler function in CHDK-PT to explore in the ROM image, looking for code matches based on the clues provided by the labels in the original files.
  +
*Take a look at the example file (addresses_ctasks_103c.txt) provide with CHDK-PT. Or, as an example of what you need to do, you can try using the examples included with CHDK-PT to create new C task code for a new camera (primary_101a.bin) based on the address_ctasks_103c.txt and primary_103c.bin files for an original reference camera.
  +
*The C task files ( boot.c, capt_seq.c & movie_rec.c) should be pretty much the same between firmware versions of the same camera. However, these routines reference addresses specific to each firmware version and so are not the same. Using CHDK-PT, you can create new versions of these C routine, and then use Notepad++ to make them equivalent to the routines from your reference port.
 
*Use the CHDK-PT '''Convert : Addresses '''function to create new C code task files for your new port (boot.c, capt_seq.c, movie_rec.c). The tool will let you select the ROM image file and and address file for the reference port and the ROM image file for the new camera. You need to create that address file so that it gives the starting address and length of each routine in the original ROM image file. Once you have selected those, it will generate a new C code file for your new camera based on finding the appropriate code in your new ROM image using information about what that code looked like in the reference ROM image. You then need to use your by now old friend '''diff '''in Notepad++ to figure out the CHDK customizations that were applied to the original C code and port those changes to your new C code.
  +
 
*Follow the same procedure for each of the files boot.c, capt_seq.c and movie_rec.c
  +
*here are some forum threads on this topic :
  +
:: [http://chdk.setepontos.com/index.php?topic=6254.msg78722#msg78722 CHDK-PT : Using the addresses.txt file - thread 1]
  +
:: [http://chdk.setepontos.com/index.php?topic=6367.msg72436#msg72436 CHDK-PT : Using the addresses.txt file - thread 2]
  +
:: [http://chdk.setepontos.com/index.php?topic=5051.msg73571#msg73571 CHDK-PT : Using the addresses.txt file - thread 3]
  +
 
===Converting lib.c and stubs_min.S===
 
*lib.c: If no variables have moved, you probably don't have to do anything here. Hardware addresses are unlikely to have changed.
  +
 
*stubs_min.S: pretty much the same as lib.c, except levent_table & FlashParamsTable which will probably have moved by the same amount as the Canon data.
  +
Note : if there are already two or more firmware versions supported for your camera, use '''diff''' to look for changes between versions in these files.
  +
 
===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
 
*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.
 
*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'''
+
===Cleaning up===
 
*That's it, you are done. Build it (from scratch with clean !) and find someone to try it it out...
 
*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.
 
*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.
  +
[[Category:Development]]

Latest revision as of 23:39, 8 June 2018

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.

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.

link to : CHDK Forum Thread for CHDK-PT

Prerequisites

  • the CHDK-PT porting tool CHDK-PT
    CHDK-PT screenshot 1

    CHDK-PT main window

    CHDK-PT Mirror
  • 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 but don't spend too much time getting lost over there.
  • 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

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.

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 add your camera model to the build. In newer source trees, add your camera name to the camera_list.csv file located in the current trunk directory. For older source trees, 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.
  • Build the new firmware version with the PRIMARY.BIN file in place and OPT_GEN_STUBS is 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.

Converting stubs_entry_2.S

  • The CHDK build process tries to find addresses in the camera ROM for CHDK code to connect with. This information is stored automatically in a file called stubs_entry.s by the build process. When the build process cannot fnd a good link, you must manually add it to the file stubs_entry_2.S. When porting different firmware versions across the same camera, CHKD-PT can convert the stubs_entry_2.S file from your existing reference port to a new version of stubs_entry_2.S for your new port.
  • Use the CHDK-PT Convert : Stubs button 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 camera port and the ROM image file for the new camera. Once you have selected those, it will generate a new stubs_entry_2.S type 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 the Save button to create the new stubs_entry_2.S file if you are happy with what you see in CHDK-PT's text box.
  • Next use CHDK-PT Analyze : Stubs function to dissassemble and create C file versions of the stubs_entry_2.S files for the existing port and for your new port (the file you just saved in the step above). Use the diff function in Notepad++ to compare the two resulting files. When the routines match, your are done! If they don't match then you need to go searching for a better match with Dissassemble mode in CHDK-PT.

Converting the C language CHDK task files

  • In the previous step of these instructions, where you copied files into trunk/platform/<camera>/sub/<firmware>, you will have created (amongst other things) three C language files - boot.c, movie_rec.c and capt_set.c. These files contain ARM assembler code written in a format that the gcc compiler can compile. Each of these files contains small programs that are actually copies of some of the tasks in the original camera. What happens with CHDK is that these copied tasks are slightly modified to support the additional functionality that CHDK provides and are then compiled as part of the CHDK executable code. When you copied the files, you got code suitable for use with your reference camera, so you need to create new files suitable for your new target camera.
  • The easiest way to create these three files is to use CHDK-PT. But first you need to figure out where the original code was taken from in the original camera port. You can then let CHDK-PT produce code for the new versions of boot.c, movie_rec.c and capt_set.c that matches your new camera. You need to create an address.txt file by looking at the original tasks, where labels and maybe comments provide clues as to where the code was taken from. You can also use the dissassembler function in CHDK-PT to explore in the ROM image, looking for code matches based on the clues provided by the labels in the original files.
  • Take a look at the example file (addresses_ctasks_103c.txt) provide with CHDK-PT. Or, as an example of what you need to do, you can try using the examples included with CHDK-PT to create new C task code for a new camera (primary_101a.bin) based on the address_ctasks_103c.txt and primary_103c.bin files for an original reference camera.
  • The C task files ( boot.c, capt_seq.c & movie_rec.c) should be pretty much the same between firmware versions of the same camera. However, these routines reference addresses specific to each firmware version and so are not the same. Using CHDK-PT, you can create new versions of these C routine, and then use Notepad++ to make them equivalent to the routines from your reference port.
  • Use the CHDK-PT Convert : Addresses function to create new C code task files for your new port (boot.c, capt_seq.c, movie_rec.c). The tool will let you select the ROM image file and and address file for the reference port and the ROM image file for the new camera. You need to create that address file so that it gives the starting address and length of each routine in the original ROM image file. Once you have selected those, it will generate a new C code file for your new camera based on finding the appropriate code in your new ROM image using information about what that code looked like in the reference ROM image. You then need to use your by now old friend diff in Notepad++ to figure out the CHDK customizations that were applied to the original C code and port those changes to your new C code.
  • Follow the same procedure for each of the files boot.c, capt_seq.c and movie_rec.c
  • here are some forum threads on this topic :
CHDK-PT : Using the addresses.txt file - thread 1
CHDK-PT : Using the addresses.txt file - thread 2
CHDK-PT : Using the addresses.txt file - thread 3

Converting lib.c and stubs_min.S

  • lib.c: If no variables have moved, you probably don't have to do anything here. Hardware addresses are unlikely to have changed.
  • stubs_min.S: pretty much the same as lib.c, except levent_table & FlashParamsTable which will probably have moved by the same amount as the Canon data.

Note : if there are already two or more firmware versions supported for your camera, use diff to look for changes between versions in these files.

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.

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.