blob: 1a7dc345a17e4d8c7723241a0cdd2d3b2c8ec03c [file] [log] [blame]
Nico Huber34e783a2023-02-11 00:30:27 +01001/*
2 * This file is part of the flashprog project.
3 *
Nico Huber9512c9c2025-01-30 22:38:18 +01004 * Copyright (C) 2023 Nico Huber <nico.h@gmx.de>
5 *
Nico Huber34e783a2023-02-11 00:30:27 +01006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#ifndef FLASHPROG_CLI_H
18#define FLASHPROG_CLI_H
19
Nico Huber8f7122c2023-02-11 18:28:33 +010020#include <stdbool.h>
21
Nico Huber0da839b2023-02-11 01:40:07 +010022#include "libflashprog.h"
23
Nico Huber34e783a2023-02-11 00:30:27 +010024enum {
Nico Huberdf6ce9f2023-02-11 16:16:04 +010025 OPTION_VERBOSE = 'V',
26 OPTION_LOGFILE = 'o',
Nico Huber34e783a2023-02-11 00:30:27 +010027 OPTION_CHIP = 'c',
28 OPTION_PROGRAMMER = 'p',
Nico Huberd91822a2023-02-11 00:43:54 +010029 OPTION_LAYOUT = 'l',
Nico Hubere7899a92023-02-11 00:39:47 +010030
31 /* Options below have only long option names, i.e. no single char: */
32 OPTION_IFD = 0x0100,
33 OPTION_FMAP,
34 OPTION_FMAP_FILE,
35 OPTION_FLASH_CONTENTS,
36 OPTION_FLASH_NAME,
37 OPTION_FLASH_SIZE,
38 OPTION_PROGRESS,
Nico Huber1f693db2023-02-11 18:28:33 +010039 OPTION_CONFIG_GET,
40 OPTION_CONFIG_SET,
41 OPTION_CONFIG_VOLATILE,
Nico Huber8f7122c2023-02-11 18:28:33 +010042 OPTION_WP_STATUS,
43 OPTION_WP_SET_RANGE,
44 OPTION_WP_SET_REGION,
45 OPTION_WP_ENABLE,
46 OPTION_WP_DISABLE,
47 OPTION_WP_LIST,
Nico Huber34e783a2023-02-11 00:30:27 +010048};
49
Nico Huberdf6ce9f2023-02-11 16:16:04 +010050struct log_args {
51 enum flashprog_log_level screen_level;
52 enum flashprog_log_level logfile_level;
53 char *logfile;
54};
55
Nico Huber34e783a2023-02-11 00:30:27 +010056struct flash_args {
57 char *chip;
58 char *prog_name;
59 char *prog_args;
60};
61
Nico Huberd91822a2023-02-11 00:43:54 +010062struct layout_args {
63 bool ifd;
64 bool fmap;
65 char *fmapfile;
66 char *layoutfile;
67};
68
69int cli_check_filename(const char *filename, const char *type);
70
Nico Huberdf6ce9f2023-02-11 16:16:04 +010071int cli_parse_log_args(struct log_args *, int opt, const char *optarg);
Nico Huber34e783a2023-02-11 00:30:27 +010072int cli_parse_flash_args(struct flash_args *, int opt, const char *optarg);
Nico Huberd91822a2023-02-11 00:43:54 +010073int cli_parse_layout_args(struct layout_args *, int opt, const char *optarg);
Nico Huber0da839b2023-02-11 01:40:07 +010074int cli_process_layout_args(struct flashprog_layout **, struct flashprog_flashctx *, const struct layout_args *);
Nico Huber34e783a2023-02-11 00:30:27 +010075
Nico Huberd39c7d62023-02-11 00:53:08 +010076int cli_init(void);
77
Nico Hubera7050432023-02-11 18:01:26 +010078int flashprog_classic_main(int argc, char *argv[]);
Nico Huber1f693db2023-02-11 18:28:33 +010079int flashprog_config_main(int argc, char *argv[]);
Nico Huber8f7122c2023-02-11 18:28:33 +010080int flashprog_wp_main(int argc, char *argv[]);
Nico Hubera7050432023-02-11 18:01:26 +010081
Nico Huberb82aadc2023-02-11 18:27:30 +010082extern enum flashprog_log_level verbose_screen;
83extern enum flashprog_log_level verbose_logfile;
84int open_logfile(const char * const filename);
85int close_logfile(void);
86void start_logging(void);
87
Nico Huber85c2cf82024-11-02 13:47:06 +010088/* generic helper, like getopt_long() but without `--' prefix, re-uses `optind` */
89struct opt_command {
90 const char *name;
91 int val;
92};
93int getopt_command(int argc, char *const argv[], const struct opt_command *);
94
Nico Huber8f7122c2023-02-11 18:28:33 +010095void print_generic_options(bool layout_options);
Nico Huber24c09772024-11-02 13:46:21 +010096
Nico Huber34e783a2023-02-11 00:30:27 +010097#endif