diff -u --recursive --new-file silo-0.4/ChangeLog silo-0.5/ChangeLog --- silo-0.4/ChangeLog +++ silo-0.5/ChangeLog Fri Mar 15 18:06:25 1996 @@ -0,0 +1,36 @@ +Fri Mar 15 18:03:38 1996 Mauricio Plaza Villegas + + * second/prom_io.c: BUG FIXED: Block Size was hardcoded as 1024, + now it should work for other block sizes. + +Thu Mar 14 19:35:51 1996 Mauricio Plaza Villegas + + * bin/uninstall: Uninstall Utility (a pretty simple one). + + * second/main.c: CHAIN LOADING, Now we are able to load another + Operating System by saving the old loader and re-running it + instead of the kernel (tree steps). There are olny two reserved + words when second stage loader prompts, "halt" and "sunos". Halt + will interrupt the whole process backing you to the "ok" + prompt. Sunos will load the original loader of the original + Operating System like SunOS. + + * instboot/instboot.c: BUG FIXED: Default parameters are keeped. + + * second/prom_io.c (load_kernel): BUG FIXED: Other partition + loading now works. + + +Wed Mar 13 09:22:32 1996 Mauricio Plaza Villegas + + * second/main.c: Adding support for default partition (same + partition where the first stage is). + (readhint): Parameters from the blocktable. + + * instboot/instboot.c: Adding the params support. Read old + parameters and give the chance to change them. + + * storage.h (struct Block_Table): Adding a field called params so + we can have default booting parameters. Also SILO_MAGIC has + changed so we can boot without prompting, if light runs out the + machine will be able to reboot. Binary files silo-0.4/bin/first.image and silo-0.5/bin/first.image differ Binary files silo-0.4/bin/instboot and silo-0.5/bin/instboot differ Binary files silo-0.4/bin/second.image and silo-0.5/bin/second.image differ diff -u --recursive --new-file silo-0.4/bin/uninstall silo-0.5/bin/uninstall --- silo-0.4/bin/uninstall +++ silo-0.5/bin/uninstall Thu Mar 14 20:32:43 1996 @@ -0,0 +1,35 @@ +#!/bin/sh + +if [ $# -ne 2 ] +then + echo Usage: $0 _old_loader _device + echo + echo _old_loader is the file where the original lodare was saved + echo please use full path. + echo + echo _device is the device you want to restore. + echo + echo + exit 1 +fi + +echo Uninstalling SILO from $2 +echo + +DD=/bin/dd +CAT=/bin/cat + +SECTOR_0=tmp.0 +RESTORED=tmp.2 + +$DD if=$2 of=$SECTOR_0 bs=512 count=1 +$CAT $SECTOR_0 $1 > $RESTORED +$DD if=$RESTORED of=$2 bs=512 + +echo Done! +sync;sync;sync +echo syncing.... +sync +sync +echo Now you can reboot. + diff -u --recursive --new-file silo-0.4/first/main.c silo-0.5/first/main.c --- silo-0.4/first/main.c Tue Mar 12 22:18:49 1996 +++ silo-0.5/first/main.c Wed Mar 13 10:20:10 1996 @@ -1,7 +1,6 @@ /* * Linux Loader for SPARC * (In fact just a very simple bootstrap block still.) - * * Pete A. Zaitcev * * Linux Sparc Loader First Stage @@ -65,9 +64,6 @@ return res; } -void bootparam(Cmdline *cmdp, Console *conp, Disk *dkp); -void sendparam(struct linux_romvec *promvec, Cmdline *cmdp, Console *conp); - /* Here we are launched */ int bootmain(struct linux_romvec *promvec){ static Console cons0; @@ -82,7 +78,7 @@ Elf32_Ehdr *e; } hp; int rc; - char rotator[5] ={"..oO0"}; + char rotator[5] ={".oOo."}; char block_buff [1024]; /* Reading from sectors 14-15 */ struct Block_Table *bt; @@ -167,111 +163,15 @@ dkclose(&dk0, promvec); - sendparam(promvec, &cmd0, &cons0); + /* sendparam(promvec, &cmd0, &cons0); */ - xprintf ((int) &cons0, "\n\n\nLoading Second Stage....\n"); + xprintf ((int) &cons0, "\n\nLoading Second Stage....\n"); return 0x4000; eread: xprintf((int) &cons0, "Read error\n"); return 0; } - -/* - * Get command line from disk. - */ -static int readhint(Cmdline *cmdp, Console *conp, Disk *dkp) -{ - static char cmdblock[512]; - - if (dkread(dkp, cmdblock, 1, 16) != 1) { - xprintf((int) conp, "Floppy error\n"); - return -1; - } - - if (cmdblock[0] != 'S' || - cmdblock[1] != 'I' || - cmdblock[2] != 'L' || - cmdblock[3] != 'O') - { - return -1; - } - - if (cmdblock[4] == '0' && cmdblock[5] == '0') { - cmdfill(cmdp, cmdblock+6); - return 0; - } - - if (cmdblock[4] == '0' && cmdblock[5] == '1') { - cmdfill(cmdp, cmdblock+6); - return 1; - } - - return -1; -} - -/* - * Obtain a command line from disk or console. - */ -void bootparam(Cmdline *cmdp, Console *conp, Disk *dkp) -{ - if (readhint(cmdp, conp, dkp) != 1) { - /* - * Cases: 0 - edit with hint, -1 - edit without hint. - */ - xprintf((int) conp, "silo: "); - cmdedit(cmdp, conp); - xprintf((int) conp, "\n"); - } - - xprintf((int) conp, "silo: \"%s\"\n", cmdp->cbuff_); -} - -/* - * Supply a command line to the kernel. - */ -void sendparam(struct linux_romvec *promvec, Cmdline *cmdp, Console *conp) -{ - /* These are for return. */ - static char arg0[CMD_LENG]; - static char *argv[2] = { arg0, 0 }; - - /* - * We expect a kernel to extract a command line - * from our dead body promptly. If somebody wants - * to boot something other than Linux kernel than - * he/she should just use a command line from PROM. - */ - if (cmdp != 0 && cmdp->cbuff_[0] != 0) { /* Be robust. */ - /** strcpy(arg0, cmdp->cbuff_); **/ - { - register char *f = cmdp->cbuff_, *t = arg0; - while(*t++ = *f++) {} - } - - switch (promvec->pv_romvers) { - case 0: - case 1: - /* strcpy(cp, (*(romvec->pv_v0bootargs))->argv[iter]); */ - { - char **p = (*(promvec->pv_v0bootargs))->argv; - p[0] = arg0; - p[1] = 0; - } - break; - case 2: - case 3: - /* strcpy(cp, *romvec->pv_v2bootargs.bootargs); */ - xprintf((int) conp, "silo: %x %x\n", argv, arg0); - xprintf((int) conp, "silo: V2 %x\n", promvec->pv_v2bootargs.bootargs); - *promvec->pv_v2bootargs.bootargs = arg0; - - break; - default: - ; - } - } -} int dkopen(Disk *t, const struct linux_romvec *promvec, Console *con){ static char name0[11]; diff -u --recursive --new-file silo-0.4/include/storage.h silo-0.5/include/storage.h --- silo-0.4/include/storage.h Tue Mar 12 22:47:25 1996 +++ silo-0.5/include/storage.h Thu Mar 14 16:28:16 1996 @@ -1,20 +1,23 @@ -/* Mauricio Plaza */ +/* 1996 Mauricio Plaza + License GPL +*/ /* The firts loader must read the parameters an dthe blocks from the bootbloks 14-15. In order to load the secondary loader which understand ext2fs */ #define SECOND_STAGE_SEC 14 #define OLD_LOADER_SEC 13 -#define SILO_MAGIC "SILO00" +#define SILO_MAGIC "SILO005" /* WARNING: This structute must be no longer than 1024 bytes */ struct Block_Table{ + char magic[10]; /* Signature */ + char params[100]; /* Booting Parameters*/ + unsigned char partno; /* Default Partition Number */ unsigned char nsect; /* Sectors per Block */ unsigned short int bs; /* Block Size */ unsigned long int DiskOffset; /* Real Cylinder to start from */ unsigned long int blocks[200]; /* File Block Table */ - unsigned char partno; /* Default Partition Number */ - char magic[7]; /* Signature */ }; diff -u --recursive --new-file silo-0.4/include/storage.h~ silo-0.5/include/storage.h~ --- silo-0.4/include/storage.h~ Tue Mar 12 21:27:21 1996 +++ silo-0.5/include/storage.h~ Wed Mar 13 11:06:30 1996 @@ -1,20 +1,23 @@ - +/* 1996 Mauricio Plaza + License GPL +*/ /* The firts loader must read the parameters an dthe blocks from the bootbloks 14-15. In order to load the secondary loader which understand ext2fs */ #define SECOND_STAGE_SEC 14 #define OLD_LOADER_SEC 13 -#define SILO_MAGIC "SILO00" +#define SILO_MAGIC "0SILO005" /* WARNING: This structute must be no longer than 1024 bytes */ struct Block_Table{ + char magic[10]; /* Signature */ + char params[100]; /* Booting Parameters*/ + unsigned char partno; /* Default Partition Number */ unsigned char nsect; /* Sectors per Block */ unsigned short int bs; /* Block Size */ unsigned long int DiskOffset; /* Real Cylinder to start from */ unsigned long int blocks[200]; /* File Block Table */ - unsigned char partno; /* Default Partition Number */ - char magic[7]; /* Signature */ }; diff -u --recursive --new-file silo-0.4/instboot/instboot.c silo-0.5/instboot/instboot.c --- silo-0.4/instboot/instboot.c Tue Mar 12 22:44:53 1996 +++ silo-0.5/instboot/instboot.c Thu Mar 14 20:00:17 1996 @@ -178,7 +178,8 @@ printf ("Cannot open %s\n",device); exit (1); } - strcpy (bt->magic, SILO_MAGIC); + bt->magic[0]='0'; + strcpy (&bt->magic[1], SILO_MAGIC); lseek (fd, boot_block_sector*512, 0); rc=write (fd, block_buff, sizeof(block_buff)); printf ("\n %d Bytes written....\n",rc); @@ -216,8 +217,8 @@ sbt = (struct Block_Table *) &buffer[512*13]; - printf ("Tabla nsect = %d, bs = %d, magic = %s", sbt->nsect, sbt->bs, sbt->magic); - if (!strcmp(sbt->magic, SILO_MAGIC)){ + printf ("Tabla nsect = %d, bs = %d, magic = %s\n", sbt->nsect, sbt->bs, sbt->magic); + if (!strcmp(&sbt->magic[1], SILO_MAGIC)){ puts ("SILO Found.....skiping backup"); return 0; } @@ -260,10 +261,35 @@ fclose (fp); } +set_booting_params(char *device){ + int fd; + char buffer[1024]; + struct Block_Table *sbt; + char aux[100]; + + sbt=(struct Block_Table *) &buffer; + printf ("Setting Boot Parameters.\nOpening device %s for writing....\n", + device); + if ((fd=open(device,O_RDWR)) == -1){ + puts ("Opening device error....aborting!"); + exit (1); + } + lseek (fd, 512*OLD_LOADER_SEC, 0); + read (fd, buffer, sizeof(buffer)); + printf ("\n\nType booting parameters (%s):", sbt->params); + gets(aux); + if (strcmp(aux, "")){ + printf ("Parameters are : %s \n", aux); + strcpy (sbt->params, aux); + lseek (fd, 512*OLD_LOADER_SEC, 0); + write (fd, buffer, sizeof(buffer)); + } + close(fd); +} + main (int argc, char *argv[]){ - bt = (struct Block_Table *) &block_buff; if (argc!=5) { usage (argv[0]); @@ -283,7 +309,7 @@ install_first_stage(argv[1], argv[2]); } - + set_booting_params(argv[1]); if (get_partition_blocks(argv[3])) { puts ("ok!"); } diff -u --recursive --new-file silo-0.4/second/main.c silo-0.5/second/main.c --- silo-0.4/second/main.c Tue Mar 12 22:45:35 1996 +++ silo-0.5/second/main.c Fri Mar 15 17:59:44 1996 @@ -1,7 +1,7 @@ /* - Based on Peter's Silo - Mauricio Plaza (Second Stage Boot Loader) - */ + Based on Peter's Silo + Mauricio Plaza (Second Stage Boot Loader) + */ #include #include @@ -10,14 +10,14 @@ /* We carry own a.out header for ease of cross-compilation. */ struct exec { - int magic; - int ltext; - int ldata; - int lbss; - int lsym; - int lentry; - int x1; - int x2; + int magic; + int ltext; + int ldata; + int lbss; + int lsym; + int lentry; + int x1; + int x2; }; #ifndef CONSOLE_H @@ -27,6 +27,7 @@ #include "cmdline.h" #endif +#include extern xprintf(int filog, char *fmt, ...); extern int load_kernel (char *S, int N); @@ -38,12 +39,12 @@ typedef int (*Read2)(int, char *, int); typedef struct { - int fd_; - int seekp_; - int floppy_; - Read0 read0_; - Seek2 seek2_; - Read2 read2_; + int fd_; + int seekp_; + int floppy_; + Read0 read0_; + Seek2 seek2_; + Read2 read2_; } Disk; extern int dkopen(Disk *, const struct linux_romvec *, Console *); @@ -55,7 +56,7 @@ int mult(int a, int b){ int i, res=0; - + for (i=0; i0 && *partno<9 && *params=='/') { - strcpy (kname, params); - } else { - xprintf ((int) &cons0, "Error parsing values .... try again\n"); - return 0; - } - - } else { - *partno = 4; /* MUST Take defualt form BOOTBLOCKS 14-15 Block_Table->partno*/ +int load_sunos(){ + char buffer[1024]; + struct Block_Table *sbt; + int i; + char *b=(char *) 0x4000; + + sbt = (struct Block_Table *) &buffer; + if (dkread (&dk0, buffer, 2, OLD_LOADER_SEC)!=2) { + xprintf ((int) &cons0, "Can not read old loader blocks....aborting\n"); + return 0; + } + xprintf ((int) &cons0, "Magic = %s, Partition = %d, Offset = %d\n", sbt->magic, (int)sbt->partno, sbt->DiskOffset); + xprintf ((int) &cons0, "Block Size = %d, NSect = %d\n", sbt->bs, (int)sbt->nsect); + xprintf ((int) &cons0, "\n\nLoading old lodaer (probably SunOS)\n"); + for (i=0; sbt->blocks[i]!=0; i++){ + dkread (&dk0, b, sbt->nsect, sbt->blocks[i]*sbt->nsect+sbt->DiskOffset); + b+=512*sbt->nsect; + xprintf ((int) &cons0,"."); } return 1; } - - + /* Here we are launched */ int bootmain(struct linux_romvec *promvec){ static Cmdline cmd0; @@ -103,7 +98,7 @@ struct exec *a; Elf32_Ehdr *e; } hp; - int isfile; + int isfile, fileok=0; dpset(&cons0, promvec); @@ -122,7 +117,7 @@ char kname[CMD_LENG]; int partno,i; - xprintf ((int) &cons0,"\nType something like /_device_/_kernel_ _bootparams_\n"); + xprintf ((int) &cons0,"\nType [device]kernel_name [parameters]\n"); for (i=0; imagic[1], SILO_MAGIC)){ + xprintf ((int) &cons0, "This is not a SILO block\n"); + return -1; + } + cmdfill(cmdp, sbt->params); + return 0; } /* @@ -229,7 +219,7 @@ void bootparam(Cmdline *cmdp, Console *conp, Disk *dkp) { - if (readhint(cmdp, conp, dkp) != 1) { + if (readhint(cmdp) != 1) { /* * Cases: 0 - edit with hint, -1 - edit without hint. */ diff -u --recursive --new-file silo-0.4/second/prom_io.c silo-0.5/second/prom_io.c --- silo-0.4/second/prom_io.c Tue Mar 12 22:45:45 1996 +++ silo-0.5/second/prom_io.c Mon Mar 18 18:42:00 1996 @@ -15,6 +15,7 @@ #endif #include "prom_io.h" +#include typedef int (*Read0)(int dev, int num_blks, int blk_st, char* buf); typedef int (*Seek2)(int, int, int); @@ -39,12 +40,56 @@ static unsigned char nsect; /* Sectors per Block */ -static unsigned int bs=1024; /* Block Size */ +static unsigned int bs; /* Block Size */ static unsigned long int DiskOffset; /* Block where partition starts */ char *buffer; /* 0x4000 */ +int select_parameters (char source[], char kname[], int *partno){ + char *params; + char buff[1024]; + struct Block_Table *stb; + + params = strchr(source, ' '); + strncpy (kname, source, strlen(source) - strlen(params)); + if (params) { + strcpy (source, params); + } else { + source[0]=0; + } + + stb = (struct Block_Table *) &buff; + dkread (&dk0, buff, 2, SECOND_STAGE_SEC); + bs = stb->bs; + + xprintf ((int) &cons0, "SELECT PARAMETERS: DiskOffset = %d, BlockS = %d\n", stb->DiskOffset, stb->bs); + + if (params = strstr(kname,"dev/sd")) { + params+=strlen("dev/sd")+1; /* Skip abcd */ + *partno = (int) (*params - '0'); + params ++; + if (*partno>0 && *partno<9 && *params=='/') { + strcpy (kname, params); + } else { + xprintf ((int) &cons0, "Error parsing values .... try again\n"); + return 0; + } + + } else { + if ((int) stb->partno != 0) { + *partno = (int) stb->partno; + xprintf ((int) &cons0, "Default partition is %d.\n", *partno); + }else{ + xprintf ((int) &cons0, "Invalid partition %d on block %d", + (int) stb->partno, OLD_LOADER_SEC); + xprintf ((int) &cons0, " defaulting to 4\n"); + *partno = 4; + } + } + return 1; +} + int read_sun_part (int partno) { int rc; @@ -55,11 +100,15 @@ DiskLabel = (struct sun_disklabel *) &sdlbuffer; rc = dkread (&dk0, sdlbuffer, 1, 0); - if (rc != 1) - xprintf ((int) &cons0, "Can not read partition...aborting!\n"); - xprintf ((int) &cons0, "Partition Table:\n"); + if (rc != 1){ + xprintf ((int) &cons0, "Can not read partition...aborting!\n"); + return 0; + } DiskOffset = DiskLabel->ntrks * DiskLabel->nsect * DiskLabel->partitions[partno-1].start_cylinder; nsect = bs / 512; + xprintf ((int) &cons0, "READ SUN PART: DiskOffset = %d, BlockSize = %d, nsect = %d\n", + DiskOffset, bs, nsect); + return 1; } #ifdef CHEAT_C_LIB @@ -113,7 +162,7 @@ io->manager = linux_io_manager; io->name = (char *) malloc (strlen (name)+1); strcpy (io->name, name); - io->block_size = 1024; + io->block_size = bs; io->read_error = 0; io->write_error = 0; @@ -121,13 +170,12 @@ partno = *(name + strlen(name) - 1) - '0'; xprintf ((int) &cons0, "DEBUG: Partition Number %d from device %s\n", partno, name); if (!read_sun_part (partno)){ - xprintf ((int) &cons0," Error on reading partition of %s (part= %d)\n", name,partno); + xprintf ((int) &cons0," ERROR: The SUN partition of %s (part= %d)is invalid.\n", name,partno); return EXT2_ET_BAD_DEVICE_NAME; } - /* FIXME - xprintf ((int) &cons0,"DEBUG: Disk Offset = %d, FileDescriptor = %d\n",DiskOffset,DiskFd); - */ + xprintf ((int) &cons0,"DEBUG: Exiting Linux_open....\n"); + *channel=io; return 0; @@ -140,24 +188,23 @@ errcode_t linux_set_blksize(io_channel channel, int blksize){ - bs = blksize; + + xprintf ((int) &cons0, "Llamando al set blksize con newblksize = %d\n", blksize); + channel->block_size = bs = blksize; } errcode_t linux_read_blk(io_channel channel, unsigned long block, int count, void *data) { int size; - + size = (count < 0) ? -count : count*bs; -#if 0 - xprintf ((int) &cons0,"DEBUG: Read Block %d, bytes %d, 512b sects %d\n", - block, size, size/512); -#endif + nsect = bs / 512; + if (size<512){ int i; char buff[512]; - xprintf ((int) &cons0, "DEBUG: Read size smaller than 512 (%d)\n",size); dkread (&dk0, buff, 1, block*nsect+DiskOffset); memcpy (data, buff, size); @@ -289,14 +336,17 @@ load_kernel(char *filename, int N) { - xprintf ((int) &cons0,"load_kernel: %s\n", filename); - if (!silo_open_ext2("/dev/sda4")){ - xprintf ((int) &cons0," DEBUG: Can not open /dev/sda4 "); + char device[]="/dev/sdaX"; /* CHEAT */ + + device[8]=(char)N + '0'; + xprintf ((int) &cons0,"Loading Kernel %s form device %s(%d)\n", filename, device, N); + if (!silo_open_ext2(device)){ + xprintf ((int) &cons0," DEBUG: Can not open partition %s \n", device); return 0; } xprintf ((int) &cons0,"DEBUG: Trying to load file\n"); - buffer = 0x4000; + buffer = (char *)0x4000; if (!load_file (filename)){ xprintf ((int) &cons0,"DEBUG: failed to load file\n"); return 0;