Main Page | Directories | File List | Globals

build.c File Reference

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h>
#include <fcntl.h>
#include <asm/boot.h>

Include dependency graph for build.c:

Go to the source code of this file.

Defines

#define DEFAULT_MAJOR_ROOT   0
#define DEFAULT_MINOR_ROOT   0
#define SETUP_SECTS   4

Typedefs

typedef unsigned char byte
typedef unsigned short word
typedef unsigned long u32

Functions

void die (const char *str,...)
void file_open (const char *name)
void usage (void)
int main (int argc, char **argv)

Variables

byte buf [1024]
int fd
int is_big_kernel


Define Documentation

#define DEFAULT_MAJOR_ROOT   0
 

Definition at line 42 of file build.c.

Referenced by main().

#define DEFAULT_MINOR_ROOT   0
 

Definition at line 43 of file build.c.

Referenced by main().

#define SETUP_SECTS   4
 

Definition at line 46 of file build.c.

Referenced by main().


Typedef Documentation

typedef unsigned char byte
 

Definition at line 38 of file build.c.

typedef unsigned long u32
 

Definition at line 40 of file build.c.

typedef unsigned short word
 

Definition at line 39 of file build.c.


Function Documentation

void die const char *  str,
  ...
 

Definition at line 52 of file build.c.

Referenced by file_open(), main(), and usage().

00053 {
00054         va_list args;
00055         va_start(args, str);
00056         vfprintf(stderr, str, args);
00057         fputc('\n', stderr);
00058         exit(1);
00059 }

void file_open const char *  name  ) 
 

Definition at line 61 of file build.c.

References die(), and fd.

Referenced by main().

00062 {
00063         if ((fd = open(name, O_RDONLY, 0)) < 0)
00064                 die("Unable to open `%s': %m", name);
00065 }

Here is the call graph for this function:

int main int  argc,
char **  argv
 

Definition at line 72 of file build.c.

References buf, DEFAULT_MAJOR_ROOT, DEFAULT_MINOR_ROOT, die(), fd, file_open(), is_big_kernel, memset(), SETUP_SECTS, strcmp(), and usage().

