blob: 1fbdef6351c82bc450e2d1422be43cb332403459 [file] [log] [blame]
Nico Huber34e783a2023-02-11 00:30:27 +01001/*
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 Huber8f7122c2023-02-11 18:28:33 +010018#include <stdbool.h>
19
Nico Huber0da839b2023-02-11 01:40:07 +010020#include "libflashprog.h"
21
Nico Huber34e783a2023-02-11 00:30:27 +010022enum {
Nico Huberdf6ce9f2023-02-11 16:16:04 +010023 OPTION_VERBOSE = 'V',
24 OPTION_LOGFILE = 'o',
Nico Huber34e783a2023-02-11 00:30:27 +010025 OPTION_CHIP = 'c',
26 OPTION_PROGRAMMER = 'p',
Nico Huberd91822a2023-02-11 00:43:54 +010027 OPTION_LAYOUT = 'l',
Nico Hubere7899a92023-02-11 00:39:47 +010028
29 /* Options below have only long option names, i.e. no single char: */
30 OPTION_IFD = 0x0100,
31 OPTION_FMAP,
32 OPTION_FMAP_FILE,
33 OPTION_FLASH_CONTENTS,
34 OPTION_FLASH_NAME,
35 OPTION_FLASH_SIZE,
36 OPTION_PROGRESS,
Nico Huber1f693db2023-02-11 18:28:33 +010037 OPTION_CONFIG_GET,
38 OPTION_CONFIG_SET,
39 OPTION_CONFIG_VOLATILE,
Nico Huber8f7122c2023-02-11 18:28:33 +010040 OPTION_WP_STATUS,
41 OPTION_WP_SET_RANGE,
42 OPTION_WP_SET_REGION,
43 OPTION_WP_ENABLE,
44 OPTION_WP_DISABLE,
45 OPTION_WP_LIST,
Nico Huber34e783a2023-02-11 00:30:27 +010046};
47
Nico Huberdf6ce9f2023-02-11 16:16:04 +010048struct log_args {
49 enum flashprog_log_level screen_level;
50 enum flashprog_log_level logfile_level;
51 char *logfile;
52};
53
Nico Huber34e783a2023-02-11 00:30:27 +010054struct flash_args {
55 char *chip;
56 char *prog_name;
57 char *prog_args;
58};
59
Nico Huberd91822a2023-02-11 00:43:54 +010060struct layout_args {
61 bool ifd;
62 bool fmap;
63 char *fmapfile;
64 char *layoutfile;
65};
66
67int cli_check_filename(const char *filename, const char *type);
68
Nico Huberdf6ce9f2023-02-11 16:16:04 +010069int cli_parse_log_args(struct log_args *, int opt, const char *optarg);
Nico Huber34e783a2023-02-11 00:30:27 +010070int cli_parse_flash_args(struct flash_args *, int opt, const char *optarg);
Nico Huberd91822a2023-02-11 00:43:54 +010071int cli_parse_layout_args(struct layout_args *, int opt, const char *optarg);
Nico Huber0da839b2023-02-11 01:40:07 +010072int cli_process_layout_args(struct flashprog_layout **, struct flashprog_flashctx *, const struct layout_args *);
Nico Huber34e783a2023-02-11 00:30:27 +010073
Nico Huberd39c7d62023-02-11 00:53:08 +010074int cli_init(void);
75
Nico Hubera7050432023-02-11 18:01:26 +010076int flashprog_classic_main(int argc, char *argv[]);
Nico Huber1f693db2023-02-11 18:28:33 +010077int flashprog_config_main(int argc, char *argv[]);
Nico Huber8f7122c2023-02-11 18:28:33 +010078int flashprog_wp_main(int argc, char *argv[]);
Nico Hubera7050432023-02-11 18:01:26 +010079
Nico Huberb82aadc2023-02-11 18:27:30 +010080extern enum flashprog_log_level verbose_screen;
81extern enum flashprog_log_level verbose_logfile;
82int open_logfile(const char * const filename);
83int close_logfile(void);
84void start_logging(void);
85
Nico Huber85c2cf82024-11-02 13:47:06 +010086/* generic helper, like getopt_long() but without `--' prefix, re-uses `optind` */
87struct opt_command {
88 const char *name;
89 int val;
90};
91int getopt_command(int argc, char *const argv[], const struct opt_command *);
92
Nico Huber8f7122c2023-02-11 18:28:33 +010093void print_generic_options(bool layout_options);
Nico Huber24c09772024-11-02 13:46:21 +010094
Nico Huber34e783a2023-02-11 00:30:27 +010095#endif