wpflash-gentoo.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. --- wpflash.c
  2. +++ wpflash.c
  3. @@ -5,6 +5,9 @@
  4. #include <termios.h>
  5. #include <linux/ppdev.h>
  6. #include <sys/ioctl.h>
  7. +#include <unistd.h>
  8. +#include <stdlib.h>
  9. +#include <string.h>
  10. int do_write(int, void *, int);
  11. int do_read(int, void *, int);
  12. @@ -74,6 +77,13 @@ struct partition_table {
  13. struct partition modified;
  14. struct partition *find_partition(char *);
  15. +void usage();
  16. +void bad_partition(char *name);
  17. +int erase_sector(int addr);
  18. +int read_object(char *filename, char *memory, int rom_size);
  19. +int read_raw(char *filename, char *memory, int rom_size);
  20. +int write_flash(int addr, char *buffer, int length);
  21. +int read_flash(int addr, char *buffer, int length);
  22. /* This structure defines the sectors
  23. on the FLASH */
  24. @@ -199,7 +209,8 @@ find_partition(char *name)
  25. return fixup_partition(partition);
  26. partition++;
  27. }
  28. - bad_partition();
  29. + bad_partition(name);
  30. + return NULL;
  31. }
  32. /* Initialize a "cmd" structure */
  33. @@ -224,6 +235,7 @@ set_cmd(struct cmd *cmd, char type, int
  34. waiting for "CONTROL-A" to signal it should jump
  35. to the programming code */
  36. +void
  37. wait_boot_prompt()
  38. {
  39. char line[256], *s;
  40. @@ -236,7 +248,7 @@ wait_boot_prompt()
  41. else if (*s == '\n') {
  42. *s = 0;
  43. if (strcmp(line, "Enter CTRL-A to enter programmer.") == 0)
  44. - return 1;
  45. + return;
  46. s = line;
  47. } else {
  48. s++;
  49. @@ -246,6 +258,7 @@ wait_boot_prompt()
  50. /* Erase a partition */
  51. +int
  52. erase_partition(char *name) {
  53. struct partition *partition = find_partition(name);
  54. @@ -328,16 +341,18 @@ erase_partition(char *name) {
  55. }
  56. }
  57. printf("done.\n");
  58. +
  59. + return 0;
  60. }
  61. /* Program a partition */
  62. +int
  63. program_partition(char *name, char *filename, int hexdump)
  64. {
  65. struct partition *partition = find_partition(name);
  66. int addr, maxaddr, maxpgm, addrincr, startaddr;
  67. - int i;
  68. /* Load data to be programmed in either hex or binary
  69. format */
  70. @@ -384,6 +399,7 @@ program_partition(char *name, char *file
  71. /* Read a partition */
  72. +int
  73. read_partition(char *name, char *filename)
  74. {
  75. struct partition *partition = find_partition(name);
  76. @@ -421,13 +437,17 @@ read_partition(char *name, char *filenam
  77. return(0);
  78. }
  79. +int pp_open();
  80. +int hello();
  81. +int initialize();
  82. +int device_id(int *deviceID1, int *deviceID2);
  83. +int device_id_v0(int *deviceID1, int *deviceID2);
  84. +int double_wide();
  85. +int parse_flash_params(char *filename);
  86. +
  87. +int
  88. main(int argc, char **argv) {
  89. - struct termios termios;
  90. - char c;
  91. - int i;
  92. - int cpid;
  93. - int count;
  94. - int maxcount;
  95. + struct termios termios;
  96. int version;
  97. int deviceID1, deviceID2;
  98. struct flash_chip *f;
  99. @@ -607,6 +627,8 @@ main(int argc, char **argv) {
  100. /* If we got to here, an invalid operation was specified */
  101. usage();
  102. +
  103. + return 0;
  104. }
  105. /* Reads a block of data from the flash.
  106. @@ -632,7 +654,7 @@ read_flash(int addr, char *buffer, int l
  107. for (count = 0; count < length + 1; count = count + readl) {
  108. readl = do_read(sfd, buffer+count, length+1-count);
  109. if (readl == 0)
  110. - exit;
  111. + exit(0);
  112. }
  113. /* Check checksum at end of data */
  114. @@ -662,7 +684,6 @@ write_flash(int addr, char *buffer, int
  115. struct cmd cmd;
  116. int count;
  117. int checksum;
  118. - int readl;
  119. char checksumbuf[1];
  120. /* Build and send "W" command to programmer.
  121. @@ -705,6 +726,7 @@ write_flash(int addr, char *buffer, int
  122. /* Send initialize command */
  123. +int
  124. initialize() {
  125. struct cmd cmd;
  126. char checksumbuf[1];
  127. @@ -770,6 +792,7 @@ int device_id_v0(int *deviceID1, int *de
  128. Note supported on Version 0 programmers. */
  129. +int
  130. double_wide() {
  131. struct cmd cmd;
  132. char checksumbuf[1];
  133. @@ -835,6 +858,7 @@ hello() {
  134. /* Send erase (whole flash) command */
  135. +int
  136. erase() {
  137. struct cmd cmd;
  138. char checksumbuf[1];
  139. @@ -857,6 +881,7 @@ erase() {
  140. /* Send erase sector command */
  141. +int
  142. erase_sector(int addr) {
  143. struct cmd cmd;
  144. char checksumbuf[1];
  145. @@ -900,7 +925,7 @@ hex(char c) {
  146. int parse_line(char *buffer, char *mem, int rom_size, int *max_mem) {
  147. char *c = buffer;
  148. - unsigned int address, word_addr;
  149. + unsigned int address;
  150. unsigned int length,type;
  151. unsigned int checksum = 0;
  152. int count = 0;
  153. @@ -1020,10 +1045,7 @@ int
  154. read_raw(char *filename, char *memory, int rom_size)
  155. {
  156. FILE *f;
  157. - char line[80];
  158. - int lines_read = 0;
  159. int count = 0;
  160. - int bytes ;
  161. static int max_mem;
  162. max_mem = 0;
  163. @@ -1042,7 +1064,7 @@ read_raw(char *filename, char *memory, i
  164. exit(1);
  165. }
  166. - while (count = fread(memory, 1, 1024, f)) {
  167. + while ((count = fread(memory, 1, 1024, f))) {
  168. memory += count;
  169. max_mem += count;
  170. }
  171. @@ -1053,12 +1075,13 @@ read_raw(char *filename, char *memory, i
  172. return max_mem; //return highest memory address used
  173. }
  174. -bad_partition(char *name)
  175. +void bad_partition(char *name)
  176. {
  177. fprintf(stderr, "Unknown partition: %s\n\n", name);
  178. usage();
  179. }
  180. +void
  181. usage() {
  182. struct partition *partition = partition_table;
  183. @@ -1077,6 +1100,7 @@ usage() {
  184. exit(1);
  185. }
  186. +void
  187. pp_write(int fd, char value)
  188. {
  189. u_char d = value;