bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

True CBD patch


From: Shaun Savage
Subject: True CBD patch
Date: Wed, 24 Jan 2001 10:07:14 +0100

I am trying to get the CBD into the linux kernel so I have many patch
that I send.

Shaun
--- grub/configure.in   Thu Jan 11 08:28:16 2001
+++ grub-20000118/configure.in  Fri Jan 19 18:34:39 2001
@@ -223,6 +223,13 @@
 dnl FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_TFTP=1"
 dnl fi
 
+AC_ARG_ENABLE(cbd,
+  [  --disable-cbd           disable CBD support in Stage 2])
+
+if test x"$enable_cbd" != xno; then
+  FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_CBD=1"
+fi
+
 AC_ARG_ENABLE(gunzip,
   [  --disable-gunzip        disable decompression in Stage 2])
 
--- grub/stage2/Makefile.am     Thu Oct 19 23:10:42 2000
+++ grub-20000118/stage2/Makefile.am    Fri Jan 19 18:39:04 2001
@@ -16,10 +16,10 @@
 noinst_LIBRARIES = libgrub.a
 libgrub_a_SOURCES = boot.c builtins.c common.c char_io.c cmdline.c \
        disk_io.c gunzip.c fsys_ffs.c fsys_ext2fs.c fsys_fat.c \
-       fsys_minix.c fsys_reiserfs.c stage2.c md5.c
+       fsys_minix.c fsys_reiserfs.c fsys_cbd.c stage2.c md5.c
 libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \
        -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
-       -DFSYS_MINIX=1 -DFSYS_REISERFS=1 -DSUPPORT_SERIAL \
+       -DFSYS_MINIX=1 -DFSYS_REISERFS=1 -DFSYS_CBD -DSUPPORT_SERIAL \
        -fwritable-strings
 
 # Stage 2 and Stage 1.5's.
@@ -29,19 +29,19 @@
 
 if DISKLESS_SUPPORT
 pkgdata_DATA = stage2 e2fs_stage1_5 fat_stage1_5 ffs_stage1_5 \
-       minix_stage1_5 reiserfs_stage1_5 nbgrub pxegrub
+       minix_stage1_5 reiserfs_stage1_5 cbd_stage1_5 nbgrub pxegrub
 noinst_DATA = pre_stage2 start nbloader pxeloader diskless
 noinst_PROGRAMS = pre_stage2.exec start.exec e2fs_stage1_5.exec \
        fat_stage1_5.exec ffs_stage1_5.exec minix_stage1_5.exec \
-       reiserfs_stage1_5.exec nbloader.exec pxeloader.exec \
+       reiserfs_stage1_5.exec cbd_stage1_5.exec nbloader.exec pxeloader.exec \
        diskless.exec
 else
 pkgdata_DATA = stage2 e2fs_stage1_5 fat_stage1_5 ffs_stage1_5 \
-       minix_stage1_5 reiserfs_stage1_5
+       minix_stage1_5 reiserfs_stage1_5 cbd_stage1_5
 noinst_DATA = pre_stage2 start
 noinst_PROGRAMS = pre_stage2.exec start.exec e2fs_stage1_5.exec \
        fat_stage1_5.exec ffs_stage1_5.exec minix_stage1_5.exec \
-       reiserfs_stage1_5.exec
+       reiserfs_stage1_5.exec cbd_stage1_5.exec
 endif
 MOSTLYCLEANFILES = $(noinst_PROGRAMS)
 
@@ -71,7 +71,8 @@
 # For stage2 target.
 pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c common.c \
        char_io.c cmdline.c disk_io.c gunzip.c fsys_ext2fs.c \
-       fsys_fat.c fsys_ffs.c fsys_minix.c fsys_reiserfs.c serial.c \
+       fsys_fat.c fsys_ffs.c fsys_minix.c fsys_reiserfs.c fsys_cbd.c \
+       serial.c \
        smp-imps.c stage2.c md5.c
 pre_stage2_exec_CFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
 pre_stage2_exec_LDFLAGS = $(PRE_STAGE2_LINK)
