Nico Huber | 34e783a | 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 | 0da839b | 2023-02-11 01:40:07 +0100 | [diff] [blame] | 18 | #include "libflashprog.h" |
| 19 | |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 20 | enum { |
Nico Huber | df6ce9f | 2023-02-11 16:16:04 +0100 | [diff] [blame] | 21 | OPTION_VERBOSE = 'V', |
| 22 | OPTION_LOGFILE = 'o', |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 23 | OPTION_CHIP = 'c', |
| 24 | OPTION_PROGRAMMER = 'p', |
Nico Huber | d91822a | 2023-02-11 00:43:54 +0100 | [diff] [blame] | 25 | OPTION_LAYOUT = 'l', |
Nico Huber | e7899a9 | 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 | 1f693db | 2023-02-11 18:28:33 +0100 | [diff] [blame] | 35 | OPTION_CONFIG_GET, |
| 36 | OPTION_CONFIG_SET, |
| 37 | OPTION_CONFIG_VOLATILE, |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 38 | }; |
| 39 | |
Nico Huber | df6ce9f | 2023-02-11 16:16:04 +0100 | [diff] [blame] | 40 | struct log_args { |
| 41 | enum flashprog_log_level screen_level; |
| 42 | enum flashprog_log_level logfile_level; |
| 43 | char *logfile; |
| 44 | }; |
| 45 | |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 46 | struct flash_args { |
| 47 | char *chip; |
| 48 | char *prog_name; |
| 49 | char *prog_args; |
| 50 | }; |
| 51 | |
Nico Huber | d91822a | 2023-02-11 00:43:54 +0100 | [diff] [blame] | 52 | struct layout_args { |
| 53 | bool ifd; |
| 54 | bool fmap; |
| 55 | char *fmapfile; |
| 56 | char *layoutfile; |
| 57 | }; |
| 58 | |
| 59 | int cli_check_filename(const char *filename, const char *type); |
| 60 | |
Nico Huber | df6ce9f | 2023-02-11 16:16:04 +0100 | [diff] [blame] | 61 | int cli_parse_log_args(struct log_args *, int opt, const char *optarg); |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 62 | int cli_parse_flash_args(struct flash_args *, int opt, const char *optarg); |
Nico Huber | d91822a | 2023-02-11 00:43:54 +0100 | [diff] [blame] | 63 | int cli_parse_layout_args(struct layout_args *, int opt, const char *optarg); |
Nico Huber | 0da839b | 2023-02-11 01:40:07 +0100 | [diff] [blame] | 64 | int cli_process_layout_args(struct flashprog_layout **, struct flashprog_flashctx *, const struct layout_args *); |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 65 | |
Nico Huber | d39c7d6 | 2023-02-11 00:53:08 +0100 | [diff] [blame] | 66 | int cli_init(void); |
| 67 | |
Nico Huber | a705043 | 2023-02-11 18:01:26 +0100 | [diff] [blame] | 68 | int flashprog_classic_main(int argc, char *argv[]); |
Nico Huber | 1f693db | 2023-02-11 18:28:33 +0100 | [diff] [blame] | 69 | int flashprog_config_main(int argc, char *argv[]); |
Nico Huber | a705043 | 2023-02-11 18:01:26 +0100 | [diff] [blame] | 70 | |
Nico Huber | b82aadc | 2023-02-11 18:27:30 +0100 | [diff] [blame] | 71 | extern enum flashprog_log_level verbose_screen; |
| 72 | extern enum flashprog_log_level verbose_logfile; |
| 73 | int open_logfile(const char * const filename); |
| 74 | int close_logfile(void); |
| 75 | void start_logging(void); |
| 76 | |
Nico Huber | 85c2cf8 | 2024-11-02 13:47:06 +0100 | [diff] [blame] | 77 | /* generic helper, like getopt_long() but without `--' prefix, re-uses `optind` */ |
| 78 | struct opt_command { |
| 79 | const char *name; |
| 80 | int val; |
| 81 | }; |
| 82 | int getopt_command(int argc, char *const argv[], const struct opt_command *); |
| 83 | |
Nico Huber | 24c0977 | 2024-11-02 13:46:21 +0100 | [diff] [blame] | 84 | void print_generic_options(void); |
| 85 | |
Nico Huber | 34e783a | 2023-02-11 00:30:27 +0100 | [diff] [blame] | 86 | #endif |