Stefan Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 1 | /* |
| 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 Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame^] | 21 | |
Stefan Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 22 | #include "flash.h" |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame^] | 23 | #include "cli.h" |
| 24 | |
| 25 | int 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 Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 62 | |
Stefan Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 63 | void print_chip_support_status(const struct flashchip *chip) |
| 64 | { |
| 65 | if (chip->feature_bits & FEATURE_OTP) { |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame] | 66 | msg_cdbg("This chip may contain one-time programmable memory. flashprog cannot read\n" |
Stefan Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 67 | "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 Huber | bb4f3b0 | 2022-12-30 14:28:06 +0100 | [diff] [blame] | 78 | (chip->tested.write == BAD) || (chip->tested.write == NT)) { |
Stefan Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 79 | msg_cinfo("===\n"); |
| 80 | if ((chip->tested.probe == BAD) || |
| 81 | (chip->tested.read == BAD) || |
| 82 | (chip->tested.erase == BAD) || |
Nico Huber | bb4f3b0 | 2022-12-30 14:28:06 +0100 | [diff] [blame] | 83 | (chip->tested.write == BAD)) { |
Stefan Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 84 | 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 Huber | bb4f3b0 | 2022-12-30 14:28:06 +0100 | [diff] [blame] | 98 | (chip->tested.write == NT)) { |
Stefan Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 99 | 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 Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame] | 111 | "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 Huber | ac90af6 | 2022-12-18 00:22:47 +0000 | [diff] [blame] | 113 | "operations work correctly for you with this flash chip. Please include the\n" |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame] | 114 | "flashprog log file for all operations you tested (see the man page for details),\n" |
Nico Huber | ac90af6 | 2022-12-18 00:22:47 +0000 | [diff] [blame] | 115 | "and mention which mainboard or programmer you tested in the subject line.\n" |
Stefan Tauner | 9b32de9 | 2014-08-08 23:52:33 +0000 | [diff] [blame] | 116 | "Thanks for your help!\n"); |
| 117 | } |
| 118 | } |