Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Apr 2015 19:40:12 +0000 (UTC)
From:      Luiz Otavio O Souza <loos@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r384677 - in head/sysutils: . u-boot-rpi2 u-boot-rpi2/files
Message-ID:  <201504241940.t3OJeCeI075706@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: loos (src committer)
Date: Fri Apr 24 19:40:12 2015
New Revision: 384677
URL: https://svnweb.freebsd.org/changeset/ports/384677

Log:
  U-Boot loader and related files for Raspberry Pi 2
  
  To install this bootloader, copy ALL the files in the share/u-boot/u-boot-rpi2
  directory to the first partition, formatted as FAT32, on an SD card.
  
  This version is patched so that:
   * ELF and API features are enabled.
   * The default environment is trimmed to just what's needed to boot.
   * The saveenv command writes to the file uboot.env on the FAT partition.
  
  For information about running FreeBSD on RaspberryPi, see
  WWW: http://wiki.freebsd.org/FreeBSD/arm/Raspberry%20Pi
  
  For general information about U-Boot see WWW: http://www.denx.de/wiki/U-Boot
  
  Approved by:	garga

Added:
  head/sysutils/u-boot-rpi2/
  head/sysutils/u-boot-rpi2/Makefile   (contents, props changed)
  head/sysutils/u-boot-rpi2/distinfo   (contents, props changed)
  head/sysutils/u-boot-rpi2/files/
  head/sysutils/u-boot-rpi2/files/patch-api_api.c   (contents, props changed)
  head/sysutils/u-boot-rpi2/files/patch-api_api__storage.c   (contents, props changed)
  head/sysutils/u-boot-rpi2/files/patch-common_cmd__elf.c   (contents, props changed)
  head/sysutils/u-boot-rpi2/files/patch-common_cmd__fdt.c   (contents, props changed)
  head/sysutils/u-boot-rpi2/files/patch-common_cmd__nvedit.c   (contents, props changed)
  head/sysutils/u-boot-rpi2/files/patch-common_cmd__test.c   (contents, props changed)
  head/sysutils/u-boot-rpi2/files/patch-drivers_mmc_mmc.c   (contents, props changed)
  head/sysutils/u-boot-rpi2/files/patch-include_configs_rpi__common.h   (contents, props changed)
  head/sysutils/u-boot-rpi2/pkg-descr   (contents, props changed)
Modified:
  head/sysutils/Makefile

Modified: head/sysutils/Makefile
==============================================================================
--- head/sysutils/Makefile	Fri Apr 24 19:34:19 2015	(r384676)
+++ head/sysutils/Makefile	Fri Apr 24 19:40:12 2015	(r384677)
@@ -979,6 +979,7 @@
     SUBDIR += u-boot-duovero
     SUBDIR += u-boot-pandaboard
     SUBDIR += u-boot-rpi
+    SUBDIR += u-boot-rpi2
     SUBDIR += u-boot-wandboard
     SUBDIR += ua
     SUBDIR += ucspi-ipc

