Allow to set kernel command line

This commit is contained in:
Laurent Vivier 2004-05-19 00:09:58 +00:00
parent 18fac5c9b6
commit e839d9fc1f
6 changed files with 135 additions and 25 deletions

View File

@ -5,25 +5,7 @@
#
PACKAGE = emile
VERSION = 0.3
# kernel arguments
# root filesystem on harddrive
#KERNEL_ARGS="root=/dev/sda7"
# ramdisk
KERNEL_ARGS = "root=/dev/ramdisk ramdisk_size=2048"
# NetBoot
#KERNEL_ARGS = "root=/dev/nfs ip=autoconf"
# ramdisk on 2nd floppy
#KERNEL_ARGS="vga=normal noinitrd load_ramdisk=1 prompt_ramdisk=1 ramdisk_size=16384 root=/dev/fd0 disksize=1.44 flavor=compact"
VERSION = 0.4CVS
# tools to use
@ -46,7 +28,7 @@ KERNEL_ARCH=$(filter Motorola PowerPC, $(shell $(FILE) $(KERNEL) | cut -d"," -f
BASE_ADDRESS = 0x00200000
all: floppy.img
all: floppy.img tools
floppy.img: first/first vmlinuz second/second
cat first/first > floppy.img.X
@ -67,8 +49,12 @@ first/first::
second/second::
$(MAKE) -C second OBJCOPY=$(OBJCOPY) LD=$(LD) CC=$(CC) AS=$(AS) \
BASE_ADDRESS=$(BASE_ADDRESS) KERNEL_ARGS=$(KERNEL_ARGS) \
VERSION=$(VERSION) KERNEL_ARCH=$(KERNEL_ARCH)
BASE_ADDRESS=$(BASE_ADDRESS) VERSION=$(VERSION) \
KERNEL_ARCH=$(KERNEL_ARCH)
tools::
$(MAKE) -C tools all
dump: floppy.img
dd if=floppy.img of=/dev/fd0 bs=512
@ -90,7 +76,8 @@ DISTFILES = second/head.S second/MMU030.c second/MMU040.c second/main.c \
second/glue.S second/enter_kernel030.S \
second/enter_kernel040.S first/first.S \
first/Makefile second/bank.c second/bank.h second/arch.h \
second/arch.c Makefile COPYING README AUTHORS ChangeLog
second/arch.c Makefile COPYING README AUTHORS ChangeLog \
tools/Makefile tools/emile-set-cmdline.c
dist:
rm -fr $(PACKAGE)-$(VERSION)

View File

@ -4,7 +4,7 @@
#
#
CPPFLAGS = -DKERNEL_ARGS="\"$(KERNEL_ARGS)\"" -DVERSION="\"$(VERSION)\""
CPPFLAGS = -DVERSION="\"$(VERSION)\""
CFLAGS = -Wno-multichar -O -m68030 -nostdlib -nodefaultlibs -Wall -Werror
ASFLAGS =
LS = ls

View File

@ -21,7 +21,8 @@
extern unsigned char _ramdisk_start;
extern unsigned char _ramdisk_end;
static char* command_line = KERNEL_ARGS;
extern char _command_line;
static char* command_line = &_command_line;
struct bootinfo boot_info = { 0 };

View File

@ -4,8 +4,20 @@
*
*/
.equ cmdline_length, 256 /* see CL_SIZE in bootinfo.c */
.global _start
_start:
jmp setup(%pc)
.word cmdline_length /* size of command line buffer */
.global _command_line
_command_line:
.skip cmdline_length, 0
.align 4
setup:
/* identify system */
bsr arch_init

12
tools/Makefile Normal file
View File

@ -0,0 +1,12 @@
#
#
# (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
#
#
CFLAGS = -Wall
all: emile-set-cmdline
clean:
rm -f *.o emile-set-cmdline

98
tools/emile-set-cmdline.c Normal file
View File

@ -0,0 +1,98 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define SECTOR_SIZE 512
#define FIRST_LEVEL_SIZE (SECTOR_SIZE * 2)
#define CMDLINE_OFFSET (FIRST_LEVEL_SIZE + 4)
static void usage(int argc, char** argv)
{
fprintf(stderr, "Usage: %s <image> <cmdline>\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, " <image> can be a file or a device (/dev/fd0)\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"
*/
}
int set_cmdline(char* image, char* cmdline)
{
int fd;
short buffer_size;
int ret;
int len = strlen(cmdline) + 1;
fd = open(image, O_RDWR);
if (fd == -1)
{
perror("Cannot open image file (rw mode)");
return 2;
}
ret = lseek(fd, CMDLINE_OFFSET, SEEK_SET);
if (ret == -1)
{
perror("Cannot go to buffer offset");
close(fd);
return 3;
}
ret = read(fd, &buffer_size, sizeof(buffer_size));
if (ret != sizeof(buffer_size))
{
perror("Cannot read buffer size");
close(fd);
return 3;
}
if (len > buffer_size)
{
fprintf(stderr, "Command line too long\n");
close(fd);
return 4;
}
ret = write(fd, cmdline, len);
if (ret != len)
{
perror("Cannot set command line");
close(fd);
return 5;
}
close(fd);
return 0;
}
int main(int argc, char** argv)
{
int ret;
if (argc != 3)
{
usage(argc, argv);
return 1;
}
ret = set_cmdline(argv[1], argv[2]);
if (ret == 0)
printf("Command line sucessfully modified\n");
return ret;
}