@@ -142,6 +143,14 @@
 reiserfs_stage1_5_exec_CFLAGS = $(STAGE1_5_COMPILE) -DFSYS_REISERFS=1 \
        -DNO_BLOCK_FILES=1
 reiserfs_stage1_5_exec_LDFLAGS = $(STAGE1_5_LINK)
+
+# For cbd_stage1_5 target.
+cbd_stage1_5_exec_SOURCES = start.S asm.S common.c char_io.c disk_io.c \
+       stage1_5.c fsys_cbd.c bios.c
+cbd_stage1_5_exec_CFLAGS = $(STAGE1_5_COMPILE) -DFSYS_CBD=1 \
+       -DNO_BLOCK_FILES=1
+cbd_stage1_5_exec_LDFLAGS = $(STAGE1_5_LINK)
+
 
 # For diskless target.
 diskless_exec_SOURCES = $(pre_stage2_exec_SOURCES)
--- grub/stage2/filesys.h       Sat Apr 15 15:39:38 2000
+++ grub-20000118/stage2/filesys.h      Fri Jan 19 18:54:14 2001
@@ -78,10 +78,21 @@
 #define FSYS_TFTP_NUM 0
 #endif
 
+#ifdef FSYS_CBD
+#define FSYS_CBD_NUM 1
+int cbd_mount (void);
+int cbd_read (char *buf, int len);
+int cbd_dir (char *dirname);
+void cbd_close(void);
+int cbd_embed (int *start_sector, int needed_sectors);
+#else
+#define FSYS_CBD_NUM 0
+#endif
+
 #ifndef NUM_FSYS
 #define NUM_FSYS       \
   (FSYS_FFS_NUM + FSYS_FAT_NUM + FSYS_EXT2FS_NUM + FSYS_MINIX_NUM      \
-   + FSYS_REISERFS_NUM + FSYS_TFTP_NUM)
+   + FSYS_REISERFS_NUM + FSYS_TFTP_NUM + FSYS_CBD_NUM)
 #endif
 
 /* defines for the block filesystem info area */
--- grub/stage2/disk_io.c       Thu Dec 21 23:42:33 2000
+++ grub-20000118/stage2/disk_io.c      Sat Jan 20 08:37:44 2001
@@ -65,6 +65,9 @@
 # ifdef FSYS_FFS
   {"ffs", ffs_mount, ffs_read, ffs_dir, 0, ffs_embed},
 # endif
+# ifdef FSYS_CBD
+  {"cbd", cbd_mount, cbd_read, cbd_dir, cbd_close, cbd_embed},
+# endif
   {0, 0, 0, 0, 0, 0}
 };

--- grub/stage2/shared.h        Wed Jan 10 21:48:50 2001
+++ grub-20000118/stage2/shared.h       Fri Jan 19 18:56:43 2001
@@ -205,6 +205,7 @@
 #define STAGE2_ID_FAT_STAGE1_5         3
 #define STAGE2_ID_MINIX_STAGE1_5       4
 #define STAGE2_ID_REISERFS_STAGE1_5    5
+#define STAGE2_ID_CBD_STAGE1_5         6
 
 #ifndef STAGE1_5
 # define STAGE2_ID     STAGE2_ID_STAGE2
@@ -219,6 +220,8 @@
 #  define STAGE2_ID    STAGE2_ID_MINIX_STAGE1_5
 # elif defined(FSYS_REISERFS)
 #  define STAGE2_ID    STAGE2_ID_REISERFS_STAGE1_5
+# elif defined(FSYS_CBD)
+#  define STAGE2_ID    STAGE2_ID_CBD_STAGE1_5
 # else
 #  error "unknown Stage 2"
 # endif