00073 {
00074         unsigned int i, c, sz, setup_sectors;
00075         u32 sys_size;
00076         byte major_root, minor_root;
00077         struct stat sb;
00078 
00079         if (argc > 2 && !strcmp(argv[1], "-b"))
00080           {
00081             is_big_kernel = 1;
00082             argc--, argv++;
00083           }
00084         if ((argc < 4) || (argc > 5))
00085                 usage();
00086         if (argc > 4) {
00087                 if (!strcmp(argv[4], "CURRENT")) {
00088                         if (stat("/", &sb)) {
00089                                 perror("/");
00090                                 die("Couldn't stat /");
00091                         }
00092                         major_root = major(sb.st_dev);
00093                         minor_root = minor(sb.st_dev);
00094                 } else if (strcmp(argv[4], "FLOPPY")) {
00095                         if (stat(argv[4], &sb)) {
00096                                 perror(argv[4]);
00097                                 die("Couldn't stat root device.");
00098                         }
00099                         major_root = major(sb.st_rdev);
00100                         minor_root = minor(sb.st_rdev);
00101                 } else {
00102                         major_root = 0;
00103                         minor_root = 0;
00104                 }
00105         } else {
00106                 major_root = DEFAULT_MAJOR_ROOT;
00107                 minor_root = DEFAULT_MINOR_ROOT;
00108         }
00109         fprintf(stderr, "Root device is (%d, %d)\n", major_root, minor_root);
00110 
00111         file_open(argv[1]);
00112         i = read(fd, buf, sizeof(buf));
00113         fprintf(stderr,"Boot sector %d bytes.\n",i);
00114         if (i != 512)
00115                 die("Boot block must be exactly 512 bytes");
00116         if (buf[510] != 0x55 || buf[511] != 0xaa)
00117                 die("Boot block hasn't got boot flag (0xAA55)");
00118         buf[508] = minor_root;
00119         buf[509] = major_root;
00120         if (write(1, buf, 512) != 512)
00121                 die("Write call failed");
00122         close (fd);
00123 
00124         file_open(argv[2]);                                 /* Copy the setup code */
00125         for (i=0 ; (c=read(fd, buf, sizeof(buf)))>0 ; i+=c )
00126                 if (write(1, buf, c) != c)
00127                         die("Write call failed");
00128         if (c != 0)
00129                 die("read-error on `setup'");
00130         close (fd);
00131 
00132         setup_sectors = (i + 511) / 512;        /* Pad unused space with zeros */
00133         /* for compatibility with ancient versions of LILO. */
00134         if (setup_sectors < SETUP_SECTS)
00135                 setup_sectors = SETUP_SECTS;
00136         fprintf(stderr, "Setup is %d bytes.\n", i);
00137         memset(buf, 0, sizeof(buf));
00138         while (i < setup_sectors * 512) {
00139                 c = setup_sectors * 512 - i;
00140                 if (c > sizeof(buf))
00141                         c = sizeof(buf);
00142                 if (write(1, buf, c) != c)
00143                         die("Write call failed");
00144                 i += c;
00145         }
00146 
00147         file_open(argv[3]);
00148         if (fstat (fd, &sb))
00149                 die("Unable to stat `%s': %m", argv[3]);
00150         sz = sb.st_size;
00151         fprintf (stderr, "System is %d kB\n", sz/1024);
00152         sys_size = (sz + 15) / 16;
00153         /* 0x28000*16 = 2.5 MB, conservative estimate for the current maximum */
00154         if (sys_size > (is_big_kernel ? 0x28000 : DEF_SYSSIZE))
00155                 die("System is too big. Try using %smodules.",
00156                         is_big_kernel ? "" : "bzImage or ");
00157         if (sys_size > 0xefff)
00158                 fprintf(stderr,"warning: kernel is too big for standalone boot "
00159                     "from floppy\n");
00160         while (sz > 0) {
00161                 int l, n;
00162 
00163                 l = (sz > sizeof(buf)) ? sizeof(buf) : sz;
00164                 if ((n=read(fd, buf, l)) != l) {
00165                         if (n < 0)
00166                                 die("Error reading %s: %m", argv[3]);
00167                         else
00168                                 die("%s: Unexpected EOF", argv[3]);
00169                 }
00170                 if (write(1, buf, l) != l)
00171                         die("Write failed");
00172                 sz -= l;
00173         }
00174         close(fd);
00175 
00176         if (lseek(1, 497, SEEK_SET) != 497)                 /* Write sizes to the bootsector */
00177                 die("Output: seek failed");
00178         buf[0] = setup_sectors;
00179         if (write(1, buf, 1) != 1)
00180                 die("Write of setup sector count failed");
00181         if (lseek(1, 500, SEEK_SET) != 500)
00182                 die("Output: seek failed");
00183         buf[0] = (sys_size & 0xff);
00184         buf[1] = ((sys_size >> 8) & 0xff);
00185         if (write(1, buf, 2) != 2)
00186                 die("Write of image length failed");
00187 
00188         return 0;                                           /* Everything is OK */
00189 }

Here is the call graph for this function:

void usage void   ) 
 

Definition at line 67 of file build.c.

References die().

Referenced by main().

00068 {
00069         die("Usage: build [-b] bootsect setup system [rootdev] [> image]");
00070 }

Here is the call graph for this function:


Variable Documentation

byte buf[1024]
 

Definition at line 48 of file build.c.

Referenced by agnix_console_main(), cpu_get_cache_latency(), main(), and net_addr().

int fd
 

Definition at line 49 of file build.c.

Referenced by do_sys_open(), file_install_fd(), file_open(), and main().

int is_big_kernel
 

Definition at line 50 of file build.c.

Referenced by main().

Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix