Skip to content

Commit 0e3ae09

Browse files
author
philmoz
committed
Add early experiments with Digic7 G7X II.
Not working, partial boot code working; but cannot get camera to restart properly after loading diskboot.bin.
1 parent 0cc71b6 commit 0e3ae09

32 files changed

+8750
-2
lines changed

arm_rules.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ ifndef THUMB_FW
4545
CFLAGS+=-mtune=arm946e-s $(ARCH)
4646
endif
4747
else
48-
CFLAGS+=-march=armv7-r -mthumb -DTHUMB_FW
48+
ifdef DIGIC7
49+
CFLAGS+=-march=armv7-a -mthumb -DTHUMB_FW
50+
else
51+
CFLAGS+=-march=armv7-r -mthumb -DTHUMB_FW
52+
endif
4953
endif
5054

5155
CFLAGS+=-I$(include) -I$(core) -I$(modules) -I$(cam) $(PLFLAGS)

loader/g7x2/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../makefile_loader.inc

loader/g7x2/blobs.S

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.globl blob_chdk_core, blob_chdk_core_size
2+
3+
.section .blob_chdk_core
4+
blob_chdk_core_start:
5+
.incbin CORE_FILE
6+
blob_chdk_core_end:
7+
8+
.text
9+
blob_chdk_core_size:
10+
.long blob_chdk_core_end - blob_chdk_core_start
11+
blob_chdk_core:
12+
.long blob_chdk_core_start

loader/g7x2/entry.S

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.section .entry
2+
// ordinary startup...
3+
.code 16
4+
.align 2
5+
.syntax unified
6+
LDR SP, =MEMBASEADDR
7+
B my_restart

loader/g7x2/main.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "../generic/check_compat.c"
2+
3+
extern long *blob_chdk_core;
4+
extern long blob_chdk_core_size;
5+
6+
void __attribute__((noreturn)) my_restart()
7+
{
8+
// check_compat();
9+
10+
long *dst = (long*)MEMISOSTART;
11+
const long *src = blob_chdk_core;
12+
long length = (blob_chdk_core_size + 3) >> 2;
13+
14+
core_copy(src, dst, length);
15+
16+
// GPIO base = 0xD2080000
17+
// 0xD20801E4 - SD led
18+
// 0xD20801E8 - AF led
19+
20+
// light up green LED
21+
volatile int* p = (int*)0xD20801E4;
22+
*p = 0x24D0002;
23+
24+
// // blinker
25+
// int i;
26+
// while (1)
27+
// {
28+
// *p = 0x24D0002;
29+
// for(i=0;i<10000000;i++) {
30+
// asm volatile(
31+
// "nop\n"
32+
// );
33+
// }
34+
// *p = 0x24C0003;
35+
// for(i=0;i<10000000;i++) {
36+
// asm volatile(
37+
// "nop\n"
38+
// );
39+
// }
40+
// }
41+
42+
asm volatile (
43+
"mov r1, %1\n"
44+
"mov r0, %0\n"
45+
"ldr r2, =0xe042eb75\n" // address is OK for 101a
46+
"blx r2\n" // caching related routine called at fw startup
47+
"mov r1, %1\n"
48+
"mov r0, %0\n"
49+
"ldr r2, =0xe042ec4d\n" // address is OK for 101a
50+
"blx r2\n" // caching related routine called at fw startup
51+
"mov r0, %0\n"
52+
"add r0, r0, #1\n"
53+
"bx r0\n"
54+
: : "r"(MEMISOSTART), "r"(((blob_chdk_core_size+3)>>2)<<2) : "memory","r0","r1","r2","r3","r4"
55+
);
56+
while(1);
57+
}
58+

loader/generic/check_compat.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ LED control methods
3030
#define LEDCNTRL_NEW1 2 // DIGIC 5; bit5, inverted
3131
#define LEDCNTRL_NEW2 3 // DIGIC 4+, 5; 0x93d800 to on, 0x83dc00 to off
3232
#define LEDCNTRL_NEW3 4 // DIGIC 6; 0x4d0002 to on, 0x4c0003 to off
33+
#define LEDCNTRL_NEW4 5 // DIGIC 7; 0x024d0002 to on, 0x024c0003 to off
3334

3435
#ifndef NEED_ENCODED_DISKBOOT
3536
#define NEED_ENCODED_DISKBOOT 0
@@ -63,6 +64,10 @@ void set_led(int led, int state, int method) {
6364
// DIGIC 6
6465
*p = ((state) ? 0x4d0002 : 0x4c0003);
6566
}
67+
else if (method == LEDCNTRL_NEW4) {
68+
// DIGIC 7
69+
*p = ((state) ? 0x024d0002 : 0x024c0003);
70+
}
6671
else if (method == LEDCNTRL_OLD) {
6772
*p = ((state) ? 0x46 : 0x44);
6873
}

makefile_base.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ endif
6464
ifndef THUMB_FW
6565
O=.o/
6666
else
67-
O=.o2/
67+
ifndef DIGIC7
68+
O=.o2/
69+
else
70+
O=.o3/
71+
endif
6872
endif
6973

7074
SILENT=SILENT

platform/g7x2/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../makefile_platform.inc

