Author Topic: ML on EOS-M2  (Read 32695 times)


  • Administrator
  • Hero Member
  • *****
  • Posts: 10061
  • 5D Mark Free
Re: ML on EOS-M2
« Reply #175 on: August 07, 2017, 09:05:47 AM »
In this case, the contents of boot-hack.c are identical on dm-spy-experiments-EOSM2.103 (de9f09df06e7) and EOSM2.103_wip (495f8c25235c):
Code: [Select]
hg diff -r 495f8c25235c -r de9f09df06e7 src/boot-hack.c
(no output)

In other words, it does not contain the dm-spy changes.

In my merge tool (Meld), if they are conflicts, I should first solve them, and then select Merge all. Sometimes I forget to select "Merge all" and run into similar errors - that's probably what happened on my side with 2214781fcb95. In this case I redo the merge and/or compare the merged changeset with both ancestors. For example, between dm-spy-experiments and dm-spy-experiments-EOSM2.103 I expect to see only the M2 changes, for example:
Code: [Select]
diff -r 63d4b3396a5f -r 501eb2ccd140 src/boot-hack.c
--- a/src/boot-hack.c
+++ b/src/boot-hack.c
@@ -660,31 +660,32 @@
     uint32_t* addr_AllocMem_end     = (void*)(CreateTaskMain_reloc_buf + ROM_ALLOCMEM_END + CreateTaskMain_offset);
     uint32_t* addr_BL_AllocMem_init = (void*)(CreateTaskMain_reloc_buf + ROM_ALLOCMEM_INIT + CreateTaskMain_offset);
+    uint32_t* addr_B_CreateTaskMain = (void*)(init_task_reloc_buf + ROM_B_CREATETASK_MAIN + init_task_offset);
-    #if defined(CONFIG_550D) || defined(CONFIG_60D) || defined(CONFIG_7D)
-    // change end limit to 0xc60000 => reserve 640K for ML
+    #if defined(CONFIG_EOSM2)
+    /* R0: 0x44C000 (start address, easier to patch, change to 0x4E0000 => reserve 592K for ML) */
+    /* R1: 0xD3C000 [6D, 700D] / 0xC3C000 [100D] / 0xD6C000 [EOSM] / 0xC2A000 [EOSM2] (end address, unchanged) */
+    addr_AllocMem_end[1] = MOV_R0_0x4E0000_INSTR;
+    ml_reserved_mem = 0x4E0000 - RESTARTSTART;
+    #elif defined(CONFIG_550D) || defined(CONFIG_60D) || defined(CONFIG_7D)
+    // change end limit from 0xd00000 to 0xc60000 => reserve 640K for ML
     *addr_AllocMem_end = MOV_R1_0xC60000_INSTR;
-    ml_reserved_mem = 640 * 1024;
+    ml_reserved_mem = 0xD00000 - RESTARTSTART;
-    // change end limit to 0xc80000 => reserve 512K for ML
+    // change end limit from 0xd00000 to 0xc80000 => reserve 512K for ML
     *addr_AllocMem_end = MOV_R1_0xC80000_INSTR;
-    ml_reserved_mem = 512 * 1024;
+    ml_reserved_mem = 0xD00000 - RESTARTSTART;
     // relocating CreateTaskMain does some nasty things, so, right after patching,
     // we jump back to ROM version; at least, what's before patching seems to be relocated properly
     *addr_BL_AllocMem_init = B_INSTR(addr_BL_AllocMem_init, ROM_ALLOCMEM_INIT);
-    uint32_t* addr_B_CreateTaskMain = (void*)init_task_reloc_buf + ROM_B_CREATETASK_MAIN + init_task_offset;
+    // replace call to CreateMainTask (last sub in init_task)
     *addr_B_CreateTaskMain = B_INSTR(addr_B_CreateTaskMain, new_CreateTaskMain);
-    /* FIO_RemoveFile("B:/dump.hex");
-    FILE* f = FIO_CreateFile("B:/dump.hex");
-    FIO_WriteFile(f, UNCACHEABLE(new_CreateTaskMain), CreateTaskMain_len);
-    FIO_CloseFile(f);
-    NotifyBox(10000, "%x ", new_CreateTaskMain); */
+    /* before we execute code, make sure a) data caches are drained and b) instruction caches are clean */
+    sync_caches();
     // Well... let's cross the fingers and call the relocated stuff
     return new_init_task;

If you run this, you'll spot the mistake right away:
Code: [Select]
hg diff -r 63d4b3396a5f -r de9f09df06e7

I've also got differences in edmac-memcpy.c (where hg considered it was a conflict, but in Meld, I only had to select Merge all without changing anything) and in qemu-util.c (which should be deleted).

That said, I've ran 495f8c25235c+2214781fcb95 in QEMU and only seems to work with CONFIG_QEMU=y, but not without. Looking into it.

BTW - two tricks to speed up the compilation:
Code: [Select]
# only recompiles and installs autoexec.bin, without modules
cd platform/EOSM2.103; make installq ML_MODULES_DYNAMIC=

Code: [Select]
# requires a tiny change from latest unified (g3gg0 found out yesterday)
make -j4


  • Hero Member
  • *****
  • Posts: 1747
Re: ML on EOS-M2
« Reply #176 on: August 08, 2017, 07:31:55 PM »
If the dm-spy-experiments branch saves a valid log in QEMU with CONFIG_DEBUG_INTERCEPT_STARTUP=y and CONFIG_QEMU=n, that means we are already there and I'll enable the boot flag.

Cleaned up and updated the EOSM2.103_wip branch so that a pull request on the latest unified branch is showing only the M2 changes. Then I used that to do a new dm-spy-experiments merge and was able to save a DM-0000.LOG. Yay! There are a few error messages in it so as a sanity check I tried the 700D from the latest dm-spy-experiments branch (without the EOSM2 merge) and there are more error messages in the 700D log than in the EOSM2 log!

We'll also need the sf_dump module - that should re-create the SFDATA.BIN file, although I've never tested it that way (todo: include this in the test suite).

Ok--so I included the sf_dump module and on the 700D I was able to get into the ML menu, turn it on and on the next QEMU run (after removing the LOADING.LCK file because of the unclean shutdown) I was able to get into the Debug menu and select "Dump serial flash" but it didn't save a SFDATA.BIN file.

Basically, the EOSM2 is behaving pretty much like the 700D except that I can't get into the ML menus because of the unresponsive LiveView behavior of the EOSM2. Haven't figured out how to workaround it yet.
EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*


  • Hero Member
  • *****
  • Posts: 1747
Re: ML on EOS-M2
« Reply #177 on: August 11, 2017, 06:26:27 PM »
I can't get to the Magic Lantern menu to check it out.

That's probably because the M2 does not show the "idle" Canon screen (the one with shooting settings); as soon as you close the date/time dialog, it will go to LiveView (which doesn't work in QEMU).

You should be able to work around it by allowing the menu to come up in any GUI state, not just when "idle".

Still struggling with this. No matter what I tried, closing the Canon menu sends it into a black abyss. The QEMU console shows activity when pressing the buttons but nothing comes up on the screen.

How does the dm-spy-experiments startup log look?

[EDIT] Superfast compilation:
Code: [Select]
make -j4 installq ML_MODULES_DYNAMIC=
Note that the card needs to have at least the ML/modules directory in order to save the .sym file or compilation will fail and running QEMU requires the other directories along with the files that belong in them or else:

EOSM.202 EOSM.203 EOSM2.103 700D.115 5D3.*