blob: c364efa17c29f5dfee0fea60022596a48f78daf0 [file] [log] [blame]
Stefan Tauner9b32de92014-08-08 23:52:33 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5 * Copyright (C) 2009 Carl-Daniel Hailfinger
6 * Copyright (C) 2011-2014 Stefan Tauner
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Stefan Tauner9b32de92014-08-08 23:52:33 +000017 */
18
19#include <stdlib.h>
20#include <string.h>
Nico Huber34e783a2023-02-11 00:30:27 +010021
Stefan Tauner9b32de92014-08-08 23:52:33 +000022#include "flash.h"
Nico Huber34e783a2023-02-11 00:30:27 +010023#include "cli.h"
24
25int cli_parse_flash_args(struct flash_args *const args, const int opt, const char *const optarg)
26{
27 switch (opt) {
28 case OPTION_PROGRAMMER:
29 if (args->prog_name) {
30 fprintf(stderr,
31 "Error: --programmer specified more than once. You can separate multiple\n"
32 "arguments for a programmer with ','. Please see the man page for details.\n");
33 return 1;
34 }
35 const char *const colon = strchr(optarg, ':');
36 if (colon) {
37 args->prog_name = strndup(optarg, colon - optarg);
38 args->prog_args = strdup(colon + 1);
39 } else {
40 args->prog_name = strdup(optarg);
41 }
42 if (!args->prog_name || (colon && !args->prog_args)) {
43 fprintf(stderr, "Out of memory!\n");
44 return 2;
45 }
46 break;
47 case OPTION_CHIP:
48 if (args->chip) {
49 fprintf(stderr, "Error: --chip specified more than once.\n");
50 return 1;
51 }
52 args->chip = strdup(optarg);
53 if (!args->chip) {
54 fprintf(stderr, "Out of memory!\n");
55 return 2;
56 }
57 break;
58 }
59
60 return 0;
61}
Stefan Tauner9b32de92014-08-08 23:52:33 +000062
Stefan Tauner9b32de92014-08-08 23:52:33 +000063void print_chip_support_status(const struct flashchip *chip)
64{
65 if (chip->feature_bits & FEATURE_OTP) {
Nico Huberc3b02dc2023-08-12 01:13:45 +020066 msg_cdbg("This chip may contain one-time programmable memory. flashprog cannot read\n"
Stefan Tauner9b32de92014-08-08 23:52:33 +000067 "and may never be able to write it, hence it may not be able to completely\n"
68 "clone the contents of this chip (see man page for details).\n");
69 }
70
71 if ((chip->tested.erase == NA) && (chip->tested.write == NA)) {
72 msg_cdbg("This chip's main memory can not be erased/written by design.\n");
73 }
74
75 if ((chip->tested.probe == BAD) || (chip->tested.probe == NT) ||
76 (chip->tested.read == BAD) || (chip->tested.read == NT) ||
77 (chip->tested.erase == BAD) || (chip->tested.erase == NT) ||
Nico Huberbb4f3b02022-12-30 14:28:06 +010078 (chip->tested.write == BAD) || (chip->tested.write == NT)) {
Stefan Tauner9b32de92014-08-08 23:52:33 +000079 msg_cinfo("===\n");
80 if ((chip->tested.probe == BAD) ||
81 (chip->tested.read == BAD) ||
82 (chip->tested.erase == BAD) ||
Nico Huberbb4f3b02022-12-30 14:28:06 +010083 (chip->tested.write == BAD)) {
Stefan Tauner9b32de92014-08-08 23:52:33 +000084 msg_cinfo("This flash part has status NOT WORKING for operations:");
85 if (chip->tested.probe == BAD)
86 msg_cinfo(" PROBE");
87 if (chip->tested.read == BAD)
88 msg_cinfo(" READ");
89 if (chip->tested.erase == BAD)
90 msg_cinfo(" ERASE");
91 if (chip->tested.write == BAD)
92 msg_cinfo(" WRITE");
93 msg_cinfo("\n");
94 }
95 if ((chip->tested.probe == NT) ||
96 (chip->tested.read == NT) ||
97 (chip->tested.erase == NT) ||
Nico Huberbb4f3b02022-12-30 14:28:06 +010098 (chip->tested.write == NT)) {
Stefan Tauner9b32de92014-08-08 23:52:33 +000099 msg_cinfo("This flash part has status UNTESTED for operations:");
100 if (chip->tested.probe == NT)
101 msg_cinfo(" PROBE");
102 if (chip->tested.read == NT)
103 msg_cinfo(" READ");
104 if (chip->tested.erase == NT)
105 msg_cinfo(" ERASE");
106 if (chip->tested.write == NT)
107 msg_cinfo(" WRITE");
108 msg_cinfo("\n");
109 }
110 msg_cinfo("The test status of this chip may have been updated in the latest development\n"
Nico Huberc3b02dc2023-08-12 01:13:45 +0200111 "version of flashprog. If you are running the latest development version,\n"
112 "please email a report to flashprog@flashprog.org if any of the above\n"
Nico Huberac90af62022-12-18 00:22:47 +0000113 "operations work correctly for you with this flash chip. Please include the\n"
Nico Huberc3b02dc2023-08-12 01:13:45 +0200114 "flashprog log file for all operations you tested (see the man page for details),\n"
Nico Huberac90af62022-12-18 00:22:47 +0000115 "and mention which mainboard or programmer you tested in the subject line.\n"
Stefan Tauner9b32de92014-08-08 23:52:33 +0000116 "Thanks for your help!\n");
117 }
118}