Skip to content

Commit

Permalink
Initial support of loader(8) for ARM machines running U-Boot.
Browse files Browse the repository at this point in the history
This uses the common U-Boot support lib (sys/boot/uboot, already used on
FreeBSD/powerpc), and assumes the underlying firmware has the modern API for
stand-alone apps enabled in the config (CONFIG_API).

Only netbooting is supported at the moment.

Obtained from:	Marvell, Semihalf
  • Loading branch information
raj authored and raj committed Oct 14, 2008
1 parent 556a646 commit 745c5c7
Show file tree
Hide file tree
Showing 15 changed files with 518 additions and 7 deletions.
9 changes: 9 additions & 0 deletions sys/arm/arm/locore.S
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ __FBSDID("$FreeBSD$");
ENTRY_NP(btext)

ASENTRY_NP(_start)

/*
* Move metadata ptr to r12 (ip)
*/

mov ip, r0

#if defined (FLASHADDR) && defined(LOADERRAMADDR)
/* Check if we're running from flash. */
ldr r7, =FLASHADDR
Expand Down Expand Up @@ -170,6 +177,8 @@ mmu_done:
ldr pc, .Lvirt_done

virt_done:
mov r0, ip /* Load argument: metadata ptr */

mov fp, #0 /* trace back starts here */
bl _C_LABEL(initarm) /* Off we go */

Expand Down
72 changes: 72 additions & 0 deletions sys/arm/include/bootinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*-
* Copyright (C) 2006-2008 Semihalf, Marian Balakowicz <m8@semihalf.com>
* 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 ``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 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$
*/

#ifndef _MACHINE_BOOTINFO_H_
#define _MACHINE_BOOTINFO_H_

#if !defined(LOCORE)

/* Platform hardware spec, received from loader(8) */

#define BI_VERSION 1

struct bi_mem_region {
vm_paddr_t mem_base;
vm_size_t mem_size;
};

struct bi_eth_addr {
u_int8_t mac_addr[6];
u_int8_t padding[2];
};

struct bootinfo {
u_int32_t bi_version;
vm_offset_t bi_bar_base;
u_int32_t bi_cpu_clk;
u_int32_t bi_bus_clk;
u_int8_t bi_mem_reg_no;
u_int8_t bi_eth_addr_no;
u_int8_t padding[2];

u_int8_t bi_data[1];
/*
* The bi_data container is allocated in run time and has the
* following layout:
*
* - bi_mem_reg_no elements of struct bi_mem_region
* - bi_eth_addr_no elements of struct bi_eth_addr
*/
};

extern struct bootinfo *bootinfo;

struct bi_mem_region *bootinfo_mr(void);
struct bi_eth_addr *bootinfo_eth(void);
#endif

#endif /* _MACHINE_BOOTINFO_H_ */
2 changes: 1 addition & 1 deletion sys/arm/include/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
#ifndef _MACHINE_METADATA_H_
#define _MACHINE_METADATA_H_

#define MODINFOMD_SMAP 0x1001
#define MODINFOMD_BOOTINFO 0x1001

#endif /* !_MACHINE_METADATA_H_ */
2 changes: 1 addition & 1 deletion sys/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SUBDIR+= ofw
.endif

# Build U-Boot library.
.if ${MACHINE_ARCH} == "powerpc"
.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "arm"
SUBDIR+= uboot
.endif

Expand Down
2 changes: 1 addition & 1 deletion sys/boot/arm/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# $FreeBSD$

SUBDIR=
SUBDIR= uboot

.include <bsd.subdir.mk>
96 changes: 96 additions & 0 deletions sys/boot/arm/uboot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# $FreeBSD$

PROG= ubldr
NEWVERSWHAT= "U-Boot loader" ${MACHINE_ARCH}
BINDIR?= /boot
INSTALLFLAGS= -b
NO_MAN=
WARNS?= 1

# Architecture-specific loader code
SRCS= start.S conf.c vers.c

LOADER_DISK_SUPPORT?= no
LOADER_UFS_SUPPORT?= no
LOADER_CD9660_SUPPORT?= no
LOADER_EXT2FS_SUPPORT?= no
LOADER_NET_SUPPORT?= yes
LOADER_NFS_SUPPORT?= yes
LOADER_TFTP_SUPPORT?= no
LOADER_GZIP_SUPPORT?= no
LOADER_BZIP2_SUPPORT?= no

.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_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 !defined(NO_FORTH)
# Enable BootForth
BOOT_FORTH= yes
CFLAGS+= -DBOOT_FORTH -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/arm
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 ${PROG}.help

CFLAGS+= -ffreestanding

LDFLAGS= -nostdlib -static -T ${.CURDIR}/ldscript.arm

# 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/

DPADD= ${LIBFICL} ${LIBUBOOT} ${LIBSTAND}
LDADD= ${LIBFICL} ${LIBUBOOT} -lstand

vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}

${PROG}.help: help.common help.uboot
cat ${.ALLSRC} | \
awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET}

.PATH: ${.CURDIR}/../../forth
FILES= ${PROG}.help

.include <bsd.prog.mk>
91 changes: 91 additions & 0 deletions sys/boot/arm/uboot/conf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*-
* 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_disk,
#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_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
};
1 change: 1 addition & 0 deletions sys/boot/arm/uboot/help.uboot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$FreeBSD$
Loading

0 comments on commit 745c5c7

Please sign in to comment.