cake
/
p7utils
Archived
1
0
Fork 0

Updated some things.

This commit is contained in:
Thomas Touhey 2017-01-17 00:46:42 +01:00
parent 1c42ed1444
commit eca43beea1
15 changed files with 204 additions and 131 deletions

View File

@ -51,9 +51,11 @@ value next to them.
Display command/subcommand help page and quit.
*-v, --version*::
Display version and quit.
*--device /dev/mydevice0*::
The device with which to interact, usually */dev/ttyUSBx*.
Will use the first device it finds by default.
*--com <port>*::
The USB-serial port, if you want to communicate with a calculator connected
using a USB-to-serial cable. (1 to 20)
If this option isn't used, the program will look for a directly connected
USB calculator.
*--storage abc0*::
The storage device with which to interact.
*--no-term, --no-exit*::

View File

@ -7,13 +7,14 @@ Thomas "Cakeisalie5" Touhey
NAME
----
p7os - get and change CASIO calculator's OSes using protocol 7
p7os - backup and setup CASIO calculator's software components using protocol 7
SYNOPSIS
--------
[source,bash]
----
p7os [-h|--help] [-v|--version] [<subcommand> [<args>]]
p7os [-h|--help] [-v|--version] [--no-prepare] [--uexe <path>]
[<subcommand> [<args>]]
----
DESCRIPTION
@ -23,11 +24,11 @@ using its communication protocol 7.00 and OS update mode.
Available submenus are :
*prepare*::
This subcommand must be run before *any* other subcommand. It will upload
a P7 server that supports the commands required by them.
*prepare-only*::
Sends the update program, but leave it for other programs to interact
with it.
*get [-o os.bin]*::
Get OS image copy.
Backup the bootcode, CASIOWIN entry and OS.
You have to *prepare* before doing any other action. Preparing means sending
a P7 server on the calculator that will be able to execute commands required
@ -42,9 +43,15 @@ value next to them.
Display command/subcommand help page and quit.
*-v, --version*::
Display version and quit.
*--device /dev/mydevice0*::
The device with which to interact.
Mostly */dev/cfx0* for USB and */dev/ttyS0* for serial connections.
*--com <port>*::
The USB-serial port, if you want to communicate with a calculator connected
using a USB-to-serial cable. (1 to 20)
If this option isn't used, the program will look for a directly connected
USB calculator.
*--no-prepare*::
Use the current environment, instead of uploading one.
*--uexe <path>*::
Use a custom update program.
*-o OUT, --output=OUT*::
When getting something, where to store.

View File

@ -30,6 +30,11 @@ value next to them.
Display help page and quit.
*-v, --version*::
Display version and quit.
*--com <port>*::
The USB-serial port, if you want to communicate with a calculator connected
using a USB-to-serial cable. (1 to 20)
If this option isn't used, the program will look for a directly connected
USB calculator.
*-z ZOOM, --zoom=ZOOM*::
Change the zoom (will change the window size too).

View File

@ -4,7 +4,7 @@
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/21 23:46:41 |___/ */
/* Last updated: 2017/01/16 23:55:54 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
@ -45,10 +45,10 @@ static const char help_main[] =
"General options:\n"
" -h, --help Display the help page of the (sub)command and quit.\n"
" -v, --version Display the version message and quit.\n"
" --com <port> The USB-serial port, if you want to connect to a\n"
" calculator connected (1 to 20).\n"
" If this option isn't given, then a USB calculator will\n"
" be searched.\n"
" --com <port> The USB-serial port, if you want to communicate with a\n"
" calculator connected using a USB-to-serial cable. (1 to 20)\n"
" If this option isn't used, the program will look for a\n"
" directly connected USB calculator.\n"
" --storage <abc0> The storage device with which to interact (fls0, crd0).\n"
" Default storage device is '" QUOTE(DEFAULT_STORAGE) "'.\n"
" --no-exit Does not terminate connection when action is completed.\n"

View File

@ -4,7 +4,7 @@
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/21 23:46:41 |___/ */
/* Last updated: 2017/01/16 23:55:54 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"

View File

@ -4,7 +4,7 @@
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/21 23:46:41 |___/ */
/* Last updated: 2017/01/16 23:55:54 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"

View File

@ -4,7 +4,7 @@
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/21 23:46:41 |___/ */
/* Last updated: 2017/01/16 23:55:54 |___/ */
/* */
/* ************************************************************************** */
#ifndef MAIN_H

View File

