Index: stand/efi/boot1/Makefile =================================================================== --- stand/efi/boot1/Makefile +++ stand/efi/boot1/Makefile @@ -23,7 +23,8 @@ CWARNFLAGS.zfs_module.c += -Wno-unused-function # architecture-specific loader code -SRCS= boot1.c self_reloc.c start.S ufs_module.c +SRCS= boot1.c self_reloc.c start.S ufs_module.c ufsread.c + .if ${MK_ZFS} != "no" SRCS+= zfs_module.c CFLAGS.zfs_module.c+= -I${ZFSSRC} @@ -51,6 +52,9 @@ .PATH: ${LDRSRC} CFLAGS+= -I${LDRSRC} +# Add libsa for ufsread.c +.PATH: ${SASRC} + FILES= boot1.efi boot1.efifat FILESMODE_boot1.efi= ${BINMODE} Index: stand/efi/boot1/ufs_module.c =================================================================== --- stand/efi/boot1/ufs_module.c +++ stand/efi/boot1/ufs_module.c @@ -38,12 +38,15 @@ #include #include +#include + #include "boot_module.h" +#include "ufsread.h" static dev_info_t *devinfo; static dev_info_t *devices; -static int +int dskread(void *buf, u_int64_t lba, int nblk) { int size; @@ -66,8 +69,6 @@ return (0); } -#include "ufsread.c" - static struct dmadat __dmadat; static int Index: stand/i386/boot2/Makefile =================================================================== --- stand/i386/boot2/Makefile +++ stand/i386/boot2/Makefile @@ -61,7 +61,7 @@ ${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o CLEANFILES+= boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \ - boot2.h sio.o + boot2.h sio.o ufsread.o BOOT2SIZE= 7680 @@ -80,10 +80,13 @@ boot2.bin: boot2.out ${OBJCOPY} -S -O binary boot2.out ${.TARGET} -boot2.out: ${BTXCRT} boot2.o sio.o +boot2.out: ${BTXCRT} boot2.o sio.o ufsread.o ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} -SRCS= boot2.c boot2.h +SRCS= boot2.c boot2.h ufsread.c +CFLAGS.ufsread.c= -DUFS_SMALL_CGBASE + +.PATH: ${SASRC} boot2.h: boot1.out ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \ Index: stand/i386/boot2/boot2.c =================================================================== --- stand/i386/boot2/boot2.c +++ stand/i386/boot2/boot2.c @@ -25,6 +25,8 @@ #include #include +#include + #include #include @@ -35,6 +37,7 @@ #include "lib.h" #include "paths.h" #include "rbx.h" +#include "ufsread.h" /* Define to 0 to omit serial support */ #ifndef SERIAL @@ -109,21 +112,23 @@ static uint8_t ioctrl = IO_KEYBOARD; #endif -int main(void); -void exit(int); -static void load(void); -static int parse(void); -static int dskread(void *, unsigned, unsigned); -static void printf(const char *,...); -static void putchar(int); -static int drvread(void *, unsigned, unsigned); -static int keyhit(unsigned); -static int xputc(int); -static int xgetc(int); -static inline int getc(int); - -static void memcpy(void *, const void *, int); -static void +int main(void); +void exit(int); +void memcpy(void *, const void *, int); +void printf(const char *, ...); +int strcmp(const char *, const char *); +int dskread(void *, unsigned, unsigned); + +static void load(void); +static int parse(void); +static void putchar(int); +static int drvread(void *, unsigned, unsigned); +static int keyhit(unsigned); +static int xputc(int); +static int xgetc(int); +static inline int getc(int); + +void memcpy(void *dst, const void *src, int len) { const char *s; @@ -135,7 +140,7 @@ *d++ = *s++; } -static inline int +int strcmp(const char *s1, const char *s2) { @@ -143,9 +148,6 @@ return ((unsigned char)*s1 - (unsigned char)*s2); } -#define UFS_SMALL_CGBASE -#include "ufsread.c" - static int xfsread(ufs_ino_t inode, void *buf, size_t nbyte) { @@ -470,7 +472,7 @@ return (0); } -static int +int dskread(void *buf, unsigned lba, unsigned nblk) { struct dos_partition *dp; @@ -537,8 +539,8 @@ return (-1); } -static void -printf(const char *fmt,...) +void +printf(const char *fmt, ...) { va_list ap; static char buf[10]; Index: stand/i386/gptboot/Makefile =================================================================== --- stand/i386/gptboot/Makefile +++ stand/i386/gptboot/Makefile @@ -63,9 +63,12 @@ gptboot.bin: gptboot.out ${OBJCOPY} -S -O binary gptboot.out ${.TARGET} -gptboot.out: ${BTXCRT} gptboot.o sio.o crc32.o drv.o cons.o ${OPENCRYPTO_XTS} +gptboot.out: ${BTXCRT} gptboot.o sio.o crc32.o drv.o cons.o ufsread.o ${OPENCRYPTO_XTS} ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBGELIBOOT} ${LIBSA32} +SRCS+= ufsread.c +CLEANFILES+= ufsread.o + .include # XXX: clang integrated-as doesn't grok .codeNN directives yet Index: stand/i386/gptboot/gptboot.c =================================================================== --- stand/i386/gptboot/gptboot.c +++ stand/i386/gptboot/gptboot.c @@ -26,6 +26,8 @@ #include #include +#include + #include #include @@ -41,6 +43,7 @@ #include "cons.h" #include "gpt.h" #include "paths.h" +#include "ufsread.h" #define ARGS 0x900 #define NOPT 14 @@ -102,15 +105,15 @@ static char *heap_next; static char *heap_end; +int dskread(void *, daddr_t, unsigned); + static void load(void); static int parse_cmds(char *, int *); -static int dskread(void *, daddr_t, unsigned); #ifdef LOADER_GELI_SUPPORT static int vdev_read(void *vdev __unused, void *priv, off_t off, void *buf, size_t bytes); #endif -#include "ufsread.c" #include "gpt.c" #ifdef LOADER_GELI_SUPPORT #include "geliboot.c" @@ -574,7 +577,7 @@ return 0; } -static int +int dskread(void *buf, daddr_t lba, unsigned nblk) { int err; Index: stand/libsa/ufsread.h =================================================================== --- /dev/null +++ stand/libsa/ufsread.h @@ -0,0 +1,40 @@ +#ifndef UFSREAD_H +#define UFSREAD_H + +typedef uint32_t ufs_ino_t; + +/* + * We use 4k `virtual' blocks for filesystem data, whatever the actual + * filesystem block size. FFS blocks are always a multiple of 4k. + */ +#define VBLKSHIFT 12 +#define VBLKSIZE (1 << VBLKSHIFT) +#define VBLKMASK (VBLKSIZE - 1) +#define DBPERVBLK (VBLKSIZE / DEV_BSIZE) +#define INDIRPERVBLK(fs) (NINDIR(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) +#define IPERVBLK(fs) (INOPB(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) +#define INO_TO_VBA(fs, ipervblk, x) \ + (fsbtodb(fs, cgimin(fs, ino_to_cg(fs, x))) + \ + (((x) % (fs)->fs_ipg) / (ipervblk) * DBPERVBLK)) +#define INO_TO_VBO(ipervblk, x) ((x) % ipervblk) +#define FS_TO_VBA(fs, fsb, off) (fsbtodb(fs, fsb) + \ + ((off) / VBLKSIZE) * DBPERVBLK) +#define FS_TO_VBO(fs, fsb, off) ((off) & VBLKMASK) + +/* Buffers that must not span a 64k boundary. */ +struct dmadat { + char blkbuf[VBLKSIZE]; /* filesystem blocks */ + char indbuf[VBLKSIZE]; /* indir blocks */ + char sbbuf[SBLOCKSIZE]; /* superblock */ + char secbuf[DEV_BSIZE]; /* for MBR/disklabel */ +}; +extern struct dmadat *dmadat; + +extern uint8_t ls, dsk_meta; +extern uint32_t fs_off; + +ufs_ino_t lookup(const char *); +ssize_t fsread(ufs_ino_t, void *, size_t); +ssize_t fsread_size(ufs_ino_t, void *, size_t, size_t *); + +#endif /* UFSREAD_H */ Index: stand/libsa/ufsread.c =================================================================== --- stand/libsa/ufsread.c +++ stand/libsa/ufsread.c @@ -46,10 +46,20 @@ #include __FBSDID("$FreeBSD$"); +#include + #include #include #include +#include "ufsread.h" + +/* These routines must be provided by other code. */ +void memcpy(void *, const void *, int); +void printf(const char *, ...); +int strcmp(const char *, const char *); +int dskread(void *, unsigned, unsigned); + #ifdef UFS_SMALL_CGBASE /* XXX: Revert to old (broken for over 1.5Tb filesystems) version of cgbase (see sys/ufs/ffs/fs.h rev 1.39) so that small boot loaders (e.g. boot2) can @@ -58,40 +68,10 @@ #define cgbase(fs, c) ((ufs2_daddr_t)((fs)->fs_fpg * (c))) #endif -typedef uint32_t ufs_ino_t; - -/* - * We use 4k `virtual' blocks for filesystem data, whatever the actual - * filesystem block size. FFS blocks are always a multiple of 4k. - */ -#define VBLKSHIFT 12 -#define VBLKSIZE (1 << VBLKSHIFT) -#define VBLKMASK (VBLKSIZE - 1) -#define DBPERVBLK (VBLKSIZE / DEV_BSIZE) -#define INDIRPERVBLK(fs) (NINDIR(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) -#define IPERVBLK(fs) (INOPB(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) -#define INO_TO_VBA(fs, ipervblk, x) \ - (fsbtodb(fs, cgimin(fs, ino_to_cg(fs, x))) + \ - (((x) % (fs)->fs_ipg) / (ipervblk) * DBPERVBLK)) -#define INO_TO_VBO(ipervblk, x) ((x) % ipervblk) -#define FS_TO_VBA(fs, fsb, off) (fsbtodb(fs, fsb) + \ - ((off) / VBLKSIZE) * DBPERVBLK) -#define FS_TO_VBO(fs, fsb, off) ((off) & VBLKMASK) - -/* Buffers that must not span a 64k boundary. */ -struct dmadat { - char blkbuf[VBLKSIZE]; /* filesystem blocks */ - char indbuf[VBLKSIZE]; /* indir blocks */ - char sbbuf[SBLOCKSIZE]; /* superblock */ - char secbuf[DEV_BSIZE]; /* for MBR/disklabel */ -}; -static struct dmadat *dmadat; - -static ufs_ino_t lookup(const char *); -static ssize_t fsread(ufs_ino_t, void *, size_t); +struct dmadat *dmadat; -static uint8_t ls, dsk_meta; -static uint32_t fs_off; +uint8_t ls, dsk_meta; +uint32_t fs_off; static __inline uint8_t fsfind(const char *name, ufs_ino_t * ino) @@ -118,7 +98,7 @@ return 0; } -static ufs_ino_t +ufs_ino_t lookup(const char *path) { static char name[UFS_MAXNAMLEN + 1]; @@ -164,7 +144,7 @@ #define DIP(field) fs.fs_magic == FS_UFS1_MAGIC ? dp1.field : dp2.field #endif -static ssize_t +ssize_t fsread_size(ufs_ino_t inode, void *buf, size_t nbyte, size_t *fsizep) { #ifndef UFS2_ONLY @@ -317,7 +297,7 @@ return nbyte; } -static ssize_t +ssize_t fsread(ufs_ino_t inode, void *buf, size_t nbyte) { Index: stand/mips/beri/boot2/Makefile =================================================================== --- stand/mips/beri/boot2/Makefile +++ stand/mips/beri/boot2/Makefile @@ -41,7 +41,8 @@ boot2.c \ altera_jtag_uart.c \ cfi.c \ - sdcard.c + sdcard.c \ + ufsread.c AFLAGS= -G0 @@ -56,10 +57,13 @@ -G0 \ -L${.CURDIR} +.PATH: ${SASRC} .PATH: ${BOOTSRC}/mips/beri/common CFLAGS+= -I${BOOTSRC}/mips/beri/common +CFLAGS.ufsread.c= -DUFS_SMALL_CGBASE -flashboot.elf: relocate.o start.o boot2.o altera_jtag_uart.o cfi.o sdcard.o +flashboot.elf: relocate.o start.o boot2.o altera_jtag_uart.o cfi.o sdcard.o \ + ufsread.o ${CC} ${LDFLAGS} -T ${.CURDIR}/flashboot.ldscript -o ${.TARGET} \ ${.ALLSRC} ${LIBSA} flashboot: flashboot.elf @@ -67,7 +71,7 @@ flashboot.md5: flashboot md5 flashboot > flashboot.md5 -jtagboot: start.o boot2.o altera_jtag_uart.o cfi.o sdcard.o +jtagboot: start.o boot2.o altera_jtag_uart.o cfi.o sdcard.o ufsread.o ${CC} ${LDFLAGS} -T ${.CURDIR}/jtagboot.ldscript -o ${.TARGET} \ ${.ALLSRC} ${LIBSA} jtagboot.md5: jtagboot Index: stand/mips/beri/boot2/boot2.c =================================================================== --- stand/mips/beri/boot2/boot2.c +++ stand/mips/beri/boot2/boot2.c @@ -54,6 +54,8 @@ #include #include +#include + #include #include #include @@ -66,6 +68,7 @@ #include "paths.h" #include "rbx.h" +#include "ufsread.h" static int beri_argc; static const char **beri_argv, **beri_envv; @@ -138,17 +141,15 @@ static uint8_t ioctrl = IO_KEYBOARD; void putchar(int); +int dskread(void *, unsigned, unsigned); + static void boot_fromdram(void); static void boot_fromfs(void); static void load(void); static int parse(void); -static int dskread(void *, unsigned, unsigned); static int xputc(int); static int xgetc(int); -#define UFS_SMALL_CGBASE -#include "ufsread.c" - static struct dmadat __dmadat; static inline int @@ -543,7 +544,7 @@ } } -static int +int dskread(void *buf, unsigned lba, unsigned nblk) { #if 0 Index: stand/powerpc/boot1.chrp/Makefile =================================================================== --- stand/powerpc/boot1.chrp/Makefile +++ stand/powerpc/boot1.chrp/Makefile @@ -7,12 +7,12 @@ INSTALLFLAGS= -b FILES= boot1.hfs -SRCS= boot1.c ashldi3.c syncicache.c +SRCS= boot1.c ashldi3.c syncicache.c ufsread.c CFLAGS+=-I${LDRSRC} LDFLAGS=-nostdlib -static -Wl,-N -.PATH: ${SYSDIR}/libkern ${SRCTOP}/lib/libc/powerpc/gen ${.CURDIR} +.PATH: ${SYSDIR}/libkern ${SASRC} ${SRCTOP}/lib/libc/powerpc/gen ${.CURDIR} # The following inserts out objects into a template HFS # created by generate-hfs.sh Index: stand/powerpc/boot1.chrp/boot1.c =================================================================== --- stand/powerpc/boot1.chrp/boot1.c +++ stand/powerpc/boot1.chrp/boot1.c @@ -24,7 +24,10 @@ #include #include +#include + #include "paths.h" +#include "ufsread.h" #define BSIZEMAX 16384 @@ -48,13 +51,14 @@ static char blkbuf[BSIZEMAX]; static unsigned int fsblks; -static uint32_t fs_off; - int main(int ac, char **av); +int dskread(void *, u_int64_t, int); +void memcpy(void *dst, const void *src, size_t len); +int printf(const char *fmt, ...); +int strcmp(const char *s1, const char *s2); static void exit(int) __dead2; static void load(const char *); -static int dskread(void *, u_int64_t, int); static void usage(void); @@ -64,7 +68,6 @@ static int domount(const char *device, int quiet); static void panic(const char *fmt, ...) __dead2; -static int printf(const char *fmt, ...); static int putchar(char c, void *arg); static int vprintf(const char *fmt, va_list ap); static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap); @@ -364,7 +367,7 @@ *d++ = *s++; } -static void +void memcpy(void *dst, const void *src, size_t len) { bcopy(src, dst, len); @@ -379,7 +382,7 @@ *p++ = 0; } -static int +int strcmp(const char *s1, const char *s2) { for (; *s1 == *s2 && *s1; s1++, s2++) @@ -387,8 +390,6 @@ return ((u_char)*s1 - (u_char)*s2); } -#include "ufsread.c" - int main(int ac, char **av) { @@ -540,7 +541,7 @@ ofw,NULL,0); } -static int +int dskread(void *buf, u_int64_t lba, int nblk) { /* @@ -567,7 +568,7 @@ exit(1); } -static int +int printf(const char *fmt, ...) { va_list ap; Index: stand/sparc64/boot1/Makefile =================================================================== --- stand/sparc64/boot1/Makefile +++ stand/sparc64/boot1/Makefile @@ -5,7 +5,7 @@ PROG= boot1.elf INTERNALPROG= FILES?= boot1 -SRCS= _start.s boot1.c +SRCS= _start.s boot1.c ufsread.c CLEANFILES+=${FILES} boot1.aout BOOTBLOCKBASE= 0x4000 @@ -15,6 +15,8 @@ CFLAGS+=-Os -I${LDRSRC} LDFLAGS+=-Ttext ${BOOTBLOCKBASE} -Wl,-N +.PATH: ${SASRC} + # Construct boot1. sunlabel expects it to contain zeroed-out space for the # label, and to be of the correct size. ${FILES}: boot1.aout Index: stand/sparc64/boot1/boot1.c =================================================================== --- stand/sparc64/boot1/boot1.c +++ stand/sparc64/boot1/boot1.c @@ -24,7 +24,10 @@ #include #include +#include + #include "paths.h" +#include "ufsread.h" #define READ_BUF_SIZE 8192 @@ -44,9 +47,12 @@ static ofwh_t bootdev; -static uint32_t fs_off; - int main(int ac, char **av); +int dskread(void *buf, u_int64_t lba, int nblk); +void memcpy(void *dst, const void *src, size_t len); +int printf(const char *fmt, ...); +int strcmp(const char *s1, const char *s2); + static void exit(int) __dead2; static void usage(void); @@ -61,10 +67,8 @@ static void bzero(void *b, size_t len); static int domount(const char *device); -static int dskread(void *buf, u_int64_t lba, int nblk); static void panic(const char *fmt, ...) __dead2; -static int printf(const char *fmt, ...); static int putchar(char c, void *arg); static int vprintf(const char *fmt, va_list ap); static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap); @@ -293,7 +297,7 @@ *d++ = *s++; } -static void +void memcpy(void *dst, const void *src, size_t len) { @@ -309,7 +313,7 @@ *p++ = 0; } -static int +int strcmp(const char *s1, const char *s2) { @@ -448,8 +452,6 @@ #else -#include "ufsread.c" - static struct dmadat __dmadat; static void @@ -514,7 +516,7 @@ return (0); } -static int +int dskread(void *buf, u_int64_t lba, int nblk) { @@ -542,7 +544,7 @@ exit(1); } -static int +int printf(const char *fmt, ...) { va_list ap;