Nico Huber | 79bb1a1 | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashprog project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #ifndef FLASHPROG_CLI_H |
| 16 | #define FLASHPROG_CLI_H |
| 17 | |
Nico Huber | 78f3ae9 | 2023-02-11 01:40:07 +0100 | [diff] [blame] | 18 | #include "libflashprog.h" |
| 19 | |
Nico Huber | 79bb1a1 | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 20 | enum { |
Nico Huber | 981a2e5 | 2023-02-11 16:16:04 +0100 | [diff] [blame] | 21 | OPTION_VERBOSE = 'V', |
| 22 | OPTION_LOGFILE = 'o', |
Nico Huber | 79bb1a1 | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 23 | OPTION_CHIP = 'c', |
| 24 | OPTION_PROGRAMMER = 'p', |
Nico Huber | 30cb07b | 2023-02-11 00:43:54 +0100 | [diff] [blame] | 25 | OPTION_LAYOUT = 'l', |
Nico Huber | 948b7e4 | 2023-02-11 00:39:47 +0100 | [diff] [blame] | 26 | |
| 27 | /* Options below have only long option names, i.e. no single char: */ |
| 28 | OPTION_IFD = 0x0100, |
| 29 | OPTION_FMAP, |
| 30 | OPTION_FMAP_FILE, |
| 31 | OPTION_FLASH_CONTENTS, |
| 32 | OPTION_FLASH_NAME, |
| 33 | OPTION_FLASH_SIZE, |
| 34 | OPTION_PROGRESS, |
Nico Huber | 706c37f | 2023-02-11 18:28:33 +0100 | [diff] [blame] | 35 | OPTION_CONFIG_GET, |
| 36 | OPTION_CONFIG_SET, |
| 37 | OPTION_CONFIG_VOLATILE, |
Nico Huber | ab809be | 2023-02-11 18:28:33 +0100 | [diff] [blame] | 38 | OPTION_WP_STATUS, |
| 39 | OPTION_WP_SET_RANGE, |
| 40 | OPTION_WP_SET_REGION, |
| 41 | OPTION_WP_ENABLE, |
| 42 | OPTION_WP_DISABLE, |
| 43 | OPTION_WP_LIST, |
Nico Huber | 79bb1a1 | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 44 | }; |
| 45 | |
Nico Huber | 981a2e5 | 2023-02-11 16:16:04 +0100 | [diff] [blame] | 46 | struct log_args { |
| 47 | enum flashprog_log_level screen_level; |
| 48 | enum flashprog_log_level logfile_level; |
| 49 | char *logfile; |
| 50 | }; |
| 51 | |
Nico Huber | 79bb1a1 | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 52 | struct flash_args { |
| 53 | char *chip; |
| 54 | char *prog_name; |
| 55 | char *prog_args; |
| 56 | }; |
| 57 | |
Nico Huber | 30cb07b | 2023-02-11 00:43:54 +0100 | [diff] [blame] | 58 | struct layout_args { |
| 59 | bool ifd; |
| 60 | bool fmap; |
| 61 | char *fmapfile; |
| 62 | char *layoutfile; |
| 63 | }; |
| 64 | |
| 65 | int cli_check_filename(const char *filename, const char *type); |
| 66 | |
Nico Huber | 981a2e5 | 2023-02-11 16:16:04 +0100 | [diff] [blame] | 67 | int cli_parse_log_args(struct log_args *, int opt, const char *optarg); |
Nico Huber | 79bb1a1 | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 68 | int cli_parse_flash_args(struct flash_args *, int opt, const char *optarg); |
Nico Huber | 30cb07b | 2023-02-11 00:43:54 +0100 | [diff] [blame] | 69 | int cli_parse_layout_args(struct layout_args *, int opt, const char *optarg); |
Nico Huber | 78f3ae9 | 2023-02-11 01:40:07 +0100 | [diff] [blame] | 70 | int cli_process_layout_args(struct flashprog_layout **, struct flashprog_flashctx *, const struct layout_args *); |
Nico Huber | 79bb1a1 | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 71 | |
Nico Huber | 1f4b0cc | 2023-02-11 00:53:08 +0100 | [diff] [blame] | 72 | int cli_init(void); |
| 73 | |
Nico Huber | 589cea6 | 2023-02-11 18:01:26 +0100 | [diff] [blame] | 74 | int flashprog_classic_main(int argc, char *argv[]); |
Nico Huber | 706c37f | 2023-02-11 18:28:33 +0100 | [diff] [blame] | 75 | int flashprog_config_main(int argc, char *argv[]); |
Nico Huber | ab809be | 2023-02-11 18:28:33 +0100 | [diff] [blame] | 76 | int flashprog_wp_main(int argc, char *argv[]); |
Nico Huber | 589cea6 | 2023-02-11 18:01:26 +0100 | [diff] [blame] | 77 | |
Nico Huber | 0461500 | 2023-02-11 18:27:30 +0100 | [diff] [blame] | 78 | extern enum flashprog_log_level verbose_screen; |
| 79 | extern enum flashprog_log_level verbose_logfile; |
| 80 | int open_logfile(const char * const filename); |
| 81 | int close_logfile(void); |
| 82 | void start_logging(void); |
| 83 | |
Nico Huber | 79bb1a1 | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 84 | #endif |