2004-05-19 00:09:58 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2004-05-21 10:42:54 +00:00
|
|
|
#include <stdlib.h>
|
2004-05-26 23:05:35 +00:00
|
|
|
#include <string.h>
|
2004-05-19 00:09:58 +00:00
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
#include "libemile.h"
|
2004-05-19 00:09:58 +00:00
|
|
|
|
|
|
|
static void usage(int argc, char** argv)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s <image> <cmdline>\n", argv[0]);
|
2004-05-21 10:42:54 +00:00
|
|
|
fprintf(stderr, "Usage: %s -r <image>\n", argv[0]);
|
2004-05-19 00:09:58 +00:00
|
|
|
fprintf(stderr, "\n Allows to set the kernel command line <cmdline>\n");
|
|
|
|
fprintf(stderr, " into the floppy image <image>\n");
|
|
|
|
fprintf(stderr, " <image> can be a file or a device (/dev/fd0)\n");
|
2004-05-21 10:42:54 +00:00
|
|
|
fprintf(stderr, " with \"-r\" flag, display current command line\n");
|
2004-05-19 00:09:58 +00:00
|
|
|
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"
|
|
|
|
*/
|
2004-06-03 11:09:28 +00:00
|
|
|
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
|
2004-05-19 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
int set_cmdline(char* image, char* cmdline, off_t base)
|
2004-05-19 00:09:58 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int ret;
|
2004-05-21 10:42:54 +00:00
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
fd = open(image, O_RDWR);
|
2004-05-19 00:09:58 +00:00
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
2004-05-21 10:42:54 +00:00
|
|
|
perror("Cannot open image file");
|
2004-05-19 00:09:58 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
ret = lseek(fd, base, SEEK_SET);
|
2004-05-19 00:09:58 +00:00
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
perror("Cannot go to buffer offset");
|
|
|
|
close(fd);
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
ret = emile_second_set_cmdline(fd, cmdline);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_cmdline(char* image, off_t base)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
char cmdline[255];
|
|
|
|
|
|
|
|
fd = open(image, O_RDONLY);
|
2004-05-19 00:09:58 +00:00
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
if (fd == -1)
|
2004-05-19 00:09:58 +00:00
|
|
|
{
|
2004-12-10 00:28:35 +00:00
|
|
|
perror("Cannot open image file");
|
|
|
|
return 2;
|
2004-05-21 10:42:54 +00:00
|
|
|
}
|
2004-05-26 23:05:35 +00:00
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
ret = lseek(fd, base, SEEK_SET);
|
|
|
|
if (ret == -1)
|
2004-05-19 00:09:58 +00:00
|
|
|
{
|
2004-12-10 00:28:35 +00:00
|
|
|
perror("Cannot go to buffer offset");
|
|
|
|
close(fd);
|
|
|
|
return 3;
|
2004-05-19 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
ret = emile_second_get_cmdline(fd, cmdline);
|
|
|
|
printf("Current command line: \"%s\"\n", cmdline);
|
|
|
|
|
2004-05-19 00:09:58 +00:00
|
|
|
close(fd);
|
2004-05-26 23:05:35 +00:00
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
return ret;
|
2004-05-19 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
int ret;
|
2004-12-10 00:28:35 +00:00
|
|
|
off_t base = FIRST_LEVEL_SIZE;
|
2004-05-19 00:09:58 +00:00
|
|
|
if (argc != 3)
|
|
|
|
{
|
|
|
|
usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-05-21 10:42:54 +00:00
|
|
|
if (strcmp(argv[1], "-r") == 0)
|
2004-12-10 00:28:35 +00:00
|
|
|
ret = get_cmdline(argv[2], base);
|
2004-05-21 10:42:54 +00:00
|
|
|
else
|
2004-12-10 00:28:35 +00:00
|
|
|
ret = set_cmdline(argv[1], argv[2], base);
|
2004-05-19 00:09:58 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|