platform/g7x2/kbd.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
2+
#include "lolevel.h"
3+
#include "platform.h"
4+
#include "keyboard.h"
5+
#include "kbd_common.h"
6+
7+
long kbd_new_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
8+
long kbd_prev_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
9+
long kbd_mod_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
10+
11+
extern void _GetKbdState(long*);
12+
13+
int get_usb_bit()
14+
{
15+
long usb_physw[3];
16+
usb_physw[USB_IDX] = 0;
17+
_kbd_read_keys_r2(usb_physw);
18+
return ((usb_physw[USB_IDX] & USB_MASK)==USB_MASK);
19+
}
20+
21+
// TODO:
22+
KeyMap keymap[] = {
23+
{ 0, KEY_PLAYBACK ,0x00008000 }, // Found @0xe05df0b0, levent 0x101
24+
{ 0, KEY_VIDEO ,0x00010000 }, // Found @0xe05df0b8, levent 0x02
25+
{ 0, KEY_ZOOM_IN ,0x00020000 }, // Found @0xe05df0c0, levent 0x03
26+
{ 0, KEY_ZOOM_OUT ,0x00040000 }, // Found @0xe05df0c8, levent 0x04
27+
{ 0, KEY_SHOOT_FULL ,0x00180000 }, // Found @0xe05df0d0, levent 0x01
28+
{ 0, KEY_SHOOT_HALF ,0x00100000 }, // Found @0xe05df0d8, levent 0x00
29+
{ 0, KEY_SHOOT_FULL_ONLY ,0x00080000 }, // Found @0xe05df0d0, levent 0x01
30+
{ 0, KEY_POWER ,0x00200000 }, // Found @0xe05df0e0, levent 0x100
31+
{ 2, KEY_UP ,0x00000200 }, // Found @0xe05df158, levent 0x06
32+
{ 2, KEY_DOWN ,0x00000400 }, // Found @0xe05df160, levent 0x07
33+
{ 2, KEY_RIGHT ,0x00000800 }, // Found @0xe05df168, levent 0x09
34+
{ 2, KEY_LEFT ,0x00001000 }, // Found @0xe05df170, levent 0x08
35+
{ 2, KEY_SET ,0x00002000 }, // Found @0xe05df178, levent 0x0a
36+
// { 0, KEY_SHOOT_FULL_ONLY ,0x00000001 },
37+
// { 0, KEY_ZOOM_OUT ,0x00000002 },
38+
// { 0, KEY_ZOOM_IN ,0x00000004 },
39+
// { 0, KEY_VIDEO ,0x00000008 },
40+
// { 0, KEY_MENU ,0x00000010 },
41+
// { 0, KEY_UP ,0x00000020 },
42+
// { 0, KEY_DOWN ,0x00000040 },
43+
// { 0, KEY_RIGHT ,0x00000080 },
44+
// { 0, KEY_LEFT ,0x00000100 },
45+
// { 0, KEY_SET ,0x00000200 },
46+
// { 0, KEY_ERASE ,0x00000400 },
47+
// { 0, KEY_PLAYBACK ,0x00000800 },
48+
// { 0, KEY_WIFI ,0x00010000 },
49+
// { 0, KEY_POWER ,0x00020000 },
50+
// { 0, KEY_SHOOT_HALF ,0x00040000 },
51+
// { 0, KEY_SHOOT_FULL ,0x00040001 },
52+
{ 1, KEY_DISPLAY ,0x00000010 },
53+
{ 0, 0, 0 }
54+
};
55+
56+
long __attribute__((naked,noinline)) wrap_kbd_p1_f()
57+
{
58+
asm volatile(
59+
"push {r1-r7, lr}\n"
60+
"movs r4, #0\n"
61+
"bl my_kbd_read_keys\n"
62+
"b _kbd_p1_f_cont\n"
63+
);
64+
65+
return 0;
66+
}
67+
68+
// no stack manipulation needed here, since we create the task directly
69+
void __attribute__((naked,noinline)) mykbd_task()
70+
{
71+
extern void kbd_p2_f_my();
72+
73+
while (physw_run)
74+
{
75+
_SleepTask(physw_sleep_delay);
76+
77+
if (wrap_kbd_p1_f() == 1)
78+
{
79+
// kbd_p2_f_my();
80+
_kbd_p2_f();
81+
}
82+
}
83+
84+
_ExitTask();
85+
}
86+
87+
int jogdial_stopped=0;
88+
89+
int get_dial_hw_position(int dial)
90+
{
91+
// mask low bits
92+
extern int _get_dial_hw_position(int dial);
93+
return _get_dial_hw_position(dial)&~3;
94+
}
95+
96+
// TODO:
97+
extern long dial_positions[6];
98+
99+
int get_jogdial_counter()
100+
{
101+
int p = get_dial_hw_position(4);
102+
return p;
103+
}
104+
105+
long get_jogdial_direction(void)
106+
{
107+
static int new_jogdial=0, old_jogdial=0 ;
108+
109+
old_jogdial=new_jogdial;
110+
new_jogdial=get_jogdial_counter();
111+
112+
if (old_jogdial>new_jogdial) return JOGDIAL_LEFT;
113+
else if (old_jogdial<new_jogdial) return JOGDIAL_RIGHT;
114+
else return 0;
115+
}
116+
117+
int handle_jogdial()
118+
{
119+
// return 0 to prevent fw dial handler
120+
if (jogdial_stopped)
121+
{
122+
// update positions in RAM
123+
dial_positions[0] = dial_positions[3] = get_jogdial_counter();
124+
return 0;
125+
}
126+
return 1;
127+
}
128+
129+
void jogdial_control(int c)
130+
{
131+
jogdial_stopped = c;
132+
}
133+
134+
void my_kbd_read_keys()
135+
{
136+
kbd_update_key_state();
137+
kbd_update_physw_bits();
138+
}
139+
140+
void kbd_fetch_data(long *dst)
141+
{
142+
_GetKbdState(dst);
143+
_kbd_read_keys_r2(dst);
144+
}

0 commit comments

Comments
 (0)