diff options
| author | Marcel Moolenaar <marcel@FreeBSD.org> | 2010-08-15 22:09:43 +0000 |
|---|---|---|
| committer | Marcel Moolenaar <marcel@FreeBSD.org> | 2010-08-15 22:09:43 +0000 |
| commit | b17f9ad2c9da34e8544d02c3d530fe9fb41fdbe2 (patch) | |
| tree | 6827a51d95474f9db8e09a30ba140b86fd2af81d /sys/boot | |
| parent | 2555a135d6553934821e9fcdc99e7b7d39984557 (diff) | |
| parent | 071c626eed7c021066c9dafe1a257845773b6dc3 (diff) | |
Notes
Diffstat (limited to 'sys/boot')
25 files changed, 331 insertions, 154 deletions
diff --git a/sys/boot/Makefile b/sys/boot/Makefile index 751a93f34d50..b2eeb9554703 100644 --- a/sys/boot/Makefile +++ b/sys/boot/Makefile @@ -13,12 +13,12 @@ SUBDIR+= efi .endif # Build Open Firmware library. -.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "sparc64" +.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "sparc64" SUBDIR+= ofw .endif # Build U-Boot library. -.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm" +.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "arm" SUBDIR+= uboot .endif @@ -31,7 +31,7 @@ SUBDIR+= fdt .endif # Pick the machine-dependent subdir based on the target architecture. -ADIR= ${MACHINE:S/amd64/i386/:S/sun4v/sparc64/} +ADIR= ${MACHINE:S/amd64/i386/:S/sun4v/sparc64/:S/powerpc64/powerpc/} .if exists(${.CURDIR}/${ADIR}/.) SUBDIR+= ${ADIR} .endif diff --git a/sys/boot/common/Makefile.inc b/sys/boot/common/Makefile.inc index 98761f4d7e9b..23f8fbf444d7 100644 --- a/sys/boot/common/Makefile.inc +++ b/sys/boot/common/Makefile.inc @@ -11,8 +11,11 @@ SRCS+= load_elf64.c load_elf64_obj.c reloc_elf64.c SRCS+= load_elf64.c load_elf64_obj.c reloc_elf64.c .elif ${MACHINE} == "pc98" SRCS+= load_elf32.c load_elf32_obj.c reloc_elf32.c -.elif ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm" +.elif ${MACHINE_ARCH} == "arm" SRCS+= load_elf32.c reloc_elf32.c +.elif ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" +SRCS+= load_elf32.c reloc_elf32.c +SRCS+= load_elf64.c reloc_elf64.c .elif ${MACHINE_ARCH} == "sparc64" SRCS+= load_elf64.c reloc_elf64.c .endif diff --git a/sys/boot/common/load_elf_obj.c b/sys/boot/common/load_elf_obj.c index 4b3aaeae7865..6f3b3493aa3d 100644 --- a/sys/boot/common/load_elf_obj.c +++ b/sys/boot/common/load_elf_obj.c @@ -221,6 +221,8 @@ __elfN(obj_loadimage)(struct preloaded_file *fp, elf_file_t ef, u_int64_t off) for (i = 0; i < hdr->e_shnum; i++) shdr[i].sh_addr = 0; for (i = 0; i < hdr->e_shnum; i++) { + if (shdr[i].sh_size == 0) + continue; switch (shdr[i].sh_type) { case SHT_PROGBITS: case SHT_NOBITS: diff --git a/sys/boot/common/loader.8 b/sys/boot/common/loader.8 index bae2f86ba811..2490e3dcdbea 100644 --- a/sys/boot/common/loader.8 +++ b/sys/boot/common/loader.8 @@ -806,7 +806,7 @@ Evaluates the remainder of the input buffer under a exception guard. .It Ic .# Works like -.Ic . +.Ic "." but without outputting a trailing space. .It Ic fclose Pq Ar fd -- Closes a file. diff --git a/sys/boot/fdt/Makefile b/sys/boot/fdt/Makefile index 32ebce8b4d4a..5df761d824b5 100644 --- a/sys/boot/fdt/Makefile +++ b/sys/boot/fdt/Makefile @@ -16,10 +16,14 @@ CFLAGS+= -I${.CURDIR}/../../contrib/libfdt/ -I${.CURDIR}/../common/ \ CFLAGS+= -ffreestanding -.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm" +.if ${MACHINE_CPUARCH} == "powerpc" || ${MACHINE_CPUARCH} == "arm" CFLAGS+= -msoft-float .endif +.if ${MACHINE_ARCH} == "powerpc64" +CFLAGS+= -m32 +.endif + CFLAGS+= -Wformat -Wall .include <bsd.lib.mk> diff --git a/sys/boot/fdt/dts/mpc8555cds.dts b/sys/boot/fdt/dts/mpc8555cds.dts index 232f8a48b72f..4f057dc2a7d0 100644 --- a/sys/boot/fdt/dts/mpc8555cds.dts +++ b/sys/boot/fdt/dts/mpc8555cds.dts @@ -343,6 +343,7 @@ compatible = "fsl,mpc8555-cpm", "fsl,cpm2"; reg = <0x80000 0x20000>; interrupts = <46 2>; + interrupt-parent = <&mpic>; }; }; diff --git a/sys/boot/ficl/Makefile b/sys/boot/ficl/Makefile index a967613ef1a3..cdc8f7eddeed 100644 --- a/sys/boot/ficl/Makefile +++ b/sys/boot/ficl/Makefile @@ -1,6 +1,6 @@ # $FreeBSD$ # -.PATH: ${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/} +.PATH: ${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/:S/powerpc64/powerpc/} BASE_SRCS= dict.c ficl.c fileaccess.c float.c loader.c math64.c \ prefix.c search.c stack.c tools.c vm.c words.c @@ -14,7 +14,7 @@ CFLAGS+= -mno-mmx -mno-3dnow -mno-sse -mno-sse2 .if ${MACHINE_ARCH} == "i386" CFLAGS+= -mno-sse3 .endif -.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm" +.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" || ${MACHINE_ARCH} == "arm" CFLAGS+= -msoft-float .endif .if ${MACHINE} == "pc98" @@ -45,7 +45,11 @@ SOFTWORDS= softcore.fr jhlocal.fr marker.fr freebsd.fr ficllocal.fr \ CFLAGS+= -m32 -march=i386 -I. .endif -CFLAGS+= -I${.CURDIR} -I${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/} \ +.if ${MACHINE_ARCH} == "powerpc64" +CFLAGS+= -m32 -mcpu=powerpc -I. +.endif + +CFLAGS+= -I${.CURDIR} -I${.CURDIR}/${MACHINE_ARCH:S/amd64/i386/:S/powerpc64/powerpc/} \ -I${.CURDIR}/../common softcore.c: ${SOFTWORDS} softcore.awk diff --git a/sys/boot/i386/loader/Makefile b/sys/boot/i386/loader/Makefile index 719e28dd73a9..71307c04606d 100644 --- a/sys/boot/i386/loader/Makefile +++ b/sys/boot/i386/loader/Makefile @@ -115,7 +115,7 @@ FILES+= loader.rc OBJS= ${BTXCRT} DPADD= ${LIBFICL} ${LIBFIREWIRE} ${LIBZFS} ${LIBI386} ${LIBSTAND} -LDADD= ${LIBFICL} ${LIBFIREWIRE} ${LIBZFS} ${LIBI386} -lstand +LDADD= ${LIBFICL} ${LIBFIREWIRE} ${LIBZFS} ${LIBI386} ${LIBSTAND} .include <bsd.prog.mk> diff --git a/sys/boot/ofw/Makefile.inc b/sys/boot/ofw/Makefile.inc index 265f86d1ed55..dab65e52621d 100644 --- a/sys/boot/ofw/Makefile.inc +++ b/sys/boot/ofw/Makefile.inc @@ -1,3 +1,8 @@ # $FreeBSD$ +.if ${MACHINE_ARCH} == "powerpc64" +CFLAGS+= -m32 -mcpu=powerpc +LDFLAGS+= -m elf32ppc +.endif + .include "../Makefile.inc" diff --git a/sys/boot/ofw/libofw/Makefile b/sys/boot/ofw/libofw/Makefile index 8a56a778f76f..5ea0de972af3 100644 --- a/sys/boot/ofw/libofw/Makefile +++ b/sys/boot/ofw/libofw/Makefile @@ -13,8 +13,9 @@ CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I. CFLAGS+= -ffreestanding -.if ${MACHINE_ARCH} == "powerpc" +.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64" CFLAGS+= -msoft-float +SRCS+= ppc64_elf_freebsd.c .endif .ifdef(BOOT_DISK_DEBUG) diff --git a/sys/boot/ofw/libofw/libofw.h b/sys/boot/ofw/libofw/libofw.h index 748233e6fe9e..5f6d7ad5e6bd 100644 --- a/sys/boot/ofw/libofw/libofw.h +++ b/sys/boot/ofw/libofw/libofw.h @@ -62,6 +62,9 @@ int ofw_elf_loadfile(char *, vm_offset_t, struct preloaded_file **); int ofw_elf_exec(struct preloaded_file *); extern struct file_format ofw_elf; +#ifdef __powerpc__ +extern struct file_format ofw_elf64; +#endif extern void reboot(void); diff --git a/sys/boot/ofw/libofw/ppc64_elf_freebsd.c b/sys/boot/ofw/libofw/ppc64_elf_freebsd.c new file mode 100644 index 000000000000..84ea40611844 --- /dev/null +++ b/sys/boot/ofw/libofw/ppc64_elf_freebsd.c @@ -0,0 +1,101 @@ +/*- + * Copyright (c) 2001 Benno Rice <benno@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define __ELF_WORD_SIZE 64 + +#include <sys/param.h> +#include <sys/linker.h> + +#include <machine/metadata.h> +#include <machine/elf.h> + +#include <stand.h> + +#include "bootstrap.h" +#include "libofw.h" +#include "openfirm.h" + +extern char end[]; +extern vm_offset_t reloc; /* From <arch>/conf.c */ + +int +ppc64_ofw_elf_loadfile(char *filename, u_int64_t dest, + struct preloaded_file **result) +{ + int r; + + r = __elfN(loadfile)(filename, dest, result); + if (r != 0) + return (r); + + /* + * No need to sync the icache for modules: this will + * be done by the kernel after relocation. + */ + if (!strcmp((*result)->f_type, "elf kernel")) + __syncicache((void *) (*result)->f_addr, (*result)->f_size); + return (0); +} + +int +ppc64_ofw_elf_exec(struct preloaded_file *fp) +{ + struct file_metadata *fmp; + vm_offset_t mdp; + Elf_Ehdr *e; + int error; + intptr_t entry; + + if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) { + return(EFTYPE); + } + e = (Elf_Ehdr *)&fmp->md_data; + + /* Handle function descriptor */ + entry = *(uint64_t *)e->e_entry; + + if ((error = md_load64(fp->f_args, &mdp)) != 0) + return (error); + + printf("Kernel entry at 0x%lx ...\n", entry); + + dev_cleanup(); + ofw_release_heap(); + + OF_chain((void *)reloc, end - (char *)reloc, (void *)entry, + (void *)mdp, sizeof(mdp)); + + panic("exec returned"); +} + +struct file_format ofw_elf64 = +{ + ppc64_ofw_elf_loadfile, + ppc64_ofw_elf_exec +}; diff --git a/sys/boot/pc98/loader/Makefile b/sys/boot/pc98/loader/Makefile index 9f2e32f483d9..e1f47cd081d8 100644 --- a/sys/boot/pc98/loader/Makefile +++ b/sys/boot/pc98/loader/Makefile @@ -94,6 +94,6 @@ FILES+= ${.CURDIR}/../../i386/loader/loader.rc OBJS= ${BTXCRT} DPADD= ${LIBFICL} ${LIBPC98} ${LIBSTAND} -LDADD= ${LIBFICL} ${LIBPC98} -lstand +LDADD= ${LIBFICL} ${LIBPC98} ${LIBSTAND} .include <bsd.prog.mk> diff --git a/sys/boot/powerpc/Makefile.inc b/sys/boot/powerpc/Makefile.inc index 265f86d1ed55..dab65e52621d 100644 --- a/sys/boot/powerpc/Makefile.inc +++ b/sys/boot/powerpc/Makefile.inc @@ -1,3 +1,8 @@ # $FreeBSD$ +.if ${MACHINE_ARCH} == "powerpc64" +CFLAGS+= -m32 -mcpu=powerpc +LDFLAGS+= -m elf32ppc +.endif + .include "../Makefile.inc" diff --git a/sys/boot/powerpc/boot1.chrp/Makefile b/sys/boot/powerpc/boot1.chrp/Makefile index 621b973ff7aa..f3f7e4dd32b2 100644 --- a/sys/boot/powerpc/boot1.chrp/Makefile +++ b/sys/boot/powerpc/boot1.chrp/Makefile @@ -13,7 +13,7 @@ SRCS= boot1.c ashldi3.c INTERNALPROG= NO_MAN= -CFLAGS= -ffreestanding -msoft-float -Os -D_KERNEL \ +CFLAGS= -ffreestanding -msoft-float -Os \ -I${.CURDIR}/../../common -I${.CURDIR}/../../../ LDFLAGS=-nostdlib -static -N diff --git a/sys/boot/powerpc/ofw/Makefile b/sys/boot/powerpc/ofw/Makefile index d42fa927ce5c..776f98e4f795 100644 --- a/sys/boot/powerpc/ofw/Makefile +++ b/sys/boot/powerpc/ofw/Makefile @@ -10,6 +10,7 @@ INSTALLFLAGS= -b # Architecture-specific loader code SRCS= conf.c metadata.c vers.c start.c +SRCS+= ucmpdi2.c LOADER_DISK_SUPPORT?= yes LOADER_UFS_SUPPORT?= yes @@ -62,9 +63,9 @@ LIBFICL= ${.OBJDIR}/../../ficl/libficl.a CFLAGS+= -DNETIF_OPEN_CLOSE_ONCE # Always add MI sources -.PATH: ${.CURDIR}/../../common +.PATH: ${.CURDIR}/../../common ${.CURDIR}/../../../libkern .include "${.CURDIR}/../../common/Makefile.inc" -CFLAGS+= -I${.CURDIR}/../../common +CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. CFLAGS+= -I. CLEANFILES+= vers.c loader.help diff --git a/sys/boot/powerpc/ofw/conf.c b/sys/boot/powerpc/ofw/conf.c index 4ab3e2334440..5666f4accae2 100644 --- a/sys/boot/powerpc/ofw/conf.c +++ b/sys/boot/powerpc/ofw/conf.c @@ -96,6 +96,7 @@ struct netif_driver *netif_drivers[] = { struct file_format *file_formats[] = { &ofw_elf, + &ofw_elf64, NULL }; diff --git a/sys/boot/powerpc/ofw/ldscript.powerpc b/sys/boot/powerpc/ofw/ldscript.powerpc index ecf8129455aa..e3b7b2c4b4c2 100644 --- a/sys/boot/powerpc/ofw/ldscript.powerpc +++ b/sys/boot/powerpc/ofw/ldscript.powerpc @@ -1,7 +1,7 @@ /* $FreeBSD$ */ OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc") -OUTPUT_ARCH(powerpc) +OUTPUT_ARCH(powerpc:common) ENTRY(_start) SEARCH_DIR(/usr/lib); /* Do we need any of these for elf? diff --git a/sys/boot/powerpc/ofw/metadata.c b/sys/boot/powerpc/ofw/metadata.c index 37c2bb717000..caed9cd0a41e 100644 --- a/sys/boot/powerpc/ofw/metadata.c +++ b/sys/boot/powerpc/ofw/metadata.c @@ -175,6 +175,9 @@ md_copyenv(vm_offset_t addr) * MOD_SIZE sizeof(size_t) module size * MOD_METADATA (variable) type-specific metadata */ + +static int align; + #define COPY32(v, a, c) { \ u_int32_t x = (v); \ if (c) \ @@ -187,7 +190,7 @@ md_copyenv(vm_offset_t addr) COPY32(strlen(s) + 1, a, c) \ if (c) \ archsw.arch_copyin(s, a, strlen(s) + 1);\ - a += roundup(strlen(s) + 1, sizeof(u_long));\ + a += roundup(strlen(s) + 1, align); \ } #define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c) @@ -199,7 +202,7 @@ md_copyenv(vm_offset_t addr) COPY32(sizeof(s), a, c); \ if (c) \ archsw.arch_copyin(&s, a, sizeof(s)); \ - a += roundup(sizeof(s), sizeof(u_long)); \ + a += roundup(sizeof(s), align); \ } #define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c) @@ -210,7 +213,7 @@ md_copyenv(vm_offset_t addr) COPY32(mm->md_size, a, c); \ if (c) \ archsw.arch_copyin(mm->md_data, a, mm->md_size);\ - a += roundup(mm->md_size, sizeof(u_long)); \ + a += roundup(mm->md_size, align); \ } #define MOD_END(a, c) { \ @@ -219,10 +222,11 @@ md_copyenv(vm_offset_t addr) } vm_offset_t -md_copymodules(vm_offset_t addr) +md_copymodules(vm_offset_t addr, int kern64) { struct preloaded_file *fp; struct file_metadata *md; + uint64_t scratch64; int c; c = addr != 0; @@ -233,8 +237,15 @@ md_copymodules(vm_offset_t addr) MOD_TYPE(addr, fp->f_type, c); if (fp->f_args) MOD_ARGS(addr, fp->f_args, c); - MOD_ADDR(addr, fp->f_addr, c); - MOD_SIZE(addr, fp->f_size, c); + if (kern64) { + scratch64 = fp->f_addr; + MOD_ADDR(addr, scratch64, c); + scratch64 = fp->f_size; + MOD_SIZE(addr, scratch64, c); + } else { + MOD_ADDR(addr, fp->f_addr, c); + MOD_SIZE(addr, fp->f_size, c); + } for (md = fp->f_metadata; md != NULL; md = md->md_next) { if (!(md->md_type & MODINFOMD_NOCOPY)) { MOD_METADATA(addr, md, c); @@ -254,7 +265,7 @@ md_copymodules(vm_offset_t addr) * - Module metadata are formatted and placed in kernel space. */ int -md_load(char *args, vm_offset_t *modulep) +md_load_dual(char *args, vm_offset_t *modulep, int kern64) { struct preloaded_file *kfp; struct preloaded_file *xp; @@ -263,11 +274,11 @@ md_load(char *args, vm_offset_t *modulep) vm_offset_t addr; vm_offset_t envp; vm_offset_t size; + uint64_t scratch64; char *rootdevname; int howto; - int dtlb_slots; - int itlb_slots; + align = kern64 ? 8 : 4; howto = md_getboothowto(args); /* @@ -298,23 +309,48 @@ md_load(char *args, vm_offset_t *modulep) addr = roundup(addr, PAGE_SIZE); kernend = 0; - kfp = file_findfile(NULL, "elf32 kernel"); + kfp = file_findfile(NULL, kern64 ? "elf64 kernel" : "elf32 kernel"); if (kfp == NULL) kfp = file_findfile(NULL, "elf kernel"); if (kfp == NULL) panic("can't find kernel file"); file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto); - file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp); - file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend); + if (kern64) { + scratch64 = envp; + file_addmetadata(kfp, MODINFOMD_ENVP, sizeof scratch64, &scratch64); + scratch64 = kernend; + file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof scratch64, &scratch64); + } else { + file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp); + file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend); + } *modulep = addr; - size = md_copymodules(0); + size = md_copymodules(0, kern64); kernend = roundup(addr + size, PAGE_SIZE); md = file_findmetadata(kfp, MODINFOMD_KERNEND); - bcopy(&kernend, md->md_data, sizeof kernend); - - (void)md_copymodules(addr); + if (kern64) { + scratch64 = kernend; + bcopy(&scratch64, md->md_data, sizeof scratch64); + } else { + bcopy(&kernend, md->md_data, sizeof kernend); + } + + (void)md_copymodules(addr, kern64); return(0); } + +int +md_load(char *args, vm_offset_t *modulep) +{ + return (md_load_dual(args, modulep, 0)); +} + +int +md_load64(char *args, vm_offset_t *modulep) +{ + return (md_load_dual(args, modulep, 1)); +} + diff --git a/sys/boot/powerpc/uboot/Makefile b/sys/boot/powerpc/uboot/Makefile index afd1b97aa89d..6ba738fd39a7 100644 --- a/sys/boot/powerpc/uboot/Makefile +++ b/sys/boot/powerpc/uboot/Makefile @@ -10,6 +10,7 @@ NO_MAN= # Architecture-specific loader code SRCS= start.S conf.c vers.c +SRCS+= ucmpdi2.c LOADER_DISK_SUPPORT?= yes LOADER_UFS_SUPPORT?= yes @@ -68,9 +69,9 @@ LIBFICL= ${.OBJDIR}/../../ficl/libficl.a .endif # Always add MI sources -.PATH: ${.CURDIR}/../../common +.PATH: ${.CURDIR}/../../common ${.CURDIR}/../../../libkern .include "${.CURDIR}/../../common/Makefile.inc" -CFLAGS+= -I${.CURDIR}/../../common +CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. CFLAGS+= -I. CLEANFILES+= vers.c ${PROG}.help diff --git a/sys/boot/powerpc/uboot/ldscript.powerpc b/sys/boot/powerpc/uboot/ldscript.powerpc index 43ef422a7f7f..fdba57c0076e 100644 --- a/sys/boot/powerpc/uboot/ldscript.powerpc +++ b/sys/boot/powerpc/uboot/ldscript.powerpc @@ -1,7 +1,7 @@ /* $FreeBSD$ */ OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc") -OUTPUT_ARCH(powerpc) +OUTPUT_ARCH(powerpc:common) ENTRY(_start) SEARCH_DIR(/usr/lib); PROVIDE (__stack = 0); diff --git a/sys/boot/uboot/Makefile.inc b/sys/boot/uboot/Makefile.inc index 265f86d1ed55..dab65e52621d 100644 --- a/sys/boot/uboot/Makefile.inc +++ b/sys/boot/uboot/Makefile.inc @@ -1,3 +1,8 @@ # $FreeBSD$ +.if ${MACHINE_ARCH} == "powerpc64" +CFLAGS+= -m32 -mcpu=powerpc +LDFLAGS+= -m elf32ppc +.endif + .include "../Makefile.inc" diff --git a/sys/boot/uboot/common/metadata.c b/sys/boot/uboot/common/metadata.c index 2c2ac3c31aa8..e346430bd4b9 100644 --- a/sys/boot/uboot/common/metadata.c +++ b/sys/boot/uboot/common/metadata.c @@ -36,9 +36,6 @@ __FBSDID("$FreeBSD$"); #include <machine/elf.h> #include <machine/metadata.h> -#if !defined(LOADER_FDT_SUPPORT) -#include <machine/bootinfo.h> -#endif #include "api_public.h" #include "bootstrap.h" @@ -259,114 +256,6 @@ md_copymodules(vm_offset_t addr) return(addr); } -#if !defined(LOADER_FDT_SUPPORT) -/* - * Prepare the bootinfo structure. Put a ptr to the allocated struct in addr, - * return size. - */ -static int -md_bootinfo(struct bootinfo **addr) -{ -#define TMP_MAX_ETH 8 -#define TMP_MAX_MR 8 - struct bootinfo *bi; - struct bi_mem_region tmp_mr[TMP_MAX_MR]; - struct bi_eth_addr tmp_eth[TMP_MAX_ETH]; - struct sys_info *si; - char *str, *end; - const char *env; - void *ptr; - u_int8_t tmp_addr[6]; - int i, n, mr_no, eth_no, size; - - if ((si = ub_get_sys_info()) == NULL) - panic("can't retrieve U-Boot sysinfo"); - - /* - * Handle mem regions (we only care about DRAM) - */ - for (i = 0, mr_no = 0; i < si->mr_no; i++) { - if (si->mr[i].flags == MR_ATTR_DRAM) { - if (mr_no >= TMP_MAX_MR) { - printf("too many memory regions: %d\n", mr_no); - break; - } - tmp_mr[mr_no].mem_base = si->mr[i].start; - tmp_mr[mr_no].mem_size = si->mr[i].size; - mr_no++; - continue; - } - } - if (mr_no == 0) - panic("can't retrieve RAM info"); - - size = (mr_no * sizeof(struct bi_mem_region) - sizeof(bi->bi_data)); - - /* - * Handle Ethernet addresses: parse u-boot env for eth%daddr - */ - env = NULL; - eth_no = 0; - while ((env = ub_env_enum(env)) != NULL) { - if (strncmp(env, "eth", 3) == 0 && - strncmp(env + (strlen(env) - 4), "addr", 4) == 0) { - - /* Extract interface number */ - i = strtol(env + 3, &end, 10); - if (end == (env + 3)) - /* 'ethaddr' means interface 0 address */ - n = 0; - else - n = i; - - if (n >= TMP_MAX_MR) { - printf("Ethernet interface number too high: %d. " - "Skipping...\n"); - continue; - } - - str = ub_env_get(env); - for (i = 0; i < 6; i++) { - tmp_addr[i] = str ? strtol(str, &end, 16) : 0; - if (str) - str = (*end) ? end + 1 : end; - - tmp_eth[n].mac_addr[i] = tmp_addr[i]; - } - - /* eth_no is 1-based number of all interfaces defined */ - if (n + 1 > eth_no) - eth_no = n + 1; - } - } - - size += (eth_no * sizeof(struct bi_eth_addr)) + sizeof(struct bootinfo); - - /* - * Once its whole size is calculated, allocate space for the bootinfo - * and copy over the contents from temp containers. - */ - if ((bi = malloc(size)) == NULL) - panic("can't allocate mem for bootinfo"); - - ptr = (struct bi_mem_region *)bi->bi_data; - bcopy(tmp_mr, ptr, mr_no * sizeof(struct bi_mem_region)); - ptr += mr_no * sizeof(struct bi_mem_region); - bcopy(tmp_eth, ptr, eth_no * sizeof(struct bi_eth_addr)); - - bi->bi_mem_reg_no = mr_no; - bi->bi_eth_addr_no = eth_no; - bi->bi_version = BI_VERSION; - bi->bi_bar_base = si->bar; - bi->bi_cpu_clk = si->clk_cpu; - bi->bi_bus_clk = si->clk_bus; - - *addr = bi; - - return (size); -} -#endif - /* * Load the information expected by a kernel. * @@ -390,7 +279,6 @@ md_load(char *args, vm_offset_t *modulep) vm_offset_t dtbp; char *rootdevname; int howto; - int bisize; int i; /* @@ -434,11 +322,6 @@ md_load(char *args, vm_offset_t *modulep) /* Pad to a page boundary */ addr = roundup(addr, PAGE_SIZE); -#if !defined(LOADER_FDT_SUPPORT) - /* prepare bootinfo */ - bisize = md_bootinfo(&bip); -#endif - kernend = 0; kfp = file_findfile(NULL, "elf32 kernel"); if (kfp == NULL) @@ -457,8 +340,6 @@ md_load(char *args, vm_offset_t *modulep) dtbp = bfp == NULL ? 0 : bfp->f_addr; file_addmetadata(kfp, MODINFOMD_DTBP, sizeof dtbp, &dtbp); -#else - file_addmetadata(kfp, MODINFOMD_BOOTINFO, bisize, bip); #endif file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend); diff --git a/sys/boot/zfs/zfsimpl.c b/sys/boot/zfs/zfsimpl.c index 5be7afa364e6..e645ebaa6cd1 100644 --- a/sys/boot/zfs/zfsimpl.c +++ b/sys/boot/zfs/zfsimpl.c @@ -328,6 +328,9 @@ vdev_read_phys(vdev_t *vdev, const blkptr_t *bp, void *buf, size_t psize; int rc; + if (!vdev->v_phys_read) + return (EIO); + if (bp) { psize = BP_GET_PSIZE(bp); } else { diff --git a/sys/boot/zfs/zfstest.c b/sys/boot/zfs/zfstest.c new file mode 100644 index 000000000000..303ef5f08efe --- /dev/null +++ b/sys/boot/zfs/zfstest.c @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 2010 Doug Rabson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* $FreeBSD$ */ +/* + * Compile with 'cc -I. -I../../cddl/boot/zfs zfstest.c -o zfstest' + */ + +#include <sys/param.h> +#include <sys/queue.h> +#include <fcntl.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <stdarg.h> +#include <stddef.h> +#include <stdlib.h> +#include <errno.h> + +#define NBBY 8 + +void +pager_output(const char *line) +{ + printf("%s", line); +} + +#include "zfsimpl.c" + +static int +vdev_read(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes) +{ + int fd = *(int *) priv; + + if (pread(fd, buf, bytes, off) != bytes) + return -1; + return 0; +} + +static int +zfs_read(spa_t *spa, dnode_phys_t *dn, void *buf, size_t size, off_t off) +{ + const znode_phys_t *zp = (const znode_phys_t *) dn->dn_bonus; + size_t n; + int rc; + + n = size; + if (off + n > zp->zp_size) + n = zp->zp_size - off; + + rc = dnode_read(spa, dn, off, buf, n); + if (rc) + return (rc); + + return (n); +} + +int +main(int argc, char** argv) +{ + int i, n, off; + int fd[99]; + spa_t *spa; + dnode_phys_t dn; + char buf[512]; + + zfs_init(); + if (argc == 1) { + static char *av[] = { + "zfstest", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2", + NULL, + }; + argc = 4; + argv = av; + } + for (i = 1; i < argc; i++) { + fd[i] = open(argv[i], O_RDONLY); + if (fd[i] < 0) + continue; + if (vdev_probe(vdev_read, &fd[i], NULL) != 0) + close(fd[i]); + } + spa_all_status(); + + spa = STAILQ_FIRST(&zfs_pools); + if (!spa || zfs_mount_pool(spa)) + exit(1); + + if (zfs_lookup(spa, "zfs.c", &dn)) + exit(1); + + off = 0; + do { + n = zfs_read(spa, &dn, buf, 512, off); + write(1, buf, n); + off += n; + } while (n == 512); +} |
