Initial root filesystem is now on a ramdisk that is part of the image.

This commit is contained in:
Philip Homburg
2006-02-15 11:18:21 +00:00
parent 3a05de3763
commit c3a88d15d8
26 changed files with 894 additions and 45 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ LIBDRIVER = $d/libdriver/driver.o $d/libdriver/drvlib.o
all build: $(DRIVER)
$(DRIVER): $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
install -S 256w $(DRIVER)
install -S 4k $(DRIVER)
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
+10 -4
View File
@@ -16,29 +16,35 @@ CFLAGS = -I$i
LDFLAGS = -i
LIBS = -lsys -lsysutil
OBJ = memory.o
OBJ = memory.o imgrd.o
LIBDRIVER = $d/libdriver/driver.o
# build local binary
all build: $(DRIVER)
$(DRIVER): $(OBJ) $(LIBDRIVER)
$(DRIVER): ramdisk_image $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
install -S 1024w $(DRIVER)
imgrd.o: ramdisk/image.c
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
ramdisk_image:
cd ramdisk && make
binsizes big
# install with other drivers
install: /sbin/$(DRIVER)
install: # /sbin/$(DRIVER)
/sbin/$(DRIVER): $(DRIVER)
install -o root -cs $? $@
# clean up local files
clean:
rm -f $(DRIVER) *.o *.bak
cd ramdisk && make clean
depend:
/usr/bin/mkdep "$(CC) -E $(CPPFLAGS)" *.c ../libdriver/*.c > .depend
+14
View File
@@ -0,0 +1,14 @@
/*
Ramdisk that is part of the image
*/
#include <stddef.h>
#include "local.h"
unsigned char imgrd[]=
{
#include "ramdisk/image.c"
};
size_t imgrd_size= sizeof(imgrd);
+6
View File
@@ -0,0 +1,6 @@
/*
local defines and declarations
*/
extern unsigned char imgrd[];
extern size_t imgrd_size;
+38 -6
View File
@@ -25,7 +25,9 @@
#include "assert.h"
#define NR_DEVS 6 /* number of minor devices */
#include "local.h"
#define NR_DEVS 7 /* number of minor devices */
PRIVATE struct device m_geom[NR_DEVS]; /* base and size of each device */
PRIVATE int m_seg[NR_DEVS]; /* segment index of each device */
@@ -191,6 +193,19 @@ unsigned nr_req; /* length of request vector */
}
break;
case IMGRD_DEV:
if (position >= dv_size) return(OK); /* check for EOF */
if (position + count > dv_size) count = dv_size - position;
if (opcode == DEV_GATHER) { /* copy actual data */
sys_vircopy(SELF, D, (vir_bytes)&imgrd[position],
proc_nr, D, user_vir, count);
} else {
sys_vircopy(proc_nr, D, user_vir,
SELF, D, (vir_bytes)&imgrd[position], count);
}
break;
/* Unknown (illegal) minor device. */
default:
return(EINVAL);
@@ -278,6 +293,10 @@ PRIVATE void m_init()
printf("MEM stored retrieved details as new RAM disk\n");
}
/* Ramdisk image built into the memory driver */
m_geom[IMGRD_DEV].dv_base= cvul64(0);
m_geom[IMGRD_DEV].dv_size= cvul64(imgrd_size);
/* Initialize /dev/zero. Simply write zeros into the buffer. */
for (i=0; i<ZERO_BUF_SIZE; i++) {
dev_zero[i] = '\0';
@@ -320,19 +339,31 @@ message *m_ptr; /* pointer to control message */
switch (m_ptr->REQUEST) {
case MIOCRAMSIZE: {
/* FS wants to create a new RAM disk with the given size. */
phys_bytes ramdev_size;
/* Someone wants to create a new RAM disk with the given size. */
static int first_time= 1;
u32_t ramdev_size;
phys_bytes ramdev_base;
message m;
int s;
/* Only FS can create RAM disk, and only on RAM disk device. */
if (m_ptr->PROC_NR != FS_PROC_NR) return(EPERM);
/* A ramdisk can be created only once, and only on RAM disk device. */
if (!first_time) return(EPERM);
if (m_ptr->DEVICE != RAM_DEV) return(EINVAL);
if ((dv = m_prepare(m_ptr->DEVICE)) == NIL_DEV) return(ENXIO);
#if 0
ramdev_size= m_ptr->POSITION;
#else
/* Get request structure */
s= sys_vircopy(m_ptr->PROC_NR, D, (vir_bytes)m_ptr->ADDRESS,
SELF, D, (vir_bytes)&ramdev_size, sizeof(ramdev_size));
if (s != OK)
return s;
#endif
printf("allocating ramdisk of size 0x%x\n", ramdev_size);
/* Try to allocate a piece of memory for the RAM disk. */
ramdev_size = m_ptr->POSITION;
if (allocmem(ramdev_size, &ramdev_base) < 0) {
report("MEM", "warning, allocmem failed", errno);
return(ENOMEM);
@@ -359,6 +390,7 @@ message *m_ptr; /* pointer to control message */
dv->dv_base = cvul64(ramdev_base);
dv->dv_size = cvul64(ramdev_size);
/* first_time= 0; */
break;
}
case MIOCMAP:
+81
View File
@@ -0,0 +1,81 @@
# Makefile for ramdisk image
PROGRAMS=at_wini bios_wini cdprobe dev2name floppy loadramdisk newroot \
sh service sysenv
all: image.c
clean:
rm -f $(PROGRAMS) bintoc image image.c
image.c: bintoc image
./bintoc -o $@ image
# Note for cross compilation: this executable has to be compiled for the
# host system
bintoc: bintoc.c
$(CC) -o $@ bintoc.c
image: proto mtab rc $(PROGRAMS)
mkfs -B1024 image proto || { rm -f image; false; }
at_wini: ../../at_wini/at_wini
install -s ../../$@/$@ $@
../../at_wini/at_wini:
cd ../../at_wini && make
bios_wini: ../../bios_wini/bios_wini
install -s ../../$@/$@ $@
../../bios_wini/bios_wini:
cd ../../bios_wini && make
floppy: ../../floppy/floppy
install -s ../../$@/$@ $@
../../floppy/floppy:
cd ../../floppy && make
cdprobe: ../../../commands/simple/cdprobe
install -s ../../../commands/simple/$@ $@
../../../commands/simple/cdprobe:
cd ../../../commands/simple && make cdprobe
dev2name: ../../../commands/simple/dev2name
install -s ../../../commands/simple/$@ $@
../../../commands/simple/dev2name:
cd ../../../commands/simple && make dev2name
loadramdisk: ../../../commands/simple/loadramdisk
install -s ../../../commands/simple/$@ $@
../../../commands/simple/loadramdisk:
cd ../../../commands/simple && make loadramdisk
newroot: ../../../commands/simple/newroot
install -s ../../../commands/simple/$@ $@
../../../commands/simple/newroot:
cd ../../../commands/simple && make newroot
sysenv: ../../../commands/simple/sysenv
install -s ../../../commands/simple/$@ $@
../../../commands/simple/sysenv:
cd ../../../commands/simple && make sysenv
sh: ../../../commands/ash/sh
install -s ../../../commands/ash/$@ $@
../../../commands/ash/sh:
cd ../../../commands/ash && make sh
service: ../../../servers/rs/service
install -s ../../../servers/rs/$@ $@
../../../servers/rs/service:
cd ../../../servers/rs && make service
+129
View File
@@ -0,0 +1,129 @@
/*
bintoc.c
Convert a (binary) file to a series of comma separated hex values suitable
for initializing a character array in C.
*/
#define _POSIX_C_SOURCE 2
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char *progname;
unsigned char buf[1024];
static void fatal(char *fmt, ...);
static void usage(void);
int main(int argc, char *argv[])
{
int c, i, r, first;
FILE *file_in, *file_out;
char *in_name;
char *o_arg;
(progname=strrchr(argv[0],'/')) ? progname++ : (progname=argv[0]);
o_arg= NULL;
while (c= getopt(argc, argv, "?o:"), c != -1)
{
switch(c)
{
case '?': usage();
case 'o': o_arg= optarg; break;
default: fatal("getopt failed: '%c'\n", c);
}
}
if (o_arg)
{
file_out= fopen(o_arg, "w");
if (file_out == NULL)
{
fatal("unable to create '%s': %s\n",
o_arg, strerror(errno));
exit(1);
}
}
else
file_out= stdout;
if (optind < argc)
{
in_name= argv[optind];
optind++;
file_in= fopen(in_name, "r");
if (file_in == NULL)
{
fatal("unable to open '%s': %s",
in_name, strerror(errno));
}
}
else
{
in_name= "(stdin)";
file_in= stdin;
}
if (optind != argc)
usage();
first= 1;
for (;;)
{
r= fread(buf, 1, sizeof(buf), file_in);
if (r == 0)
break;
for (i= 0; i<r; i++)
{
if ((i % 8) == 0)
{
if (first)
{
fprintf(file_out, "\t");
first= 0;
}
else
fprintf(file_out, ",\n\t");
}
else
fprintf(file_out, ", ");
fprintf(file_out, "0x%02x", buf[i]);
}
}
if (ferror(file_in))
{
fatal("read error on %s: %s\n",
in_name, strerror(errno));
}
fprintf(file_out, "\n");
exit(0);
}
static void fatal(char *fmt, ...)
{
va_list ap;
fprintf(stderr, "%s: ", progname);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}
static void usage(void)
{
fprintf(stderr, "Usage: bintoc [-o <out-file>] [<in-file>]\n");
exit(1);
}
+1
View File
@@ -0,0 +1 @@
/dev/imgrd / 3 rw
+66
View File
@@ -0,0 +1,66 @@
boot
200 100
d--755 0 0
bin d--755 0 0
at_wini ---755 0 0 at_wini
bios_wini ---755 0 0 bios_wini
cdprobe ---755 0 0 cdprobe
dev2name ---755 0 0 dev2name
floppy ---755 0 0 floppy
loadramdisk ---755 0 0 loadramdisk
newroot ---755 0 0 newroot
sh ---755 0 0 sh
service ---755 0 0 service
sysenv ---755 0 0 sysenv
$
dev d--755 0 0
c0d0 b--222 0 0 3 0
c0d1 b--222 0 0 3 5
c0d2 b--222 0 0 3 10
c0d3 b--222 0 0 3 15
c0d0p0 b--222 0 0 3 1
c0d0p1 b--222 0 0 3 2
c0d0p2 b--222 0 0 3 3
c0d0p3 b--222 0 0 3 4
c0d1p0 b--222 0 0 3 6
c0d1p1 b--222 0 0 3 7
c0d1p2 b--222 0 0 3 8
c0d1p3 b--222 0 0 3 9
c0d2p0 b--222 0 0 3 11
c0d2p1 b--222 0 0 3 12
c0d2p2 b--222 0 0 3 13
c0d2p3 b--222 0 0 3 14
c0d3p0 b--222 0 0 3 16
c0d3p1 b--222 0 0 3 17
c0d3p2 b--222 0 0 3 18
c0d3p3 b--222 0 0 3 19
c0d0p0s0 b--222 0 0 3 128
c0d0p1s0 b--222 0 0 3 132
c0d0p2s0 b--222 0 0 3 136
c0d0p3s0 b--222 0 0 3 140
c0d1p0s0 b--222 0 0 3 144
c0d1p1s0 b--222 0 0 3 148
c0d1p2s0 b--222 0 0 3 152
c0d1p3s0 b--222 0 0 3 156
c0d2p0s0 b--222 0 0 3 160
c0d2p1s0 b--222 0 0 3 164
c0d2p2s0 b--222 0 0 3 168
c0d2p3s0 b--222 0 0 3 172
c0d3p0s0 b--222 0 0 3 176
c0d3p1s0 b--222 0 0 3 180
c0d3p2s0 b--222 0 0 3 184
c0d3p3s0 b--222 0 0 3 188
fd0 b--222 0 0 2 0
fd0p0 b--222 0 0 2 112
fd0p1 b--222 0 0 2 116
fd0p2 b--222 0 0 2 120
fd0p3 b--222 0 0 2 124
log c--222 0 0 4 15
null c--666 0 0 1 3
ram b--600 0 0 1 0
$
etc d--755 0 0
mtab ---644 0 0 mtab
rc ---755 0 0 rc
$
$
+37
View File
@@ -0,0 +1,37 @@
#!/bin/sh
set -e
/bin/service up /bin/floppy -dev /dev/fd0
if [ X`/bin/sysenv bios_wini` = Xyes ]
then
echo Using bios_wini.
/bin/service up /bin/bios_wini -dev /dev/c0d0
else
/bin/service up /bin/at_wini -dev /dev/c0d0
fi
rootdev=`sysenv rootdev` || echo 'No rootdev?'
rootdevname=`/bin/dev2name "$rootdev"` ||
{ echo 'No device name for root device'; exit 1; }
if sysenv cdproberoot >/dev/null
then
echo
echo 'Looking for boot CD. This may take a minute.'
echo 'Please ignore any error messages.'
echo
cddev=`cdprobe` || { echo 'No CD found'; exit 1; }
export cddev
echo "Loading ramdisk from ${cddev}p1"
loadramdisk "$cddev"p1
elif [ "$rootdevname" = "/dev/ram" ]
then
ramimagedev=`sysenv ramimagedev` ||
{ echo 'ramimagedev not found'; exit 1; }
ramimagename=`/bin/dev2name "$ramimagedev"` ||
{ echo 'No device name for ramimagedev'; exit 1; }
echo "Loading ramdisk from $ramimagename"
loadramdisk "$ramimagename"
fi
echo "Root device name is $rootdevname"
/bin/newroot "$rootdevname"
exec /bin/sh /etc/rc start