1 | #define _XOPEN_SOURCE 700
|
---|
2 |
|
---|
3 | // C99
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <string.h>
|
---|
7 |
|
---|
8 | // POSIX/XSI
|
---|
9 | #include <getopt.h>
|
---|
10 |
|
---|
11 | // FreeBSD
|
---|
12 | #include <osreldate.h>
|
---|
13 | #include <sys/types.h>
|
---|
14 | #include <machine/cpufunc.h>
|
---|
15 | #include <machine/sysarch.h>
|
---|
16 |
|
---|
17 | #include "device.h"
|
---|
18 | #include "at29c040.h"
|
---|
19 |
|
---|
20 | /* TODO
|
---|
21 | Linux compatibility (ioperm, reversed outb)
|
---|
22 | wrap IOs in a class to hide the mess (BSD/Linux)
|
---|
23 | wrap ROM access in a class as well (read or write a byte/block, and so on)
|
---|
24 | */
|
---|
25 |
|
---|
26 | int main(int argc, char* argv[])
|
---|
27 | {
|
---|
28 | char c;
|
---|
29 | const char* file;
|
---|
30 | char opcode = 0;
|
---|
31 | int port_base = 0x378;
|
---|
32 | Device* device = NULL;
|
---|
33 |
|
---|
34 | puts("EPRoxygen - UNIX driver for SEEIT EPR-02 ROM programmer\n"
|
---|
35 | "Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.tk>\n"
|
---|
36 | "Distributed under the terms of the MIT licence\n"
|
---|
37 | );
|
---|
38 |
|
---|
39 | while(c = getopt(argc, argv, "p:d:r:w:e"))
|
---|
40 | {
|
---|
41 | switch(c)
|
---|
42 | {
|
---|
43 | case '?':
|
---|
44 | case ':':
|
---|
45 | fprintf(stderr, "Unrecognized option -%c\n", optopt);
|
---|
46 | // TODO print help
|
---|
47 | exit(-1);
|
---|
48 | case 'p':
|
---|
49 | // Set port
|
---|
50 | if(sscanf(optarg, "%d", &port_base) != 1)
|
---|
51 | {
|
---|
52 | fprintf(stderr, "Invalid I/O port address\n");
|
---|
53 | exit(-4);
|
---|
54 | }
|
---|
55 | break;
|
---|
56 | case 'd':
|
---|
57 | // TODO Set device
|
---|
58 | if (strcmp(optarg, "AT29C040"))
|
---|
59 | {
|
---|
60 | fprintf(stderr,"Unknown device (only AT29C040 is supported)\n");
|
---|
61 | exit(-3);
|
---|
62 | }
|
---|
63 | device = new AT29C040();
|
---|
64 | break;
|
---|
65 | case 'r':
|
---|
66 | case 'w':
|
---|
67 | // Set file
|
---|
68 | file = optarg;
|
---|
69 | // Fallthrough
|
---|
70 | case 'e':
|
---|
71 | // Set operation
|
---|
72 | if (opcode != 0)
|
---|
73 | {
|
---|
74 | fprintf(stderr, "Multiple operations requested (only one of r,w,e is allowed)\n");
|
---|
75 | exit(-2);
|
---|
76 | }
|
---|
77 | opcode = c;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (opcode == 0)
|
---|
82 | {
|
---|
83 | fprintf(stderr, "No operation specified (one of r,w,e). Aborting.\n");
|
---|
84 | exit(-5);
|
---|
85 | }
|
---|
86 |
|
---|
87 | i386_set_ioperm(port_base, 3, true);
|
---|
88 |
|
---|
89 | // Configure voltage and powerpins according to device
|
---|
90 |
|
---|
91 | // Ask user to put ROM on socket
|
---|
92 |
|
---|
93 | // Do action (program/erase/write)
|
---|
94 | switch(opcode)
|
---|
95 | {
|
---|
96 | case 'r':
|
---|
97 | device->read(file);
|
---|
98 | break;
|
---|
99 | case 'w':
|
---|
100 | device->write(file);
|
---|
101 | break;
|
---|
102 | case 'e':
|
---|
103 | device->erase();
|
---|
104 | break;
|
---|
105 | }
|
---|
106 |
|
---|
107 | exit(0);
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|