diff options
-rw-r--r-- | Makefile | 72 | ||||
-rw-r--r-- | dos/Makefile | 31 | ||||
-rw-r--r-- | dos/syslinux.asm | 2 | ||||
-rw-r--r-- | mtools/Makefile | 5 | ||||
-rw-r--r-- | syslinux-nomtools.c | 440 | ||||
-rw-r--r-- | syslinux.h | 1 | ||||
-rw-r--r-- | unix/Makefile | 10 | ||||
-rw-r--r-- | win32/Makefile | 11 |
8 files changed, 81 insertions, 491 deletions
@@ -46,29 +46,38 @@ LIB_SO = libsyslinux.so.$(VERSION) # The BTARGET refers to objects that are derived from ldlinux.asm; we # like to keep those uniform for debugging reasons; however, distributors # want to recompile the installers (ITARGET). +# +# BOBJECTS and IOBJECTS are the same thing, except used for +# installation, so they include objects that may be in subdirectories +# with their own Makefiles. Finally, there is a list of those +# directories. # CSRC = syslxmod.c gethostip.c -NASMSRC = ldlinux.asm syslinux.asm copybs.asm \ - pxelinux.asm mbr.asm isolinux.asm +NASMSRC = ldlinux.asm copybs.asm pxelinux.asm mbr.asm isolinux.asm SOURCES = $(CSRC) *.h $(NASMSRC) *.inc # syslinux.exe is BTARGET so as to not require everyone to have the # mingw suite installed -BTARGET = kwdhash.gen version.gen ldlinux.bss ldlinux.sys ldlinux.bin \ - pxelinux.0 mbr.bin isolinux.bin isolinux-debug.bin \ - libsyslinux.a syslinux.exe $(LIB_SO) -ITARGET = syslinux.com syslinux syslinux-nomtools copybs.com gethostip \ - mkdiskimage -DOCS = COPYING NEWS README TODO BUGS *.doc sample menu com32 -OTHER = Makefile bin2c.pl now.pl genhash.pl keywords findpatch.pl \ - keytab-lilo.pl version version.pl sys2ansi.pl \ - ppmtolss16 lss16toppm memdisk bin2hex.pl mkdiskimage.in +BTARGET = kwdhash.gen version.gen ldlinux.bss ldlinux.sys ldlinux.bin \ + pxelinux.0 mbr.bin isolinux.bin isolinux-debug.bin \ + bootsect_bin.c ldlinux_bin.c + # libsyslinux.a $(LIB_SO) +BOBJECTS = $(BTARGET) dos/syslinux.com win32/syslinux.exe memdisk/memdisk +BSUBDIRS = memdisk dos win32 +ITARGET = copybs.com gethostip mkdiskimage +IOBJECTS = $(ITARGET) mtools/syslinux unix/syslinux +ISUBDIRS = mtools unix sample com32 +DOCS = COPYING NEWS README TODO BUGS *.doc sample menu com32 +OTHER = Makefile bin2c.pl now.pl genhash.pl keywords findpatch.pl \ + keytab-lilo.pl version version.pl sys2ansi.pl \ + ppmtolss16 lss16toppm memdisk bin2hex.pl mkdiskimage.in OBSOLETE = pxelinux.bin # Things to install in /usr/bin -INSTALL_BIN = syslinux gethostip ppmtolss16 lss16toppm +INSTALL_BIN = mtools/syslinux gethostip ppmtolss16 lss16toppm # Things to install in /usr/lib/syslinux INSTALL_AUX = pxelinux.0 isolinux.bin isolinux-debug.bin \ - syslinux.com syslinux.exe copybs.com memdisk/memdisk + dos/syslinux.com win32/syslinux.exe \ + copybs.com memdisk/memdisk # Things to install in /usr/lib INSTALL_LIB = $(LIB_SO) libsyslinux.a # Things to install in /usr/include @@ -90,16 +99,19 @@ MAKE += DATE=$(DATE) HEXDATE=$(HEXDATE) # want to remove win32 from this list; otherwise you're going to get an # error every time you try to build. # -BSUBDIRS = memdisk -ISUBDIRS = mtools unix win32 sample com32 all: $(BTARGET) $(ITARGET) - for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done - -ls -l $(BTARGET) $(ITARGET) memdisk/memdisk + set -e ; for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done + $(MAKE) all-local + -ls -l $(BOBJECTS) $(IOBJECTS) + +all-local: $(BTARGET) $(ITARGET) + +installer: installer-local installer: $(ITARGET) - for i in $(ISUBDIRS); do $(MAKE) -C $$i all ; done - -ls -l $(BTARGET) $(ITARGET) + set -e ; for i in $(ISUBDIRS); do $(MAKE) -C $$i all ; done + -ls -l $(BOBJECTS) $(IOBJECTS) version.gen: version version.pl $(PERL) version.pl version @@ -139,9 +151,6 @@ ldlinux.sys: ldlinux.bin mbr.bin: mbr.asm $(NASM) -f bin -l mbr.lst -o mbr.bin mbr.asm -syslinux.com: syslinux.asm ldlinux.bss ldlinux.sys - $(NASM) -f bin -l syslinux.lst -o syslinux.com syslinux.asm - copybs.com: copybs.asm $(NASM) -f bin -l copybs.lst -o copybs.com copybs.asm @@ -159,19 +168,6 @@ libsyslinux.a: bootsect_bin.o ldlinux_bin.o syslxmod.o $(LIB_SO): bootsect_bin.o ldlinux_bin.o syslxmod.o $(CC) $(LDFLAGS) -shared -Wl,-soname,$(LIB_SONAME) -o $@ $^ -syslinux: syslinux.o libsyslinux.a - $(CC) $(LDFLAGS) -o $@ $^ - -syslinux-nomtools: syslinux-nomtools.o libsyslinux.a - $(CC) $(LDFLAGS) -o $@ $^ - -syslxmod.o: syslxmod.c patch.offset - $(CC) $(INCLUDE) $(CFLAGS) $(PIC) -DPATCH_OFFSET=`cat patch.offset` \ - -c -o $@ $< - -syslinux.exe: win32/syslinux-mingw.c libsyslinux.a - $(MAKE) -C win32 all - gethostip.o: gethostip.c gethostip: gethostip.o @@ -201,13 +197,13 @@ local-tidy: rm -f $(OBSOLETE) tidy: local-tidy - for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done + set -e ; for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done local-clean: rm -f $(ITARGET) clean: local-tidy local-clean - for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done + set -e ; for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done dist: tidy for dir in . sample memdisk ; do \ @@ -218,7 +214,7 @@ local-spotless: rm -f $(BTARGET) .depend *.so.* spotless: local-clean dist local-spotless - for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done + set -e ; for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done .depend: rm -f .depend diff --git a/dos/Makefile b/dos/Makefile new file mode 100644 index 00000000..5319daf2 --- /dev/null +++ b/dos/Makefile @@ -0,0 +1,31 @@ +CC = gcc +OPTFLAGS = -g -Os +INCLUDES = -I./ -I../ -I../libfat/ +CFLAGS = -W -Wall $(OPTFLAGS) $(INCLUDES) +LDFLAGS = -s +NASM = nasm + +SRCS = +OBJS = + +.SUFFIXES: .c .o .i .s .S .asm .bin .lst .com + +VPATH = .:..:../libfat + +all: syslinux.com + +tidy: + -rm -f *.o *.i *.s *.a .*.d *.lst + +clean: tidy + -rm -f syslinux.com + +spotless: clean + -rm -f *~ + +installer: + +syslinux.com: syslinux.asm ../ldlinux.bss ../ldlinux.sys + +.asm.com: + $(NASM) $(INCLUDES) -f bin -o $@ -l $*.lst $< diff --git a/dos/syslinux.asm b/dos/syslinux.asm index 9b61f242..bb2df313 100644 --- a/dos/syslinux.asm +++ b/dos/syslinux.asm @@ -444,7 +444,7 @@ die_common: ; make_stupid: ; Only access one sector at a time - mov word [LDLinuxSYS+PATCH_OFFSET],1 + mov word [BootSector+0x1FC],1 ret section .data diff --git a/mtools/Makefile b/mtools/Makefile index a13642cc..920c85af 100644 --- a/mtools/Makefile +++ b/mtools/Makefile @@ -1,8 +1,8 @@ CC = gcc -OPTFLAGS = -g -O -Dinline= +OPTFLAGS = -g -Os INCLUDES = -I. -I.. -I../libfat CFLAGS = -W -Wall -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) $(INCLUDES) -LDFLAGS = +LDFLAGS = -s SRCS = syslinux.c ../syslxmod.c ../bootsect_bin.c ../ldlinux_bin.c $(wildcard ../libfat/*.c) OBJS = $(patsubst %.c,%.o,$(notdir $(SRCS))) @@ -20,6 +20,7 @@ clean: tidy -rm -f syslinux spotless: clean + -rm -f *~ installer: syslinux diff --git a/syslinux-nomtools.c b/syslinux-nomtools.c deleted file mode 100644 index 98795c83..00000000 --- a/syslinux-nomtools.c +++ /dev/null @@ -1,440 +0,0 @@ -#ident "$Id$" -/* ----------------------------------------------------------------------- * - * - * Copyright 1998-2004 H. Peter Anvin - All Rights Reserved - * - * 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, Inc., 53 Temple Place Ste 330, - * Boston MA 02111-1307, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * syslinux.c - Linux installer program for SYSLINUX - * - * This program ought to be portable. I hope so, at least. - * - * This is an alternate version of the installer which doesn't require - * mtools, but requires root privilege. - */ - -#ifdef __KLIBC__ -# define DO_DIRECT_MOUNT 1 /* Call mount(2) directly */ -#else -# define DO_DIRECT_MOUNT 0 /* Call /bin/mount instead */ -#endif - -#define _XOPEN_SOURCE 500 /* For pread() pwrite() */ -#define _LARGEFILE64_SOURCE /* For O_LARGEFILE */ -#include <alloca.h> -#include <errno.h> -#include <fcntl.h> -#include <paths.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/mount.h> - -#include "syslinux.h" - -#if DO_DIRECT_MOUNT - -# include <linux/loop.h> - -#else - -# include <paths.h> -# ifndef _PATH_MOUNT -# define _PATH_MOUNT "/bin/mount" -# endif -# ifndef _PATH_UMOUNT -# define _PATH_UMOUNT "/bin/umount" -# endif - -#endif - -const char *program; /* Name of program */ -const char *device; /* Device to install to */ -pid_t mypid; -char *mntpath = NULL; /* Path on which to mount */ -#if DO_DIRECT_MOUNT -int loop_fd = -1; /* Loop device */ -#endif - -void __attribute__((noreturn)) usage(void) -{ - fprintf(stderr, "Usage: %s [-sf] [-o offset] device\n", program); - exit(1); -} - -void __attribute__((noreturn)) die(const char *msg) -{ - fprintf(stderr, "%s: %s\n", program, msg); - -#if DO_DIRECT_MOUNT - if ( loop_fd != -1 ) { - ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */ - close(loop_fd); - loop_fd = -1; - } -#endif - - if ( mntpath ) - unlink(mntpath); - - exit(1); -} - -/* - * read/write wrapper functions - */ -ssize_t xpread(int fd, void *buf, size_t count, off_t offset) -{ - ssize_t rv; - ssize_t done = 0; - - while ( count ) { - rv = pread(fd, buf, count, offset); - if ( rv == 0 ) { - die("short read"); - } else if ( rv == -1 ) { - if ( errno == EINTR ) { - continue; - } else { - perror(program); - exit(1); - } - } else { - offset += rv; - done += rv; - count -= rv; - } - } - - return done; -} - -ssize_t xpwrite(int fd, void *buf, size_t count, off_t offset) -{ - ssize_t rv; - ssize_t done = 0; - - while ( count ) { - rv = pwrite(fd, buf, count, offset); - if ( rv == 0 ) { - die("short write"); - } else if ( rv == -1 ) { - if ( errno == EINTR ) { - continue; - } else { - perror(program); - exit(1); - } - } else { - offset += rv; - done += rv; - count -= rv; - } - } - - return done; -} - -int main(int argc, char *argv[]) -{ - static unsigned char sectbuf[512]; - unsigned char *dp; - const unsigned char *cdp; - int dev_fd, fd; - struct stat st; - int nb, left; - int err = 0; - pid_t f, w; - int status; - char mntname[64], devfdname[64]; - char *ldlinux_name, **argp, *opt; - int my_umask; - int force = 0; /* -f (force) option */ - int offset = 0; /* -o (offset) option */ - - program = argv[0]; - mypid = getpid(); - - device = NULL; - - umask(077); - - for ( argp = argv+1 ; *argp ; argp++ ) { - if ( **argp == '-' ) { - opt = *argp + 1; - if ( !*opt ) - usage(); - - while ( *opt ) { - if ( *opt == 's' ) { - syslinux_make_stupid(); /* Use "safe, slow and stupid" code */ - } else if ( *opt == 'f' ) { - force = 1; /* Force install */ - } else if ( *opt == 'o' && argp[1] ) { - offset = strtoul(*++argp, NULL, 0); /* Byte offset */ - } else { - usage(); - } - opt++; - } - } else { - if ( device ) - usage(); - device = *argp; - } - } - - if ( !device ) - usage(); - - /* - * First make sure we can open the device at all, and that we have - * read/write permission. - */ - dev_fd = open(device, O_RDWR|O_LARGEFILE); - if ( dev_fd < 0 || fstat(dev_fd, &st) < 0 ) { - perror(device); - exit(1); - } - - if ( !force && !S_ISBLK(st.st_mode) && !S_ISREG(st.st_mode) ) { - die("not a block device or regular file (use -f to override)"); - } - - if ( !force && offset != 0 && !S_ISREG(st.st_mode) ) { - die("not a regular file and an offset specified (use -f to override)"); - } - - xpread(dev_fd, sectbuf, 512, offset); - fsync(dev_fd); - - /* - * Check to see that what we got was indeed an MS-DOS boot sector/superblock - */ - if(!syslinux_check_bootsect(sectbuf,device)) { - exit(1); - } - - /* - * Now mount the device. - */ - if ( geteuid() ) { - die("This program needs root privilege"); - } else { - int i = 0; - struct stat dst; - int rv; - - /* We're root or at least setuid. - Make a temp dir and pass all the gunky options to mount. */ - - if ( chdir("/tmp") ) { - perror(program); - exit(1); - } - -#define TMP_MODE (S_IXUSR|S_IWUSR|S_IXGRP|S_IWGRP|S_IWOTH|S_IXOTH|S_ISVTX) - - if ( stat(".", &dst) || !S_ISDIR(dst.st_mode) || - (dst.st_mode & TMP_MODE) != TMP_MODE ) { - die("possibly unsafe /tmp permissions"); - } - - for ( i = 0 ; ; i++ ) { - snprintf(mntname, sizeof mntname, "syslinux.mnt.%lu.%d", - (unsigned long)mypid, i); - - if ( lstat(mntname, &dst) != -1 || errno != ENOENT ) - continue; - - rv = mkdir(mntname, 0000); - - if ( rv == -1 ) { - if ( errno == EEXIST || errno == EINTR ) - continue; - perror(program); - exit(1); - } - - if ( lstat(mntname, &dst) || dst.st_mode != (S_IFDIR|0000) || - dst.st_uid != 0 ) { - die("someone is trying to symlink race us!"); - } - break; /* OK, got something... */ - } - - mntpath = mntname; - -#if DO_DIRECT_MOUNT - if ( S_ISREG(st.st_mode) ) { - /* It's file, need to mount it loopback */ - unsigned int n = 0; - struct loop_info64 loopinfo; - - for ( n = 0 ; loop_fd < 0 ; n++ ) { - snprintf(devfdname, sizeof devfdname, "/dev/loop%u", n); - loop_fd = open(devfdname, O_RDWR); - if ( loop_fd < 0 && errno == ENOENT ) { - die("no available loopback device!"); - } - if ( ioctl(loop_fd, LOOP_SET_FD, (void *)dev_fd) ) { - close(loop_fd); loop_fd = -1; - if ( errno != EBUSY ) - die("cannot set up loopback device"); - else - continue; - } - - if ( ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo) || - (loopinfo.lo_offset = offset, - ioctl(loop_fd, LOOP_SET_STATUS64, &loopinfo)) ) - die("cannot set up loopback device"); - } - } else { - snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d", - (unsigned long)mypid, dev_fd); - } - - if ( mount(devfdname, mntpath, "msdos", - MS_NOEXEC|MS_NOSUID, "umask=077,quiet") ) - die("could not mount filesystem"); - -#else - - snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d", - (unsigned long)mypid, dev_fd); - - f = fork(); - if ( f < 0 ) { - perror(program); - rmdir(mntpath); - exit(1); - } else if ( f == 0 ) { - char mnt_opts[128]; - if ( S_ISREG(st.st_mode) ) { - snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,loop,offset=%llu,umask=077,quiet", - (unsigned long long)offset); - } else { - snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,umask=077,quiet"); - } - execl(_PATH_MOUNT, _PATH_MOUNT, "-t", "msdos", "-o", mnt_opts,\ - devfdname, mntpath, NULL); - _exit(255); /* execl failed */ - } - - w = waitpid(f, &status, 0); - if ( w != f || status ) { - rmdir(mntpath); - exit(1); /* Mount failed */ - } - -#endif - } - - ldlinux_name = alloca(strlen(mntpath)+13); - if ( !ldlinux_name ) { - perror(program); - err = 1; - goto umount; - } - sprintf(ldlinux_name, "%s/ldlinux.sys", mntpath); - - unlink(ldlinux_name); - fd = open(ldlinux_name, O_WRONLY|O_CREAT|O_TRUNC, 0444); - if ( fd < 0 ) { - perror(device); - err = 1; - goto umount; - } - - cdp = syslinux_ldlinux; - left = syslinux_ldlinux_len; - while ( left ) { - nb = write(fd, cdp, left); - if ( nb == -1 && errno == EINTR ) - continue; - else if ( nb <= 0 ) { - perror(device); - err = 1; - goto umount; - } - - dp += nb; - left -= nb; - } - - /* - * I don't understand why I need this. Does the DOS filesystems - * not honour the mode passed to open()? - */ - fchmod(fd, 0400); - - close(fd); - -umount: -#if DO_DIRECT_MOUNT - - if ( umount2(mntpath, 0) ) - die("could not umount path"); - - if ( loop_fd != -1 ) { - ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */ - close(loop_fd); - loop_fd = -1; - } - -#else - - f = fork(); - if ( f < 0 ) { - perror("fork"); - exit(1); - } else if ( f == 0 ) { - execl(_PATH_UMOUNT, _PATH_UMOUNT, mntpath, NULL); - } - - w = waitpid(f, &status, 0); - if ( w != f || status ) { - exit(1); - } - -#endif - - sync(); - rmdir(mntpath); - - if ( err ) - exit(err); - - /* - * To finish up, write the boot sector - */ - - /* Read the superblock again since it might have changed while mounted */ - xpread(dev_fd, sectbuf, 512, offset); - - /* Copy the syslinux code into the boot sector */ - syslinux_make_bootsect(sectbuf); - - /* Write new boot sector */ - xpwrite(dev_fd, sectbuf, 512, offset); - - close(dev_fd); - sync(); - - /* Done! */ - - return 0; -} - @@ -14,6 +14,7 @@ #ifndef SYSLINUX_H #define SYSLINUX_H +#include <inttypes.h> /* The standard boot sector and ldlinux image */ extern unsigned char syslinux_bootsect[]; diff --git a/unix/Makefile b/unix/Makefile index 9ba5e554..12c5cf9d 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -1,8 +1,8 @@ CC = gcc -OPTFLAGS = -g -O +OPTFLAGS = -g -Os INCLUDES = -I. -I.. -I../libfat CFLAGS = -W -Wall -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) $(INCLUDES) -LDFLAGS = +LDFLAGS = -s SRCS = syslinux.c ../syslxmod.c ../bootsect_bin.c ../ldlinux_bin.c $(wildcard ../libfat/*.c) OBJS = $(patsubst %.c,%.o,$(notdir $(SRCS))) @@ -20,12 +20,16 @@ clean: tidy -rm -f syslinux spotless: clean + -rm -f *~ -installer: syslinux +installer: syslinux syslinux-nomtools syslinux: $(OBJS) $(CC) $(LDFLAGS) -o $@ $^ +syslinux-nomtools: syslinux + cp -f $< $@ + %.o: %.c $(CC) -Wp,-MT,$@,-MMD,.$@.d $(CFLAGS) -c -o $@ $< %.i: %.c diff --git a/win32/Makefile b/win32/Makefile index f01369ab..c0894261 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -23,9 +23,9 @@ ifeq ($(findstring CYGWIN,$(OSTYPE)),CYGWIN) CC = gcc AR = ar RANLIB = ranlib -CFLAGS = -mno-cygwin -W -Wall -O2 -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 +CFLAGS = -mno-cygwin -W -Wall -Os -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 PIC = -LDFLAGS = -mno-cygwin -O2 -s +LDFLAGS = -mno-cygwin -Os -s else ifeq ($(findstring MINGW32,$(OSTYPE)),MINGW32) CC = gcc @@ -37,9 +37,9 @@ AR = mingw-ar RANLIB = mingw-ranlib endif -CFLAGS = -W -Wall -O2 -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 +CFLAGS = -W -Wall -Os -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 PIC = -LDFLAGS = -O2 -s +LDFLAGS = -Os -s endif CFLAGS += -I. -I.. -I../libfat @@ -76,6 +76,3 @@ syslinux.exe: $(OBJS) $(CC) $(CFLAGS) -S -o $@ $< -include .*.d - - - |