Author Topic: Canon Basic scripting (DIGIC 8, DIGIC X models)  (Read 8201 times)

srsa

  • Contributor
  • New to the forum
  • *****
  • Posts: 44
Canon Basic scripting (DIGIC 8, DIGIC X models)
« on: September 03, 2020, 01:11:27 AM »
I'm moving this to a separate thread as it turned out that more models have support for scripting.

So far confirmed to exist on:
PowerShot SX740
EOS M50
EOS R, RP, R5, R6
EOS 250D

About the language. Card setup.
Note that some people have problems making a usable script card. If that happens, try again. If in doubt, a card prepared for scripting can be verified on any older PowerShot from ~2005 on. The card probably needs to be formatted FAT16/32.

Any script error will crash the camera and require a battery pull.

The language used on DIGIC 8 models is the same as described on the above links, but CHDK-related scripts will not work. The reason for this is that the so-called event procedures (named firmware functions) are mostly different.
Unlike on older PowerShots, most of the available event procedures are pre-registered - can be used without running registration procedures.
Also unlike on older cameras, it is possible to try executing an eventproc that may not exist. This can be achieved by using ExecuteEventProcedure.

Code: [Select]
ExecuteEventProcedure("Peek32",0x1000)is equivalent to
Code: [Select]
Peek32(0x1000)and will return the word read from address 0x1000
Code: [Select]
ExecuteEventProcedure("arbitrary_invalid_function")will return -1

Native code can be executed by using ExportToEventProcedure
Code: [Select]
ExportToEventProcedure("my_func",0xe1234567)will make the firmware function at 0xe1234566 (with thumb bit) available for script as eventproc my_func

All variables of the script are 32-bit signed integers, interpreted as integer, pointer, pointer to string, as required.
It's worth to note that operator precedence is different from other languages. Negative numbers (that includes pointers to ROM) can have funny effects in expressions involving more than two numbers.

File handling capabilities are quite limited when using only available event procedures - native code must be found and used for reading anything from file, writing a binary file, erasing a file, etc.
String constants are limited to 127 bytes. sprintf() only allows up to 8 substitutions (probably a language limit).

The available event procedures can be harvested from ROM, by looking up the registration functions in the disassembly.

Some example scripts
ROM dumper (main image from 0xe0040000, without bootloader)
Code: [Select]
private sub Initialize()
    SaveBootableToFile()
end sub
ROM dumper, not working on M50 due to missing eventproc
Code: [Select]
private sub Initialize()
    SaveAllRomImageToFile()
end sub
Enable bootflag
Code: [Select]
private sub Initialize()
EnableBootDisk()
end sub
Disable bootflag
Code: [Select]
private sub Initialize()
DisableBootDisk()
end sub
Dumping camera log (current session)
Code: [Select]
private sub Initialize()
dumpf()
end sub

I posted a slow dumper script in this older post.

Finally, the usual warning: do not post your ROM dumps publicly.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12464
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #1 on: September 03, 2020, 07:45:20 AM »
Very cool, thanks for sharing the low-level details!

Also confirmed to work on EOS RP.

kitor

  • Contributor
  • Member
  • *****
  • Posts: 193
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #2 on: September 03, 2020, 07:49:40 AM »
So all eyes are now on R5/R6?  8)

Thank you srsa! I'm still amazed how we overlooked your original post for a few months.
EOS R

chris_overseas

  • Moderators
  • Member
  • *****
  • Posts: 233
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #3 on: September 03, 2020, 08:08:00 AM »
Is there any chance someone could create a known-working 256MB SD card image that contains a sample (ROM dumper or otherwise) script, compress it and get that added to the first post? I for one would like to try it with the R5, to eliminate any possibility I messed up when trying to create my own scriptable card.

