Date: Thu, 4 Feb 2016 10:36:47 +0000 From: "Sgalabov_gmail.com (Stanislav Galabov)" <phabric-noreply@FreeBSD.org> To: freebsd-mips@freebsd.org Subject: [Differential] [Request, 597 lines] D5187: U-Boot loader (ubldr) support for MIPS Message-ID: <differential-rev-PHID-DREV-lydkabzwr6zbaqctozb5-req@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] Sgalabov_gmail.com created this revision. Sgalabov_gmail.com added reviewers: MIPS, loader, adrian, imp, ray. Sgalabov_gmail.com added a subscriber: freebsd-mips-list. Sgalabov_gmail.com set the repository for this revision to rS FreeBSD src repository. Sgalabov_gmail.com added a project: MIPS. REVISION SUMMARY This revision implements ubldr support for MIPS. A lot of it just mimics the ARM support for ubldr, basically the biggest change is in the start.S file. Apart from that, several Makefiles in sys/boot were not including the bsd.stand.mk, which prevented proper build for MIPS targets (due to some things compiled as PIC and others - as non-PIC). These Makefiles now include bsd.stand.mk and things build fine for MIPS (everything is build as non-PIC). I've used the head version of U-Boot and modified it to support the FreeBSD API for MIPS architectures. I've submitted the patch to U-Boot as well. In case it doesn't go through for some reason, I am also putting a copy of the patch here: https://www.dropbox.com/s/dmgz9idpj4beqpr/0001-Add-FreeBSD-API-support-for-MIPS-platforms.patch?dl=0 TEST PLAN I've tested this with the following setup: - QEMU with its 'mips' target in little endian mode - u-boot compiled for quemu-mips (little endian) - ubldr compiled for mipsel - a kernel quickly put together for the qemu-mips target that only supports basic UART (so we can see the bootlog). Output of the whole thing booting can be seen below: > qemu-system-mipsel -M mips -bios u-boot.bin -nographic -net nic,macaddr=00:16:3e:00:00:01 -net tap -hda hda.img -cpu 24Kc W: /etc/qemu-ifup: no bridge for guest interface found Could not open option rom 'vgabios-cirrus.bin': No such file or directory U-Boot 2016.03-rc1-dirty (Feb 04 2016 - 11:41:10 +0200) Board: Qemu -M mips CPU: 24Kc proc_id=0x19300 DRAM: 128 MiB Using default environment In: serial Out: serial Err: serial Net: NE2000 IDE: Bus 0: OK Bus 1: OK Device 0: Model: QEMU HARDDISK Firm: 2.0.0 Ser#: QM00001 Type: Hard Disk Capacity: 50.0 MB = 0.0 GB (102400 x 512) Device 1: not available Device 2: not available Device 3: not available Hit any key to stop autoboot: 0 qemu-mipsel # tftp; bootelf Using NE2000 device TFTP from server 192.168.78.1; our IP address is 192.168.78.10 Filename 'demo'. Load address: 0x80500000 Loading: ################# 5.6 MiB/s done Bytes transferred = 244995 (3bd03 hex) Starting application at 0x80800080 ... -------------------------------------- Consoles: U-Boot console Compatible U-Boot API signature found @87f6e0a8 FreeBSD/mipsel U-Boot loader, Revision 1.2 (root@stassi-bsd9, Wed Feb 3 17:44:10 EET 2016) DRAM: 128MB Number of U-Boot devices: 2 U-Boot env: loaderdev not set, will probe all devices. Found U-Boot device: disk Probing all disk devices... Checking unit=0 slice=<auto> partition=<auto>... good. Booting from disk0s1: / /boot/kernel/kernel data=0x3ebaa8+0x27ff8 syms=[0x4+0x43a90+0x4+0x5e7cf] Hit [Enter] to boot immediately, or any other key for command prompt. Booting [/boot/kernel/kernel]... Kernel entry at 0x80100100... Kernel args: (null) U-Boot args (from -2141491201 args): Environment: ???m?? disk0s1: entry: mips_init() Cache info: picache_stride = 4096 picache_loopcount = 0 pdcache_stride = 1024 pdcache_loopcount = 2 cpu0: MIPS Technologies processor v0.147 MMU: Standard TLB, 16 entries (4K 16K 64K 256K 1M 16M 64M 256M pg sizes) L1 i-cache: 2 ways of 64 sets, 16 bytes per line L1 d-cache: 2 ways of 64 sets, 16 bytes per line L2 cache: disabled Config1=0x9e190c8e<WatchRegs,MIPS16,EJTAG> Config2=0x80000000 Physical memory chunk(s): 0x514000 - 0x1ffffff, 28229632 bytes (6892 pages) Maxmem is 0x2000000 KDB: debugger backends: ddb KDB: current backend: ddb Copyright (c) 1992-2016 The FreeBSD Project. Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 The Regents of the University of California. All rights reserved. FreeBSD is a registered trademark of The FreeBSD Foundation. FreeBSD 11.0-CURRENT #0 733656d(local/sgalabov_mtk)-dirty: Wed Feb 3 19:56:05 EET 2016 root@stassi-bsd9:/usr/obj/mips.mipsel/src/sgalabov/sys/QEMU-MIPS mips gcc version 4.2.1 20070831 patched [FreeBSD] Preloaded elf kernel "kernel" at 0x8050dfe0. real memory = 33554432 (32768K bytes) Physical memory chunk(s): 0x005a8000 - 0x01f47fff, 26869760 bytes (6560 pages) avail memory = 26456064 (25MB) ULE: setup cpu 0 random: entropy device external interface null: <full device, null device, zero device> mem: <memory> nfslock: pseudo-device nexus0: <MIPS32 root nexus> random: harvesting attach, 8 bytes (4 bits) from nexus0 clock0: <Generic MIPS32 ticker> on nexus0 Timecounter "MIPS32" frequency 50000000 Hz quality 800 Event timer "MIPS32" frequency 50000000 Hz quality 800 random: harvesting attach, 8 bytes (4 bits) from clock0 obio0 at mem 0x10000000-0x1fffffff on nexus0 uart0: <16550 or compatible> on obio0 uart0: console (-1,n,8,1) uart0: fast interrupt uart0: PPS capture mode 2 (DCD) random: harvesting attach, 8 bytes (4 bits) from uart0 random: harvesting attach, 8 bytes (4 bits) from obio0 Device configuration finished. Timecounters tick every 10.000 msec tcp_init: net.inet.tcp.tcbhashsize auto tuned to 512 lo0: bpf attached Trying to mount root from ufs:ada0 []... mountroot: waiting for device ada0... Mounting from ufs:ada0 failed with error 19. Loader variables: <snip> REPOSITORY rS FreeBSD src repository REVISION DETAIL https://reviews.freebsd.org/D5187 AFFECTED FILES sys/boot/Makefile.mips sys/boot/common/Makefile.inc sys/boot/common/self_reloc.c sys/boot/fdt/Makefile sys/boot/ficl/Makefile sys/boot/mips/Makefile sys/boot/mips/uboot/Makefile sys/boot/mips/uboot/conf.c sys/boot/mips/uboot/help.uboot sys/boot/mips/uboot/ldscript.mips sys/boot/mips/uboot/loader.conf sys/boot/mips/uboot/start.S sys/boot/mips/uboot/version sys/boot/uboot/fdt/Makefile sys/boot/uboot/lib/Makefile sys/boot/uboot/lib/elf_freebsd.c sys/boot/uboot/lib/glue.c EMAIL PREFERENCES https://reviews.freebsd.org/settings/panel/emailpreferences/ To: Sgalabov_gmail.com, MIPS, loader, adrian, imp, ray Cc: freebsd-mips-list [-- Attachment #2 --] diff --git a/sys/boot/uboot/lib/glue.c b/sys/boot/uboot/lib/glue.c --- a/sys/boot/uboot/lib/glue.c +++ b/sys/boot/uboot/lib/glue.c @@ -83,8 +83,13 @@ if (uboot_address == 0) uboot_address = 255 * 1024 * 1024; +#ifdef __mips + sp = (void *)(uboot_address & ~0x0000ffff); + spend = sp + 0x00010000 - API_SIG_MAGLEN; +#else sp = (void *)(uboot_address & ~0x000fffff); spend = sp + 0x00300000 - API_SIG_MAGLEN; +#endif while (sp < spend) { if (!bcmp(sp, API_SIG_MAGIC, API_SIG_MAGLEN)) { *sig = (struct api_signature *)sp; diff --git a/sys/boot/uboot/lib/elf_freebsd.c b/sys/boot/uboot/lib/elf_freebsd.c --- a/sys/boot/uboot/lib/elf_freebsd.c +++ b/sys/boot/uboot/lib/elf_freebsd.c @@ -31,6 +31,10 @@ #include <sys/param.h> #include <sys/linker.h> +#ifdef __mips +#include <sys/proc.h> +#include <machine/frame.h> +#endif #include <machine/md_var.h> #include <machine/metadata.h> #include <machine/elf.h> diff --git a/sys/boot/uboot/lib/Makefile b/sys/boot/uboot/lib/Makefile --- a/sys/boot/uboot/lib/Makefile +++ b/sys/boot/uboot/lib/Makefile @@ -46,6 +46,7 @@ CLEANFILES+= machine +.include <bsd.stand.mk> .include <bsd.lib.mk> beforedepend ${OBJS}: machine diff --git a/sys/boot/uboot/fdt/Makefile b/sys/boot/uboot/fdt/Makefile --- a/sys/boot/uboot/fdt/Makefile +++ b/sys/boot/uboot/fdt/Makefile @@ -28,6 +28,7 @@ CLEANFILES+= machine +.include <bsd.stand.mk> .include <bsd.lib.mk> beforedepend ${OBJS}: machine diff --git a/sys/boot/mips/uboot/version b/sys/boot/mips/uboot/version new file mode 100644 --- /dev/null +++ b/sys/boot/mips/uboot/version @@ -0,0 +1,9 @@ +$FreeBSD$ + +NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this +file is important. Make sure the current version number is on line 6. + +1.2: Extended with NAND FS support. +1.1: Flattened Device Tree blob support. +1.0: Added storage support. Booting from HDD, USB, etc. is now possible. +0.5: Initial U-Boot/arm version (netbooting only). diff --git a/sys/boot/mips/uboot/start.S b/sys/boot/mips/uboot/start.S new file mode 100644 --- /dev/null +++ b/sys/boot/mips/uboot/start.S @@ -0,0 +1,107 @@ +/*- + * Copyright (c) 2016 Stanislav Galabov + * 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$ + */ + +#include <machine/asm.h> + + .text +#ifdef SUPPORT_SELF_RELOC + .extern _C_LABEL(self_reloc) +#endif + .extern _C_LABEL(main) + .weak _DYNAMIC + +/* + * Entry point to the loader that U-Boot passes control to. + */ +ENTRY(_start) +#ifdef SUPPORT_SELF_RELOC + /* XXX: Does anyone need this part at all? It currently doesn't work. */ + .set mips32r2 + /* + * Do self-relocation when the weak external symbol _DYNAMIC is non-NULL + * When linked as a dynamic relocatable file, the linker automatically + * defines _DYNAMIC with a value that is the offset of the dynamic + * relocation info section. + * Note that we're still on u-boot's stack here, but the self_reloc + * code uses only a couple dozen bytes of stack space. + */ + lw t0, .here_off /* .here_off is a symbol whose value */ + /* is its own offset in the text seg. */ + /* Get its pc-relative address and */ + lw t1, .dynamic_off /* subtract its value and we get */ + nop + add t2, t0, t1 + movn t1, t2, t1 + beqz t1, 1f + nop + b _C_LABEL(self_reloc) /* Do reloc if _DYNAMIC is non-NULL. */ + nop +1: +#endif + sw sp, uboot_address + b main +END(_start) + +#ifdef SUPPORT_SELF_RELOC + /* + * Data for self-relocation, in the text segment for pc-rel access. + */ +.here_off: + .word . - _start +.dynamic_off: + .word _DYNAMIC +#endif + +/* + * syscall() + */ +ENTRY(syscall) + sw ra, ret_address + lw t9, syscall_ptr + jalr t9 + nop + lw ra, ret_address + jr ra + nop +END(syscall) + +/* + * Data section + */ + .data + .align 4 + .globl syscall_ptr +syscall_ptr: + .long 0 + + .globl uboot_address +uboot_address: + .long 0 + +ret_address: + .long 0 diff --git a/sys/boot/mips/uboot/loader.conf b/sys/boot/mips/uboot/loader.conf new file mode 100644 --- /dev/null +++ b/sys/boot/mips/uboot/loader.conf @@ -0,0 +1,13 @@ +# This is defaults/loader.conf for ARM, containing defaults for loader(8). +# Do not modify the contents of this file, instead put your customizations +# into /boot/loader.conf or /boot/loader.conf.local +# $FreeBSD$ + +autoboot_delay=10 +bootfile="kernel" # Kernel name (possibly absolute path) +kernel="kernel" # /boot sub-directory containing kernel and modules +loader_conf_files="/boot/loader.conf /boot/loader.conf.local" +module_path="/boot/kernel;/boot/modules;/boot/dtb" +nextboot_conf="/boot/nextboot.conf" +nextboot_enable="NO" +verbose_loading="NO" diff --git a/sys/boot/mips/uboot/ldscript.mips b/sys/boot/mips/uboot/ldscript.mips new file mode 100644 --- /dev/null +++ b/sys/boot/mips/uboot/ldscript.mips @@ -0,0 +1,133 @@ +/* $FreeBSD$ */ + +OUTPUT_ARCH(mips) +ENTRY(_start) +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + . = UBLDR_LOADADDR + SIZEOF_HEADERS; + .text : + { + *(.text) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.gnu.linkonce.t*) + } =0 + _etext = .; + PROVIDE (etext = .); + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rela.text : + { *(.rela.text) *(.rela.gnu.linkonce.t*) } + .rela.data : + { *(.rela.data) *(.rela.gnu.linkonce.d*) } + .rela.rodata : + { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } + .rela.got : { *(.rela.got) } + .rela.got1 : { *(.rela.got1) } + .rela.got2 : { *(.rela.got2) } + .rela.ctors : { *(.rela.ctors) } + .rela.dtors : { *(.rela.dtors) } + .rela.init : { *(.rela.init) } + .rela.fini : { *(.rela.fini) } + .rela.bss : { *(.rela.bss) } + .rela.plt : { *(.rela.plt) } + .rela.sdata : { *(.rela.sdata) } + .rela.sbss : { *(.rela.sbss) } + .rela.sdata2 : { *(.rela.sdata2) } + .rela.sbss2 : { *(.rela.sbss2) } + .init : { *(.init) } =0 + .fini : { *(.fini) } =0 + .rodata : { *(.rodata) *(.gnu.linkonce.r*) } + .rodata1 : { *(.rodata1) } + .sdata2 : { *(.sdata2) } + .sbss2 : { *(.sbss2) } + /* Adjust the address for the data segment to the next page up. */ + . = ((. + 0x1000) & ~(0x1000 - 1)); + .data : + { + *(.data) + *(.gnu.linkonce.d*) + CONSTRUCTORS + } + .data1 : { *(.data1) } + .got1 : { *(.got1) } + .dynamic : { *(.dynamic) } + /* Put .ctors and .dtors next to the .got2 section, so that the pointers + get relocated with -mrelocatable. Also put in the .fixup pointers. + The current compiler no longer needs this, but keep it around for 2.7.2 */ + PROVIDE (_GOT2_START_ = .); + .got2 : { *(.got2) } + PROVIDE (__CTOR_LIST__ = .); + .ctors : { *(.ctors) } + PROVIDE (__CTOR_END__ = .); + PROVIDE (__DTOR_LIST__ = .); + .dtors : { *(.dtors) } + PROVIDE (__DTOR_END__ = .); + PROVIDE (_FIXUP_START_ = .); + .fixup : { *(.fixup) } + PROVIDE (_FIXUP_END_ = .); + PROVIDE (_GOT2_END_ = .); + PROVIDE (_GOT_START_ = .); + .got : { *(.got) } + .got.plt : { *(.got.plt) } + PROVIDE (_GOT_END_ = .); + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + .sdata : { *(.sdata) } + _edata = .; + PROVIDE (edata = .); + .sbss : + { + PROVIDE (__sbss_start = .); + *(.sbss) + *(.scommon) + *(.dynsbss) + PROVIDE (__sbss_end = .); + } + .plt : { *(.plt) } + .bss : + { + PROVIDE (__bss_start = .); + *(.dynbss) + *(.bss) + *(COMMON) + } + _end = . ; + PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* These must appear regardless of . */ +} diff --git a/sys/boot/mips/uboot/help.uboot b/sys/boot/mips/uboot/help.uboot new file mode 100644 --- /dev/null +++ b/sys/boot/mips/uboot/help.uboot @@ -0,0 +1,27 @@ +$FreeBSD$ + +############################################################################### +# Tubenv DShow or import U-Boot environment variables + + ubenv <import | show> [varname ...] + + Display U-Boot environment variables, or import them into the + loader environment (which makes them available in the kernel). + +############################################################################### +# Tubenv Simport DImport U-Boot env vars + + ubenv import [varname ...] + + If no variable names are specified, all U-Boot environment + variables are imported. Each variable is prefixed with "uboot." + to avoid any possible conflicts with loader or kernel variables. + +############################################################################### +# Tubenv Sshow DShow U-Boot env vars + + ubenv show [varname ...] + + If no variable names are specified, all U-Boot environment + variables are shown. + diff --git a/sys/boot/mips/uboot/conf.c b/sys/boot/mips/uboot/conf.c new file mode 100644 --- /dev/null +++ b/sys/boot/mips/uboot/conf.c @@ -0,0 +1,110 @@ +/*- + * Copyright (c) 2008 Semihalf, Rafal Jaworowski + * 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$"); + +#include <stand.h> +#include "bootstrap.h" +#include "libuboot.h" + +#if defined(LOADER_NET_SUPPORT) +#include "dev_net.h" +#endif + +struct devsw *devsw[] = { +#if defined(LOADER_DISK_SUPPORT) || defined(LOADER_CD9660_SUPPORT) + &uboot_storage, +#endif +#if defined(LOADER_NET_SUPPORT) + &netdev, +#endif + NULL +}; + +struct fs_ops *file_system[] = { +#if defined(LOADER_UFS_SUPPORT) + &ufs_fsops, +#endif +#if defined(LOADER_CD9660_SUPPORT) + &cd9660_fsops, +#endif +#if defined(LOADER_EXT2FS_SUPPORT) + &ext2fs_fsops, +#endif +#if defined(LOADER_NANDFS_SUPPORT) + &nandfs_fsops, +#endif +#if defined(LOADER_NFS_SUPPORT) + &nfs_fsops, +#endif +#if defined(LOADER_TFTP_SUPPORT) + &tftp_fsops, +#endif +#if defined(LOADER_GZIP_SUPPORT) + &gzipfs_fsops, +#endif +#if defined(LOADER_BZIP2_SUPPORT) + &bzipfs_fsops, +#endif + NULL +}; + +struct netif_driver *netif_drivers[] = { +#if defined(LOADER_NET_SUPPORT) + &uboot_net, +#endif + NULL, +}; + +struct file_format *file_formats[] = { + &uboot_elf, + NULL +}; + +extern struct console uboot_console; + +struct console *consoles[] = { + &uboot_console, + NULL +}; + +void +abort(void) +{ + + printf("error: loader abort\n"); + while (1); +} + +void +longjmperror(void) +{ + + printf("error: loader longjmp error\n"); + while (1); +} diff --git a/sys/boot/mips/uboot/Makefile b/sys/boot/mips/uboot/Makefile new file mode 100644 --- /dev/null +++ b/sys/boot/mips/uboot/Makefile @@ -0,0 +1,171 @@ +# $FreeBSD$ + +.include <src.opts.mk> + +SELF_RELOC?= no + +FILES= ubldr + +NEWVERSWHAT= "U-Boot loader" ${MACHINE_ARCH} +BINDIR?= /boot +INSTALLFLAGS= -b +WARNS?= 1 +# Address at which ubldr will be loaded. +# This varies for different boards and SOCs. +UBLDR_LOADADDR?= 0x80800000 + +# Architecture-specific loader code +SRCS= start.S conf.c vers.c + +.if ${SELF_RELOC} != "no" +FILES+= ubldr.bin +CFLAGS+= -DSUPPORT_SELF_RELOC +SRCS+= self_reloc.c +.endif + +.if !defined(LOADER_NO_DISK_SUPPORT) +LOADER_DISK_SUPPORT?= yes +.else +LOADER_DISK_SUPPORT= no +.endif +LOADER_UFS_SUPPORT?= yes +LOADER_CD9660_SUPPORT?= no +LOADER_EXT2FS_SUPPORT?= no +.if ${MK_NAND} != "no" +LOADER_NANDFS_SUPPORT?= yes +.else +LOADER_NANDFS_SUPPORT?= no +.endif +LOADER_NET_SUPPORT?= yes +LOADER_NFS_SUPPORT?= yes +LOADER_TFTP_SUPPORT?= no +LOADER_GZIP_SUPPORT?= no +LOADER_BZIP2_SUPPORT?= no +.if ${MK_FDT} != "no" +LOADER_FDT_SUPPORT= yes +.else +LOADER_FDT_SUPPORT= no +.endif + +.if ${LOADER_DISK_SUPPORT} == "yes" +CFLAGS+= -DLOADER_DISK_SUPPORT +.endif +.if ${LOADER_UFS_SUPPORT} == "yes" +CFLAGS+= -DLOADER_UFS_SUPPORT +.endif +.if ${LOADER_CD9660_SUPPORT} == "yes" +CFLAGS+= -DLOADER_CD9660_SUPPORT +.endif +.if ${LOADER_EXT2FS_SUPPORT} == "yes" +CFLAGS+= -DLOADER_EXT2FS_SUPPORT +.endif +.if ${LOADER_NANDFS_SUPPORT} == "yes" +CFLAGS+= -DLOADER_NANDFS_SUPPORT +.endif +.if ${LOADER_GZIP_SUPPORT} == "yes" +CFLAGS+= -DLOADER_GZIP_SUPPORT +.endif +.if ${LOADER_BZIP2_SUPPORT} == "yes" +CFLAGS+= -DLOADER_BZIP2_SUPPORT +.endif +.if ${LOADER_NET_SUPPORT} == "yes" +CFLAGS+= -DLOADER_NET_SUPPORT +.endif +.if ${LOADER_NFS_SUPPORT} == "yes" +CFLAGS+= -DLOADER_NFS_SUPPORT +.endif +.if ${LOADER_TFTP_SUPPORT} == "yes" +CFLAGS+= -DLOADER_TFTP_SUPPORT +.endif +.if ${LOADER_FDT_SUPPORT} == "yes" +CFLAGS+= -I${.CURDIR}/../../fdt +CFLAGS+= -I${.OBJDIR}/../../fdt +CFLAGS+= -DLOADER_FDT_SUPPORT +LIBUBOOT_FDT= ${.OBJDIR}/../../uboot/fdt/libuboot_fdt.a +LIBFDT= ${.OBJDIR}/../../fdt/libfdt.a +.endif + +CFLAGS+= -DNETIF_OPEN_CLOSE_ONCE + +.if ${MK_FORTH} != "no" +# Enable BootForth +BOOT_FORTH= yes +CFLAGS+= -DBOOT_FORTH -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/mips +LIBFICL= ${.OBJDIR}/../../ficl/libficl.a +.endif + +# Always add MI sources +.PATH: ${.CURDIR}/../../common +.include "${.CURDIR}/../../common/Makefile.inc" +CFLAGS+= -I${.CURDIR}/../../common +CFLAGS+= -I. + +CLEANFILES+= vers.c loader.help + +CFLAGS+= -ffreestanding -msoft-float + +LDFLAGS= -nostdlib -static -T ${.CURDIR}/ldscript.${MACHINE_CPUARCH} + +# Pull in common loader code +.PATH: ${.CURDIR}/../../uboot/common +.include "${.CURDIR}/../../uboot/common/Makefile.inc" +CFLAGS+= -I${.CURDIR}/../../uboot/common + +# U-Boot standalone support library +LIBUBOOT= ${.OBJDIR}/../../uboot/lib/libuboot.a +CFLAGS+= -I${.CURDIR}/../../uboot/lib +CFLAGS+= -I${.OBJDIR}/../../uboot/lib + +# where to get libstand from +CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ + +# clang doesn't understand %D as a specifier to printf +NO_WERROR.clang= +NO_WERROR= + +DPADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBUBOOT_FDT} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBUBOOT_FDT} -lstand + +OBJS+= ${SRCS:N*.h:R:S/$/.o/g} + +vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version + sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} + +loader.help: help.common help.uboot ${.CURDIR}/../../fdt/help.fdt + cat ${.ALLSRC} | \ + awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} + +ldscript.abs: + echo "UBLDR_LOADADDR = ${UBLDR_LOADADDR};" >${.TARGET} + +ldscript.pie: + echo "UBLDR_LOADADDR = 0;" >${.TARGET} + +ubldr: ${OBJS} ldscript.abs ${.CURDIR}/ldscript.${MACHINE_CPUARCH} ${DPADD} + ${CC} ${CFLAGS} -T ldscript.abs ${LDFLAGS} \ + -o ${.TARGET} ${OBJS} ${LDADD} + +.if ${SELF_RELOC} != "no" +ubldr.pie: ${OBJS} ldscript.pie ${.CURDIR}/ldscript.${MACHINE_CPUARCH} ${DPADD} + ${CC} ${CFLAGS} -T ldscript.pie ${LDFLAGS} -pie -Wl,-Bsymbolic \ + -o ${.TARGET} ${OBJS} ${LDADD} + +ubldr.bin: ubldr.pie + ${OBJCOPY} -S -O binary ubldr.pie ${.TARGET} +.endif + +CLEANFILES+= ldscript.abs ldscript.pie ubldr ubldr.pie ubldr.bin + +.if !defined(LOADER_ONLY) +.PATH: ${.CURDIR}/../../forth +.include "${.CURDIR}/../../forth/Makefile.inc" + +# Install loader.rc. +FILES+= loader.rc +# Put sample menu.rc on disk but don't enable it by default. +FILES+= menu.rc +FILESNAME_menu.rc= menu.rc.sample +.endif + +.include <bsd.stand.mk> +.include <bsd.prog.mk> diff --git a/sys/boot/mips/Makefile b/sys/boot/mips/Makefile --- a/sys/boot/mips/Makefile +++ b/sys/boot/mips/Makefile @@ -1,12 +1,14 @@ # $FreeBSD$ +SUBDIR= uboot + # # The BERI boot loader port works only on 64-bit MIPS; not a hard port to # 32-bit if someone is interested. Build on all 64-bit MIPS platforms to # ensure it gets adequate build-test coverage. # .if ${MACHINE_ARCH} == "mips64" -SUBDIR= beri +SUBDIR+= beri .endif .include <bsd.subdir.mk> diff --git a/sys/boot/ficl/Makefile b/sys/boot/ficl/Makefile --- a/sys/boot/ficl/Makefile +++ b/sys/boot/ficl/Makefile @@ -7,6 +7,8 @@ .PATH: ${FICLDIR}/${MACHINE_CPUARCH:S/amd64/i386/} .elif ${MACHINE_ARCH} == "mips64" || ${MACHINE_ARCH} == "mips64el" .PATH: ${FICLDIR}/mips64 +.elif ${MACHINE_ARCH} == "mips32" || ${MACHINE_ARCH} == "mips32el" +.PATH: ${FICLDIR}/mips .else .PATH: ${FICLDIR}/${MACHINE_CPUARCH} .endif diff --git a/sys/boot/fdt/Makefile b/sys/boot/fdt/Makefile --- a/sys/boot/fdt/Makefile +++ b/sys/boot/fdt/Makefile @@ -26,4 +26,5 @@ CFLAGS+= -Wformat -Wall +.include <bsd.stand.mk> .include <bsd.lib.mk> diff --git a/sys/boot/common/self_reloc.c b/sys/boot/common/self_reloc.c --- a/sys/boot/common/self_reloc.c +++ b/sys/boot/common/self_reloc.c @@ -36,7 +36,7 @@ #define ElfW_Dyn Elf64_Dyn #define ELFW_R_TYPE ELF64_R_TYPE #define ELF_RELA -#elif defined(__arm__) || defined(__i386__) +#elif defined(__arm__) || defined(__i386__) || defined(__mips__) #define ElfW_Rel Elf32_Rel #define ElfW_Dyn Elf32_Dyn #define ELFW_R_TYPE ELF32_R_TYPE @@ -56,6 +56,9 @@ #elif defined(__arm__) #define RELOC_TYPE_NONE R_ARM_NONE #define RELOC_TYPE_RELATIVE R_ARM_RELATIVE +#elif defined(__mips__) +#define RELOC_TYPE_NONE R_MIPS_NONE +#define RELOC_TYPE_RELATIVE R_MIPS_REL #elif defined(__i386__) #define RELOC_TYPE_NONE R_386_NONE #define RELOC_TYPE_RELATIVE R_386_RELATIVE diff --git a/sys/boot/common/Makefile.inc b/sys/boot/common/Makefile.inc --- a/sys/boot/common/Makefile.inc +++ b/sys/boot/common/Makefile.inc @@ -20,6 +20,8 @@ SRCS+= load_elf64.c reloc_elf64.c .elif ${MACHINE_ARCH} == "mips64" || ${MACHINE_ARCH} == "mips64el" SRCS+= load_elf64.c reloc_elf64.c +.elif ${MACHINE_ARCH} == "mips" || ${MACHINE_ARCH} == "mipsel" +SRCS+= load_elf32.c reloc_elf32.c .endif .if defined(LOADER_NET_SUPPORT) diff --git a/sys/boot/Makefile.mips b/sys/boot/Makefile.mips --- a/sys/boot/Makefile.mips +++ b/sys/boot/Makefile.mips @@ -3,3 +3,5 @@ .if ${MK_FDT} != "no" SUBDIR+= fdt .endif + +SUBDIR+= uboot
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?differential-rev-PHID-DREV-lydkabzwr6zbaqctozb5-req>