@ -1,10 +1,10 @@
/* ************************************************************************** */
/* _____ _ */
/* args.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7os | |/ _ \| | | | '_ \ / _ \ | | | */
/* p7os/args.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/09/28 06:00:10 |___/ */
/* Last updated: 2017/01/16 23:55:54 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
@ -29,22 +29,23 @@ QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n
/* Main help message */
static const char help_main[] =
"Usage: " QUOTE(BIN) " [--version|-v] [--help|-h] [--com <port>]\n"
" [--no-prepare] [--uexe <path>]\n"
" <subcommand> [options...]\n"
"\n"
"Subcommands you can use are :\n"
" prepare Prepare server on distant machine\n"
" get Get the OS image\n"
"\n"
"All subcommands that aren't \"prepare\" require \"prepare\" to be run\n"
"before them.\n"
" prepare-only Set-up the update program, but leave it for other programs\n"
" to interact with it.\n"
" get Get the OS image.\n"
"\n"
"General options:\n"
" -h, --help Display the help page of the (sub)command and quit.\n"
" -v, --version Display the version message and quit.\n"
" --com <port> The USB-serial port, if you want to connect to a\n"
" calculator connected (1 to 20).\n"
" If this option isn't given, then a USB calculator will\n"
" be searched.\n"
" --com <port> The USB-serial port, if you want to communicate with a\n"
" calculator connected using a USB-to-serial cable. (1 to 20)\n"
" If this option isn't used, the program will look for a\n"
" directly connected USB calculator.\n"
" --no-prepare Use the current environment, instead of uploading one.\n"
" --uexe <path> Use a custom update program.\n"
"\n"
"Type \"" QUOTE(BIN) " <subcommand> --help\" for some help about a subcommand.\n"
"Report bugs to " QUOTE(MAINTAINER) ".";
@ -54,15 +55,15 @@ static const char help_main[] =
"\nType \"" QUOTE(BIN) " --help\" for other subcommands and general options."
/* Help message for prepare subcommand */
static const char help_prepare[] =
"Usage: p7os prepare\n"
static const char help_prepare_only[] =
"Usage: " QUOTE(BIN) " prepare-only\n"
"Send the P7 server on the calculator for further operations.\n"
"This must be used before any other p7os operation.\n"
FOOT;
/* Help message for get subcommand */
static const char help_get[] =
"Usage: p7os get [-o <os.bin>]\n"
"Usage: " QUOTE(BIN) " get [-o <os.bin>]\n"
"Get the calculator OS image.\n"
"You must have \"p7os prepare\"-ed before.\n"
"\n"
@ -96,16 +97,20 @@ int parse_args(int ac, char **av, args_t *args)
{
/* initialize args */
*args = (args_t){
.com = 0,
.menu = 0,
.com = 0, .noprepare = 0,
.uexe = NULL,
.local = NULL, .localpath = NULL
};
/* define options */
const char short_options[] = "hvo:";
const struct option long_options[] = {
const char shopts[] = "hvo:";
const struct option longopts[] = {
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{"com", required_argument, NULL, 'c'},
{"no-prepare", no_argument, NULL, 'n'},
{"uexe", no_argument, NULL, 'u'},
{"output", required_argument, NULL, 'o'},
{NULL, 0, NULL, 0}
};
@ -113,15 +118,18 @@ int parse_args(int ac, char **av, args_t *args)
/* get all options */
int c; opterr = 0;
int help = 0, version = 0;
const char *s_out = "os.bin", *s_com = 0;
while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1) {
switch (c) {
const char *s_out = "os.bin", *s_com = 0, *s_uexe = NULL;
while ((c = getopt_long(ac, av, shopts, longopts, NULL)) != -1) switch (c) {
/* help */
case 'h': help = 1; break;
/* version */
case 'v': version = 1; break;
/* device */
/* com port */
case 'c': s_com = optarg; break;
/* no prepare */
case 'n': args->noprepare = 1; break;
/* uexe */
case 'u': s_uexe = optarg; break;
/* output */
case 'o': s_out = optarg; break;
@ -131,23 +139,11 @@ int parse_args(int ac, char **av, args_t *args)
log("-o, --output: expected an argument\n");
else if (optopt == 'c')
log("--com: expected an argument\n");
else if (optopt == 'u')
log("--uexe: expected an argument\n");
else
break;
return (1);
}
}
/* check com port */
if (s_com) {
if (!isdigit(s_com[0])) {
log("-c, --com: expected a number\n");
return (0);
}
args->com = atoi(s_com);
if (args->com < 1 || args->com > 20) {
log("-c, --com: COM port number should be between 1 and 20\n");
return (0);
}
}
/* check for version */
@ -170,8 +166,13 @@ int parse_args(int ac, char **av, args_t *args)
} else if (!strcmp(sub, "version")) {
puts(version_message);
return (1);
} else if (!strcmp(sub, "prepare")) {
sub_init(prepare, 0)
} else if (!strcmp(sub, "prepare-only")) {
sub_init(prepare_only, 0)
if (args->noprepare) {
log("So we should prepare but we should not prepare? Duh!\n");
return (1);
}
} else if (!strcmp(sub, "get")) {
sub_init(get, 0)
args->localpath = s_out;
@ -181,11 +182,34 @@ int parse_args(int ac, char **av, args_t *args)
return (1);
}
/* check com port */
if (s_com) {
if (!isdigit(s_com[0])) {
log("-c, --com: expected a number\n");
return (0);
}
args->com = atoi(s_com);
if (args->com < 1 || args->com > 20) {
log("-c, --com: COM port number should be between 1 and 20\n");
return (0);
}
}
/* open destination file */
if (args->localpath) {
args->local = fopen(args->localpath, fpmode);
if (!args->local) {
log("Could not open local file: '%s'\n", strerror(errno));
log("Could not open local file: %s\n", strerror(errno));
return (1);
}
}
/* open update.exe file */
if (s_uexe) {
args->uexe = fopen(s_uexe, "r");
if (!args->uexe) {
log("Could not open update program: %s\n", strerror(errno));
if (args->local) fclose(args->local);
return (1);
}
}

View File

@ -1,10 +1,10 @@
/* ************************************************************************** */
/* _____ _ */
/* main.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7os | |/ _ \| | | | '_ \ / _ \ | | | */
/* p7os/main.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/09/28 06:00:10 |___/ */
/* Last updated: 2017/01/16 23:55:54 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
@ -14,24 +14,24 @@
/* Error messages */
/* ************************************************************************** */
/* Couldn't initialize connexion to calculator. */
const char error_noconnexion[] =
static const char error_noconnexion[] =
"Could not connect to the calculator.\n"
"- Is it plugged in and in Receive mode/OS Update?\n"
"- Have you tried changing the cable ?\n";
/* Calculator was found but program wasn't allowed to communicate with it. */
const char error_noaccess[] =
static const char error_noaccess[] =
"Could not get access to the calculator.\n"
"Install the appropriate udev rule, or run as root.\n";
/* The calculator acted in a weird way. */
const char error_unplanned[] =
static const char error_unplanned[] =
"The calculator didn't act as planned: %s.\n"
"Stop receive mode on calculator and start it again before re-running " \
QUOTE(BIN) ".\n";
/* Unsupported operation -> OS Update, not receive mode! */
const char error_unsupported[] =
static const char error_unsupported[] =
"Required operation was unsupported.\n"
"- If you were using anything else than the *prepare* subcommand, are you\n"
" sure you've run *prepare* before?\n"
@ -77,26 +77,21 @@ int main(int ac, char **av)
return (1);
}
/* check according to menu */
FILE *cake_exe;
switch (args.menu) {
/* prepare menu */
case mn_prepare:;
/* open memory stream for the update.exe */
size_t uexe_size = (size_t)&cake_exe_end - (size_t)&cake_exe_str;
cake_exe = fmemopen(cake_exe_str, uexe_size, "r");
if (!cake_exe) break;
/* prepare */
if (!args.noprepare && prepare_ops(handle, args.uexe)) {
if (args.local) fclose(args.local);
return (1);
}
/* send the update.exe */
if ((err = p7_sendexe_stream(handle, cake_exe, (p7uint_t)uexe_size,
0x88030000, 0x88030000)))
fprintf(stderr, "An error has occurred: %s\n", p7_strerror(err));
break;
/* check according to menu */
switch (args.menu) {
/* prepare-only menu, skip */
case mn_prepare_only: break;
/* get menu */
case mn_get:
/* get the os */
err = !get_os(handle, args.local);
fprintf(stderr, "Unimplemented, yet.\n"); err = 1;
fclose(args.local);
/* if there was an error, delete created file */
if (err) unlink(args.localpath);

View File

@ -1,10 +1,10 @@
/* ************************************************************************** */
/* _____ _ */
/* main.h |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7os | |/ _ \| | | | '_ \ / _ \ | | | */
/* p7os/main.h |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/09/28 06:00:10 |___/ */
/* Last updated: 2017/01/16 23:55:55 |___/ */
/* */
/* ************************************************************************** */
#ifndef MAIN_H
@ -15,20 +15,12 @@
# define QUOTE(x) Q(x)
# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__)
/* ************************************************************************** */
/* Embedded update.exe */
/* ************************************************************************** */
#define cake_exe_str (_binary_cake_exe_bin_start)
#define cake_exe_end (_binary_cake_exe_bin_end)
extern char _binary_cake_exe_bin_start[];
extern char _binary_cake_exe_bin_end[];
/* ************************************************************************** */
/* CLI options */
/* ************************************************************************** */
/* Menu */
typedef enum {
mn_prepare,
mn_prepare_only,
mn_get
} menu_t;
@ -37,8 +29,11 @@ typedef struct {
/* basic things */
menu_t menu;
/* communication and tweaks */
int com, noprepare;
FILE *uexe;
/* others */
int com;
FILE *local; const char *localpath;
} args_t;
@ -49,6 +44,7 @@ int parse_args(int ac, char **av, args_t *args);
/* Actual things */
/* ************************************************************************** */
/* Main functions */
int prepare_ops(p7_handle_t *handle, FILE *uexe);
int get_os(p7_handle_t *handle, FILE *dest);
#endif /* MAIN_H */

74
src/p7os/prepare.c Normal file
View File

@ -0,0 +1,74 @@
/* ************************************************************************** */
/* _____ _ */
/* p7os/prepare.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2017/01/16 23:56:41 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
/* ************************************************************************** */
/* Error messages */
/* ************************************************************************** */
/* Generic error */
static const char error_gen[] =
"An error has occured: %s\n";
/* Unable to open the embedded thingy */
static const char error_fmemopen[] =
"Unable to open the embedded update.exe.\n";
/* ************************************************************************** */
/* Embedded update.exe */
/* ************************************************************************** */
#define cake_exe_str (_binary_cake_exe_bin_start)
#define cake_exe_end (_binary_cake_exe_bin_end)
extern char _binary_cake_exe_bin_start[];
extern char _binary_cake_exe_bin_end[];
/* ************************************************************************** */
/* Main function */
/* ************************************************************************** */
/**
* prepare_ops:
* Prepare the operation, by uploading the update.exe.
*
* @arg handle the libp7 handle.
* @arg uexe the update.exe to use (NULL if use the embedded one).
* @return if something went wrong (0 if ok).
*/
int prepare_ops(p7_handle_t *handle, FILE *uexe)
{
int err; size_t usize;
/* prepare the update.exe */
if (uexe) {
/* calculate the size */
fseek(uexe, 0, SEEK_END);
usize = ftell(uexe);
fseek(uexe, 0, SEEK_SET);
} else {
/* take the default uexe */
usize = (size_t)&cake_exe_end - (size_t)&cake_exe_str;
uexe = fmemopen(cake_exe_str, usize, "r");
if (!uexe) {
fprintf(stderr, error_fmemopen);
return (1);
}
}
/* send the thing */
if ((err = p7_sendexe_stream(handle, uexe, (p7uint_t)usize,
0x88030000, 0x88030000))) {
fprintf(stderr, error_gen, p7_strerror(err));
fclose(uexe);
return (1);
}
/* no error! */
fclose(uexe);
return (0);
}

View File

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* _____ _ */
/* stuff.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7os | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/09/28 06:00:10 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
/**
* get_os:
* Gather the OS.
*
* @arg handle the libp7 handle
* @arg dest the destination file
* @return if it worked
*/
int get_os(p7_handle_t *handle, FILE *dest)
{
/* TODO */
fprintf(stderr, "Unimplemented yet.\n");
(void)handle;
(void)dest;
/* then nothing */
return (0);
}

View File

@ -4,7 +4,7 @@
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/21 23:46:41 |___/ */
/* Last updated: 2017/01/16 23:55:55 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
@ -34,10 +34,10 @@ static const char help_main[] =
"Options are:\n"
" -h, --help Display this help page\n"
" -v, --version Displays the version\n"
" --com <port> The USB-serial port, if you want to connect to a\n"
" calculator connected (1 to 20).\n"
" If this option isn't given, then a USB calculator will\n"
" be searched.\n"
" --com <port> The USB-serial port, if you want to communicate with a\n"
" calculator connected using a USB-to-serial cable. (1 to 20)\n"
" If this option isn't used, the program will look for a\n"
" directly connected USB calculator.\n"
" -z ZOOM Change the zoom (1 to 16)\n"
" By default, the zoom will be " QUOTE(DEFAULT_ZOOM) ".\n"
"\n"

View File

@ -4,7 +4,7 @@
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/21 23:46:41 |___/ */
/* Last updated: 2017/01/16 23:55:55 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"

View File

@ -4,7 +4,7 @@
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/21 23:46:41 |___/ */
/* Last updated: 2017/01/16 23:55:55 |___/ */
/* */
/* ************************************************************************** */
#ifndef MAIN_H