I'd also like to try this on a CFExpress card to eliminate any drive letter issues. I have one on order but unfortunately it might not arrive in time for my departure on a long trip next week. If it does get here before then I'll test and report back. The SD card slot shows up as "Card 2" in the Canon menus, if that helps (the 5D Mark IV also shows its SD slot as "Card 2").
EOS R5 1.1.0 | Canon 16-35mm f4.0L | Tamron SP 24-70mm f/2.8 Di VC USD G2 | Canon 70-200mm f2.8L IS II | Canon 100-400mm f4.5-5.6L II | Canon 800mm f5.6L | Canon 100mm f2.8L macro | Sigma 14mm f/1.8 DG HSM Art | Yongnuo YN600EX-RT II

c_joerg

  • Freshman
  • **
  • Posts: 82
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #4 on: September 03, 2020, 03:38:10 PM »
How do you test Canon basic scripts?
Is there a syntax check or debug facility?
Or do you have to take out the card every time and try again?
6D

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7606
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #5 on: September 03, 2020, 03:52:15 PM »
I recommend removing battery ...

kitor

  • Contributor
  • Member
  • *****
  • Posts: 193
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #6 on: September 03, 2020, 03:58:02 PM »
When I got ERR70 due to calling wrong (not existing?) function on R, it was enough to open card door. Error disappeared from top screen, camera booted as usual.
EOS R

yourboylloyd

  • Senior
  • ****
  • Posts: 301
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #7 on: September 04, 2020, 10:04:02 AM »
Is there any chance someone could create a known-working 256MB SD card image that contains a sample (ROM dumper or otherwise) script, compress it and get that added to the first post? I for one would like to try it with the R5, to eliminate any possibility I messed up when trying to create my own scriptable card.

I second this statement. It is super unlikely that we both messed up, but this would be to make sure that we didn't mess up.

Can someone please create that working SD card image so that we can try it on the R5 and R6?
Join the ML discord! https://discord.gg/H7h6rfq

kitor

  • Contributor
  • Member
  • *****
  • Posts: 193
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #8 on: September 04, 2020, 11:14:45 AM »
I'll do it. Expect dd image around 5PM CEST.
EOS R

kitor

  • Contributor
  • Member
  • *****
  • Posts: 193
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #9 on: September 04, 2020, 04:02:20 PM »
Card image

Image of 512MB card. Uncompress, and use DD or Win32DiskImager to write to any card of the same size, or above.
Has rom dumper script. Worked fine on R.

After you put card in your camera, go to play mode and press ???. In case of R it was Q/Set, but those are separate buttons now. Set is better candidate as it's Func./Set on powershots :)
If access led will go red, or camera will crash - we are golden.
EOS R

chris_overseas

  • Moderators
  • Member
  • *****
  • Posts: 233
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #10 on: September 04, 2020, 05:07:06 PM »
Thanks kitor, much appreciated. I tried various combinations of Play followed by buttons and dials, pulling the battery each time (not sure that's needed or not?) using your image. I also tried it with and without an image on the card in case that matters, and with the card write protected. Unfortunately still no luck on the R5, so either the way to trigger it isn't very obvious or scripting doesn't work at all :(
EOS R5 1.1.0 | Canon 16-35mm f4.0L | Tamron SP 24-70mm f/2.8 Di VC USD G2 | Canon 70-200mm f2.8L IS II | Canon 100-400mm f4.5-5.6L II | Canon 800mm f5.6L | Canon 100mm f2.8L macro | Sigma 14mm f/1.8 DG HSM Art | Yongnuo YN600EX-RT II

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7606
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #11 on: September 04, 2020, 05:14:00 PM »
Maybe subject needs to be chanced a bit. My 250D/200D Mark II/Rebel SL3/Kiss X10 does execute Canon Basic script and produces ROM.TXT. Zero Bytes but it is written nevertheless!
Correction: 2 129 920 Bytes
Want to have a look? -> PN

Any hints what is needed to dump valid bits and bytes?

90D, M6 II, G7X III: Users around? Making a script card is easy!
If there are troubles I promise to assist via Teamviewer (or else).

srsa

  • Contributor
  • New to the forum
  • *****
  • Posts: 44
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #12 on: September 04, 2020, 06:07:23 PM »
Maybe subject needs to be chanced a bit. My 250D/200D Mark II/Rebel SL3/Kiss X10 does execute Canon Basic script and produces ROM.TXT.
Hmmm, what an avalanche. Changed the 1st post and thread title.
If you want something more useful and faster, try
Code: [Select]
private sub Initialize()
    r = ExecuteEventProcedure("SaveAllRomImageToFile")
    if r = -1 then
        ExecuteEventProcedure("SaveBootableToFile")
    end if
end sub
I gladly accept (links to) dumps in PM.

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7606
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #13 on: September 04, 2020, 06:14:35 PM »
Thanks! Cam is 250D, not 200D. ;-)

