/
dump.c
42 lines (34 loc) · 951 Bytes
/
dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include "i2c-dev.h"
#include "gg.h"
int main()
{
const char * devName = "/dev/i2c-0";
// Open up the I2C bus
int file = open(devName, O_RDWR);
if (file == -1)
{
perror(devName);
exit(1);
}
// Specify the address of the slave device.
// don't use I2C_SLAVE_FORCE or disable i2c device locking, disable the sbs-battery driver instead!
// the gg is too easily bricked to risk having the driver send commands at the same time as us.
if (ioctl(file, I2C_SLAVE_FORCE, GG_ADDRESS) < 0)
{
perror("Failed to acquire bus access and/or talk to slave");
exit(1);
}
firmwareVersion(file);
enterBootRom(file);
dumpDataFlash(file, "gg.dfi");
// dumpInstructionFlash(file, "gg.ifi");
exitBootRom(file);
return 0;
}