Index: sysutils/u-boot-master/Makefile =================================================================== --- sysutils/u-boot-master/Makefile +++ sysutils/u-boot-master/Makefile @@ -61,6 +61,9 @@ UBOOT_PLIST_ZYNQ_7000=u-boot.img boot.bin uEnv.txt UBOOT_MOVE_ZYNQ_7000=${WRKSRC}/spl/boot.bin ${.CURDIR}/files/uEnv.txt +# Overrides for RPI family +UBOOT_PLIST_RPI= u-boot.bin + # Uboot variables .if !defined(UBOOT_VERSION) && defined(UBOOT_VERSION_${FAMILY:tu}) UBOOT_VERSION=${UBOOT_VERSION_${FAMILY:tu}} Index: sysutils/u-boot-rpi/Makefile =================================================================== --- sysutils/u-boot-rpi/Makefile +++ sysutils/u-boot-rpi/Makefile @@ -1,60 +1,12 @@ # $FreeBSD$ -PORTNAME= u-boot -PORTVERSION= 2016.01 -PORTREVISION= 1 -CATEGORIES= sysutils -MASTER_SITES= ftp://ftp.denx.de/pub/u-boot/ \ - LOCAL/ian/:bootfiles -PKGNAMESUFFIX= -rpi -DISTFILES= ${DISTNAME}${EXTRACT_SUFX} \ - rpi-boot-files-2016.01.tar.bz2:bootfiles +MAINTAINER= manu@FreeBSD.org +MASTERDIR= ${.CURDIR}/../u-boot-master -MAINTAINER= ian@FreeBSD.org -COMMENT= Cross-build U-Boot loader for Raspberry Pi +MODEL= rpi +BOARD_CONFIG= rpi_defconfig +FAMILY= rpi -LICENSE= GPLv2 +DEPENDS= ${LOCALBASE}/share/rpi-firmware/bootcode.bin:sysutils/rpi-firmware -BUILD_DEPENDS= arm-none-eabi-gcc:devel/arm-none-eabi-gcc - -NO_ARCH= yes - -USES= gmake tar:bzip2 -SSP_UNSAFE= yes # cross-LD does not support -fstack-protector - -WRK_BOOTFILES= ${WRKDIR}/rpi-boot-files - -U_BOOT_DIR= share/u-boot/${PORTNAME}${PKGNAMESUFFIX} -PLIST_FILES= ${U_BOOT_DIR}/u-boot.img \ - ${U_BOOT_DIR}/LICENCE.broadcom \ - ${U_BOOT_DIR}/README-BootDetails \ - ${U_BOOT_DIR}/bootcode.bin \ - ${U_BOOT_DIR}/config.txt \ - ${U_BOOT_DIR}/fixup.dat \ - ${U_BOOT_DIR}/fixup_cd.dat \ - ${U_BOOT_DIR}/fixup_db.dat \ - ${U_BOOT_DIR}/fixup_x.dat \ - ${U_BOOT_DIR}/start.elf \ - ${U_BOOT_DIR}/start_cd.elf - -MAKE_ARGS+= ARCH=arm \ - CROSS_COMPILE=arm-none-eabi- - -post-patch: - @${LN} -sf compiler-gcc5.h ${WRKSRC}/include/linux/compiler-gcc6.h - -do-configure: - (cd ${WRKSRC}; ${MAKE_CMD} rpi_defconfig) - -# The output of the u-boot build process is u-boot.bin. We have to put a -# standard (for the RPi) image header on the front of it, and the resulting -# file is named u-boot.img. 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} - ${GZCAT} ${FILESDIR}/imgprefix.bin.gz >${IMGFILE} - ${CAT} ${WRKSRC}/u-boot.bin >>${IMGFILE} - ${INSTALL_DATA} ${WRK_BOOTFILES}/* ${STAGEDIR}/${PREFIX}/${U_BOOT_DIR} - -.include +.include "${MASTERDIR}/Makefile" Index: sysutils/u-boot-rpi/distinfo =================================================================== --- sysutils/u-boot-rpi/distinfo +++ /dev/null @@ -1,4 +0,0 @@ -SHA256 (u-boot-2016.01.tar.bz2) = e5792fba9399d9804aa2ef667f14ff771e2cdece72367d340250265bf095a5d5 -SIZE (u-boot-2016.01.tar.bz2) = 10602974 -SHA256 (rpi-boot-files-2016.01.tar.bz2) = d912abb1e91a1f38f7fa62cbf2202e8279a832106b15a76c30989ce36a04aea7 -SIZE (rpi-boot-files-2016.01.tar.bz2) = 2006903 Index: sysutils/u-boot-rpi/files/patch-api_api.c =================================================================== --- sysutils/u-boot-rpi/files/patch-api_api.c +++ /dev/null @@ -1,94 +0,0 @@ ---- api/api.c.orig 2015-08-05 16:53:17 UTC -+++ api/api.c -@@ -290,6 +290,14 @@ static int API_dev_close(va_list ap) - if (!err) - di->state = DEV_STA_CLOSED; - -+ /* -+ * FreeBSD loader(8) just loaded code to some random location that may -+ * contain stale icache entries. Now that the device is closed it's -+ * about to run that code, so clean the caches. -+ */ -+ flush_dcache_all(); -+ invalidate_icache_all(); -+ - return err; - } - -@@ -495,45 +503,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; - } - - /* Index: sysutils/u-boot-rpi/files/patch-arch_arm_cpu_arm11_cpu.c =================================================================== --- sysutils/u-boot-rpi/files/patch-arch_arm_cpu_arm11_cpu.c +++ /dev/null @@ -1,17 +0,0 @@ ---- arch/arm/cpu/arm11/cpu.c.orig 2015-10-19 23:59:38 UTC -+++ arch/arm/cpu/arm11/cpu.c -@@ -52,6 +52,14 @@ static void cache_flush(void) - asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i)); - } - -+void invalidate_icache_all(void) -+{ -+ /* invalidate entire icache and btb */ -+ asm volatile("mcr p15, 0, %0, c7, c5, 0" : : "r" (0)); -+ /* mem barrier to sync things */ -+ asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); -+} -+ - #ifndef CONFIG_SYS_DCACHE_OFF - - #ifndef CONFIG_SYS_CACHELINE_SIZE Index: sysutils/u-boot-rpi/files/patch-common_cmd__boot.c =================================================================== --- sysutils/u-boot-rpi/files/patch-common_cmd__boot.c +++ /dev/null @@ -1,18 +0,0 @@ ---- common/cmd_boot.c.orig 2015-10-19 23:59:38 UTC -+++ common/cmd_boot.c -@@ -19,6 +19,15 @@ __attribute__((weak)) - unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, - char * const argv[]) - { -+ /* -+ * 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 invalidate the icache (because we DMA'd new data into that -+ * memory recently) and launch the program directly. -+ */ -+ flush_dcache_all(); -+ invalidate_icache_all(); - return entry (argc, argv); - } - Index: sysutils/u-boot-rpi/files/patch-common_cmd__elf.c =================================================================== --- sysutils/u-boot-rpi/files/patch-common_cmd__elf.c +++ /dev/null @@ -1,32 +0,0 @@ ---- common/cmd_elf.c.orig 2016-01-12 14:06:54 UTC -+++ common/cmd_elf.c -@@ -110,22 +110,15 @@ static unsigned long do_bootelf_exec(ulo - 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 invalidate the icache (because we DMA'd new data into that -+ * memory recently) and launch the program directly. - */ -+ flush_dcache_all(); -+ invalidate_icache_all(); - ret = entry(argc, argv); -- -- if (dcache) -- dcache_enable(); -- - return ret; - } - Index: sysutils/u-boot-rpi/files/patch-common_cmd__test.c =================================================================== --- sysutils/u-boot-rpi/files/patch-common_cmd__test.c +++ /dev/null @@ -1,19 +0,0 @@ ---- common/cmd_test.c.orig 2015-10-19 23:59:38 UTC -+++ common/cmd_test.c -@@ -56,9 +56,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 - { Index: sysutils/u-boot-rpi/files/patch-include_configs_rpi-common.h =================================================================== --- sysutils/u-boot-rpi/files/patch-include_configs_rpi-common.h +++ /dev/null @@ -1,58 +0,0 @@ ---- include/configs/rpi-common.h.orig 2016-01-12 14:06:54 UTC -+++ include/configs/rpi-common.h -@@ -182,4 +182,55 @@ - - #define CONFIG_BOOTDELAY 2 - -+/***************************************************************************** -+ * FreeBSD customizations from here down. -+ ****************************************************************************/ -+ -+#define CONFIG_API -+#define CONFIG_EFI_PARTITION -+#define CONFIG_PREBOOT -+ -+#define CONFIG_SYS_MMC_MAX_DEVICE 1 -+ -+/* Create a small(ish) boot environment for FreeBSD. */ -+#undef CONFIG_EXTRA_ENV_SETTINGS -+#define CONFIG_EXTRA_ENV_SETTINGS \ -+ ENV_MEM_LAYOUT_SETTINGS \ -+ "stdin=serial,lcd\0" \ -+ "stderr=serial,lcd\0" \ -+ "stdout=serial,lcd\0" \ -+ \ -+ "Fatboot=" \ -+ "env exists bootfile || bootfile=ubldr.bin; " \ -+ "env exists loaderdev || env set loaderdev ${fatdev}; " \ -+ "test ${loaderdev} = net && env exists SetupNetconfig && run SetupNetconfig; " \ -+ "echo Booting from: ${fatdev} ${bootfile}; " \ -+ "fatload ${fatdev} ${loadaddr} ${bootfile} && bootelf || go ${loadaddr}; " \ -+ "\0" \ -+ "Preboot=" \ -+ "fdt addr 0x100; " \ -+ "env exists uenv_file || uenv_file=uEnv.txt; " \ -+ "env exists SetupFatdev && run SetupFatdev; " \ -+ "env exists SetupUenv && run SetupUenv; " \ -+ "env exists UserPreboot && run UserPreboot; " \ -+ "\0" \ -+ "SetupFatdev=" \ -+ "env exists fatdev || fatdev='mmc 0'; " \ -+ "\0" \ -+ "SetupNetconfig=" \ -+ "env exists ethact || usb start; " \ -+ "env exists UserNetconfig && run UserNetconfig; " \ -+ "\0" \ -+ "SetupUenv=" \ -+ "fatload ${fatdev} ${loadaddr} ${uenv_file} && " \ -+ "env import -t ${loadaddr} ${filesize}; " \ -+ "\0" -+ -+#undef CONFIG_BOOTCOMMAND -+#define CONFIG_BOOTCOMMAND "run Fatboot" -+#undef CONFIG_PREBOOT -+#define CONFIG_PREBOOT "run Preboot" -+ -+#define CONFIG_CMD_CACHE -+ - #endif Index: sysutils/u-boot-rpi/pkg-descr =================================================================== --- sysutils/u-boot-rpi/pkg-descr +++ sysutils/u-boot-rpi/pkg-descr @@ -1,12 +1,15 @@ -U-Boot loader and related files for Raspberry Pi +U-Boot loader for Raspberry Pi -To install this bootloader, copy ALL the files in the share/u-boot/u-boot-rpi +To install this bootloader, copy u-boot.bin in the share/u-boot/u-boot-rpi directory to the first partition, formatted as FAT16 or FAT32, on an SD card. +You will also need the firmware files from the rpi-firmware package. 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. + * The distroboot command knows how to load FreeBSD loader(8) + * By default, it loads ubldr.bin (PIE) from file ubldr.bin on the FAT + partition to address ${kernel_addr_r}, and launches it. If ubldr.bin is + not found, it falls back on ubldr For information about running FreeBSD on RaspberryPi, see WWW: http://wiki.freebsd.org/FreeBSD/arm/Raspberry%20Pi