blob: ab8e54d9e236f4765423234b864f3c1417baf3b5 [file] [log] [blame]
Nico Huber79bb1a12023-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 Huber78f3ae92023-02-11 01:40:07 +010018#include "libflashprog.h"
19
Nico Huber79bb1a12023-02-11 00:30:27 +010020enum {
Nico Huber981a2e52023-02-11 16:16:04 +010021 OPTION_VERBOSE = 'V',
22 OPTION_LOGFILE = 'o',
Nico Huber79bb1a12023-02-11 00:30:27 +010023 OPTION_CHIP = 'c',
24 OPTION_PROGRAMMER = 'p',
Nico Huber30cb07b2023-02-11 00:43:54 +010025 OPTION_LAYOUT = 'l',
Nico Huber948b7e42023-02-11 00:39:47 +010026
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 Huber706c37f2023-02-11 18:28:33 +010035 OPTION_CONFIG_GET,
36 OPTION_CONFIG_SET,
37 OPTION_CONFIG_VOLATILE,
Nico Huberab809be2023-02-11 18:28:33 +010038 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 Huber79bb1a12023-02-11 00:30:27 +010044};
45
Nico Huber981a2e52023-02-11 16:16:04 +010046struct log_args {
47 enum flashprog_log_level screen_level;
48 enum flashprog_log_level logfile_level;
49 char *logfile;
50};
51
Nico Huber79bb1a12023-02-11 00:30:27 +010052struct flash_args {
53 char *chip;
54 char *prog_name;
55 char *prog_args;
56};
57
Nico Huber30cb07b2023-02-11 00:43:54 +010058struct layout_args {
59 bool ifd;
60 bool fmap;
61 char *fmapfile;
62 char *layoutfile;
63};
64
65int cli_check_filename(const char *filename, const char *type);
66
Nico Huber981a2e52023-02-11 16:16:04 +010067int cli_parse_log_args(struct log_args *, int opt, const char *optarg);
Nico Huber79bb1a12023-02-11 00:30:27 +010068int cli_parse_flash_args(struct flash_args *, int opt, const char *optarg);
Nico Huber30cb07b2023-02-11 00:43:54 +010069int cli_parse_layout_args(struct layout_args *, int opt, const char *optarg);
Nico Huber78f3ae92023-02-11 01:40:07 +010070int cli_process_layout_args(struct flashprog_layout **, struct flashprog_flashctx *, const struct layout_args *);
Nico Huber79bb1a12023-02-11 00:30:27 +010071
Nico Huber1f4b0cc2023-02-11 00:53:08 +010072int cli_init(void);
73
Nico Huber589cea62023-02-11 18:01:26 +010074int flashprog_classic_main(int argc, char *argv[]);
Nico Huber706c37f2023-02-11 18:28:33 +010075int flashprog_config_main(int argc, char *argv[]);
Nico Huberab809be2023-02-11 18:28:33 +010076int flashprog_wp_main(int argc, char *argv[]);
Nico Huber589cea62023-02-11 18:01:26 +010077
Nico Huber04615002023-02-11 18:27:30 +010078extern enum flashprog_log_level verbose_screen;
79extern enum flashprog_log_level verbose_logfile;
80int open_logfile(const char * const filename);
81int close_logfile(void);
82void start_logging(void);
83
Nico Huber79bb1a12023-02-11 00:30:27 +010084#endif