annotate loadtools/flamdsec.c @ 998:fb7442e3d430

CHANGES: mention flash write protection support
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 04 Dec 2023 02:17:54 +0000
parents ad3041e19884
children
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>
994
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
13 #include <time.h>
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
14 #include <unistd.h>
977
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "flash.h"
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 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
18
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
19 /*
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
20 * 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
21 * flash lock-state retrieval and active PPB programming.
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
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
24 static
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
25 pln_special_mode_entry(base_addr, mode_opc)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
26 uint32_t base_addr;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
27 uint16_t mode_opc;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
28 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
29 if (do_w16(base_addr + 0xAAA, 0xAA)) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
30 bad_w16: fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
31 "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
32 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
33 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
34 if (do_w16(base_addr + 0x554, 0x55))
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
35 goto bad_w16;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
36 if (do_w16(base_addr + 0xAAA, mode_opc))
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
37 goto bad_w16;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
38 return(0);
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
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
41 static
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
42 pln_special_mode_exit(base_addr)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
43 uint32_t base_addr;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
44 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
45 if (do_w16(base_addr, 0x90)) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
46 bad_w16: fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
47 "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
48 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
49 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
50 if (do_w16(base_addr, 0x00))
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
51 goto bad_w16;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
52 return(0);
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 /*
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
56 * flash lock-state implementation with its helper functions.
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
57 */
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
58
977
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 static
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 issue_read_id(base_addr)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 uint32_t base_addr;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (do_w16(base_addr + 0xAAA, 0xAA)) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 bad_w16: fprintf(stderr,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 "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
66 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (do_w16(base_addr + 0x554, 0x55))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (do_w16(base_addr + 0xAAA, 0x90))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return(0);
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
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 static
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 issue_reset_cmd(base_addr)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 uint32_t base_addr;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (do_w16(base_addr + 0xAAA, 0xF0)) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fprintf(stderr,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 "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
82 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return(0);
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
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 static
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 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
89 uint32_t base_addr, word_offset;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 uint16_t *retp;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (do_w16(base_addr + 0xAAA, 0xAA)) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 bad_w16: fprintf(stderr,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 "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
95 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if (do_w16(base_addr + 0x554, 0x55))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 if (do_w16(base_addr + 0xAAA, 0x60))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 if (do_w16(base_addr + word_offset, 0x48))
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 goto bad_w16;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 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
104 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 return(0);
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
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 flashcmd_lock_state(argc, argv, bank)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 char **argv;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 struct flash_bank_info *bi;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 struct amd_lock_info *li;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 struct lock_group_desc *grp;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 uint32_t offset, part_addr;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 uint16_t word;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 unsigned ng, nb;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (argc > 2) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 fprintf(stderr, "error: too many arguments\n");
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (flash_detect(bank, 0) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 bi = flash_bank_info + bank;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 li = bi->amd_lock;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (!li) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 fprintf(stderr,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 "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
129 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 offset = 0;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 for (ng = 0; ng < li->ngroups; ng++) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 grp = li->groups + ng;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 if (grp->part_begin) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 part_addr = bi->base_addr + offset;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (issue_read_id(part_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 if (offset == 0 && li->have_status_word_3) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 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
141 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 printf("Global status word 3: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 if (offset == 0 && li->have_status_word_7) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 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
146 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 printf("Global status word 7: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 for (nb = 0; nb < grp->nblocks; nb++) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 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
151 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 printf("Sector%s at 0x%X: %s\n",
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 grp->is_group ? " group" : "", offset,
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 (word & 1) ? "locked" : "unlocked");
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 offset += grp->block_size;
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 if (grp->part_end) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 if (issue_reset_cmd(part_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 return(-1);
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 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (li->have_mode_lock_bits) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 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
164 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 printf("Password Protection Mode lock: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (issue_reset_cmd(bi->base_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 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
169 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 printf("Persistent Protection Mode lock: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if (issue_reset_cmd(bi->base_addr) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 if (li->have_pln_lock_reg) {
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 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
176 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 if (do_r16(bi->base_addr, &word) < 0)
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 printf("PL-N Lock Register: %04X\n", word);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 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
181 return(-1);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 }
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 return(0);
511e2b85c115 fc-loadtool: implement flash lock-state command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
185
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
186 /*
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
187 * 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
188 * 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
189 * 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
190 */
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
191
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
192 static
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
193 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
194 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
195 {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
196 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
197 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
198 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
199 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
200 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
201 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
202
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
203 offset = 0;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
204 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
205 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
206 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
207 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
208 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
209 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
210 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
211 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
212 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
213 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
214 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
215 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
216 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
217 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
218 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
219 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
220 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
221 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
222 return(0);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
223 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
224 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
225 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
226 return(-1);
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 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
229 return(1);
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
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
232 /*
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
233 * 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
234 * in fldevs.c device descriptions.
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
235 */
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
236
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
237 static
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
238 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
239 uint32_t base_addr;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
240 uint16_t *retp;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
241 {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
242 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
243 bad_w16: fprintf(stderr,
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
244 "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
245 return(-1);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
246 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
247 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
248 goto bad_w16;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
249 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
250 goto bad_w16;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
251 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
252 goto bad_w16;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
253 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
254 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
255 goto bad_w16;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
256 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
257 return(-1);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
258 return(0);
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
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
261 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
262 struct flash_bank_info *bi;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
263 uint32_t sector_addr;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
264 {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
265 uint16_t stat;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
266 unsigned pulsecnt;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
267 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
268
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
269 for (pulsecnt = 0; pulsecnt < 25; ) {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
270 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
271 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
272 return(rc);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
273 pulsecnt++;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
274 if (!(stat & 1))
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
275 continue;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
276 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
277 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
278 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
279 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
280 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
281 sector_addr, pulsecnt);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
282 return(-1);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
283 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
284
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
285 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
286 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
287 {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
288 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
289 struct lock_group_desc *grp;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
290 uint32_t offset;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
291 unsigned ng, nb;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
292 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
293
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
294 offset = 0;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
295 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
296 grp = li->groups + ng;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
297 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
298 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
299 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
300 return(rc);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
301 offset += grp->block_size;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
302 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
303 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
304 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
305 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
306 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
307 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
308 if (rc)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
309 return(0);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
310 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
311 return(-1);
979
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
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
314 static
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
315 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
316 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
317 {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
318 uint16_t stat;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
319 unsigned pulsecnt;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
320 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
321
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
322 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
323 for (pulsecnt = 0; pulsecnt < 1000; ) {
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
324 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
325 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
326 return(rc);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
327 pulsecnt++;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
328 if (stat & 1)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
329 continue;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
330 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
331 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
332 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
333 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
334 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
335 return(-1);
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
336 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
337
993
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
338 plj_ppb_erase_all_single(bi, raw_mode)
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
339 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
340 {
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
341 unsigned pulsecnt;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
342 uint16_t stat;
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
343 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
344
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
345 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
346 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
347 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
348 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
349 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
350 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
351 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
352 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
353 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
354 fprintf(stderr,
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
355 "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
356 pulsecnt);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
357 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
358 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
359 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
360 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
361 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
362 pulsecnt++;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
363 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
364 continue;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
365 putchar('.');
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
366 fflush(stdout);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
367 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
368 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
369 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
370 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
371 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
372 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
373 if (rc)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
374 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
375 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
376 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
377 return(0);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
378 }
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
379
993
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
380 plj_ppb_erase_all_dualbank(dummy_bi, raw_mode)
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
381 void *dummy_bi;
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
382 {
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
383 unsigned pulsecnt;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
384 uint16_t stat;
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
385 int rc;
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
386
993
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
387 if (flash_detect(0, 0) < 0)
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
388 return(-1);
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
389 if (flash_detect(1, 0) < 0)
983
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 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
392 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
393 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
394 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
395 if (raw_mode)
993
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
396 return plj_ppb_erase_cycle(&flash_bank_info[0]);
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
397 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
398 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
399 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
400 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
401 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
402 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
403 if (rc < 0)
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
404 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
405 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
406 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
407 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
408 fprintf(stderr,
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
409 "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
410 pulsecnt);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
411 return(-1);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
412 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
413 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
414 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
415 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
416 pulsecnt++;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
417 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
418 continue;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
419 putchar('.');
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
420 fflush(stdout);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
421 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
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 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
425 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
426 return(rc);
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)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
428 continue;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
429 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
430 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
431 return(rc);
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
432 if (rc)
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
433 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
434 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
435 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
436 return(0);
979
c5133c3c11b1 fc-loadtool flash: implement PL-J PPB programming functions
Mychaela Falconia <falcon@freecalypso.org>
parents: 977
diff changeset
437 }
981
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 /*
994
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
440 * Spansion PL-N PPB write functions, referenced from lock_info structures
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
441 * in fldevs.c device descriptions.
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
442 */
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
443
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
444 static
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
445 pln_ppb_write_op(oper_addr, write1, write2, expect_stat)
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
446 uint32_t oper_addr;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
447 uint16_t write1, write2, expect_stat;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
448 {
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
449 int rc;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
450 uint16_t read_stat, prev_stat;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
451 time_t start_time, curtime;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
452
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
453 rc = pln_special_mode_entry(oper_addr, 0xC0);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
454 if (rc < 0)
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
455 return(rc);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
456 if (do_w16(oper_addr, write1)) {
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
457 bad_w16: fprintf(stderr,
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
458 "unexpected response to w16 in PPB command sequence - aborting\n");
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
459 return(-1);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
460 }
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
461 if (do_w16(oper_addr, write2))
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
462 goto bad_w16;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
463 printf("Polling for completion status\n");
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
464 usleep(10000); /* make sure we don't get state before op starts */
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
465 start_time = time(0);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
466 rc = do_r16(oper_addr, &read_stat);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
467 if (rc < 0)
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
468 return(rc);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
469 for (;;) {
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
470 prev_stat = read_stat;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
471 rc = do_r16(oper_addr, &read_stat);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
472 if (rc < 0)
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
473 return(rc);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
474 if (read_stat == expect_stat && prev_stat == expect_stat)
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
475 break;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
476 curtime = time(0);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
477 if (curtime >= start_time + 10) {
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
478 fprintf(stderr, "operation timeout, aborting\n");
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
479 return(-1);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
480 }
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
481 }
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
482 printf("Operation completed successfully\n");
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
483 return pln_special_mode_exit(oper_addr);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
484 }
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
485
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
486 pln_ppb_program_one(bi, sector_addr)
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
487 struct flash_bank_info *bi;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
488 uint32_t sector_addr;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
489 {
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
490 printf("Issuing PPB Program command\n");
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
491 return pln_ppb_write_op(bi->base_addr + sector_addr, 0xA0, 0, 0);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
492 }
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
493
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
494 pln_ppb_erase_all(bi, raw_mode)
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
495 struct flash_bank_info *bi;
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
496 {
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
497 printf("Issuing All PPB Erase command\n");
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
498 return pln_ppb_write_op(bi->base_addr, 0x80, 0x30, 1);
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
499 }
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
500
ad3041e19884 fc-loadtool flash: implement PPB ops for Spansion PL-N
Mychaela Falconia <falcon@freecalypso.org>
parents: 993
diff changeset
501 /*
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
502 * Front end functions for PPB operation commands.
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
503 */
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
504
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
505 flashcmd_ppb_program(argc, argv, bank)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
506 char **argv;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
507 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
508 struct flash_bank_info *bi;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
509 struct amd_lock_info *li;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
510 u_long offset_arg;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
511 struct sector_info *sp;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
512 char *strtoul_endp;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
513
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
514 if (argc != 3) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
515 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
516 argv[0], argv[1]);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
517 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
518 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
519 offset_arg = strtoul(argv[2], &strtoul_endp, 16);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
520 if (*strtoul_endp)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
521 goto inv;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
522 if (flash_detect(bank, 0) < 0)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
523 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
524 bi = flash_bank_info + bank;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
525 li = bi->amd_lock;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
526 if (!li || !li->ppb_program_one) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
527 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
528 "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
529 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
530 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
531 if (offset_arg >= bi->geom->total_size) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
532 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
533 "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
534 (u_long) bi->geom->total_size);
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 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
537 if (get_flash_sector_table(bi) < 0)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
538 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
539 for (sp = bi->sectors; sp->size; sp++)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
540 if (sp->start == offset_arg)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
541 break;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
542 if (!sp->size) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
543 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
544 "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
545 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
546 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
547 return li->ppb_program_one(bi, sp->start);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
548 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
549
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
550 flashcmd_ppb_program_all(argc, argv, bank)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
551 char **argv;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
552 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
553 struct flash_bank_info *bi;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
554 struct amd_lock_info *li;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
555
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
556 if (argc > 2) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
557 fprintf(stderr, "error: too many arguments\n");
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
558 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
559 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
560 if (flash_detect(bank, 0) < 0)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
561 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
562 bi = flash_bank_info + bank;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
563 li = bi->amd_lock;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
564 if (!li || !li->ppb_program_all) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
565 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
566 "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
567 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
568 }
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
569 return li->ppb_program_all(bi);
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
570 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
571
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
572 flashcmd_ppb_erase_all(argc, argv, bank)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
573 char **argv;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
574 {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
575 struct flash_bank_info *bi;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
576 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
577 int raw_mode;
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
578
983
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
579 switch (argc) {
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
580 case 2:
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
581 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
582 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
583 case 3:
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
584 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
585 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
586 break;
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
587 }
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
588 /* FALL THRU */
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
589 default:
0407d14fb854 PL-J flash PPB ops: rework for full verification of lock state
Mychaela Falconia <falcon@freecalypso.org>
parents: 982
diff changeset
590 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
591 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
592 }
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
593 if (flash_detect(bank, 0) < 0)
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
594 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
595 bi = flash_bank_info + bank;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
596 li = bi->amd_lock;
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
597 if (!li || !li->ppb_erase_all) {
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
598 fprintf(stderr,
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
599 "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
600 return(-1);
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
601 }
993
84c9869a3659 flash PPB erase: make internal API more consistent
Mychaela Falconia <falcon@freecalypso.org>
parents: 983
diff changeset
602 return li->ppb_erase_all(bi, raw_mode);
981
f21798eb13cf fc-loadtool: implement flash ppb-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 979
diff changeset
603 }