Added: head/sysutils/u-boot-rpi2/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/Makefile	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,58 @@
+# $FreeBSD$
+
+PORTNAME=	u-boot
+PORTVERSION=	2015.04
+CATEGORIES=	sysutils
+MASTER_SITES=	ftp://ftp.denx.de/pub/u-boot/ \
+		LOCAL/loos/rpi2-boot-files:bootfiles
+PKGNAMESUFFIX=	-rpi2
+DISTFILES=	u-boot-${PORTVERSION}.tar.bz2 \
+		rpi2-boot-files-2015.04.tar.bz2:bootfiles
+
+MAINTAINER=	loos@FreeBSD.org
+COMMENT=	Cross-build U-Boot loader for Raspberry Pi 2
+
+LICENSE=	GPLv2
+
+BUILD_DEPENDS=	arm-none-eabi-gcc:${PORTSDIR}/devel/arm-none-eabi-gcc
+
+NO_ARCH=	yes
+
+WRKSRC=		${WRKDIR}/u-boot-${DISTVERSION}
+USES=		gmake tar:bzip2
+SSP_UNSAFE=	yes # cross-LD does not support -fstack-protector
+
+WRK_BOOTFILES=	${WRKDIR}/rpi2-boot-files
+
+U_BOOT_DIR=	share/u-boot/${PORTNAME}${PKGNAMESUFFIX}
+PLIST_FILES=	${U_BOOT_DIR}/u-boot.bin \
+		${U_BOOT_DIR}/README \
+		${U_BOOT_DIR}/bootcode.bin \
+		${U_BOOT_DIR}/fixup.dat \
+		${U_BOOT_DIR}/fixup_cd.dat \
+		${U_BOOT_DIR}/fixup_x.dat \
+		${U_BOOT_DIR}/start.elf \
+		${U_BOOT_DIR}/start_cd.elf \
+		${U_BOOT_DIR}/start_x.elf \
+		${U_BOOT_DIR}/config.txt \
+		${U_BOOT_DIR}/LICENCE.broadcom
+
+MAKE_ARGS+=	ARCH=arm \
+		CROSS_COMPILE=arm-none-eabi-
+
+do-configure:
+	(cd ${WRKSRC}; ${GMAKE} rpi_2_defconfig)
+
+# The output of the u-boot build process is u-boot.bin.  Older firmware
+# versions require a standard header, but the recent versions (our case)
+# are capable of booting u-boot.bin directly.  Also copy the entire
+# contents of the bootfiles distribution (these are proprietary binary
+# files required to boot).
+IMGFILE=${STAGEDIR}/${PREFIX}/${U_BOOT_DIR}/u-boot.img
+do-install:
+	${MKDIR} ${STAGEDIR}/${PREFIX}/${U_BOOT_DIR}
+	${CP} ${WRKSRC}/u-boot.bin ${STAGEDIR}/${PREFIX}/${U_BOOT_DIR}/
+	${CP} ${DESCR} ${STAGEDIR}/${PREFIX}/${U_BOOT_DIR}/README
+	${CP} ${WRK_BOOTFILES}/* ${STAGEDIR}/${PREFIX}/${U_BOOT_DIR}/
+
+.include <bsd.port.mk>

Added: head/sysutils/u-boot-rpi2/distinfo
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/distinfo	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,4 @@
+SHA256 (u-boot-2015.04.tar.bz2) = 0a1a70df586655f527befa6f12e184e96ed61b126e5a567382321b17200f5d60
+SIZE (u-boot-2015.04.tar.bz2) = 9471487
+SHA256 (rpi2-boot-files-2015.04.tar.bz2) = 3bf315837492c63ce3bd13dbe8f63fd54a3bc9b611bf5cf2d0a79e0e716e16bb
+SIZE (rpi2-boot-files-2015.04.tar.bz2) = 4106827

Added: head/sysutils/u-boot-rpi2/files/patch-api_api.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/files/patch-api_api.c	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,79 @@
+--- api/api.c.orig	2014-10-14 08:47:15 UTC
++++ api/api.c
+@@ -495,45 +495,47 @@ static int API_env_set(va_list ap)
+  */
+ static int API_env_enum(va_list ap)
+ {
+-	int i, n;
+-	char *last, **next;
++	int i;
++	char *last, **next, *s;
++	ENTRY *match, search;
++	static char *buf;
+ 
+ 	last = (char *)va_arg(ap, u_int32_t);
+ 
+ 	if ((next = (char **)va_arg(ap, u_int32_t)) == NULL)
+ 		return API_EINVAL;
+ 
+-	if (last == NULL)
+-		/* start over */
+-		*next = ((char *)env_get_addr(0));
+-	else {
+-		*next = last;
+-
+-		for (i = 0; env_get_char(i) != '\0'; i = n + 1) {
+-			for (n = i; env_get_char(n) != '\0'; ++n) {
+-				if (n >= CONFIG_ENV_SIZE) {
+-					/* XXX shouldn't we set *next = NULL?? */
+-					return 0;
+-				}
+-			}
+-
+-			if (envmatch((uchar *)last, i) < 0)
+-				continue;
+-
+-			/* try to get next name */
+-			i = n + 1;
+-			if (env_get_char(i) == '\0') {
+-				/* no more left */
+-				*next = NULL;
+-				return 0;
+-			}
+-
+-			*next = ((char *)env_get_addr(i));
+-			return 0;
++	/*
++	 * This leverages realloc's behavior of growing but never shrinking the
++	 * existing buffer.
++	 */
++	if (last == NULL) {
++		i = 0;
++		buf = realloc(buf, 512); /* Start with reasonable size buf. */
++	} else {
++		buf = realloc(buf, strlen(last) + 1);
++		strcpy(buf, last);
++		if ((s = strchr(buf, '=')) != NULL)
++		     *s = 0;
++		search.key = buf;
++		if ((i = hsearch_r(search, FIND, &match, &env_htab, 0)) == 0) {
++			i = API_EINVAL;
++			goto done;
+ 		}
+ 	}
+ 
++	/* hmatch on empty string is effectively "get next entry after i". */
++	if ((i = hmatch_r("", i, &match, &env_htab)) == 0)
++		goto done;
++	buf = realloc(buf, strlen(match->key) + strlen(match->data) + 2);
++	snprintf(buf, buflen, "%s=%s", match->key, match->data);
++	*next = buf;
+ 	return 0;
++done:
++	free(buf);
++	buf = NULL;
++	*next = NULL;
++	return i;
+ }
+ 
+ /*

Added: head/sysutils/u-boot-rpi2/files/patch-api_api__storage.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/files/patch-api_api__storage.c	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,28 @@
+--- api/api_storage.c.orig	2014-10-14 08:47:15 UTC
++++ api/api_storage.c
+@@ -107,10 +107,13 @@ static int dev_stor_get(int type, int fi
+ 
+ 	if (first) {
+ 		di->cookie = (void *)get_dev(specs[type].name, 0);
+-		if (di->cookie == NULL)
++		if (di->cookie == NULL) {
+ 			return 0;
+-		else
++		} else {
+ 			found = 1;
++			if (specs[type].max_dev > 1)
++				*more = 1;
++		}
+ 
+ 	} else {
+ 		for (i = 0; i < specs[type].max_dev; i++)
+@@ -146,7 +149,8 @@ static int dev_stor_get(int type, int fi
+ 			dd = (block_dev_desc_t *)di->cookie;
+ 			if (dd->type == DEV_TYPE_UNKNOWN) {
+ 				debugf("device instance exists, but is not active..");
+-				found = 0;
++				di->di_stor.block_count = 0;
++				di->di_stor.block_size = 0;
+ 			} else {
+ 				di->di_stor.block_count = dd->lba;
+ 				di->di_stor.block_size = dd->blksz;

Added: head/sysutils/u-boot-rpi2/files/patch-common_cmd__elf.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/files/patch-common_cmd__elf.c	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,29 @@
+--- common/cmd_elf.c.orig	2014-10-14 08:47:15 UTC
++++ common/cmd_elf.c
+@@ -35,22 +35,12 @@ unsigned long do_bootelf_exec(ulong (*en
+ 	unsigned long ret;
+ 
+ 	/*
+-	 * QNX images require the data cache is disabled.
+-	 * Data cache is already flushed, so just turn it off.
+-	 */
+-	int dcache = dcache_status();
+-	if (dcache)
+-		dcache_disable();
+-
+-	/*
+-	 * pass address parameter as argv[0] (aka command name),
+-	 * and all remaining args
++	 * FreeBSD wants the caches enabled while ubldr runs, and as of r276397
++	 * the kernel can tolerate being entered with internal (but not external
++	 * PL310) caches enabled on armv6/7 systems.  So don't disable caches
++	 * here, just launch the program directly.
+ 	 */
+ 	ret = entry(argc, argv);
+-
+-	if (dcache)
+-		dcache_enable();
+-
+ 	return ret;
+ }
+ 

Added: head/sysutils/u-boot-rpi2/files/patch-common_cmd__fdt.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/files/patch-common_cmd__fdt.c	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,11 @@
+--- common/cmd_fdt.c.orig	2015-04-23 20:55:46.193272000 -0300
++++ common/cmd_fdt.c
+@@ -44,7 +44,7 @@
+ 
+ 	buf = map_sysmem(addr, 0);
+ 	working_fdt = buf;
+-	setenv_ulong("fdtaddr", addr);
++	setenv_hex("fdtaddr", addr);
+ }
+ 
+ /*

Added: head/sysutils/u-boot-rpi2/files/patch-common_cmd__nvedit.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/files/patch-common_cmd__nvedit.c	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,11 @@
+--- common/cmd_nvedit.c.orig	2015-04-24 11:11:51.572065000 -0300
++++ common/cmd_nvedit.c
+@@ -321,7 +321,7 @@
+ {
+ 	char str[17];
+ 
+-	sprintf(str, "%lx", value);
++	sprintf(str, "%#lx", value);
+ 	return setenv(varname, str);
+ }
+ 

Added: head/sysutils/u-boot-rpi2/files/patch-common_cmd__test.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/files/patch-common_cmd__test.c	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,19 @@
+--- common/cmd_test.c.orig	2014-10-14 08:47:15 UTC
++++ common/cmd_test.c
+@@ -65,9 +65,14 @@ static int do_test(cmd_tbl_t *cmdtp, int
+ 	char * const *ap;
+ 	int i, op, left, adv, expr, last_expr, last_unop, last_binop;
+ 
+-	/* args? */
+-	if (argc < 3)
++	/*
++	 * If no args, that's bogus, return false.
++	 * If op is -z and no other args, answer is Yes, string is empty.
++	 */
++	if (argc < 2)
+ 		return 1;
++	else if (argc == 2)
++		return !(strcmp(argv[1], "-z") == 0);
+ 
+ #ifdef DEBUG
+ 	{

Added: head/sysutils/u-boot-rpi2/files/patch-drivers_mmc_mmc.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/files/patch-drivers_mmc_mmc.c	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,80 @@
+--- drivers/mmc/mmc.c.orig	2014-10-14 08:47:15 UTC
++++ drivers/mmc/mmc.c
+@@ -20,6 +20,7 @@
+ 
+ static struct list_head mmc_devices;
+ static int cur_dev_num = -1;
++static int mmc_error_print_max = -1;
+ 
+ __weak int board_mmc_getwp(struct mmc *mmc)
+ {
+@@ -1270,9 +1271,14 @@ void mmc_destroy(struct mmc *mmc)
+ block_dev_desc_t *mmc_get_dev(int dev)
+ {
+ 	struct mmc *mmc = find_mmc_device(dev);
+-	if (!mmc || mmc_init(mmc))
++	if (!mmc)
+ 		return NULL;
+ 
++	/* If mmc_init fails, mmc->block_dev will be of type
++	 * DEV_TYPE_UNKNOWN with blksz and lba set to zero.
++	 */
++	mmc_init(mmc);
++
+ 	return &mmc->block_dev;
+ }
+ #endif
+@@ -1297,7 +1303,7 @@ int mmc_start_init(struct mmc *mmc)
+ 	err = mmc->cfg->ops->init(mmc);
+ 
+ 	if (err)
+-		return err;
++		goto done;
+ 
+ 	mmc_set_bus_width(mmc, 1);
+ 	mmc_set_clock(mmc, 1);
+@@ -1306,7 +1312,7 @@ int mmc_start_init(struct mmc *mmc)
+ 	err = mmc_go_idle(mmc);
+ 
+ 	if (err)
+-		return err;
++		goto done;
+ 
+ 	/* The internal partition reset to user partition(0) at every CMD0*/
+ 	mmc->part_num = 0;
+@@ -1323,15 +1329,33 @@ int mmc_start_init(struct mmc *mmc)
+ 
+ 		if (err && err != IN_PROGRESS) {
+ #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
+-			printf("Card did not respond to voltage select!\n");
++			if (mmc_error_print_max < 4) {
++				mmc_error_print_max++;
++				printf("Card did not respond to voltage select!\n");
++
++				if (mmc_error_print_max == 4) {
++					printf("Discarding further error messages\n");
++				}
++			}
+ #endif
+-			return UNUSABLE_ERR;
++//			return UNUSABLE_ERR;
++			goto done;
+ 		}
+ 	}
+ 
+ 	if (err == IN_PROGRESS)
+ 		mmc->init_in_progress = 1;
+ 
++done:
++	if (err) {
++		mmc->has_init = 0;
++		mmc->block_dev.type = DEV_TYPE_UNKNOWN;
++		mmc->block_dev.blksz = 0;
++		mmc->block_dev.lba = 0;
++	} else {
++		mmc->has_init = 1;
++	}
++
+ 	return err;
+ }
+ 

