annotate loadtools/flamdsec.c @ 987:6b87de9e385b

pln-ppb-test: implement mode-exit
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2023 00:01:03 +0000
parents 0407d14fb854
children 84c9869a3659
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
977
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
2 * This module is a place to implement commands and functions for
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
3 * sector write-protection (locking and unlocking, checking current
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
4 * lock state) on AMD-style flash chips.
977
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
11 #include <string.h>
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
12 #include <strings.h>
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
13 #include <unistd.h>
977
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "flash.h"
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern struct flash_bank_info flash_bank_info[2];
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
18 /*
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
19 * Some common functions for Spansion PL-N flash: common between
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
20 * flash lock-state retrieval and active PPB programming.
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
21 */
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
22
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
23 static
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
24 pln_special_mode_entry(base_addr, mode_opc)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
25 uint32_t base_addr;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
26 uint16_t mode_opc;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
27 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
28 if (do_w16(base_addr + 0xAAA, 0xAA)) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
29 bad_w16: fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
30 "unexpected response to w16 in PL-N special mode entry sequence - aborting\n");
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
31 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
32 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
33 if (do_w16(base_addr + 0x554, 0x55))
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
34 goto bad_w16;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
35 if (do_w16(base_addr + 0xAAA, mode_opc))
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
36 goto bad_w16;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
37 return(0);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
38 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
39
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
40 static
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
41 pln_special_mode_exit(base_addr)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
42 uint32_t base_addr;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
43 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
44 if (do_w16(base_addr, 0x90)) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
45 bad_w16: fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
46 "unexpected response to w16 in PL-N special mode exit sequence - aborting\n");
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
47 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
48 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
49 if (do_w16(base_addr, 0x00))
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
50 goto bad_w16;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
51 return(0);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
52 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
53
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
54 /*
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
55 * flash lock-state implementation with its helper functions.
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
56 */
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
57
977
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 static
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 issue_read_id(base_addr)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 uint32_t base_addr;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (do_w16(base_addr + 0xAAA, 0xAA)) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 bad_w16: fprintf(stderr,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 "unexpected response to w16 in read ID cmd sequence - aborting\n");
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (do_w16(base_addr + 0x554, 0x55))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (do_w16(base_addr + 0xAAA, 0x90))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return(0);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 static
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 issue_reset_cmd(base_addr)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 uint32_t base_addr;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (do_w16(base_addr + 0xAAA, 0xF0)) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 fprintf(stderr,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 "unexpected response to w16 when resetting flash to read mode!\n");
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 return(0);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 static
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 read_mode_lock_word(base_addr, word_offset, retp)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 uint32_t base_addr, word_offset;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 uint16_t *retp;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if (do_w16(base_addr + 0xAAA, 0xAA)) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 bad_w16: fprintf(stderr,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 "unexpected response to w16 in mode lock query sequence - aborting\n");
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (do_w16(base_addr + 0x554, 0x55))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (do_w16(base_addr + 0xAAA, 0x60))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (do_w16(base_addr + word_offset, 0x48))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (do_r16(base_addr + word_offset, retp) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 return(0);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 flashcmd_lock_state(argc, argv, bank)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 char **argv;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 struct flash_bank_info *bi;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 struct amd_lock_info *li;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 struct lock_group_desc *grp;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 uint32_t offset, part_addr;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 uint16_t word;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 unsigned ng, nb;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (argc > 2) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 fprintf(stderr, "error: too many arguments\n");
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 if (flash_detect(bank, 0) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 bi = flash_bank_info + bank;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 li = bi->amd_lock;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (!li) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 fprintf(stderr,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 "Operation not supported for this flash chip type\n");
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 offset = 0;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 for (ng = 0; ng < li->ngroups; ng++) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 grp = li->groups + ng;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 if (grp->part_begin) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 part_addr = bi->base_addr + offset;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 if (issue_read_id(part_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 if (offset == 0 && li->have_status_word_3) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 if (do_r16(bi->base_addr + 6, &word) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 printf("Global status word 3: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 if (offset == 0 && li->have_status_word_7) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 if (do_r16(bi->base_addr + 0xE, &word) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 printf("Global status word 7: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 for (nb = 0; nb < grp->nblocks; nb++) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 if (do_r16(bi->base_addr + offset + 4, &word) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 printf("Sector%s at 0x%X: %s\n",
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 grp->is_group ? " group" : "", offset,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 (word & 1) ? "locked" : "unlocked");
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 offset += grp->block_size;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 if (grp->part_end) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 if (issue_reset_cmd(part_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 if (li->have_mode_lock_bits) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (read_mode_lock_word(bi->base_addr, 0x14, &word) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 printf("Password Protection Mode lock: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 if (issue_reset_cmd(bi->base_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 if (read_mode_lock_word(bi->base_addr, 0x24, &word) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 printf("Persistent Protection Mode lock: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 if (issue_reset_cmd(bi->base_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 if (li->have_pln_lock_reg) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 if (pln_special_mode_entry(bi->base_addr, 0x40) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 if (do_r16(bi->base_addr, &word) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 printf("PL-N Lock Register: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 if (pln_special_mode_exit(bi->base_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 return(0);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
184
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
185 /*
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
186 * Here comes a version of the above lock-state checking code,
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
187 * modified for use from within ppb-program-all and ppb-erase-all
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
188 * functions for chips that don't do this work internally.
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
189 */
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
190
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
191 static
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
192 int_lock_state_check(bi, sought_state)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
193 struct flash_bank_info *bi;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
194 {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
195 struct amd_lock_info *li = bi->amd_lock;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
196 struct lock_group_desc *grp;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
197 uint32_t offset, part_addr;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
198 uint16_t word;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
199 unsigned ng, nb;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
200 int lock_state;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
201
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
202 offset = 0;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
203 for (ng = 0; ng < li->ngroups; ng++) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
204 grp = li->groups + ng;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
205 if (grp->part_begin) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
206 part_addr = bi->base_addr + offset;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
207 if (issue_read_id(part_addr) < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
208 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
209 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
210 for (nb = 0; nb < grp->nblocks; nb++) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
211 if (do_r16(bi->base_addr + offset + 4, &word) < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
212 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
213 lock_state = word & 1;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
214 if (lock_state != sought_state)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
215 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
216 offset += grp->block_size;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
217 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
218 if (lock_state != sought_state) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
219 if (issue_reset_cmd(part_addr) < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
220 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
221 return(0);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
222 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
223 if (grp->part_end) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
224 if (issue_reset_cmd(part_addr) < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
225 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
226 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
227 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
228 return(1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
229 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
230
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
231 /*
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
232 * Spansion PL-J PPB write functions, referenced from lock_info structures
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
233 * in fldevs.c device descriptions.
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
234 */
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
235
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
236 static
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
237 plj_ppb_write_op(base_addr, is_erase, retp)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
238 uint32_t base_addr;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
239 uint16_t *retp;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
240 {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
241 if (do_w16(base_addr + 0xAAA, 0xAA)) {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
242 bad_w16: fprintf(stderr,
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
243 "unexpected response to w16 in PPB command sequence - aborting\n");
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
244 return(-1);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
245 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
246 if (do_w16(base_addr + 0x554, 0x55))
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
247 goto bad_w16;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
248 if (do_w16(base_addr + 0xAAA, 0x60))
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
249 goto bad_w16;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
250 if (do_w16(base_addr + 4, is_erase ? 0x60 : 0x68))
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
251 goto bad_w16;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
252 usleep(1200); /* per S29PL-J datasheet */
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
253 if (do_w16(base_addr + 4, is_erase ? 0x40 : 0x48))
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
254 goto bad_w16;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
255 if (do_r16(base_addr + 4, retp) < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
256 return(-1);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
257 return(0);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
258 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
259
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
260 plj_ppb_program_one(bi, sector_addr)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
261 struct flash_bank_info *bi;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
262 uint32_t sector_addr;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
263 {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
264 uint16_t stat;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
265 unsigned pulsecnt;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
266 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
267
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
268 for (pulsecnt = 0; pulsecnt < 25; ) {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
269 rc = plj_ppb_write_op(bi->base_addr + sector_addr, 0, &stat);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
270 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
271 return(rc);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
272 pulsecnt++;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
273 if (!(stat & 1))
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
274 continue;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
275 printf("PPB 0x%X programmed with %u pulse%s\n", sector_addr,
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
276 pulsecnt, pulsecnt > 1 ? "s" : "");
982
1c5b485f10ba fc-loadtool flash: do AMD reset after PL-J PPB write operations
Mychaela Falconia <falcon@freecalypso.org>
parents: 981
diff changeset
277 return amd_reset_cmd(bi);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
278 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
279 fprintf(stderr, "PPB 0x%X programming FAILED, tried %u pulses\n",
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
280 sector_addr, pulsecnt);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
281 return(-1);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
282 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
283
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
284 plj_ppb_program_all(bi)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
285 struct flash_bank_info *bi;
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
286 {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
287 struct amd_lock_info *li = bi->amd_lock;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
288 struct lock_group_desc *grp;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
289 uint32_t offset;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
290 unsigned ng, nb;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
291 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
292
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
293 offset = 0;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
294 for (ng = 0; ng < li->ngroups; ng++) {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
295 grp = li->groups + ng;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
296 for (nb = 0; nb < grp->nblocks; nb++) {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
297 rc = plj_ppb_program_one(bi, offset);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
298 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
299 return(rc);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
300 offset += grp->block_size;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
301 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
302 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
303 printf("Verifying PPB programming\n");
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
304 rc = int_lock_state_check(bi, 1);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
305 if (rc < 0)
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
306 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
307 if (rc)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
308 return(0);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
309 fprintf(stderr, "flash error: one or more PPBs failed to program\n");
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
310 return(-1);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
311 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
312
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
313 static
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
314 plj_ppb_erase_cycle(bi)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
315 struct flash_bank_info *bi;
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
316 {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
317 uint16_t stat;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
318 unsigned pulsecnt;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
319 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
320
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
321 printf("Performing PPB erase cycle\n");
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
322 for (pulsecnt = 0; pulsecnt < 1000; ) {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
323 rc = plj_ppb_write_op(bi->base_addr, 1, &stat);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
324 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
325 return(rc);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
326 pulsecnt++;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
327 if (stat & 1)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
328 continue;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
329 printf("PPB erase cycle succeeded after %u pulse%s\n",
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
330 pulsecnt, pulsecnt > 1 ? "s" : "");
982
1c5b485f10ba fc-loadtool flash: do AMD reset after PL-J PPB write operations
Mychaela Falconia <falcon@freecalypso.org>
parents: 981
diff changeset
331 return amd_reset_cmd(bi);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
332 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
333 fprintf(stderr, "PPB erase cycle FAILED, tried %u pulses\n", pulsecnt);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
334 return(-1);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
335 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
336
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
337 plj_ppb_erase_all_single(bank, raw_mode)
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
338 {
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
339 struct flash_bank_info *bi = flash_bank_info + bank;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
340 unsigned pulsecnt;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
341 uint16_t stat;
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
342 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
343
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
344 if (raw_mode)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
345 return plj_ppb_erase_cycle(bi);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
346 printf("Programming all PPBs before erase cycle\n");
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
347 rc = plj_ppb_program_all(bi);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
348 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
349 return(-1);
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
350 printf("Entering PPB erase and verify loop\n");
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
351 for (pulsecnt = 0; ; ) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
352 if (pulsecnt >= 1000) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
353 fprintf(stderr,
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
354 "flash error: unable to complete PPB erase after %u pulses\n",
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
355 pulsecnt);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
356 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
357 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
358 rc = plj_ppb_write_op(bi->base_addr, 1, &stat);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
359 if (rc < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
360 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
361 pulsecnt++;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
362 if (stat & 1)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
363 continue;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
364 putchar('.');
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
365 fflush(stdout);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
366 rc = amd_reset_cmd(bi);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
367 if (rc < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
368 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
369 rc = int_lock_state_check(bi, 0);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
370 if (rc < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
371 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
372 if (rc)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
373 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
374 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
375 printf("\nPPB erase complete, total pulses: %u\n", pulsecnt);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
376 return(0);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
377 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
378
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
379 plj_ppb_erase_all_dualbank(reqbank, raw_mode)
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
380 {
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
381 int altbank = !reqbank;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
382 unsigned pulsecnt;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
383 uint16_t stat;
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
384 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
385
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
386 if (flash_detect(altbank, 0) < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
387 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
388 if (flash_bank_info[0].device != flash_bank_info[1].device) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
389 fprintf(stderr, "error: mismatch between two flash banks\n");
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
390 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
391 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
392 if (raw_mode)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
393 return plj_ppb_erase_cycle(flash_bank_info + reqbank);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
394 printf("Programming all PPBs in flash bank 0\n");
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
395 rc = plj_ppb_program_all(&flash_bank_info[0]);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
396 if (rc < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
397 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
398 printf("Programming all PPBs in flash bank 1\n");
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
399 rc = plj_ppb_program_all(&flash_bank_info[1]);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
400 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
401 return(-1);
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
402 printf("Entering PPB erase and verify loop\n");
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
403 for (pulsecnt = 0; ; ) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
404 if (pulsecnt >= 1000) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
405 fprintf(stderr,
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
406 "flash error: unable to complete PPB erase after %u pulses\n",
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
407 pulsecnt);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
408 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
409 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
410 rc = plj_ppb_write_op(flash_bank_info[0].base_addr, 1, &stat);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
411 if (rc < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
412 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
413 pulsecnt++;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
414 if (stat & 1)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
415 continue;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
416 putchar('.');
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
417 fflush(stdout);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
418 rc = amd_reset_cmd(&flash_bank_info[0]);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
419 if (rc < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
420 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
421 rc = int_lock_state_check(&flash_bank_info[0], 0);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
422 if (rc < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
423 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
424 if (!rc)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
425 continue;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
426 rc = int_lock_state_check(&flash_bank_info[1], 0);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
427 if (rc < 0)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
428 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
429 if (rc)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
430 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
431 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
432 printf("\nPPB erase complete, total pulses: %u\n", pulsecnt);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
433 return(0);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
434 }
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
435
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
436 /*
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
437 * Front end functions for PPB operation commands.
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
438 */
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
439
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
440 flashcmd_ppb_program(argc, argv, bank)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
441 char **argv;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
442 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
443 struct flash_bank_info *bi;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
444 struct amd_lock_info *li;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
445 u_long offset_arg;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
446 struct sector_info *sp;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
447 char *strtoul_endp;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
448
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
449 if (argc != 3) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
450 inv: fprintf(stderr, "usage: %s %s sector-offset\n",
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
451 argv[0], argv[1]);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
452 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
453 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
454 offset_arg = strtoul(argv[2], &strtoul_endp, 16);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
455 if (*strtoul_endp)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
456 goto inv;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
457 if (flash_detect(bank, 0) < 0)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
458 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
459 bi = flash_bank_info + bank;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
460 li = bi->amd_lock;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
461 if (!li || !li->ppb_program_one) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
462 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
463 "Operation not supported for this flash chip type\n");
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
464 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
465 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
466 if (offset_arg >= bi->geom->total_size) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
467 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
468 "error: specified offset exceeds flash bank size (0x%lx)\n",
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
469 (u_long) bi->geom->total_size);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
470 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
471 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
472 if (get_flash_sector_table(bi) < 0)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
473 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
474 for (sp = bi->sectors; sp->size; sp++)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
475 if (sp->start == offset_arg)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
476 break;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
477 if (!sp->size) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
478 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
479 "error: specified offset not aligned to a flash sector boundary\n");
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
480 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
481 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
482 return li->ppb_program_one(bi, sp->start);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
483 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
484
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
485 flashcmd_ppb_program_all(argc, argv, bank)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
486 char **argv;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
487 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
488 struct flash_bank_info *bi;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
489 struct amd_lock_info *li;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
490
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
491 if (argc > 2) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
492 fprintf(stderr, "error: too many arguments\n");
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
493 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
494 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
495 if (flash_detect(bank, 0) < 0)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
496 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
497 bi = flash_bank_info + bank;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
498 li = bi->amd_lock;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
499 if (!li || !li->ppb_program_all) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
500 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
501 "Operation not supported for this flash chip type\n");
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
502 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
503 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
504 return li->ppb_program_all(bi);
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
505 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
506
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
507 flashcmd_ppb_erase_all(argc, argv, bank)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
508 char **argv;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
509 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
510 struct flash_bank_info *bi;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
511 struct amd_lock_info *li;
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
512 int raw_mode;
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
513
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
514 switch (argc) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
515 case 2:
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
516 raw_mode = 0;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
517 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
518 case 3:
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
519 if (!strcmp(argv[2], "raw")) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
520 raw_mode = 1;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
521 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
522 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
523 /* FALL THRU */
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
524 default:
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
525 fprintf(stderr, "usage: %s %s [raw]\n", argv[0], argv[1]);
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
526 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
527 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
528 if (flash_detect(bank, 0) < 0)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
529 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
530 bi = flash_bank_info + bank;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
531 li = bi->amd_lock;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
532 if (!li || !li->ppb_erase_all) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
533 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
534 "Operation not supported for this flash chip type\n");
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
535 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
536 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
537 return li->ppb_erase_all(bank, raw_mode);
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
538 }