Can work on floppy image or directly on second level binary

This commit is contained in:
Laurent Vivier 2004-12-24 20:12:30 +00:00
parent a700a2f1f7
commit 4c85e103ed
2 changed files with 55 additions and 27 deletions

View File

@ -16,10 +16,10 @@
static void usage(int argc, char** argv)
{
fprintf(stderr, "Usage: %s <image> <cmdline>\n", argv[0]);
fprintf(stderr, "Usage: %s -r <image>\n", argv[0]);
fprintf(stderr, "Usage: %s <file> <cmdline>\n", argv[0]);
fprintf(stderr, "Usage: %s -r <file>\n", argv[0]);
fprintf(stderr, "\n Allows to set the kernel command line <cmdline>\n");
fprintf(stderr, " into the floppy image <image>\n");
fprintf(stderr, " into the floppy image or the second level file\n");
fprintf(stderr, " <image> 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;
}

View File

@ -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 <image> --display [--width <width>] [--height <height>] [--depth <depth>]\n", argv[0]);
fprintf(stderr, "\n%s <file> --display [--width <width>] [--height <height>] [--depth <depth>]\n", argv[0]);
fprintf(stderr, " Enable output to display and set configuration\n");
fprintf(stderr, "\n%s <image> --modem [--bitrate <bitrate>] [--datasize <datasize>] [--parity <parity>] [--stopbits <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,