From 4c85e103edf0b0d70dda214a6aea40053c3168b0 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Fri, 24 Dec 2004 20:12:30 +0000 Subject: [PATCH] Can work on floppy image or directly on second level binary --- tools/emile-set-cmdline.c | 59 ++++++++++++++++++++++++++------------- tools/emile-set-output.c | 23 ++++++++++----- 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/tools/emile-set-cmdline.c b/tools/emile-set-cmdline.c index dd15915..68ba8d9 100644 --- a/tools/emile-set-cmdline.c +++ b/tools/emile-set-cmdline.c @@ -16,10 +16,10 @@ static void usage(int argc, char** argv) { - fprintf(stderr, "Usage: %s \n", argv[0]); - fprintf(stderr, "Usage: %s -r \n", argv[0]); + fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "Usage: %s -r \n", argv[0]); fprintf(stderr, "\n Allows to set the kernel command line \n"); - fprintf(stderr, " into the floppy image \n"); + fprintf(stderr, " into the floppy image or the second level file\n"); fprintf(stderr, " can be a file or a device (/dev/fd0)\n"); fprintf(stderr, " with \"-r\" flag, display current command line\n"); fprintf(stderr, "\n Examples:\n"); @@ -35,10 +35,11 @@ static void usage(int argc, char** argv) fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE); } -int set_cmdline(char* image, char* cmdline, off_t base) +int set_cmdline(char* image, char* cmdline) { int fd; int ret; + int drive, second, size; fd = open(image, O_RDWR); @@ -48,12 +49,20 @@ int set_cmdline(char* image, char* cmdline, off_t base) return 2; } - ret = lseek(fd, base, SEEK_SET); - if (ret == -1) + /* can work on an image or directly on second level file */ + + ret = emile_first_get_param(fd, &drive, &second, &size); + if (ret == EEMILE_UNKNOWN_FIRST) { - perror("Cannot go to buffer offset"); - close(fd); - return 3; + /* should be a second level file */ + + ret = lseek(fd, 0, SEEK_SET); + if (ret == -1) + { + perror("Cannot go to buffer offset"); + close(fd); + return 3; + } } ret = emile_second_set_cmdline(fd, cmdline); @@ -63,40 +72,50 @@ int set_cmdline(char* image, char* cmdline, off_t base) return ret; } -int get_cmdline(char* image, off_t base) +int get_cmdline(char* image) { int fd; int ret; char cmdline[255]; + int drive, second, size; fd = open(image, O_RDONLY); - if (fd == -1) { perror("Cannot open image file"); return 2; } - ret = lseek(fd, base, SEEK_SET); - if (ret == -1) + /* can work on an image or directly on second level file */ + + ret = emile_first_get_param(fd, &drive, &second, &size); + if (ret == EEMILE_UNKNOWN_FIRST) { - perror("Cannot go to buffer offset"); - close(fd); - return 3; + /* should be a second level file */ + + ret = lseek(fd, 0, SEEK_SET); + if (ret == -1) + { + perror("Cannot go to buffer offset"); + close(fd); + return 3; + } } ret = emile_second_get_cmdline(fd, cmdline); + if (ret == -1) + return 4; + printf("Current command line: \"%s\"\n", cmdline); close(fd); - return ret; + return 0; } int main(int argc, char** argv) { int ret; - off_t base = FIRST_LEVEL_SIZE; if (argc != 3) { usage(argc, argv); @@ -104,9 +123,9 @@ int main(int argc, char** argv) } if (strcmp(argv[1], "-r") == 0) - ret = get_cmdline(argv[2], base); + ret = get_cmdline(argv[2]); else - ret = set_cmdline(argv[1], argv[2], base); + ret = set_cmdline(argv[1], argv[2]); return ret; } diff --git a/tools/emile-set-output.c b/tools/emile-set-output.c index 6bf7bc9..5f0131f 100644 --- a/tools/emile-set-output.c +++ b/tools/emile-set-output.c @@ -19,7 +19,7 @@ static char *parity[3] = { "None", "Odd", "Even" }; static void usage(int argc, char** argv) { fprintf(stderr, "Usage:\n"); - fprintf(stderr, "\n%s --display [--width ] [--height ] [--depth ]\n", argv[0]); + fprintf(stderr, "\n%s --display [--width ] [--height ] [--depth ]\n", argv[0]); fprintf(stderr, " Enable output to display and set configuration\n"); fprintf(stderr, "\n%s --modem [--bitrate ] [--datasize ] [--parity ] [--stopbits ]\n", argv[0]); fprintf(stderr, " Enable output to serial port 0 (modem) and set configuration\n"); @@ -51,6 +51,7 @@ static int display_output(char* image) int parity1; int stopbits1; int gestaltid; + int drive, second, size; int fd; int ret; @@ -59,16 +60,24 @@ static int display_output(char* image) if (fd == -1) { - perror("Cannot open image file"); + perror("Cannot open file"); return 2; } - ret = lseek(fd, FIRST_LEVEL_SIZE, SEEK_SET); - if (ret == -1) + /* can work on an image or directly on second level file */ + + ret = emile_first_get_param(fd, &drive, &second, &size); + if (ret == EEMILE_UNKNOWN_FIRST) { - perror("Cannot go to buffer offset"); - close(fd); - return 3; + /* should be a second level file */ + + ret = lseek(fd, 0, SEEK_SET); + if (ret == -1) + { + perror("Cannot go to buffer offset"); + close(fd); + return 3; + } } ret = emile_second_get_output(fd, &console_mask, &bitrate0,