blob: be0b2413834d8bfcfccd3810b9ffb5c43ae08529 [file] [log] [blame]
David Hendricksee712472012-05-23 21:50:59 -07001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2012 The Chromium OS Authors. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * Neither the name of Google or the names of contributors or
18 * licensors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * This software is provided "AS IS," without a warranty of any kind.
22 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
23 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
24 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
25 * GOOGLE INC AND ITS LICENSORS SHALL NOT BE LIABLE
26 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
27 * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
28 * GOOGLE OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
29 * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
30 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
31 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
32 * EVEN IF GOOGLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33 */
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +080034
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include <unistd.h>
39#include "flashchips.h"
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +080040#include "fmap.h"
Louis Yung-Chieh Loc0505242012-08-09 23:11:32 +080041#include "gec_lock.h"
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080042#include "gec_ec_commands.h"
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +080043#include "programmer.h"
44#include "spi.h"
45#include "writeprotect.h"
46
Louis Yung-Chieh Lo05b7a7b2012-08-06 19:10:39 +080047/* FIXME: used for wp hacks */
48#include <sys/types.h>
49#include <sys/stat.h>
50#include <fcntl.h>
51#include <unistd.h>
52struct wp_data {
53 int enable;
54 unsigned int start;
55 unsigned int len;
56};
57static struct wp_data fake_wp;
58#define WP_STATE_HACK_FILENAME "/mnt/stateful_partition/flashrom_wp_state"
59
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +080060/* 1 if we want the flashrom to call erase_and_write_flash() again. */
61static int need_2nd_pass = 0;
62
Louis Yung-Chieh Lodeefd822012-07-09 17:07:43 +080063/* 1 if we want the flashrom to try jumping to new firmware after update. */
64static int try_latest_firmware = 0;
65
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +080066/* The range of each firmware copy from the image file to update.
67 * But re-define the .flags as the valid flag to indicate the firmware is
68 * new or not (if flags = 1).
69 */
70static struct fmap_area fwcopy[4]; // [0] is not used.
71
72/* The names of enum lpc_current_image to match in FMAP area names. */
David Hendricksbf8c4dd2012-07-19 12:13:17 -070073static const char *sections[3] = {
74 "UNKNOWN SECTION", // EC_IMAGE_UNKNOWN -- never matches
75 "EC_RO",
76 "EC_RW",
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +080077};
78
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +080079
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +080080/* Given the range not able to update, mark the corresponding
81 * firmware as old.
82 */
83static void gec_invalidate_copy(unsigned int addr, unsigned int len)
84{
85 int i;
86
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080087 for (i = EC_IMAGE_RO; i < ARRAY_SIZE(fwcopy); i++) {
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +080088 struct fmap_area *fw = &fwcopy[i];
89 if ((addr >= fw->offset && (addr < fw->offset + fw->size)) ||
90 (fw->offset >= addr && (fw->offset < addr + len))) {
91 msg_pdbg("Mark firmware [%s] as old.\n",
92 sections[i]);
93 fw->flags = 0; // mark as old
94 }
95 }
96}
97
98
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080099/* Asks EC to jump to a firmware copy. If target is EC_IMAGE_UNKNOWN,
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800100 * then this functions picks a NEW firmware copy and jumps to it. Note that
101 * RO is preferred, then A, finally B.
102 *
103 * Returns 0 for success.
104 */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800105static int gec_jump_copy(enum ec_current_image target) {
106 struct ec_response_get_version c;
107 struct ec_params_reboot_ec p;
David Hendricks7cfbd022012-05-20 17:25:51 -0700108 struct gec_priv *priv = (struct gec_priv *)opaque_programmer->data;
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800109 int rc;
110
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800111 /* Since the EC may return EC_RES_SUCCESS twice if the EC doesn't
112 * jump to different firmware copy. The second EC_RES_SUCCESS would
113 * set the OBF=1 and the next command cannot be executed.
114 * Thus, we call EC to jump only if the target is different.
115 */
116 rc = priv->ec_command(EC_CMD_GET_VERSION, 0, NULL, 0, &c, sizeof(c));
117 if (rc || c.current_image == EC_IMAGE_UNKNOWN) {
118 msg_perr("GEC cannot get the running copy: rc=%d\n", rc);
119 return 1;
120 }
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800121
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800122 memset(&p, 0, sizeof(p));
123 p.cmd = target != EC_IMAGE_UNKNOWN ? target :
124 fwcopy[EC_IMAGE_RO].flags ? EC_IMAGE_RO :
125 fwcopy[EC_IMAGE_RW].flags ? EC_IMAGE_RW :
126 EC_IMAGE_UNKNOWN;
127 msg_pdbg("GEC is jumping to [%s]\n", sections[p.cmd]);
128 if (p.cmd == EC_IMAGE_UNKNOWN) return 1;
129
130 if (c.current_image == p.cmd) {
131 msg_pdbg("GEC is already in [%s]\n", sections[p.cmd]);
132 return 0;
133 }
134
135 rc = priv->ec_command(EC_CMD_REBOOT_EC, 0,
David Hendricks7cfbd022012-05-20 17:25:51 -0700136 &p, sizeof(p), NULL, 0);
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800137 if (rc < 0) {
138 msg_perr("GEC cannot jump to [%s]:%d\n",
139 sections[p.cmd], rc);
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800140 } else {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800141 msg_pdbg("GEC has jumped to [%s]\n", sections[p.cmd]);
142 rc = EC_RES_SUCCESS;
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800143 }
144
145 /* Sleep 1 sec to wait the EC re-init. */
146 usleep(1000000);
147
148 return rc;
149}
150
151
152/* Given an image, this function parses FMAP and recognize the firmware
153 * ranges.
154 */
155int gec_prepare(uint8_t *image, int size) {
David Hendricks7cfbd022012-05-20 17:25:51 -0700156 struct gec_priv *priv = (struct gec_priv *)opaque_programmer->data;
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800157 struct fmap *fmap;
158 int i, j;
159
Louis Yung-Chieh Lo0eaa0ca2012-05-29 15:28:58 +0800160 if (!(priv && priv->detected)) return 0;
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800161
162 // Parse the fmap in the image file and cache the firmware ranges.
163 fmap = fmap_find_in_memory(image, size);
164 if (!fmap) return 0;
165
166 // Lookup RO/A/B sections in FMAP.
167 for (i = 0; i < fmap->nareas; i++) {
168 struct fmap_area *fa = &fmap->areas[i];
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800169 for (j = EC_IMAGE_RO; j < ARRAY_SIZE(sections); j++) {
David Hendricks5b06c882012-05-20 18:27:25 -0700170 if (!strcmp(sections[j], (const char *)fa->name)) {
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800171 msg_pdbg("Found '%s' in image.\n", fa->name);
172 memcpy(&fwcopy[j], fa, sizeof(*fa));
173 fwcopy[j].flags = 1; // mark as new
174 }
175 }
176 }
177
Louis Yung-Chieh Lodeefd822012-07-09 17:07:43 +0800178 /* Warning: before update, we jump the EC to RO copy. If you want to
179 * change this behavior, please also check the gec_finish().
180 */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800181 return gec_jump_copy(EC_IMAGE_RO);
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800182}
183
184
185/* Returns >0 if we need 2nd pass of erase_and_write_flash().
186 * <0 if we cannot jump to any firmware copy.
187 * ==0 if no more pass is needed.
188 *
189 * This function also jumps to new-updated firmware copy before return >0.
190 */
191int gec_need_2nd_pass(void) {
David Hendricks7cfbd022012-05-20 17:25:51 -0700192 struct gec_priv *priv = (struct gec_priv *)opaque_programmer->data;
193
Louis Yung-Chieh Lo0eaa0ca2012-05-29 15:28:58 +0800194 if (!(priv && priv->detected)) return 0;
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800195
196 if (need_2nd_pass) {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800197 if (gec_jump_copy(EC_IMAGE_UNKNOWN)) {
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800198 return -1;
199 }
200 }
201
202 return need_2nd_pass;
203}
204
205
Louis Yung-Chieh Lodeefd822012-07-09 17:07:43 +0800206/* Returns 0 for success.
207 *
208 * Try latest firmware: B > A > RO
209 *
210 * This function assumes the EC jumps to RO at gec_prepare() so that
211 * the fwcopy[RO].flags is old (0) and A/B are new. Please also refine
212 * this code logic if you change the gec_prepare() behavior.
213 */
214int gec_finish(void) {
215 struct gec_priv *priv = (struct gec_priv *)opaque_programmer->data;
216
217 if (!(priv && priv->detected)) return 0;
218
219 if (try_latest_firmware) {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800220 if (fwcopy[EC_IMAGE_RW].flags &&
221 gec_jump_copy(EC_IMAGE_RW) == 0) return 0;
222 return gec_jump_copy(EC_IMAGE_RO);
Louis Yung-Chieh Lodeefd822012-07-09 17:07:43 +0800223 }
224
225 return 0;
226}
227
228
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800229int gec_read(struct flashchip *flash, uint8_t *readarr,
230 unsigned int blockaddr, unsigned int readcnt) {
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800231 int rc = 0;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800232 struct ec_params_flash_read p;
David Hendricks7cfbd022012-05-20 17:25:51 -0700233 struct gec_priv *priv = (struct gec_priv *)opaque_programmer->data;
David Hendricksd6a0f662012-05-29 14:39:50 -0700234 int maxlen = opaque_programmer->max_data_read;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800235 uint8_t buf[maxlen];
David Hendricks133083b2012-07-17 20:39:38 -0700236 int offset = 0, count;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800237
David Hendricks133083b2012-07-17 20:39:38 -0700238 while (offset < readcnt) {
239 count = min(maxlen, readcnt - offset);
240 p.offset = blockaddr + offset;
241 p.size = count;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800242 rc = priv->ec_command(EC_CMD_FLASH_READ, 0,
243 &p, sizeof(p), buf, count);
244 if (rc < 0) {
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800245 msg_perr("GEC: Flash read error at offset 0x%x\n",
David Hendricks133083b2012-07-17 20:39:38 -0700246 blockaddr + offset);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800247 return rc;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800248 } else {
249 rc = EC_RES_SUCCESS;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800250 }
251
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800252 memcpy(readarr + offset, buf, count);
David Hendricks133083b2012-07-17 20:39:38 -0700253 offset += count;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800254 }
255
256 return rc;
257}
258
259
David Hendricks7cfbd022012-05-20 17:25:51 -0700260int gec_block_erase(struct flashchip *flash,
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800261 unsigned int blockaddr,
262 unsigned int len) {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800263 struct ec_params_flash_erase erase;
David Hendricks7cfbd022012-05-20 17:25:51 -0700264 struct gec_priv *priv = (struct gec_priv *)opaque_programmer->data;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800265 int rc;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800266
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800267 erase.offset = blockaddr;
268 erase.size = len;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800269 rc = priv->ec_command(EC_CMD_FLASH_ERASE, 0,
David Hendricks7cfbd022012-05-20 17:25:51 -0700270 &erase, sizeof(erase), NULL, 0);
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800271 if (rc == -EC_RES_ACCESS_DENIED) {
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800272 // this is active image.
273 gec_invalidate_copy(blockaddr, len);
274 need_2nd_pass = 1;
275 return ACCESS_DENIED;
276 }
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800277 if (rc < 0) {
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800278 msg_perr("GEC: Flash erase error at address 0x%x, rc=%d\n",
279 blockaddr, rc);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800280 return rc;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800281 } else {
282 rc = EC_RES_SUCCESS;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800283 }
284
Louis Yung-Chieh Lodeefd822012-07-09 17:07:43 +0800285 try_latest_firmware = 1;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800286 return rc;
287}
288
289
290int gec_write(struct flashchip *flash, uint8_t *buf, unsigned int addr,
291 unsigned int nbytes) {
292 int i, rc = 0;
293 unsigned int written = 0;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800294 struct ec_params_flash_write p;
David Hendricks7cfbd022012-05-20 17:25:51 -0700295 struct gec_priv *priv = (struct gec_priv *)opaque_programmer->data;
David Hendricksd6a0f662012-05-29 14:39:50 -0700296 int maxlen = opaque_programmer->max_data_write;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800297
298 for (i = 0; i < nbytes; i += written) {
David Hendricksd6a0f662012-05-29 14:39:50 -0700299 written = min(nbytes - i, maxlen);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800300 p.offset = addr + i;
301 p.size = written;
302 memcpy(p.data, &buf[i], written);
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800303 rc = priv->ec_command(EC_CMD_FLASH_WRITE, 0,
David Hendricks7cfbd022012-05-20 17:25:51 -0700304 &p, sizeof(p), NULL, 0);
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800305 if (rc == -EC_RES_ACCESS_DENIED) {
Louis Yung-Chieh Lo8d0971e2012-03-23 00:07:38 +0800306 // this is active image.
307 gec_invalidate_copy(addr, nbytes);
308 need_2nd_pass = 1;
309 return ACCESS_DENIED;
310 }
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800311
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800312 if (rc < 0) break;
313 rc = EC_RES_SUCCESS;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800314 }
315
Louis Yung-Chieh Lodeefd822012-07-09 17:07:43 +0800316 try_latest_firmware = 1;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800317 return rc;
318}
319
320
321static int gec_list_ranges(const struct flashchip *flash) {
322 msg_pinfo("You can specify any range:\n");
323 msg_pinfo(" from: 0x%06x, to: 0x%06x\n", 0, flash->total_size * 1024);
Randall Spangler6e160ef2012-07-18 09:36:25 -0700324 msg_pinfo(" unit: 0x%06x (%dKB)\n", 2048, 2);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800325 return 0;
326}
327
328
Louis Yung-Chieh Lo05b7a7b2012-08-06 19:10:39 +0800329/* Temporary solution before the real EC WP is ready. This is a hack to
330 * avoid breaking factory procedure.
331 * This should be removed after crosbug.com/p/11320 and 11219 are fixed.
332 */
333static int load_fake_wp(void) {
334 int fd;
335
336 if ((fd = open(WP_STATE_HACK_FILENAME, O_RDONLY)) == -1)
337 goto read_err;
338
339 if (read(fd, &fake_wp, sizeof(fake_wp)) != sizeof(fake_wp))
340 goto read_err;
341
342 close(fd);
343 return 0;
344
345read_err:
346 memset(&fake_wp, 0 , sizeof(fake_wp));
347 return 0;
348}
349
350static int save_fake_wp(void) {
351 int fd;
352
353 if ((fd = open(WP_STATE_HACK_FILENAME,
354 O_CREAT | O_TRUNC | O_RDWR, 0644)) == -1)
355 return -1;
356
357 if (write(fd, &fake_wp, sizeof(fake_wp)) != sizeof(fake_wp))
358 return -1;
359
360 close(fd);
361 return 0;
362}
363
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800364static int gec_set_range(const struct flashchip *flash,
365 unsigned int start, unsigned int len) {
Randall Spangler6e160ef2012-07-18 09:36:25 -0700366 /* TODO: update to latest ec_commands.h and reimplement. */
Louis Yung-Chieh Lo05b7a7b2012-08-06 19:10:39 +0800367 int rc;
368
369 rc = system("crossystem wpsw_cur?1");
370 if (rc) /* change-able only when WP pin is de-asserted. */
371 return -1;
372 load_fake_wp();
373 fake_wp.start = start;
374 fake_wp.len = len;
375 return save_fake_wp();
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800376}
377
378
379static int gec_enable_writeprotect(const struct flashchip *flash) {
Randall Spangler6e160ef2012-07-18 09:36:25 -0700380 /* TODO: update to latest ec_commands.h and reimplement. */
Louis Yung-Chieh Lo05b7a7b2012-08-06 19:10:39 +0800381 load_fake_wp();
382 fake_wp.enable = 1;
383 return save_fake_wp();
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800384}
385
386
387static int gec_disable_writeprotect(const struct flashchip *flash) {
Randall Spangler6e160ef2012-07-18 09:36:25 -0700388 /* TODO: update to latest ec_commands.h and reimplement. */
Louis Yung-Chieh Lo05b7a7b2012-08-06 19:10:39 +0800389 int rc;
390
391 rc = system("crossystem wpsw_cur?1");
392 if (rc) /* change-able only when WP pin is de-asserted. */
393 return -1;
394 load_fake_wp();
395 fake_wp.enable = 0;
396 return save_fake_wp();
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800397}
398
399
400static int gec_wp_status(const struct flashchip *flash) {
Randall Spangler6e160ef2012-07-18 09:36:25 -0700401 /*
402 * TODO: update to latest ec_commands.h and reimplement. For now,
403 * just claim chip is unprotected.
404 */
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800405
Louis Yung-Chieh Lo05b7a7b2012-08-06 19:10:39 +0800406 load_fake_wp();
Randall Spangler6e160ef2012-07-18 09:36:25 -0700407 msg_pinfo("WP: status: 0x%02x\n", 0);
408 msg_pinfo("WP: status.srp0: %x\n", 0);
Louis Yung-Chieh Lo05b7a7b2012-08-06 19:10:39 +0800409 msg_pinfo("WP: write protect is %s.\n",
410 fake_wp.enable ? "enabled" : "disabled");
411 msg_pinfo("WP: write protect range: start=0x%08x, len=0x%08x\n",
412 fake_wp.start, fake_wp.len);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800413
Louis Yung-Chieh Lo05b7a7b2012-08-06 19:10:39 +0800414 /* TODO: Fix scripts which rely on SPI-specific terminology. */
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800415 return 0;
416}
417
418
David Hendricks7cfbd022012-05-20 17:25:51 -0700419int gec_probe_size(struct flashchip *flash) {
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800420 int rc;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800421 struct ec_response_flash_info info;
David Hendricks7cfbd022012-05-20 17:25:51 -0700422 struct gec_priv *priv = (struct gec_priv *)opaque_programmer->data;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800423 struct block_eraser *eraser;
424 static struct wp wp = {
425 .list_ranges = gec_list_ranges,
426 .set_range = gec_set_range,
427 .enable = gec_enable_writeprotect,
428 .disable = gec_disable_writeprotect,
429 .wp_status = gec_wp_status,
430 };
431
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800432 rc = priv->ec_command(EC_CMD_FLASH_INFO, 0,
David Hendricks7cfbd022012-05-20 17:25:51 -0700433 NULL, 0, &info, sizeof(info));
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800434 if (rc < 0) {
435 msg_perr("%s(): FLASH_INFO returns %d.\n", __func__, rc);
436 return 0;
437 }
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800438
439 flash->total_size = info.flash_size / 1024;
David Hendricks0d3fcb52012-07-08 18:37:43 -0700440 flash->page_size = 64;
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800441 flash->tested = TEST_OK_PREW;
442 eraser = &flash->block_erasers[0];
443 eraser->eraseblocks[0].size = info.erase_block_size;
444 eraser->eraseblocks[0].count = info.flash_size /
445 eraser->eraseblocks[0].size;
446 flash->wp = &wp;
447
448 return 1;
449};