Added: head/sysutils/u-boot-rpi2/files/patch-include_configs_rpi__common.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/files/patch-include_configs_rpi__common.h	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,66 @@
+--- include/configs/rpi-common.h.orig	2015-04-13 11:53:03.000000000 -0300
++++ include/configs/rpi-common.h
+@@ -183,4 +183,63 @@
+ 
+ #define CONFIG_BOOTDELAY 2
+ 
++/*****************************************************************************
++ * FreeBSD customizations from here down.
++ ****************************************************************************/
++
++/* Add the API and ELF features needed for ubldr. */
++#ifndef CONFIG_SPL_BUILD
++#define CONFIG_API
++#define CONFIG_CMD_ELF
++#define CONFIG_CMD_ENV_EXISTS
++#define CONFIG_EFI_PARTITION
++#endif
++
++/* Turn off dcache. */
++#ifndef CONFIG_SPL_BUILD
++#define CONFIG_SYS_DCACHE_OFF
++#define CONFIG_CMD_CACHE
++#endif
++
++#ifndef CONFIG_SPL_BUILD
++#define CONFIG_SYS_MMC_MAX_DEVICE	1
++#endif
++
++/* Create a small(ish) boot environment for FreeBSD. */
++#ifndef CONFIG_SPL_BUILD
++#undef  CONFIG_EXTRA_ENV_SETTINGS
++#define CONFIG_EXTRA_ENV_SETTINGS \
++	ENV_DEVICE_SETTINGS \
++	"loadaddr=0x02000000\0" \
++	"scriptaddr=0x00000000\0" \
++	"pxefile_addr_r=0x00100000\0" \
++	"kernel_addr_r=0x01000000\0" \
++	"ramdisk_addr_r=0x02100000\0" \
++	"Fatboot=" \
++	  "env exists loaderdev || env set loaderdev ${fatdev}; " \
++	  "env exists UserFatboot && run UserFatboot; " \
++	  "echo Booting from: ${fatdev} ${bootfile}; " \
++	  "fatload ${fatdev} ${loadaddr} ${bootfile} && bootelf ${loadaddr}; " \
++	"\0" \
++	"Netboot=" \
++	  "env exists ethact || usb start; " \
++	  "env exists loaderdev || env set loaderdev net; " \
++	  "env exists UserNetboot && run UserNetboot; " \
++	  "dhcp ${loadaddr} ${bootfile} && bootelf ${loadaddr}; " \
++	"\0" \
++	"preboot=" \
++	  "fdt addr 0x100; " \
++	  "env exists bootfile || env set bootfile ubldr; " \
++	  "env exists SetupFatdev && run SetupFatdev; " \
++	  "env exists UserPreboot && run UserPreboot; " \
++	"\0" \
++	"SetupFatdev=" \
++	  "env exists fatdev || env set fatdev 'mmc 0'; " \
++	"\0"
++#undef  CONFIG_BOOTCOMMAND
++#define CONFIG_BOOTCOMMAND     "run Fatboot"
++#undef  CONFIG_PREBOOT
++#define CONFIG_PREBOOT         "run preboot"
++#endif
++
+ #endif

Added: head/sysutils/u-boot-rpi2/pkg-descr
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/u-boot-rpi2/pkg-descr	Fri Apr 24 19:40:12 2015	(r384677)
@@ -0,0 +1,14 @@
+U-Boot loader and related files for Raspberry Pi 2
+
+To install this bootloader, copy ALL the files in the share/u-boot/u-boot-rpi2
+directory to the first partition, formatted as FAT32, on an SD card.
+
+This version is patched so that:
+ * ELF and API features are enabled.
+ * The default environment is trimmed to just what's needed to boot.
+ * The saveenv command writes to the file uboot.env on the FAT partition.
+
+For information about running FreeBSD on RaspberryPi, see
+WWW: http://wiki.freebsd.org/FreeBSD/arm/Raspberry%20Pi
+
+For general information about U-Boot see WWW: http://www.denx.de/wiki/U-Boot



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504241940.t3OJeCeI075706>