allow to kernel path, ramdisk path

This commit is contained in:
Laurent Vivier 2006-06-02 11:45:10 +00:00
parent 8406b30f6d
commit d449f26966

View File

@ -6,6 +6,7 @@
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -14,28 +15,39 @@
#include "libemile.h"
enum {
ARG_NONE = 0,
ARG_HELP ='h',
ARG_KERNEL = 'k',
ARG_RAMDISK = 'r',
ARG_APPEND = 'a',
ARG_GETINFO = 'g',
};
static struct option long_options[] =
{
{"help", 0, NULL, ARG_HELP },
{"kernel", 1, NULL, ARG_KERNEL },
{"ramdisk", 1, NULL, ARG_RAMDISK },
{"append", 1, NULL, ARG_APPEND },
{"getinfo", 1, NULL, ARG_GETINFO },
{NULL, 0, NULL, 0 },
};
static void usage(int argc, char** argv)
{
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 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");
fprintf(stderr, "\n To set root filesystem on disk 1 partition 4\n");
fprintf(stderr, "\n %s floppy.img \"root=/dev/sda4\"\n", argv[0]);
fprintf(stderr, "\n To set root filesystem on ramdisk\n");
fprintf(stderr, "\n %s floppy.img \"root=/dev/ramdisk ramdisk_size=2048\"\n", argv[0]);
fprintf(stderr, "\n To set root filesystem on NFS\n");
fprintf(stderr, "\n %s floppy.img \"root=/dev/nfs ip=dhcp nfsroot=192.168.100.1:/tftboot/192.168.100.51/\"\n", argv[0]);
/* and when kernel will support floppy driver:
* KERNEL_ARGS="vga=normal noinitrd load_ramdisk=1 prompt_ramdisk=1 ramdisk_size=16384 root=/dev/fd0 disksize=1.44 flavor=compact"
*/
fprintf(stderr, "Usage: %s [OPTION] <file>\n", argv[0]);
fprintf(stderr, "Configure second level to load kernel and ramdisk\n");
fprintf(stderr, " <file> can be a file or a device (/dev/fd0)\n");
fprintf(stderr, " -h, --help display this text\n");
fprintf(stderr, " -k, --kernel set kernel path\n");
fprintf(stderr, " -r, --ramdisk set ramdisk path\n");
fprintf(stderr, " -a, --append set kernel command line\n");
fprintf(stderr, " -g, --getinfo get second level information\n");
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
}
int set_cmdline(char* image, char* cmdline)
static int set_cmdline(char* image, char *kernel, char* cmdline, char *ramdisk)
{
int fd;
int ret;
@ -48,7 +60,7 @@ int set_cmdline(char* image, char* cmdline)
return 2;
}
ret = emile_second_set_param(fd, NULL, cmdline, NULL);
ret = emile_second_set_param(fd, kernel, cmdline, ramdisk);
close(fd);
@ -59,7 +71,9 @@ int get_cmdline(char* image)
{
int fd;
int ret;
char kernel[255];
char cmdline[255];
char ramdisk[255];
fd = open(image, O_RDONLY);
if (fd == -1)
@ -68,12 +82,20 @@ int get_cmdline(char* image)
return 2;
}
ret = emile_second_get_param(fd, NULL, cmdline, NULL);
ret = emile_second_get_param(fd, kernel, cmdline, ramdisk);
if (kernel[0])
printf("kernel path: \"%s\"\n", kernel);
else
fprintf(stderr, "No kernel path found\n");
if (cmdline[0])
printf("Current command line: \"%s\"\n", cmdline);
printf("command line: \"%s\"\n", cmdline);
else
fprintf(stderr, "No command line found\n");
if (ramdisk[0])
printf("ramdisk path: \"%s\"\n", ramdisk);
else
fprintf(stderr, "No ramdisk path found\n");
close(fd);
@ -83,16 +105,66 @@ int get_cmdline(char* image)
int main(int argc, char** argv)
{
int ret;
char *kernel = NULL;
char *cmdline = NULL;
char *ramdisk = NULL;
char *file = NULL;
int action_getinfo = 0;
int option_index;
int c;
if (argc != 3)
{
usage(argc, argv);
return 1;
}
if (strcmp(argv[1], "-r") == 0)
ret = get_cmdline(argv[2]);
while(1)
{
c = getopt_long(argc, argv, "ha:k:r:g", long_options,
&option_index);
if (c == -1)
break;
switch(c)
{
case ARG_HELP:
usage(argc, argv);
return 0;
case ARG_KERNEL:
kernel = optarg;
break;
case ARG_APPEND:
cmdline = optarg;
break;
case ARG_RAMDISK:
ramdisk = optarg;
break;
case ARG_GETINFO:
action_getinfo = 1;
break;
}
}
if (optind < argc)
file = argv[optind];
if (file == NULL)
{
fprintf(stderr,
"ERROR: you must provide an image file or a block device.\n");
usage(argc, argv);
return 1;
}
if ( action_getinfo && ( kernel || cmdline || ramdisk) )
{
fprintf(stderr, "Incompatible parameters\n");
return 1;
}
if (action_getinfo)
ret = get_cmdline(file);
else
ret = set_cmdline(argv[1], argv[2]);
ret = set_cmdline(file, kernel, cmdline, ramdisk);
return ret;
}