diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-09-20 07:57:01 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-11-13 13:22:36 +0100 |
commit | afaeccc05a556f6aa25ba044a7e49d6aa634a59e (patch) | |
tree | 09021686e43641fe7f2ec89996a808a5ca3f06e4 /freebsd/sbin/nvmecontrol | |
parent | NVMECONTROL(8): Add to build (diff) | |
download | rtems-libbsd-afaeccc05a556f6aa25ba044a7e49d6aa634a59e.tar.bz2 |
NVMECONTROL(8): Port to RTEMS
Update #3821.
Diffstat (limited to 'freebsd/sbin/nvmecontrol')
22 files changed, 201 insertions, 7 deletions
diff --git a/freebsd/sbin/nvmecontrol/comnd.c b/freebsd/sbin/nvmecontrol/comnd.c index 3074cfb9..a4fa686f 100644 --- a/freebsd/sbin/nvmecontrol/comnd.c +++ b/freebsd/sbin/nvmecontrol/comnd.c @@ -27,6 +27,11 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#define __need_getopt_newlib +#include <getopt.h> +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -182,6 +187,16 @@ arg_parse(int argc, char * const * argv, const struct cmd *f) char *shortopts, *p; const struct opts *opts = f->opts; const struct args *args = f->args; +#ifdef __rtems__ + struct getopt_data getopt_data; + memset(&getopt_data, 0, sizeof(getopt_data)); +#define optind getopt_data.optind +#define optarg getopt_data.optarg +#define opterr getopt_data.opterr +#define optopt getopt_data.optopt +#define getopt_long(argc, argv, shortopts, longopts, longind) \ + getopt_long_r(argc, argv, shortopts, longopts, longind, &getopt_data) +#endif /* __rtems__ */ if (opts == NULL) n = 0; @@ -191,9 +206,16 @@ arg_parse(int argc, char * const * argv, const struct cmd *f) lopts = malloc((n + 2) * sizeof(struct option)); if (lopts == NULL) err(1, "option memory"); - p = shortopts = malloc((n + 3) * sizeof(char)); +#ifndef __rtems__ + p = shortopts = malloc((2 * n + 2) * sizeof(char)); +#else /* __rtems__ */ + p = shortopts = malloc((2 * n + 3) * sizeof(char)); +#endif /* __rtems__ */ if (shortopts == NULL) err(1, "shortopts memory"); +#ifdef __rtems__ + *p++ = '+'; +#endif /* __rtems__ */ idx = 0; for (i = 0; i < n; i++) { lopts[i].name = opts[i].long_arg; @@ -284,6 +306,7 @@ bad_arg: exit(1); } +#ifndef __rtems__ /* * Loads all the .so's from the specified directory. */ @@ -315,6 +338,7 @@ cmd_load_dir(const char *dir __unused, cmd_load_cb_t cb __unused, void *argp __u } closedir(d); } +#endif /* __rtems__ */ void cmd_register(struct cmd *up, struct cmd *cmd) diff --git a/freebsd/sbin/nvmecontrol/comnd.h b/freebsd/sbin/nvmecontrol/comnd.h index 91c97d4a..0f06cd29 100644 --- a/freebsd/sbin/nvmecontrol/comnd.h +++ b/freebsd/sbin/nvmecontrol/comnd.h @@ -86,12 +86,48 @@ struct cmd { }; void cmd_register(struct cmd *, struct cmd *); +#ifndef __rtems__ #define CMD_COMMAND(c) \ static void cmd_register_##c(void) __attribute__((constructor)); \ static void cmd_register_##c(void) { cmd_register(NULL, &c); } #define CMD_SUBCOMMAND(c,sc) \ static void cmd_register_##c_##sc(void) __attribute__((constructor)); \ static void cmd_register_##c_##sc(void) { cmd_register(&c, &sc); } +#else /* __rtems__ */ +#define CMD_COMMAND(c) \ + void cmd_register_##c(void) { cmd_register(NULL, &c); } +#define CMD_SUBCOMMAND(c,sc) \ + void cmd_register_##c##_##sc(void) { cmd_register(&c, &sc); } +void cmd_register_admin_pass_cmd(void); +void cmd_register_devlist_cmd(void); +void cmd_register_firmware_cmd(void); +void cmd_register_format_cmd(void); +void cmd_register_identify_cmd(void); +void cmd_register_io_pass_cmd(void); +void cmd_register_logpage_cmd(void); +void cmd_register_ns_cmd(void); +void cmd_register_ns_cmd_active_cmd(void); +void cmd_register_ns_cmd_allocated_cmd(void); +void cmd_register_ns_cmd_attach_cmd(void); +void cmd_register_ns_cmd_attached_cmd(void); +void cmd_register_ns_cmd_controllers_cmd(void); +void cmd_register_ns_cmd_create_cmd(void); +void cmd_register_ns_cmd_delete_cmd(void); +void cmd_register_ns_cmd_detach_cmd(void); +void cmd_register_ns_cmd_identify_cmd(void); +void cmd_register_nsid_cmd(void); +void cmd_register_perftest_cmd(void); +void cmd_register_power_cmd(void); +void cmd_register_reset_cmd(void); +void cmd_register_resv_cmd(void); +void cmd_register_resv_cmd_acquire_cmd(void); +void cmd_register_resv_cmd_register_cmd(void); +void cmd_register_resv_cmd_release_cmd(void); +void cmd_register_resv_cmd_report_cmd(void); +void cmd_register_sanitize_cmd(void); +void cmd_register_wdc_cmd(void); +void cmd_register_wdc_cmd_cap_diag_cmd(void); +#endif /* __rtems__ */ int arg_parse(int argc, char * const *argv, const struct cmd *f); void arg_help(int argc, char * const *argv, const struct cmd *f); diff --git a/freebsd/sbin/nvmecontrol/devlist.c b/freebsd/sbin/nvmecontrol/devlist.c index 58e1153b..543c358f 100644 --- a/freebsd/sbin/nvmecontrol/devlist.c +++ b/freebsd/sbin/nvmecontrol/devlist.c @@ -28,6 +28,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/firmware.c b/freebsd/sbin/nvmecontrol/firmware.c index 482ceb3c..0c4a264e 100644 --- a/freebsd/sbin/nvmecontrol/firmware.c +++ b/freebsd/sbin/nvmecontrol/firmware.c @@ -31,6 +31,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/format.c b/freebsd/sbin/nvmecontrol/format.c index 95b57cb4..0ed693f9 100644 --- a/freebsd/sbin/nvmecontrol/format.c +++ b/freebsd/sbin/nvmecontrol/format.c @@ -27,6 +27,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/identify.c b/freebsd/sbin/nvmecontrol/identify.c index be2fb00c..e494fb59 100644 --- a/freebsd/sbin/nvmecontrol/identify.c +++ b/freebsd/sbin/nvmecontrol/identify.c @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/identify_ext.c b/freebsd/sbin/nvmecontrol/identify_ext.c index 2ec8f100..44e0011b 100644 --- a/freebsd/sbin/nvmecontrol/identify_ext.c +++ b/freebsd/sbin/nvmecontrol/identify_ext.c @@ -29,6 +29,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/logpage.c b/freebsd/sbin/nvmecontrol/logpage.c index 7a36f17a..8ab50bea 100644 --- a/freebsd/sbin/nvmecontrol/logpage.c +++ b/freebsd/sbin/nvmecontrol/logpage.c @@ -30,6 +30,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/modules/intel/intel.c b/freebsd/sbin/nvmecontrol/modules/intel/intel.c index 8c6c2564..1dcd3a09 100644 --- a/freebsd/sbin/nvmecontrol/modules/intel/intel.c +++ b/freebsd/sbin/nvmecontrol/modules/intel/intel.c @@ -31,6 +31,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -48,7 +51,7 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <sys/endian.h> -#include "nvmecontrol.h" +#include "../../nvmecontrol.h" /* * Intel specific log pages from diff --git a/freebsd/sbin/nvmecontrol/modules/wdc/wdc.c b/freebsd/sbin/nvmecontrol/modules/wdc/wdc.c index 4a6a90dc..3cd5cdb7 100644 --- a/freebsd/sbin/nvmecontrol/modules/wdc/wdc.c +++ b/freebsd/sbin/nvmecontrol/modules/wdc/wdc.c @@ -26,6 +26,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -42,7 +45,7 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <unistd.h> -#include "nvmecontrol.h" +#include "../../nvmecontrol.h" /* Tables for command line parsing */ diff --git a/freebsd/sbin/nvmecontrol/nc_util.c b/freebsd/sbin/nvmecontrol/nc_util.c index 443bef24..f2818871 100644 --- a/freebsd/sbin/nvmecontrol/nc_util.c +++ b/freebsd/sbin/nvmecontrol/nc_util.c @@ -26,6 +26,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/ns.c b/freebsd/sbin/nvmecontrol/ns.c index bb9b0011..841c1a87 100644 --- a/freebsd/sbin/nvmecontrol/ns.c +++ b/freebsd/sbin/nvmecontrol/ns.c @@ -28,6 +28,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -368,7 +371,7 @@ struct ns_result_str { const char * str; }; -static struct ns_result_str ns_result[] = { +static const struct ns_result_str ns_result[] = { { 0x2, "Invalid Field"}, { 0xa, "Invalid Format"}, { 0xb, "Invalid Namespace or format"}, @@ -387,7 +390,7 @@ static struct ns_result_str ns_result[] = { static const char * get_res_str(uint16_t res) { - struct ns_result_str *t = ns_result; + const struct ns_result_str *t = ns_result; while (t->res != 0xFFFF) { if (t->res == res) diff --git a/freebsd/sbin/nvmecontrol/nsid.c b/freebsd/sbin/nvmecontrol/nsid.c index 74ed06c8..f12b78ea 100644 --- a/freebsd/sbin/nvmecontrol/nsid.c +++ b/freebsd/sbin/nvmecontrol/nsid.c @@ -27,6 +27,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/nvmecontrol.c b/freebsd/sbin/nvmecontrol/nvmecontrol.c index c33d42ef..4fcef3b5 100644 --- a/freebsd/sbin/nvmecontrol/nvmecontrol.c +++ b/freebsd/sbin/nvmecontrol/nvmecontrol.c @@ -1,4 +1,4 @@ -#include <machine/rtems-bsd-kernel-space.h> +#include <machine/rtems-bsd-user-space.h> /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -28,6 +28,11 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#include <machine/rtems-bsd-commands.h> +#include <pthread.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -175,14 +180,68 @@ get_nsid(int fd, char **ctrlr_str, uint32_t *nsid) *nsid = gnsid.nsid; } +#ifdef __rtems__ +static int main(int argc, char *argv[]); + +static pthread_once_t nvmecontrol_once = PTHREAD_ONCE_INIT; + +static void +nvmecontrol_cmd_register(void) +{ + + cmd_register_admin_pass_cmd(); + cmd_register_devlist_cmd(); + cmd_register_firmware_cmd(); + cmd_register_format_cmd(); + cmd_register_identify_cmd(); + cmd_register_io_pass_cmd(); + cmd_register_logpage_cmd(); + cmd_register_ns_cmd(); + cmd_register_ns_cmd_active_cmd(); + cmd_register_ns_cmd_allocated_cmd(); + cmd_register_ns_cmd_attach_cmd(); + cmd_register_ns_cmd_attached_cmd(); + cmd_register_ns_cmd_controllers_cmd(); + cmd_register_ns_cmd_create_cmd(); + cmd_register_ns_cmd_delete_cmd(); + cmd_register_ns_cmd_detach_cmd(); + cmd_register_ns_cmd_identify_cmd(); + cmd_register_nsid_cmd(); + cmd_register_power_cmd(); + cmd_register_reset_cmd(); + cmd_register_resv_cmd(); + cmd_register_resv_cmd_acquire_cmd(); + cmd_register_resv_cmd_register_cmd(); + cmd_register_resv_cmd_release_cmd(); + cmd_register_resv_cmd_report_cmd(); + cmd_register_sanitize_cmd(); +} + +int +rtems_bsd_command_nvmecontrol(int argc, char *argv[]) +{ + int exit_code; + + pthread_once(&nvmecontrol_once, nvmecontrol_cmd_register); + + rtems_bsd_program_lock(); + exit_code = rtems_bsd_program_call_main("nvmecontrol", main, argc, + argv); + rtems_bsd_program_unlock(); + + return exit_code; +} +#endif /* __rtems__ */ int main(int argc, char *argv[]) { cmd_init(); +#ifndef __rtems__ cmd_load_dir("/lib/nvmecontrol", NULL, NULL); cmd_load_dir("/usr/local/lib/nvmecontrol", NULL, NULL); +#endif /* __rtems__ */ cmd_dispatch(argc, argv, NULL); diff --git a/freebsd/sbin/nvmecontrol/nvmecontrol.h b/freebsd/sbin/nvmecontrol/nvmecontrol.h index f5dc61f2..138ca80c 100644 --- a/freebsd/sbin/nvmecontrol/nvmecontrol.h +++ b/freebsd/sbin/nvmecontrol/nvmecontrol.h @@ -33,6 +33,9 @@ #include <dev/nvme/nvme.h> #include "comnd.h" +#ifdef __rtems__ +#include <sys/ioctl.h> +#endif /* __rtems__ */ typedef void (*print_fn_t)(const struct nvme_controller_data *cdata, void *buf, uint32_t size); @@ -87,6 +90,7 @@ void print_intel_add_smart(const struct nvme_controller_data *cdata __unused, vo * ints in sofware. */ #define UINT128_DIG 39 +#ifndef __rtems__ #ifdef __i386__ typedef uint64_t uint128_t; #else @@ -98,6 +102,23 @@ to128(void *p) { return *(uint128_t *)p; } +#else /* __rtems__ */ +#if __SIZEOF_LONG__ < 8 +typedef uint64_t uint128_t; +#else +typedef unsigned __int128 uint128_t; +#endif + +static __inline uint128_t +to128(void *p) +{ +#if __SIZEOF_LONG__ < 8 && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + return *(uint128_t *)(char *)(p + 8); +#else + return *(uint128_t *)p; +#endif +} +#endif /* __rtems__ */ uint64_t le48dec(const void *pp); char * uint128_to_str(uint128_t u, char *buf, size_t buflen); diff --git a/freebsd/sbin/nvmecontrol/passthru.c b/freebsd/sbin/nvmecontrol/passthru.c index 979cc873..5705ec1f 100644 --- a/freebsd/sbin/nvmecontrol/passthru.c +++ b/freebsd/sbin/nvmecontrol/passthru.c @@ -28,6 +28,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/perftest.c b/freebsd/sbin/nvmecontrol/perftest.c index 6f6bacbf..5d135400 100644 --- a/freebsd/sbin/nvmecontrol/perftest.c +++ b/freebsd/sbin/nvmecontrol/perftest.c @@ -28,6 +28,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/power.c b/freebsd/sbin/nvmecontrol/power.c index e33680a0..9f6eeda4 100644 --- a/freebsd/sbin/nvmecontrol/power.c +++ b/freebsd/sbin/nvmecontrol/power.c @@ -26,6 +26,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/reset.c b/freebsd/sbin/nvmecontrol/reset.c index 519594e3..ad5cfc6a 100644 --- a/freebsd/sbin/nvmecontrol/reset.c +++ b/freebsd/sbin/nvmecontrol/reset.c @@ -28,6 +28,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/resv.c b/freebsd/sbin/nvmecontrol/resv.c index 5f615941..b22b390a 100644 --- a/freebsd/sbin/nvmecontrol/resv.c +++ b/freebsd/sbin/nvmecontrol/resv.c @@ -27,6 +27,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/sanitize.c b/freebsd/sbin/nvmecontrol/sanitize.c index cc8e2417..21b6927a 100644 --- a/freebsd/sbin/nvmecontrol/sanitize.c +++ b/freebsd/sbin/nvmecontrol/sanitize.c @@ -27,6 +27,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); diff --git a/freebsd/sbin/nvmecontrol/wdc.c b/freebsd/sbin/nvmecontrol/wdc.c index 0c7f3c90..f12a2284 100644 --- a/freebsd/sbin/nvmecontrol/wdc.c +++ b/freebsd/sbin/nvmecontrol/wdc.c @@ -26,6 +26,9 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -53,7 +56,7 @@ static void wdc_cap_diag(int argc, char *argv[]); #define WDC_CAP_DIAG_USAGE "\tnvmecontrol wdc cap-diag [-o path-template]\n" -static struct nvme_function wdc_funcs[] = { +static const struct nvme_function wdc_funcs[] = { {"cap-diag", wdc_cap_diag, WDC_CAP_DIAG_USAGE}, {NULL, NULL, NULL}, }; |