diff -uN grub/stage2/cbd.h grub-20000118/stage2/cbd.h
--- grub/stage2/cbd.h   Thu Jan  1 01:00:00 1970
+++ grub-20000118/stage2/cbd.h  Fri Jan 19 18:31:53 2001
@@ -0,0 +1,125 @@
+/*
+ * This header file defines the ioctls
+ * for the CBD DRIVER
+ * we use 'i' as "our letter" (c.f. linux/Documentation/ioctl-number.txt)
+ */
+
+#ifndef _CBD_H_
+#define _CBD_H_
+
+#define CBD_MAJOR 61
+
+#define CBD_LETTER                     'i'
+#define CBD_ERASE_SECTION           _IOWR(CBD_LETTER, 1, long *)
+#define CBD_INVAL_BUFFERS           _IOWR(CBD_LETTER, 2, long *)
+#define CBD_INVAL_PARTITION         _IOWR(CBD_LETTER, 3, long *)
+#define CBD_GET_FREE_SECTION        _IOWR(CBD_LETTER, 4, long *)
+#define CBD_GET_PARTITION_VERSION   _IOWR(CBD_LETTER, 5, long *)
+#define CBD_COMMIT_SECTION          _IOWR(CBD_LETTER, 6, long *)
+#define CBD_GET_SIZE                _IOWR(CBD_LETTER, 7, long *)
+#define CBD_GET_HWCONFIG            _IOWR(CBD_LETTER, 8, long *)
+#define CBD_GET_RAWDEVICE           _IOWR(CBD_LETTER, 9, long *)
+#define CBD_NEW_FORMAT              _IOWR(CBD_LETTER, 10, long *)
+
+/*
+ * Section Header:
+ * 
+ * Each section (except BIOS-sections and unintialized sections)
+ * starts with a section header:
+ */
+
+#define CBD_SECTION_SIZE  0x10000L      /* 64 K */
+#define IGF_SECT_HDR_LEN  32    /* we assume section hdrs to be that long! */
+#define IGF_SECT_DATA_LEN (CBD_SECTION_SIZE - IGF_SECT_HDR_LEN)
+#define CBD_DEV_0_NAME    "/dev/igf0"
+#define CBD_MAGIC 0x4c454749
+#define CBD_PARTHDR_CRC_START  (2 * sizeof (ulong))
+#define DRIVER_VERSION -1
+#define CBD_MAX_MINORS 16
+
+/* typedef unsigned long ulong; */
+/* typedef unsigned short unsigned short; */
+#ifndef uchar
+
+typedef unsigned char uchar; 
+#endif
+
+/*  content types */
+/*  NONE       nothing */
+#define NONE   0x454E4F4E
+/*  CLST       cluster map */
+#define CLST   0x54534C43
+/*  SECT       section map */
+#define SECT   0x54434553
+/*  KRNL       kernel */
+#define KRNL   0x4C4E524B
+/*  BOOT       boot */
+#define BOOT   0x544F4F42
+/*  BOT1       boot1 */
+#define BOT1   0x31544F42
+/*  BOT2       boot2 */
+#define BOT2   0x32544F42
+/*  BOT3       boot3 */
+#define BOT3   0x33544F42
+/*  SPLS       splash */
+#define SPLS   0x534C5053
+/*  INRD       initrd */
+#define INRD   0x44544E49
+/*  DICT       dictionary */
+#define DICT   0x54434944
+/*  MKEY       make public key */
+#define MKEY   0x59454B4D
+/*  OKEY       oem public key */
+#define OKEY   0x59454B4F
+/*  RKEY       register public key */
+#define RKEY   0x59454B52
+/*  SIGN        signature */
+#define SIGN   0x4E474953
+
+typedef struct cbd_part_content {
+       char    name[4];
+       unsigned int    offset;
+       unsigned int    length;
+       unsigned int    crc;
+} cbd_part_content_t; /* struct cbd_part_content */
+
+typedef struct cbd_part_hdr {
+       
+       unsigned int    magic;                          /* 0 IGEL */
+       
+       unsigned int    hdr_crc;                        /* 4 checksum */
+       
+       char    drvver;                         /* 8 driver version */
+       uchar   cluster_shift;                  /* 9 cluster size 32k */
+       uchar   n_content;                      /* A number of types */
+       uchar   cbd_minor;                      /* B minor nimber */
+
+       unsigned short  hdr_len;                        /* C length */
+       unsigned short  n_sections;                     /* E number of sections 
*/
+
+       unsigned int    version;                        /* 10 partition version 
*/
+       unsigned int    update_count;                   /* 14 sequence */
+
+       unsigned int    n_clusters;                     /* 18 number of cluster 
*/
+
+       unsigned int    offset_section_table;           /* 1C start of section 
table */
+
+       cbd_part_content_t content_table[0];    /* 20 content table */
+
+} cbd_part_hdr_t; /* struct cbd_part_hdr */
+
+/* now comes section table */
+/* then comes contents */
+
+#define align(a,b) (((a + b -1)/b) * b)
+
+/* proc data information */
+/* size:       total  free */
+#define CBD_PROC_SIZE "%d %d"
+/* map:                array of status and partition */
+/* part:       lines of 
+       "part# version update# cluster# section# mounted*/
+#define CBD_PROC_PART "%d %x %x %x %x %d"
+/* info:       ??? */
+/* device:     lines of block devices */
+#endif
diff -uN grub/stage2/fsys_cbd.c grub-20000118/stage2/fsys_cbd.c
--- grub/stage2/fsys_cbd.c      Thu Jan  1 01:00:00 1970
+++ grub-20000118/stage2/fsys_cbd.c     Sat Jan 20 11:23:32 2001
@@ -0,0 +1,254 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 1996  Erich Boleyn  <address@hidden>
+ *  Copyright (C) 2000  Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * Elements of this file were originally from the FreeBSD "biosboot"
+ * bootloader file "disk.c" dated 4/12/95.
+ *
+ * The license and header comments from that file are included here.
+ */
+
+/*
+ * Mach Operating System
+ * Copyright (c) 1992, 1991 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ *  Software Distribution Coordinator  or  address@hidden
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ *
+ *     from: Mach, Revision 2.2  92/04/04  11:35:49  rpd
+ *     $Id: fsys_ffs.c,v 1.8 2000/04/15 13:39:38 okuji Exp $
+ */
+
+#ifdef FSYS_CBD
+
+#include "shared.h"
+
+#include "filesys.h"
+
+#include "defs.h"
+#include "dir.h"
+#include "fs.h"
+#include "cbd.h"
+
+typedef struct part_s {
+    unsigned int start;
+    unsigned int hdr_len;
+    unsigned int n_sections;
+    unsigned long version, update_count;
+} part_t;
+
+
+/* used for filesystem map blocks */
+static unsigned short section_map[2048];
+static part_t part_map[15];
+static int n_parts;
+static int version, update_count;
+static cbd_part_content_t *content;
+
+/* pointer to superblock */
+#define SUPERBLOCK ((struct fs *) ( FSYS_BUF + 8192 ))
+#define INODE ((struct icommon *) ( FSYS_BUF + 16384 ))
+#define MAPBUF ( FSYS_BUF + 24576 )
+#define MAPBUF_LEN 8192
+
+
+static int data_read(cbd_part_content_t *cont, unsigned long foffset, char* 
buf,int len)
+{
+    int rslt;
+    part_t *ppart = &part_map[0];
+    unsigned long sector,offset,section;
+    int orcnt, tioncnt;
+
+    section = ppart->start;
+    offset = foffset + cont->offset;
+    sector = (section<<7) + (offset >> 9);
+    offset = offset & 0x01ff;
+    orcnt  = (len + 511)>> 9;
+    tioncnt = (orcnt + 127 )>>7;
+
+#ifndef STAGE1_5
+      disk_read_func = disk_read_hook;
+#endif /* STAGE1_5 */
+      
+    rslt = devread(sector,offset,len, buf);
+      
+#ifndef STAGE1_5
+      disk_read_func = NULL;
+#endif /* STAGE1_5 */
+
+    if(rslt <1)
+       return 0;
+
+    //    memcpy(buf,FSYS_BUF,len);
+    filepos += len;
+    return len;
+}
+
+
+int
+cbd_mount (void)
+{
+    unsigned long start_sector;
+    unsigned int section=0, part_size;
+    cbd_part_hdr_t hdr;
+    part_t *ppart;
+    
+    start_sector=0;
+    n_parts=0;
+    part_size = part_length>>7;
+    content = NULL;
+
+    if(part_size > 1024)
+       return 0;
+
+    for(section=1;section < part_size;section++) {
+       section_map[section] = 0;
+    }
+
+    for(section=1;(!start_sector) && (section < part_size); section++) {
+       if(section_map[section])
+           continue;           /* used already */
+       devread(section<<7,0,0x20,(char*)&hdr);
+       if(hdr.magic != CBD_MAGIC)
+           continue;
+       /* found something */
+       if(hdr.drvver > -1)
+           continue;           /* first check */
+       
+       ppart = &part_map[n_parts];
+       section_map[section] =  n_parts++;
+
+       ppart->start = section;
+       ppart->n_sections = hdr.n_sections;
+       ppart->version = version = hdr.version;
+       ppart->hdr_len = hdr.hdr_len;
+       ppart->update_count = update_count = hdr.update_count;
+
+       if(hdr.cbd_minor != 1)
+           continue;
+       start_sector = section<<7;
+    }
+    if(!start_sector)
+       return 0;
+    return 1;
+}
+
+int
+cbd_read (char *buf, int len)
+{
+
+    if((content == NULL) || (filemax == 0)) 
+       return 0;
+    if(len==0)
+       return 0;
+    
+    return data_read(content, filepos, buf, len);
+}
+
+
+int
+cbd_dir (char *dirname)
+{
+    int i;
+    part_t *ppart = &part_map[0];
+    cbd_part_hdr_t *hdr = (cbd_part_hdr_t*)FSYS_BUF;
+    unsigned short *section_tbl;
+
+    filemax = 0;
+    devread(ppart->start<<7,0,ppart->hdr_len,(char*)FSYS_BUF);
+    for(i=0 ; i< hdr->hdr_len ; i++) {
+       if((*(int*)hdr->content_table[i].name) == *(int*)&dirname[1] ) {
+           content = &hdr->content_table[i];
+           filepos = 0;
+           filemax = content->length;
+           section_tbl = (unsigned short*) ((char*)hdr + 
hdr->offset_section_table);
+           for( i=0 ; i < hdr->n_sections ; i++) {
+               section_map[i] = section_tbl[i];
+           }
+           return 1;
+       }
+    }
+    return 0;
+}
+
+void
+cbd_close(void)
+{
+}
+
+
+int
+cbd_embed (int *start_sector, int needed_sectors)
+{
+    unsigned int section=0;
+    cbd_part_hdr_t hdr;
+    part_t *ppart;
+    
+    start_sector=0;
+    n_parts=0;
+
+    for(section=1;;section++) {
+       section_map[section] = 0;
+    }
+
+    for(section=1;!start_sector; section++) {
+       if(section_map)
+           continue;           /* used already */
+       devread(section<<7,0,0x20,(char*)&hdr);
+       if(hdr.magic != CBD_MAGIC)
+           continue;
+       /* found something */
+       if(hdr.drvver > -1)
+           continue;           /* first check */
+       
+       ppart = &part_map[n_parts];
+       section_map[section] =  n_parts++;
+
+       ppart->start = section;
+       ppart->n_sections = hdr.n_sections;
+       ppart->version = version = hdr.version;
+       ppart->update_count = update_count = hdr.update_count;
+
+       if(hdr.cbd_minor != 1)
+           continue;
+       *start_sector = section<<7;
+    }
+    return 1;
+}
+
+#endif /* FSYS_CBD */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]