srsa

  • Contributor
  • New to the forum
  • *****
  • Posts: 44
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #14 on: September 04, 2020, 06:19:22 PM »
Thanks! Cam is 250D, not 200D. ;-)
Corrected.

kitor

  • Contributor
  • Member
  • *****
  • Posts: 193
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #15 on: September 04, 2020, 08:10:42 PM »
I also tried it with and without an image on the card in case that matters, and with the card write protected

Have you tried both card slots? It was mentioned a couple of times that this needs to be B:\ from DryOS PoV, and we don't know the actual mapping.
EOS R

yourboylloyd

  • Senior
  • ****
  • Posts: 301
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #16 on: September 04, 2020, 08:36:29 PM »
Have you tried both card slots?

I tried the Kitor card.img on both slots on the R6. Nothing
Join the ML discord! https://discord.gg/H7h6rfq

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7606
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #17 on: September 04, 2020, 08:39:24 PM »
Card verified to work in other cam?
If not: Card size? Partition size? File system?

yourboylloyd

  • Senior
  • ****
  • Posts: 301
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #18 on: September 04, 2020, 08:47:37 PM »
Yes. Kitor sent us his card image that has been verified. If you have another working card image I'll be happy to try that
Join the ML discord! https://discord.gg/H7h6rfq

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7606
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #19 on: September 04, 2020, 08:55:32 PM »
No, there is no verification this card is working. It is verified Kitor's card is working not the one in your hand.
Use a Digic 8 camera or almost any PowerShot codebased cam produced after 2005.

kitor

  • Contributor
  • Member
  • *****
  • Posts: 193
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #20 on: September 04, 2020, 09:13:33 PM »
Just FYI - in both cases (512MB SD and 32GB via adapter) it was Sandisk cards.
EOS R

Ant123

  • Contributor
  • Member
  • *****
  • Posts: 162
Re: Canon Basic scripting (DIGIC 8 mirrorless models)
« Reply #21 on: September 04, 2020, 09:21:05 PM »
I tried the Kitor card.img on both slots on the R6. Nothing
What is the size of the card you tried?

yourboylloyd

  • Senior
  • ****
  • Posts: 301
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #22 on: September 04, 2020, 09:48:59 PM »
The card I tried is 128GB originally. I don't have any other card size. I'll go out and try to buy a cheap sd card that's smaller.

I also don't have any other camera. ( I do know someone with an M50 though. Maybe I can try to borrow that one but I won't be able to do that until sunday or monday.)
Join the ML discord! https://discord.gg/H7h6rfq

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7606
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #23 on: September 04, 2020, 09:53:21 PM »
You can create a partition <32 GB.
See Kitor's post https://www.magiclantern.fm/forum/index.php?topic=25305.msg230427#msg230427

Ant123

  • Contributor
  • Member
  • *****
  • Posts: 162
Re: Canon Basic scripting (DIGIC 8 models)
« Reply #24 on: September 04, 2020, 09:59:23 PM »
There need to try SD or SDHC(not SDXC) card first. Is that so hard?