Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Volunteer for "Add FFS support to U-Boot"



Hi folks,

You can find my patch as an attachment.

As I mentioned before, I still not sure about DEV_STRATEGY and alignment also u-boot fstype_info->probe missing. I'll investigate and clarify asap.

Any idea/suggestion/feedback would be more than welcome :-)


Task Status: 
    Add an ffs driver to U-Boot (read-only) -> done, but some open points exists
    Add the following commands to U-Boot: ffssize, ffsload, ffsls -> done
    Integrate changes with existing U-Boot packages (sysutils/u-boot*) in pkgsrc ->done

    Update armv7.img to support booting directly from FFS. -> wip
    Modify sysinst to allow for installation without an MSDOS partition. -> tba
        Some of this will be SoC-specific. Need to detect the SoC type and select the correct kernel/dtb and adjust partition layout to not interfere with U-Boot / SoC specific bootloaders.



20.02.2018, 16:07, "berte" <behzaterte%yandex.com@localhost>:
> Hey folks,
>
> I've another tag for this task -> version_check_part01 but it's little bit premature.
>
> Please give me your feedbacks/feelings.
>
> 20.02.2018, 11:38, "berte" <behzaterte%yandex.com@localhost>:
>>  Hi Martin,
>>
>>  At the moment I'm changing source with using magic numbers, thanks for your support/advice :-)
>>
>>  20.02.2018, 11:27, "Martin Husemann" <martin%duskware.de@localhost>:
>>>   On Tue, Feb 20, 2018 at 12:02:57AM +0300, berte wrote:
>>>>    Some modifications are done and pushed ufs_taks01_02_part1_done tag.
>>>>
>>>>    Jared, I added +1 argument into uboot_cmd which is type argument and
>>>>    it'll define filesystem types such as ffsv1,ffsv2, lfs, etc.(but I've
>>>>    to need some know-how for u-boot stuff)
>>>
>>>   I wouldn't do that - the supberblock easily tells you what type it is,
>>>   don't bother the user with it.
>>>
>>>   Martin
>>
>>  --
>>  Cheers,
>>  --berte.
>
> --
> Cheers,
> --berte.

-- 
Cheers,
--berte.
Index: u-boot/distinfo
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot/distinfo,v
retrieving revision 1.11
diff -u -p -u -r1.11 distinfo
--- u-boot/distinfo	10 Jan 2018 00:55:27 -0000	1.11
+++ u-boot/distinfo	22 Feb 2018 20:03:30 -0000
@@ -7,8 +7,23 @@ Size (u-boot-2017.11.tar.bz2) = 11982382
 SHA1 (patch-arch_arm_cpu_armv8_Kconfig) = 63cbbf2e3cebd46793fc03cc8e62297f6dc01aa9
 SHA1 (patch-arch_arm_dts_Makefile) = 13e812abd46ffd7bf6dca6c78e2f5adf9731b7c6
 SHA1 (patch-arch_arm_dts_sun50i-h5-nanopi-neo-plus2.dts) = af01f257b0bec9a71a3fbf2324bed6a4471062b0
+SHA1 (patch-cmd_Kconfig) = 0e69c8324d753001eb2a42ebb477171589105bab
+SHA1 (patch-cmd_Makefile) = a209a85c8931d2e89fde49d95937b7d8c2353b82
+SHA1 (patch-cmd_ufs.c) = 27312ffaebc1aa302020016742f0864e8a4d8d35
 SHA1 (patch-configs_nanopi__neo__plus2__defconfig) = 58156ff8c5f9bd841b3039413911e67ddf8d692a
 SHA1 (patch-drivers_video_sunxi_sunxi__display.c) = 8e6a6a781cce25af5cba289fc2ca76e30b62aff6
+SHA1 (patch-fs_Kconfig) = bb3842739588e663199c8646bb8a768a62b3a2a1
+SHA1 (patch-fs_Makefile) = eba50453e44211424099acc4092563d8f99566bc
+SHA1 (patch-fs_fs.c) = 78fa9f3c013b9c02e5ac01677e2537659367c8b5
+SHA1 (patch-fs_ufs_Kconfig) = 57db80a693714ff1a37d324ba98eb651b75a5410
+SHA1 (patch-fs_ufs_Makefile) = 65199dd5ffb6ce7648041ee852deb34e73217cb6
+SHA1 (patch-fs_ufs_dinode.h) = b1b253d5339af9349307ecc8cd20165a6b707f1c
+SHA1 (patch-fs_ufs_ffs.c) = bf97856afcfb3b4eed523ba2f17194b230dd59ce
+SHA1 (patch-fs_ufs_ffs__common.c) = 44c164788d952a9b64e05e9f83476402b95fb7d1
+SHA1 (patch-fs_ufs_ffs__common.h) = 80965b3a2ac92232f5dbfb32bf03d9cce53b215c
+SHA1 (patch-fs_ufs_fs.h) = b6e954b467712bd3daa95d691902acf98383ccb3
 SHA1 (patch-include_configs_tegra-common.h) = 01b68620414f85edd029e54f7f8dc158888c4072
+SHA1 (patch-include_fs.h) = d5cc6bf247cafa9bd48779a93c7f30812bae9036
+SHA1 (patch-include_ufs_ufs.h) = 155b2d7fd4151321f7ea0d9f1eafa51a3671a9fd
 SHA1 (patch-lib_bch.c) = b1f1c7418f1004c151b9e5e06ab7047a1736ae47
 SHA1 (patch-tools_Makefile) = adc5082d369363113135d5c892822b57ee80ff19
Index: u-boot/u-boot-arm64.mk
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot/u-boot-arm64.mk,v
retrieving revision 1.2
diff -u -p -u -r1.2 u-boot-arm64.mk
--- u-boot/u-boot-arm64.mk	7 Sep 2017 15:30:31 -0000	1.2
+++ u-boot/u-boot-arm64.mk	22 Feb 2018 20:03:30 -0000
@@ -6,12 +6,24 @@ BUILD_DEPENDS+=	cross-aarch64-none-elf-g
 UBOOT_ENV+=	CROSS_COMPILE=${PREFIX}/cross-aarch64-none-elf/bin/aarch64-none-elf-
 
 PKG_OPTIONS_VAR=	PKG_OPTIONS.u-boot-${UBOOT_TARGET}
-PKG_SUPPORTED_OPTIONS=	el1
+PKG_SUPPORTED_OPTIONS=	el1 cmd_ffs fs_ufs fs_ufs_write
 
 .include "../../mk/bsd.options.mk"
 
 .if !empty(PKG_OPTIONS:Mel1)
-UBOOT_OPTIONS+=	CONFIG_ARMV8_SWITCH_TO_EL1=y
+UBOOT_OPTIONS+= CONFIG_ARMV8_SWITCH_TO_EL1=y
+.endif
+
+.if !empty(PKG_OPTIONS:Mcmd_ffs)
+UBOOT_OPTIONS+= CONFIG_CMD_UFS=y
+.endif
+
+.if !empty(PKG_OPTIONS:Mfs_ufs)
+UBOOT_OPTIONS+= CONFIG_FS_UFS=y
+.endif
+
+.if !empty(PKG_OPTIONS:Mfs_ufs_write)
+UBOOT_OPTIONS+= CONFIG_FS_UFS_WRITE=n
 .endif
 
 .include "u-boot.mk"
Index: u-boot/patches/patch-cmd_Kconfig
===================================================================
RCS file: u-boot/patches/patch-cmd_Kconfig
diff -N u-boot/patches/patch-cmd_Kconfig
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-cmd_Kconfig	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,16 @@
+$NetBSD$
+
+--- cmd/Kconfig.orig	2017-11-14 01:08:06.000000000 +0000
++++ cmd/Kconfig
+@@ -1466,6 +1466,11 @@ config CMD_ZFS
+ 
+ 	  See doc/README.zfs for more details.
+ 
++config CMD_UFS
++	bool "ffs command support"
++	help
++	  This provides commands for accessing a FFSv1/FFSv2 filesystem.
++
+ endmenu
+ 
+ menu "Debug commands"
Index: u-boot/patches/patch-cmd_Makefile
===================================================================
RCS file: u-boot/patches/patch-cmd_Makefile
diff -N u-boot/patches/patch-cmd_Makefile
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-cmd_Makefile	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- cmd/Makefile.orig	2017-11-14 01:08:06.000000000 +0000
++++ cmd/Makefile
+@@ -129,6 +129,7 @@ obj-$(CONFIG_CMD_UNZIP) += unzip.o
+ obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o
+ 
+ obj-$(CONFIG_CMD_USB) += usb.o disk.o
++obj-$(CONFIG_CMD_UFS) += ufs.o
+ obj-$(CONFIG_CMD_FASTBOOT) += fastboot.o
+ obj-$(CONFIG_CMD_FS_UUID) += fs_uuid.o
+ 
Index: u-boot/patches/patch-cmd_ufs.c
===================================================================
RCS file: u-boot/patches/patch-cmd_ufs.c
diff -N u-boot/patches/patch-cmd_ufs.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-cmd_ufs.c	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,51 @@
+$NetBSD$
+
+--- cmd/ufs.c.orig	2018-02-22 19:29:00.711674090 +0000
++++ cmd/ufs.c
+@@ -0,0 +1,46 @@
++/*-
++ * Command for UFS filesystem support.
++ * Created by berte <behzaterte at yandex.com>
++ *
++ * SPDX-License-Identifier: BSD-3-Clause 
++ */
++
++#include <fs.h>
++
++static int do_ffsls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
++{
++    return do_ls(cmdtp, flag, argc, argv, FS_TYPE_UFS);
++}
++
++int do_ffsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
++{
++	return do_load(cmdtp, flag, argc, argv, FS_TYPE_UFS);
++}
++
++int do_ffssize(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
++{
++	return do_size(cmdtp, flag, argc, argv, FS_TYPE_UFS);
++}
++
++U_BOOT_CMD(
++	ffssize,       4,      0,      do_ffssize,
++	"determine a file's size",
++    "<interface> <dev[:part]> <filename>\n"
++    "    - Find file 'filename' from 'dev' on 'interface'\n"
++	"      and determine its size."
++);
++
++U_BOOT_CMD(
++	ffsls,	4,	1,	do_ffsls,
++	"list files in a directory (default /)",
++	"<interface> <type> <dev[:part]> [directory]\n"
++	"    - list files from 'dev' on 'interface' in a 'directory'"
++)
++
++U_BOOT_CMD(
++	ffsload,	6,	0,	do_ffsload,
++	"load binary file from a ffs filesystem",
++	"<interface> <type> [<dev[:part]> [addr [filename [bytes [pos]]]]]\n"
++	"    - load binary file 'filename' from 'dev' on 'interface'\n"
++	"      to address 'addr' from ffs filesystem."
++)
Index: u-boot/patches/patch-fs_Kconfig
===================================================================
RCS file: u-boot/patches/patch-fs_Kconfig
diff -N u-boot/patches/patch-fs_Kconfig
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_Kconfig	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,11 @@
+$NetBSD$
+
+--- fs/Kconfig.orig	2017-11-14 01:08:06.000000000 +0000
++++ fs/Kconfig
+@@ -22,4 +22,6 @@ source "fs/cramfs/Kconfig"
+ 
+ source "fs/yaffs2/Kconfig"
+ 
++source "fs/ufs/Kconfig"
++
+ endmenu
Index: u-boot/patches/patch-fs_Makefile
===================================================================
RCS file: u-boot/patches/patch-fs_Makefile
diff -N u-boot/patches/patch-fs_Makefile
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_Makefile	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- fs/Makefile.orig	2017-11-14 01:08:06.000000000 +0000
++++ fs/Makefile
+@@ -21,6 +21,7 @@ obj-$(CONFIG_FS_JFFS2) += jffs2/
+ obj-$(CONFIG_CMD_REISER) += reiserfs/
+ obj-$(CONFIG_SANDBOX) += sandbox/
+ obj-$(CONFIG_CMD_UBIFS) += ubifs/
++obj-$(CONFIG_FS_UFS) += ufs/
+ obj-$(CONFIG_YAFFS2) += yaffs2/
+ obj-$(CONFIG_CMD_ZFS) += zfs/
+ endif
Index: u-boot/patches/patch-fs_fs.c
===================================================================
RCS file: u-boot/patches/patch-fs_fs.c
diff -N u-boot/patches/patch-fs_fs.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_fs.c	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,39 @@
+$NetBSD$
+
+--- fs/fs.c.orig	2017-11-14 01:08:06.000000000 +0000
++++ fs/fs.c
+@@ -15,6 +15,7 @@
+ #include <sandboxfs.h>
+ #include <ubifs_uboot.h>
+ #include <btrfs.h>
++#include <ufs/ufs.h>
+ #include <asm/io.h>
+ #include <div64.h>
+ #include <linux/math64.h>
+@@ -236,6 +237,26 @@ static struct fstype_info fstypes[] = {
+ 		.opendir = fs_opendir_unsupported,
+ 	},
+ #endif
++#ifdef CONFIG_FS_UFS
++	{
++		.fstype = FS_TYPE_UFS,
++		.name = "ufs",
++		.null_dev_desc_ok = false,
++		.probe = fs_probe_unsupported,
++		.close = ufs_close,
++		.ls = ufs_ls,
++		.exists = ufs_exists,
++		.size = ufs_size,
++		.read = ufs_read,
++#ifdef CONFIG_FS_UFS_WRITE
++		.write = ufs_write,
++#else
++        .write = fs_write_unsupported,
++#endif
++		.uuid = fs_uuid_unsupported,
++		.opendir = fs_opendir_unsupported,
++	},
++#endif
+ 	{
+ 		.fstype = FS_TYPE_ANY,
+ 		.name = "unsupported",
Index: u-boot/patches/patch-fs_ufs_Kconfig
===================================================================
RCS file: u-boot/patches/patch-fs_ufs_Kconfig
diff -N u-boot/patches/patch-fs_ufs_Kconfig
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_ufs_Kconfig	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- fs/ufs/Kconfig.orig	2018-02-22 19:29:00.713949062 +0000
++++ fs/ufs/Kconfig
+@@ -0,0 +1,13 @@
++config FS_UFS
++    bool "Enable UFS/FFSv1/FFSv2 filesystem support"
++    help
++    This provides support for reading images from the ufs and variant filesystem.
++    ufs is a widely used general-purpose filesystem for NetBSD.
++    You can also enable CMD_UFS to get access to UFS commands.
++
++config FS_UFS_WRITE
++    depends on FS_UFS
++    bool "Enable UFS/FFSv1/FFSv2 filesystem write support(NOT IMPLEMENTED, DO NOT USE)"
++    help
++    This provides support for writing data to the ufs and variant filesystem.
++    NOT IMLEMENTED, PLEASE DO NOT USE THIS.
Index: u-boot/patches/patch-fs_ufs_Makefile
===================================================================
RCS file: u-boot/patches/patch-fs_ufs_Makefile
diff -N u-boot/patches/patch-fs_ufs_Makefile
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_ufs_Makefile	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- fs/ufs/Makefile.orig	2018-02-22 19:29:00.714527276 +0000
++++ fs/ufs/Makefile
+@@ -0,0 +1,8 @@
++#
++# UFS/FFSv1/FFSv2 filesystem support
++# Created by berte <behzaterte at yandex.com>
++#
++# SPDX-License-Identifier:   BSD 2-Clause License
++
++obj-$(CONFIG_FS_UFS) := ffs.o ffs_common.o
++obj-$(CONFIG_FS_UFS_WRITE) += ffs_write.o
Index: u-boot/patches/patch-fs_ufs_dinode.h
===================================================================
RCS file: u-boot/patches/patch-fs_ufs_dinode.h
diff -N u-boot/patches/patch-fs_ufs_dinode.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_ufs_dinode.h	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,184 @@
+$NetBSD$
+
+--- fs/ufs/dinode.h.orig	2018-02-22 19:29:00.715099916 +0000
++++ fs/ufs/dinode.h
+@@ -0,0 +1,179 @@
++/*
++ * Copyright (c) 2002 Networks Associates Technology, Inc.
++ * All rights reserved.
++ *
++ * This software was developed for the FreeBSD Project by Marshall
++ * Kirk McKusick and Network Associates Laboratories, the Security
++ * Research Division of Network Associates, Inc. under DARPA/SPAWAR
++ * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
++ * research program
++ *
++ * Copyright (c) 1982, 1989, 1993
++ *	The Regents of the University of California.  All rights reserved.
++ * (c) UNIX System Laboratories, Inc.
++ * All or some portions of this file are derived from material licensed
++ * to the University of California by American Telephone and Telegraph
++ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
++ * the permission of UNIX System Laboratories, Inc.
++ *
++ * 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.
++ * 3. Neither the name of the University nor the names of its contributors
++ *    may be used to endorse or promote products derived from this software
++ *    without specific prior written permission.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
++ *
++ *	@(#)dinode.h	8.9 (Berkeley) 3/29/95
++ */
++
++/*
++ * NOTE: COORDINATE ON-DISK FORMAT CHANGES WITH THE FREEBSD PROJECT.
++ */
++
++/* Ported by berte <behzaterte at yandex.com>
++ * SPDX-License-Identifier:     BSD 2-Clause License
++ * 
++ */
++
++#ifndef	_UFS_UFS_DINODE_H_
++#define	_UFS_UFS_DINODE_H_
++
++/*
++ * The root inode is the root of the file system.  Inode 0 can't be used for
++ * normal purposes and historically bad blocks were linked to inode 1, thus
++ * the root inode is 2.  (Inode 1 is no longer used for this purpose, however
++ * numerous dump tapes make this assumption, so we are stuck with it).
++ */
++#define	UFS_ROOTINO	((ino_t)2)
++
++/*
++ * The Whiteout inode# is a dummy non-zero inode number which will
++ * never be allocated to a real file.  It is used as a place holder
++ * in the directory entry which has been tagged as a DT_W entry.
++ * See the comments about UFS_ROOTINO above.
++ */
++#define	UFS_WINO	((ino_t)1)
++
++/*
++ * A dinode contains all the meta-data associated with a UFS file.
++ * This structure defines the on-disk format of a dinode. Since
++ * this structure describes an on-disk structure, all its fields
++ * are defined by types with precise widths.
++ */
++
++#define UFS_NXADDR	2
++#define	UFS_NDADDR	12		/* Direct addresses in inode. */
++#define	UFS_NIADDR	3		/* Indirect addresses in inode. */
++
++struct ufs1_dinode {
++	uint16_t	di_mode;	/*   0: IFMT, permissions; see below. */
++	int16_t		di_nlink;	/*   2: File link count. */
++	uint16_t	di_oldids[2];	/*   4: Ffs: old user and group ids. */
++	uint64_t	di_size;	/*   8: File byte count. */
++	int32_t		di_atime;	/*  16: Last access time. */
++	int32_t		di_atimensec;	/*  20: Last access time. */
++	int32_t		di_mtime;	/*  24: Last modified time. */
++	int32_t		di_mtimensec;	/*  28: Last modified time. */
++	int32_t		di_ctime;	/*  32: Last inode change time. */
++	int32_t		di_ctimensec;	/*  36: Last inode change time. */
++	int32_t		di_db[UFS_NDADDR]; /*  40: Direct disk blocks. */
++	int32_t		di_ib[UFS_NIADDR]; /*  88: Indirect disk blocks. */
++	uint32_t	di_flags;	/* 100: Status flags (chflags). */
++	uint32_t	di_blocks;	/* 104: Blocks actually held. */
++	int32_t		di_gen;		/* 108: Generation number. */
++	uint32_t	di_uid;		/* 112: File owner. */
++	uint32_t	di_gid;		/* 116: File group. */
++	uint64_t	di_modrev;	/* 120: i_modrev for NFSv4 */
++};
++
++struct ufs2_dinode {
++	uint16_t	di_mode;	/*   0: IFMT, permissions; see below. */
++	int16_t		di_nlink;	/*   2: File link count. */
++	uint32_t	di_uid;		/*   4: File owner. */
++	uint32_t	di_gid;		/*   8: File group. */
++	uint32_t	di_blksize;	/*  12: Inode blocksize. */
++	uint64_t	di_size;	/*  16: File byte count. */
++	uint64_t	di_blocks;	/*  24: Bytes actually held. */
++	int64_t		di_atime;	/*  32: Last access time. */
++	int64_t		di_mtime;	/*  40: Last modified time. */
++	int64_t		di_ctime;	/*  48: Last inode change time. */
++	int64_t		di_birthtime;	/*  56: Inode creation time. */
++	int32_t		di_mtimensec;	/*  64: Last modified time. */
++	int32_t		di_atimensec;	/*  68: Last access time. */
++	int32_t		di_ctimensec;	/*  72: Last inode change time. */
++	int32_t		di_birthnsec;	/*  76: Inode creation time. */
++	int32_t		di_gen;		/*  80: Generation number. */
++	uint32_t	di_kernflags;	/*  84: Kernel flags. */
++	uint32_t	di_flags;	/*  88: Status flags (chflags). */
++	int32_t		di_extsize;	/*  92: External attributes block. */
++	int64_t		di_extb[UFS_NXADDR];/* 96: External attributes block. */
++	int64_t		di_db[UFS_NDADDR]; /* 112: Direct disk blocks. */
++	int64_t		di_ib[UFS_NIADDR]; /* 208: Indirect disk blocks. */
++	uint64_t	di_modrev;	/* 232: i_modrev for NFSv4 */
++	int64_t		di_spare[2];	/* 240: Reserved; currently unused */
++};
++
++/*
++ * The di_db fields may be overlaid with other information for
++ * file types that do not have associated disk storage. Block
++ * and character devices overlay the first data block with their
++ * dev_t value. Short symbolic links place their path in the
++ * di_db area.
++ */
++#define	di_ogid		di_oldids[1]
++#define	di_ouid		di_oldids[0]
++#define	di_rdev		di_db[0]
++#define UFS1_MAXSYMLINKLEN	((UFS_NDADDR + UFS_NIADDR) * sizeof(int32_t))
++#define UFS2_MAXSYMLINKLEN	((UFS_NDADDR + UFS_NIADDR) * sizeof(int64_t))
++
++#define UFS_MAXSYMLINKLEN(ip) \
++	((ip)->i_ump->um_fstype == UFS1) ? \
++	UFS1_MAXSYMLINKLEN : UFS2_MAXSYMLINKLEN
++
++/* NeXT used to keep short symlinks in the inode even when using
++ * FS_42INODEFMT.  In that case fs->fs_maxsymlinklen is probably -1,
++ * but short symlinks were stored in inodes shorter than this:
++ */
++#define	APPLEUFS_MAXSYMLINKLEN 60
++
++/* File permissions. */
++#define	IEXEC		0000100		/* Executable. */
++#define	IWRITE		0000200		/* Writable. */
++#define	IREAD		0000400		/* Readable. */
++#define	ISVTX		0001000		/* Sticky bit. */
++#define	ISGID		0002000		/* Set-gid. */
++#define	ISUID		0004000		/* Set-uid. */
++
++/* File types. */
++#define	IFMT		0170000		/* Mask of file type. */
++#define	IFIFO		0010000		/* Named pipe (fifo). */
++#define	IFCHR		0020000		/* Character device. */
++#define	IFDIR		0040000		/* Directory file. */
++#define	IFBLK		0060000		/* Block device. */
++#define	IFREG		0100000		/* Regular file. */
++#define	IFLNK		0120000		/* Symbolic link. */
++#define	IFSOCK		0140000		/* UNIX domain socket. */
++#define	IFWHT		0160000		/* Whiteout. */
++
++/* Size of the on-disk inode. */
++#define	DINODE1_SIZE	(sizeof(struct ufs1_dinode))		/* 128 */
++#define	DINODE2_SIZE	(sizeof(struct ufs2_dinode))
++
++#endif /* !_UFS_UFS_DINODE_H_ */
Index: u-boot/patches/patch-fs_ufs_ffs.c
===================================================================
RCS file: u-boot/patches/patch-fs_ufs_ffs.c
diff -N u-boot/patches/patch-fs_ufs_ffs.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_ufs_ffs.c	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,534 @@
+$NetBSD$
+
+--- fs/ufs/ffs.c.orig	2018-02-22 19:29:00.715701201 +0000
++++ fs/ufs/ffs.c
+@@ -0,0 +1,529 @@
++ /*
++ * Copyright (c) 1993
++ * The Regents of the University of California.  All rights reserved.
++ *
++ * This code is derived from software contributed to Berkeley by
++ * The Mach Operating System project at Carnegie-Mellon University.
++ *
++ * 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.
++ * 3. Neither the name of the University nor the names of its contributors
++ *    may be used to endorse or promote products derived from this software
++ *    without specific prior written permission.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
++ *
++ *
++ * Copyright (c) 1990, 1991 Carnegie Mellon University
++ * All Rights Reserved.
++ *
++ * Author: David Golub
++ *
++ * Permission to use, copy, modify and distribute this software and its
++ * documentation is hereby granted, provided that both the copyright
++ * notice and this permission notice appear in all copies of the
++ * software, derivative works or modified versions, and any portions
++ * thereof, and that both notices appear in supporting documentation.
++ *
++ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
++ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
++ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
++ *
++ * Carnegie Mellon requests users of this software to return to
++ *
++ *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
++ *  School of Computer Science
++ *  Carnegie Mellon University
++ *  Pittsburgh PA 15213-3890
++ *
++ * any improvements or extensions that they make and grant Carnegie the
++ * rights to redistribute these changes.
++ *
++ * Stand-alone file reading package for UFS and LFS filesystems.
++ *
++ * UFS/FFS filesystem ported to u-boot by
++ * berte <behzaterte at yandex.com>
++ *
++ * SPDX-License-Identifier:  BSD 2-Clause License
++ */
++
++#include <common.h>
++#include <malloc.h>
++
++#include <stdio.h>
++#include <stdlib.h>
++#include <time.h>
++#include <errno.h>
++#include <linux/stat.h>
++#include <ufs/ufs.h>
++
++#include "ffs_common.h"
++
++struct open_file *gFile = NULL;
++
++off_t
++ffs_seek(struct open_file *f, off_t offset, int where)
++{
++    struct file *fp = (struct file *)f->f_fsdata;
++ 
++    switch (where) {
++	case SEEK_SET:
++	    fp->f_seekp = offset;
++	    break;
++	case SEEK_CUR:
++	    fp->f_seekp += offset;
++	    break;
++	case SEEK_END:
++	    if (get_ufs_version(f) == FS_UFS1_MAGIC)
++		fp->f_seekp = fp->f_di.v1.di_size - offset;
++	    fp->f_seekp = fp->f_di.v2.di_size - offset;
++	    break;
++	default:
++	    return -1;
++    }
++    return fp->f_seekp;
++}
++int ffs_close(struct open_file *f)
++{
++    struct file *fp = (struct file *)f->f_fsdata;
++
++    f->f_fsdata = NULL;
++    if (fp == NULL)
++        return 0;
++
++    if (fp->f_buf)
++        dealloc(fp->f_buf, fp->f_fs->fs_bsize);
++
++    dealloc(fp->f_fs, SBLOCKSIZE);
++    dealloc(fp, sizeof(struct file));
++
++    return 0;
++}
++
++
++
++void ffs_ls(struct open_file *f, const char *pattern)
++{
++    struct file *fp = (struct file *)f->f_fsdata;
++    char *buf;
++    size_t buf_size;
++    lsentry_t *names = NULL;
++
++    fp->f_seekp = 0;
++    while (fp->f_seekp < (off_t)fp->f_di.v1.di_size) {
++        struct direct  *dp, *edp;
++        int rc = buf_read_file(f, &buf, &buf_size);
++        if (rc)
++            goto out;
++        /* some firmware might use block size larger than DEV_BSIZE */
++        if (buf_size < UFS_DIRBLKSIZ)
++            goto out;
++
++        dp = (struct direct *)buf;
++        edp = (struct direct *)(buf + buf_size);
++
++        for (; dp < edp; dp = (void *)((char *)dp + dp->d_reclen)) {
++            const char *t;
++            if (dp->d_ino ==  0)
++                continue;
++
++            if (dp->d_type >= NELEM(typestr) ||
++                !(t = typestr[dp->d_type])) {
++                /*
++                 * This does not handle "old"
++                 * filesystems properly. On little
++                 * endian machines, we get a bogus
++                 * type name if the namlen matches a
++                 * valid type identifier. We could
++                 * check if we read namlen "0" and
++                 * handle this case specially, if
++                 * there were a pressing need...
++                 */
++                printf("bad dir entry\n");
++                goto out;
++            }
++            lsadd(&names, pattern, dp->d_name, strlen(dp->d_name),
++                dp->d_ino, t);
++        }
++        fp->f_seekp += buf_size;
++    }
++    lsprint(names);
++out:    lsfree(names);
++}
++
++int
++ffs_read(struct open_file *f, void *start, size_t size, size_t *resid)
++{
++    struct file *fp = (struct file *)f->f_fsdata;
++    size_t csize;
++    char *buf;
++    size_t buf_size;
++    int rc = 0;
++    char *addr = start;
++
++    while (size != 0) {
++        if (fp->f_seekp >= (off_t)fp->f_di.v1.di_size)
++            break;
++
++        rc = buf_read_file(f, &buf, &buf_size);
++        if (rc)
++            break;
++
++        csize = size;
++        if (csize > buf_size)
++            csize = buf_size;
++
++        memcpy(addr, buf, csize);
++
++        fp->f_seekp += csize;
++        addr += csize;
++        size -= csize;
++    }
++    if (resid)
++        *resid = size;
++    return rc;
++}
++
++int
++ffs_open(const char *path, struct open_file *f)
++{
++#ifndef LIBSA_FS_SINGLECOMPONENT
++    const char *cp, *ncp;
++    int c;
++#endif
++    ino32_t inumber;
++    struct file *fp;
++    FS *fs;
++    int rc, flag;
++    int64_t version;
++#ifndef LIBSA_NO_FS_SYMLINK
++    ino32_t parent_inumber;
++    int nlinks = 0;
++    char namebuf[MAXPATHLEN+1];
++    char *buf;
++#endif
++
++    /* allocate file system specific data structure */
++    fp = alloc(sizeof(struct file));
++    memset(fp, 0, sizeof(struct file));
++    f->f_fsdata = (void *)fp;
++
++    /* allocate space and read super block */
++    fs = alloc(SBLOCKSIZE);
++    fp->f_fs = fs;
++    twiddle();
++    version = get_ufs_version(f);
++
++#ifdef LIBSA_FFSv2
++    rc = ffs_find_superblock(f, fs);
++    if (rc)
++        goto out;
++#else
++    {
++        size_t buf_size = 0;
++        /*rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
++            SBLOCKOFFSET / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size);
++        if (rc)
++            goto out;*/
++        if (buf_size != SBLOCKSIZE ||
++#ifdef LIBSA_FFS
++            fs->lfs_version != REQUIRED_LFS_VERSION ||
++#endif
++            fs->fs_magic != FS_MAGIC) {
++            rc = EINVAL;
++            goto out;
++        }
++    }
++#if defined(LIBSA_LFS) && REQUIRED_LFS_VERSION == 2
++    /*
++     * XXX  We should check the second superblock and use the eldest
++     *  of the two.  See comments near the top of lfs_mountfs()
++     *  in sys/ufs/lfs/lfs_vfsops.c.
++     *      This may need a LIBSA_LFS_SMALL check as well.
++     */
++#endif
++#if defined(LIBSA_LFS)
++    fs->lfs_is64 = 0;
++    fs->lfs_dobyteswap = 0;
++    fs->lfs_hasolddirfmt = (fs->fs_maxsymlinklen <= 0);
++#endif
++#endif
++
++    if (version == FS_UFS1_MAGIC)
++	ffs_oldfscompat(fs);
++
++    if (fs->fs_bsize > MAXBSIZE ||
++        (size_t)fs->fs_bsize < sizeof(FS)) {
++        rc = EINVAL;
++        goto out;
++    }
++
++    /*
++     * Calculate indirect block levels.
++     */
++    {
++        indp_t mult;
++        int ln2;
++
++        /*
++         * We note that the number of indirect blocks is always
++         * a power of 2.  This lets us use shifts and masks instead
++         * of divide and remainder and avoinds pulling in the
++         * 64bit division routine into the boot code.
++         */
++        mult = FFS_NINDIR(fs);
++#ifdef DEBUG
++        if (mult & (mult - 1)) {
++            /* Hummm was't a power of 2 */
++            rc = EINVAL;
++            goto out;
++        }
++#endif
++        for (ln2 = 0; mult != 1; ln2++)
++            mult >>= 1;
++
++        fp->f_nishift = ln2;
++    }
++
++    /* alloc a block sized buffer used for all fs transfers */
++    fp->f_buf = alloc(fs->fs_bsize);
++    inumber = UFS_ROOTINO;
++    if ((rc = read_inode(inumber, f)) != 0)
++        goto out;
++
++#ifndef LIBSA_FS_SINGLECOMPONENT
++    cp = path;
++    while (*cp) {
++
++        /*
++         * Remove extra separators
++         */
++        while (*cp == '/')
++            cp++;
++        if (*cp == '\0')
++            break;
++
++        /*
++         * Check that current node is a directory.
++         */
++	if (version == FS_UFS1_MAGIC) {/*ffs version check*/
++	    flag = (fp->f_di.v1.di_mode & IFMT) != IFDIR;
++	}
++	else {
++	    flag = (fp->f_di.v2.di_mode & IFMT) != IFDIR;
++	}
++	    
++	if (flag) {
++		rc = ENOTDIR;
++		goto out;
++	    }
++
++        /*
++         * Get next component of path name.
++         */
++        ncp = cp;
++        while ((c = *cp) != '\0' && c != '/')
++            cp++;
++
++        /*
++         * Look up component in current directory.
++         * Save directory inumber in case we find a
++         * symbolic link.
++         */
++#ifndef LIBSA_NO_FS_SYMLINK
++        parent_inumber = inumber;
++#endif
++        rc = search_directory(ncp, cp - ncp, f, &inumber);
++        if (rc)
++            goto out;
++
++        /*
++         * Open next component.
++         */
++        if ((rc = read_inode(inumber, f)) != 0)
++            goto out;
++
++#ifndef LIBSA_NO_FS_SYMLINK
++        /*
++         * Check for symbolic link.
++         */
++	if (version == FS_UFS1_MAGIC) {/*ffs version check*/
++	    flag = (fp->f_di.v1.di_mode & IFMT) != IFLNK;
++	}
++	else {
++    	    flag = (fp->f_di.v2.di_mode & IFMT) != IFLNK;
++	}
++        
++	if (flag) {
++            int link_len =  (version == FS_UFS1_MAGIC) ? fp->f_di.v1.di_size : fp->f_di.v2.di_size;
++            int len;
++
++            len = strlen(cp);
++
++            if (link_len + len > MAXPATHLEN ||
++                ++nlinks > MAXSYMLINKS) {
++                rc = ENOENT;
++                goto out;
++            }
++
++            memmove(&namebuf[link_len], cp, len + 1);
++
++            if (link_len < fs->fs_maxsymlinklen) {
++		(version == FS_UFS1_MAGIC) ?
++		    memcpy(namebuf, fp->f_di.v1.di_db, link_len) : 
++		    memcpy(namebuf, fp->f_di.v2.di_db, link_len);
++            } else {
++                /*
++                 * Read file for symbolic link
++                 */
++                //size_t buf_size;
++                indp_t  disk_block;
++
++                buf = fp->f_buf;
++                rc = block_map(f, (indp_t)0, &disk_block);
++                if (rc)
++                    goto out;
++
++                twiddle();
++                /*rc = DEV_STRATEGY(f->f_dev)(f->f_devdata,
++                    F_READ, FSBTODB(fs, disk_block),
++                    fs->fs_bsize, buf, &buf_size);*/
++                if (rc)
++                    goto out;
++
++                memcpy(namebuf, buf, link_len);
++            }
++
++            /*
++             * If relative pathname, restart at parent directory.
++             * If absolute pathname, restart at root.
++             */
++            cp = namebuf;
++            if (*cp != '/')
++                inumber = parent_inumber;
++            else
++                inumber = (ino32_t)UFS_ROOTINO;
++
++            if ((rc = read_inode(inumber, f)) != 0)
++                goto out;
++        }
++#endif  /* !LIBSA_NO_FS_SYMLINK */
++    }
++
++    /*
++     * Found terminal component.
++     */
++    rc = 0;
++
++#else /* !LIBSA_FS_SINGLECOMPONENT */
++
++    /* look up component in the current (root) directory */
++    rc = search_directory(path, strlen(path), f, &inumber);
++    if (rc)
++        goto out;
++
++    /* open it */
++    rc = read_inode(inumber, f);
++
++#endif /* !LIBSA_FS_SINGLECOMPONENT */
++
++    fp->f_seekp = 0;        /* reset seek pointer */
++
++out:
++    if (rc)
++        ffs_close(f);
++#ifdef FSMOD        /* Only defined for lfs */
++    else
++        fsmod = FSMOD;
++#endif
++    return rc;
++}
++
++int
++ffs_stat(struct open_file *f, struct stat *sb)
++{
++    int64_t version = get_ufs_version(f);
++    struct file *fp = (struct file *)f->f_fsdata;
++    
++    /* only important stuff */
++    memset(sb, 0, sizeof *sb);
++    sb->st_mode = (version == FS_UFS1_MAGIC) ? fp->f_di.v1.di_mode : fp->f_di.v2.di_mode;
++    sb->st_uid = (version == FS_UFS1_MAGIC) ? fp->f_di.v1.di_uid : fp->f_di.v2.di_uid;
++    sb->st_gid = (version == FS_UFS1_MAGIC) ? fp->f_di.v1.di_gid : fp->f_di.v2.di_gid;
++    sb->st_size = (version == FS_UFS1_MAGIC)? fp->f_di.v1.di_size : fp->f_di.v2.di_size;
++    return 0;
++}
++
++
++
++/*
++ * wrappers for fstype_info
++ *
++ */
++int ufs_ls(const char *pattern)
++{
++   ffs_ls(gFile, pattern);
++   return 0; 
++}
++
++int ufs_size(const char *filename, loff_t *size)
++{
++    struct stat st;
++
++    ffs_stat(gFile, &st);
++
++    *size = st.st_size;
++    return 0;
++}
++
++int ufs_read(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *len_read)
++{
++    int error;
++    size_t sz;
++
++    error = ffs_open(filename, gFile);
++    if (!error)
++    {
++	if (offset != -1)
++	    ffs_seek(gFile, offset, SEEK_SET);
++
++        error = ffs_read(gFile, buf, len, &sz);
++        debug("ffs_read return with %d, read byte size: %d", error, (int)sz);
++    }
++
++    return error;
++}
++
++void ufs_close(void)
++{
++    int ret = 0;
++    ret = ffs_close(gFile);
++
++    printf("ffs_close return value is %d\n", ret);
++}
++
++int  ufs_exists(const char *filename)
++{
++    int error;
++ 
++    error = ffs_open(filename, gFile);
++    
++    return error;
++}
++
Index: u-boot/patches/patch-fs_ufs_ffs__common.c
===================================================================
RCS file: u-boot/patches/patch-fs_ufs_ffs__common.c
diff -N u-boot/patches/patch-fs_ufs_ffs__common.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_ufs_ffs__common.c	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,589 @@
+$NetBSD$
+
+--- fs/ufs/ffs_common.c.orig	2018-02-22 19:29:00.716370569 +0000
++++ fs/ufs/ffs_common.c
+@@ -0,0 +1,584 @@
++/*-
++ * Copyright (c) 1993
++ *	The Regents of the University of California.  All rights reserved.
++ *
++ * This code is derived from software contributed to Berkeley by
++ * The Mach Operating System project at Carnegie-Mellon University.
++ *
++ * 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.
++ * 3. Neither the name of the University nor the names of its contributors
++ *    may be used to endorse or promote products derived from this software
++ *    without specific prior written permission.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
++ *
++ *
++ * Copyright (c) 1990, 1991 Carnegie Mellon University
++ * All Rights Reserved.
++ *
++ * Author: David Golub
++ *
++ * Permission to use, copy, modify and distribute this software and its
++ * documentation is hereby granted, provided that both the copyright
++ * notice and this permission notice appear in all copies of the
++ * software, derivative works or modified versions, and any portions
++ * thereof, and that both notices appear in supporting documentation.
++ *
++ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
++ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
++ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
++ *
++ * Carnegie Mellon requests users of this software to return to
++ *
++ *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
++ *  School of Computer Science
++ *  Carnegie Mellon University
++ *  Pittsburgh PA 15213-3890
++ *
++ * any improvements or extensions that they make and grant Carnegie the
++ * rights to redistribute these changes.
++ *
++ * Stand-alone file reading package for UFS and LFS filesystems.
++ *
++ * UFS/FFS filesystem ported to u-boot by
++ * berte <behzaterte at yandex.com>
++ *
++ * SPDX-License-Identifier:     BSD 2-Clause License
++ */
++
++
++#include <common.h>
++#include "ffs_common.h"
++
++char  twiddle_toggle;
++struct fl {
++    unsigned int    size;
++    struct fl   *next;
++} *freelist;
++
++void
++twiddle(void)
++{
++    static int pos;
++
++    if (!twiddle_toggle) {
++        /*putchar(TWIDDLE_CHARS[pos++ & 3]);
++        putchar('\b');*/
++        putc(TWIDDLE_CHARS[pos++ & 3]);
++        putc('\b');
++    }
++
++}
++
++void 
++dealloc(void *ptr, size_t size)
++{
++    struct fl *f = (struct fl *)(void *) ((char *)(void *)ptr - sizeof(unsigned int));
++#ifdef DEBUG
++    if (size > (size_t)f->size) {
++        printf("dealloc %zu bytes @%lx, should be <=%u\n",
++            size, (u_long)ptr, f->size);
++    }
++
++    if (ptr < (void *)HEAP_START)
++        printf("dealloc: %lx before start of heap.\n", (u_long)ptr);
++
++#ifdef HEAP_LIMIT
++    if (ptr > (void *)HEAP_LIMIT)
++        printf("dealloc: %lx beyond end of heap.\n", (u_long)ptr);
++#endif
++#endif /* DEBUG */
++    /* put into freelist */
++    f->next = freelist;
++    freelist = f;
++}
++
++static char *top = NULL;
++
++void *
++alloc(size_t size)
++{
++    struct fl **f = &freelist, **bestf = NULL;
++    unsigned int bestsize = 0xffffffff; /* greater than any real size */
++    char *help = NULL;
++    int failed;
++
++    /* scan freelist */
++    while (*f) {
++        if ((size_t)(*f)->size >= size) {
++            if ((size_t)(*f)->size == size) /* exact match */
++                goto found;
++
++            if ((*f)->size < bestsize) {
++                /* keep best fit */
++                bestf = f;
++                bestsize = (*f)->size;
++            }
++        }
++        f = &((*f)->next);
++    }
++
++    /* no match in freelist if bestsize unchanged */
++    failed = (bestsize == 0xffffffff);
++
++    if (failed) { /* nothing found */
++        /*
++         * allocate from heap, keep chunk len in
++         * first word
++         */
++        //help = top;
++
++        /* make _sure_ the region can hold a struct fl. */
++        if (size < sizeof (struct fl *))
++            size = sizeof (struct fl *);
++        top += sizeof(unsigned int) + size;
++#ifdef HEAP_LIMIT
++        if (top > (char *)HEAP_LIMIT)
++            panic("heap full (%p+%zu)", help, size);
++#endif
++        *(unsigned int *)(void *)help = (unsigned int)(size);
++        return help + sizeof(unsigned int);
++    }
++
++    /* we take the best fit */
++    f = bestf;
++
++found:
++    /* remove from freelist */
++    help = (char *)(void *)*f;
++    *f = (*f)->next;
++    return help + sizeof(unsigned int);
++}
++
++int 
++fnmatch(const char *fname, const char *pattern)
++{
++    char fc, pc;
++
++    do {
++        fc = *fname++;
++        pc = *pattern++;
++        if (!fc && !pc)
++            return 1;
++        if (pc == '?' && fc)
++            pc = fc;
++    } while (fc == pc);
++
++    if (pc != '*')
++        return 0;
++    /*
++     * Too hard (and unnecessary really) too check for "*?name" etc....
++     * "**" will look for a '*' and "*?" a '?'
++     */
++    pc = *pattern++;
++    if (!pc)
++        return 1;
++    while ((fname = strchr(fname, pc)))
++        if (fnmatch(++fname, pattern))
++            return 1;
++    return 0;
++}
++void
++lsadd(lsentry_t **names, const char *pattern, const char *name, size_t namelen,
++    uint32_t ino, const char *type)
++{
++    lsentry_t *n, **np;
++
++    if (pattern && !fnmatch(name, pattern))
++        return;
++
++    n = alloc(sizeof *n + namelen);
++    if (!n) {
++        printf("%d: %.*s (%s)\n", ino, (int)namelen, name, type);
++        return;
++    }
++
++    n->e_ino = ino;
++    n->e_type = type;
++    memcpy(n->e_name, name, namelen);
++    n->e_name[namelen] = '\0';
++
++    for (np = names; *np; np = &(*np)->e_next) {
++        if (strcmp(n->e_name, (*np)->e_name) < 0)
++            break;
++    }
++    n->e_next = *np;
++    *np = n;
++}
++
++void
++lsprint(lsentry_t *names) {
++    if (!names) {
++        printf("not found\n");
++        return;
++    }
++    do {
++        lsentry_t *n = names;
++        printf("%d: %s (%s)\n", n->e_ino, n->e_name, n->e_type);
++        names = n->e_next;
++    } while (names);
++}
++
++void
++lsfree(lsentry_t *names) {
++    if (!names)
++        return;
++    do {
++        lsentry_t *n = names;
++        names = n->e_next;
++        dealloc(n, 0);
++    } while (names);
++}
++
++int
++read_inode(ino32_t inumber, struct open_file *f)
++{
++    int64_t version = get_ufs_version(f);
++    struct file *fp = (struct file *)f->f_fsdata;
++    FS *fs = fp->f_fs;
++    char *buf;
++    size_t rsize = 0;
++    int rc;
++    daddr_t inode_sector = 0; /* XXX: gcc */
++#ifdef LIBSA_LFS
++    struct ufs_dinode *dip;
++    int cnt;
++#endif
++
++#ifdef LIBSA_LFS
++    if (inumber == LFS_IFILE_INUM)
++        inode_sector = FSBTODB(fs, lfs_sb_getidaddr(fs));
++    else if ((rc = find_inode_sector(inumber, f, &inode_sector)) != 0)
++        return rc;
++#else
++    inode_sector = FSBTODB(fs, ino_to_fsba(fs, inumber));
++#endif
++
++    /*
++     * Read inode and save it.
++     */
++    buf = fp->f_buf;
++    twiddle();
++    /*rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
++        inode_sector, fs->fs_bsize, buf, &rsize);
++    if (rc)
++        return rc;*/
++    if (rsize != fs->fs_bsize)
++        return EIO;
++
++#ifdef LIBSA_LFS
++    cnt = INOPBx(fs);
++    dip = (struct ufs_dinode *)buf + (cnt - 1);
++    for (; dip->di_inumber != inumber; --dip) {
++        /* kernel code panics, but boot blocks which panic are Bad. */
++        if (--cnt == 0)
++            return EINVAL;
++    }
++    fp->f_di = *dip;
++#else
++    if (version == FS_UFS1_MAGIC) {
++    	fp->f_di.v1 = ((struct ufs1_dinode *)buf)[ino_to_fsbo(fs, inumber)];
++    }
++    else {
++	fp->f_di.v2 = ((struct ufs2_dinode *)buf)[ino_to_fsbo(fs, inumber)];
++    }
++#endif
++
++    /*
++     * Clear out the old buffers
++     */
++    fp->f_ind_cache_block = ~0;
++    fp->f_buf_blkno = -1;
++    return rc;
++}
++
++/*
++ * Given an offset in a file, find the disk block number that
++ * contains that block.
++ */
++int
++block_map(struct open_file *f, indp_t file_block, indp_t *disk_block_p)
++{
++    int64_t version = get_ufs_version(f);
++    struct file *fp = (struct file *)f->f_fsdata;
++    FS *fs = fp->f_fs;
++    uint level;
++    indp_t ind_cache;
++    indp_t ind_block_num;
++    size_t rsize = 0;
++    indp_t *buf = (void *)fp->f_buf;
++
++    /*
++     * Index structure of an inode:
++     *
++     * di_db[0..UFS_NDADDR-1]   hold block numbers for blocks
++     *          0..UFS_NDADDR-1
++     *
++     * di_ib[0]     index block 0 is the single indirect block
++     *          holds block numbers for blocks
++     *          UFS_NDADDR .. UFS_NDADDR + UFS_NINDIR(fs)-1
++     *
++     * di_ib[1]     index block 1 is the double indirect block
++     *          holds block numbers for INDEX blocks for blocks
++     *          UFS_NDADDR + UFS_NINDIR(fs) ..
++     *          UFS_NDADDR + UFS_NINDIR(fs) + UFS_NINDIR(fs)**2 - 1
++     *
++     * di_ib[2]     index block 2 is the triple indirect block
++     *          holds block numbers for double-indirect
++     *          blocks for blocks
++     *          UFS_NDADDR + UFS_NINDIR(fs) + UFS_NINDIR(fs)**2 ..
++     *          UFS_NDADDR + UFS_NINDIR(fs) + UFS_NINDIR(fs)**2
++     *              + UFS_NINDIR(fs)**3 - 1
++     */
++
++    if (file_block < UFS_NDADDR) {
++        /* Direct block. */
++        *disk_block_p = (version == FS_UFS1_MAGIC) ? fp->f_di.v1.di_db[file_block] : fp->f_di.v2.di_db[file_block];
++        return 0;
++    }
++
++    file_block -= UFS_NDADDR;
++
++    ind_cache = file_block >> LN2_IND_CACHE_SZ;
++    if (ind_cache == fp->f_ind_cache_block) {
++        *disk_block_p = fp->f_ind_cache[file_block & IND_CACHE_MASK];
++        return 0;
++    }
++
++    for (level = 0;;) {
++        level += fp->f_nishift;
++        if (file_block < (indp_t)1 << level)
++            break;
++        if (level > UFS_NIADDR * fp->f_nishift)
++            /* Block number too high */
++            return EFBIG;
++        file_block -= (indp_t)1 << level;
++    }
++
++    ind_block_num = (version == FS_UFS1_MAGIC) ? fp->f_di.v1.di_ib[level / fp->f_nishift - 1] :  fp->f_di.v2.di_ib[level / fp->f_nishift - 1];
++
++    for (;;) {
++        level -= fp->f_nishift;
++        if (ind_block_num == 0) {
++            *disk_block_p = 0;  /* missing */
++            return 0;
++        }
++
++        twiddle();
++        /*
++         * If we were feeling brave, we could work out the number
++         * of the disk sector and read a single disk sector instead
++         * of a filesystem block.
++         * However we don't do this very often anyway...
++         */
++        /*rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
++            FSBTODB(fp->f_fs, ind_block_num), fs->fs_bsize,
++            buf, &rsize);
++        if (rc)
++            return rc;*/
++        if (rsize != fs->fs_bsize)
++            return EIO;
++        ind_block_num = buf[file_block >> level];
++        if (level == 0)
++            break;
++        file_block &= (1 << level) - 1;
++    }
++
++    /* Save the part of the block that contains this sector */
++    memcpy(fp->f_ind_cache, &buf[file_block & ~IND_CACHE_MASK],
++        IND_CACHE_SZ * sizeof fp->f_ind_cache[0]);
++    fp->f_ind_cache_block = ind_cache;
++
++    *disk_block_p = ind_block_num;
++
++    return 0;
++}
++
++/*
++ * Read a portion of a file into an internal buffer.
++ * Return the location in the buffer and the amount in the buffer.
++ */
++int
++buf_read_file(struct open_file *f, char **buf_p, size_t *size_p)
++{
++    int64_t version = get_ufs_version(f);
++    struct file *fp = (struct file *)f->f_fsdata;
++    FS *fs = fp->f_fs;
++    long off;
++    indp_t file_block;
++    size_t block_size;
++    int rc;
++
++    off = ufs_blkoff(fs, fp->f_seekp);
++    file_block = ufs_lblkno(fs, fp->f_seekp);
++#ifdef LIBSA_LFS
++    block_size = (version == FS_UFS1_MAGIC) ? dblksize(fs, &fp->f_di.v1, file_block) :  
++					    dblksize(fs, &fp->f_di.v2, file_block);
++#else
++    block_size = (version == FS_UFS1_MAGIC) ? ffs_sblksize(fs, (int64_t)fp->f_di.v1.di_size, file_block) :
++						ffs_sblksize(fs, (int64_t)fp->f_di.v2.di_size, file_block);
++#endif
++
++    if (file_block != fp->f_buf_blkno) {
++        indp_t disk_block = 0; /* XXX: gcc */
++        rc = block_map(f, file_block, &disk_block);
++        if (rc)
++            return rc;
++
++        if (disk_block == 0) {
++            memset(fp->f_buf, 0, block_size);
++            fp->f_buf_size = block_size;
++        } else {
++            twiddle();
++            /*rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
++                FSBTODB(fs, disk_block),
++                block_size, fp->f_buf, &fp->f_buf_size);
++            if (rc)
++                return rc;*/
++        }
++
++        fp->f_buf_blkno = file_block;
++    }
++
++    /*
++     * Return address of byte in buffer corresponding to
++     * offset, and size of remainder of buffer after that
++     * byte.
++     */
++    *buf_p = fp->f_buf + off;
++    *size_p = block_size - off;
++
++    /*
++     * But truncate buffer at end of file.
++     */
++   int32_t sum = (version == FS_UFS1_MAGIC) ? (fp->f_di.v1.di_size - fp->f_seekp) : (fp->f_di.v2.di_size - fp->f_seekp); 
++    if (*size_p > sum)
++        *size_p = (version == FS_UFS1_MAGIC) ? (fp->f_di.v1.di_size - fp->f_seekp) : (fp->f_di.v2.di_size - fp->f_seekp);
++
++    return 0;
++}
++
++/*
++ * Search a directory for a name and return its
++ * inode number.
++ */
++int
++search_directory(const char *name, int length, struct open_file *f,
++    ino32_t *inumber_p)
++{
++    int64_t version = get_ufs_version(f);
++    struct file *fp = (struct file *)f->f_fsdata;
++    struct direct *dp;
++    struct direct *edp;
++    char *buf;
++    size_t buf_size;
++    int namlen;
++    int rc;
++
++    fp->f_seekp = 0;
++    int16_t di_size = (version == FS_UFS1_MAGIC) ? (off_t)fp->f_di.v1.di_size : (off_t)fp->f_di.v2.di_size;
++    while (fp->f_seekp < di_size) {
++        rc = buf_read_file(f, &buf, &buf_size);
++        if (rc)
++            return rc;
++
++        dp = (struct direct *)buf;
++        edp = (struct direct *)(buf + buf_size);
++        for (;dp < edp; dp = (void *)((char *)dp + dp->d_reclen)) {
++            if (dp->d_reclen <= 0)
++                break;
++            if (dp->d_ino == (ino32_t)0)
++                continue;
++#if BYTE_ORDER == LITTLE_ENDIAN
++            if (fp->f_fs->fs_maxsymlinklen <= 0)
++                namlen = dp->d_type;
++            else
++#endif
++                namlen = dp->d_namlen;
++            if (namlen == length &&
++                !memcmp(name, dp->d_name, length)) {
++                /* found entry */
++                *inumber_p = dp->d_ino;
++                return 0;
++            }
++        }
++        fp->f_seekp += buf_size;
++    }
++    return ENOENT;
++}
++
++
++/*
++ * Sanity checks for old file systems.
++ *
++ * XXX - goes away some day.
++ * Stripped of stuff libsa doesn't need.....
++ */
++void
++ffs_oldfscompat(FS *fs)
++{
++
++    /*
++     * Newer Solaris versions have a slightly incompatible
++     * superblock - so always calculate this values on the fly, which
++     * is good enough for libsa purposes
++     */
++    if (fs->fs_magic == FS_UFS1_MAGIC
++#ifndef COMPAT_SOLARIS_UFS
++        && fs->fs_old_inodefmt < FS_44INODEFMT
++#endif
++        ) {
++        fs->fs_qbmask = ~fs->fs_bmask;
++        fs->fs_qfmask = ~fs->fs_fmask;
++    }
++}
++
++daddr_t sblock_try[] = SBLOCKSEARCH;
++int
++ffs_find_superblock(struct open_file *f, FS *fs)
++{
++    int i;
++
++    for (i = 0; sblock_try[i] != -1; i++) {
++        /*rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
++            sblock_try[i] / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size);
++        if (rc != 0 || buf_size != SBLOCKSIZE)
++            return rc;*/
++        if (fs->fs_sblockloc != sblock_try[i])
++            /* an alternate superblock - try again */
++            continue;
++        if (fs->fs_magic == FS_UFS2_MAGIC) {
++            return 0;
++        }
++    }
++    return EINVAL;
++}
++
++int64_t get_ufs_version(struct open_file *f)
++{
++    struct file *fp = (struct file *)f->f_fsdata;
++    
++    FS *fs = fp->f_fs;
++    
++    if (fs->fs_magic == FS_UFS1_MAGIC)
++	return FS_UFS1_MAGIC;
++    
++    return FS_UFS2_MAGIC;
++}
Index: u-boot/patches/patch-fs_ufs_ffs__common.h
===================================================================
RCS file: u-boot/patches/patch-fs_ufs_ffs__common.h
diff -N u-boot/patches/patch-fs_ufs_ffs__common.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_ufs_ffs__common.h	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,359 @@
+$NetBSD$
+
+--- fs/ufs/ffs_common.h.orig	2018-02-22 19:29:00.717066503 +0000
++++ fs/ufs/ffs_common.h
+@@ -0,0 +1,354 @@
++/*-
++ * Copyright (c) 1993
++ *	The Regents of the University of California.  All rights reserved.
++ *
++ * This code is derived from software contributed to Berkeley by
++ * The Mach Operating System project at Carnegie-Mellon University.
++ *
++ * 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.
++ * 3. Neither the name of the University nor the names of its contributors
++ *    may be used to endorse or promote products derived from this software
++ *    without specific prior written permission.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
++ *
++ *
++ * Copyright (c) 1990, 1991 Carnegie Mellon University
++ * All Rights Reserved.
++ *
++ * Author: David Golub
++ *
++ * Permission to use, copy, modify and distribute this software and its
++ * documentation is hereby granted, provided that both the copyright
++ * notice and this permission notice appear in all copies of the
++ * software, derivative works or modified versions, and any portions
++ * thereof, and that both notices appear in supporting documentation.
++ *
++ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
++ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
++ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
++ *
++ * Carnegie Mellon requests users of this software to return to
++ *
++ *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
++ *  School of Computer Science
++ *  Carnegie Mellon University
++ *  Pittsburgh PA 15213-3890
++ *
++ * any improvements or extensions that they make and grant Carnegie the
++ * rights to redistribute these changes.
++ *
++ * Stand-alone file reading package for UFS and LFS filesystems.
++ *
++ * UFS/FFS filesystem ported to u-boot by
++ * berte <behzaterte at yandex.com>
++ *
++ * SPDX-License-Identifier:>GPL-2.0+
++ */
++
++#ifndef __FFS_COMMON_H__
++#define __FFS_COMMON_H__
++
++#include "fs.h"
++
++#define UFS_NXADDR 2
++#define UFS_NDADDR 12      /* Direct addresses in inode. */
++#define UFS_NIADDR 3       /* Indirect addresses in inode. */
++
++/*#define indp_t      int32_t*/
++#define indp_t      int64_t
++
++#define FS_MAGIC        	0x070162/*LFS_MAGIC*/
++#define SBLOCKSIZE      	8192/*LFS_SBPAD*/
++#define SBLOCKOFFSET    	8192/*LFS_LABELPAD*/
++#define FS_UFS1_MAGIC   	0x011954    /* UFS1 fast file system magic number */
++#define FS_UFS2_MAGIC   	0x19540119  /* UFS2 fast file system magic number */
++#define FS_UFS1_MAGIC_SWAPPED   0x54190100
++#define FS_UFS2_MAGIC_SWAPPED   0x19015419
++
++#define SBLOCK_FLOPPY      0
++#define SBLOCK_UFS1     8192
++#define SBLOCK_UFS2    	65536
++#define SBLOCK_PIGGY  	262144
++#define SBLOCKSIZE      8192
++#define DEV_BSIZE   	512
++
++#ifndef SEEK_SET
++#define	SEEK_SET	0	/* set file offset to offset */
++#endif
++#ifndef SEEK_CUR
++#define	SEEK_CUR	1	/* set file offset to current plus offset */
++#endif
++#ifndef SEEK_END
++#define	SEEK_END	2	/* set file offset to EOF plus offset */
++#endif
++
++/*
++ * NB: Do not, under any circumstances, look for an ffsv1 filesystem at
++ * SBLOCK_UFS2.  Doing so will find the wrong superblock for filesystems
++ * with a 64k block size.
++ */
++#define SBLOCKSEARCH \
++    { SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 }
++
++
++#define FS_OKAY     		0x7c269d38  /* superblock checksum */
++#define FS_42INODEFMT   	-1      /* 4.2BSD inode format */
++#define FS_44INODEFMT   	2       /* 4.4BSD inode format */
++#define LN2_IND_CACHE_SZ    	6
++#define IND_CACHE_SZ        	(1 << LN2_IND_CACHE_SZ)
++#define IND_CACHE_MASK      	(IND_CACHE_SZ - 1)
++
++#define UFS_DIRBLKSIZ       	512 
++#define FFS_MAXNAMLEN       	255
++#define APPLEUFS_DIRBLKSIZ  	1024
++#define MAXPHYS     		65536       /* max I/O transfer size */
++#define MAXPATHLEN  		1024/*PATH_MAX*/
++#define MAXSYMLINKS 		32
++#define MAXBSIZE    		MAXPHYS
++
++#define ffs_blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \
++        ((loc) & (fs)->fs_qbmask)
++
++#define ffs_lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \
++        ((loc) >> (fs)->fs_bshift)
++
++#define ffs_blksize(fs, ip, lbn) \
++    (((lbn) >= UFS_NDADDR || (ip)->i_size >= ffs_lblktosize(fs, (lbn) + 1)) \
++        ? (fs)->fs_bsize \
++        : ((int32_t)ffs_fragroundup(fs, ffs_blkoff(fs, (ip)->i_size))))
++
++#define ffs_sblksize(fs, size, lbn) \
++    (((lbn) >= UFS_NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \
++      ? (fs)->fs_bsize \
++      : ((int32_t)ffs_fragroundup(fs, ffs_blkoff(fs, (uint64_t)(size)))))
++
++
++#define DEV_NAME(d)     ((d)->dv_name)
++#define FFS_FSBTODB(fs, b)  ((b) << (fs)->fs_fsbtodb)
++#define FFS_DBTOFSB(fs, b)  ((b) >> (fs)->fs_fsbtodb)
++
++#ifndef FSBTODB
++    #define FSBTODB(fs, indp) FFS_FSBTODB(fs, indp)
++#endif
++#ifndef UFS_NINDIR
++    #define UFS_NINDIR FFS_NINDIR
++#endif
++#ifndef ufs_blkoff
++    #define ufs_blkoff ffs_blkoff
++#endif
++#ifndef ufs_lblkno
++    #define ufs_lblkno ffs_lblkno
++#endif
++
++#define FFS_NINDIR(fs)  ((fs)->fs_nindir)
++#define    cgbase(fs, c)   (((daddr_t)(fs)->fs_fpg) * (c))
++
++#define cgstart_ufs1(fs, c) \
++    (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask)))
++
++#define cgstart_ufs2(fs, c) cgbase((fs), (c))
++
++#define cgstart(fs, c) ((fs)->fs_magic == FS_UFS2_MAGIC \
++                ? cgstart_ufs2((fs), (c)) : cgstart_ufs1((fs), (c)))
++
++#define cgdmin(fs, c)   (cgstart(fs, c) + (fs)->fs_dblkno)  /* 1st data */
++#define cgimin(fs, c)   (cgstart(fs, c) + (fs)->fs_iblkno)  /* inode blk */
++#define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno)  /* super blk */
++#define cgtod(fs, c)    (cgstart(fs, c) + (fs)->fs_cblkno)  /* cg block */
++
++#define ino_to_cg(fs, x)    ((x) / (fs)->fs_ipg)
++
++#define ino_to_fsba(fs, x)                      \
++    ((daddr_t)(cgimin(fs, ino_to_cg(fs, x)) +           \
++        (ffs_blkstofrags((fs), (((x) % (fs)->fs_ipg) / FFS_INOPB(fs))))))
++
++#define ino_to_fsbo(fs, x)  ((x) % FFS_INOPB(fs))
++
++/* f_flags values */
++#define F_READ      0x0001  /* file opened for reading */
++#define F_WRITE     0x0002  /* file opened for writing */
++#define F_RAW       0x0004  /* raw device open - no file system */
++#define F_NODEV     0x0008  /* network open - no device */
++
++#define UFS_ROOTINO ((ino_t)2)
++#define UFS_ROOTINO ((ino_t)2)
++
++/* File permissions. */
++#define IEXEC       0000100     /* Executable. */
++#define IWRITE      0000200     /* Writable. */
++#define IREAD       0000400     /* Readable. */
++#define ISVTX       0001000     /* Sticky bit. */
++#define ISGID       0002000     /* Set-gid. */
++#define ISUID       0004000     /* Set-uid. */
++
++/* File types. */
++#define IFMT        0170000     /* Mask of file type. */
++#define IFIFO       0010000     /* Named pipe (fifo). */
++#define IFCHR       0020000     /* Character device. */
++#define IFDIR       0040000     /* Directory file. */
++#define IFBLK       0060000     /* Block device. */
++#define IFREG       0100000     /* Regular file. */
++#define IFLNK       0120000     /* Symbolic link. */
++#define IFSOCK      0140000     /* UNIX domain socket. */
++#define IFWHT       0160000     /* Whiteout. */
++
++#define TWIDDLE_CHARS   "|/-\\"
++
++extern int ndevs;       /* number of elements in devsw[] */
++typedef uint32_t ino32_t;
++typedef struct fs FS;
++typedef struct _ufs_dinode ufs_dinode;
++
++struct ufs1_dinode {
++    uint16_t    di_mode;    /*   0: IFMT, permissions; see below. */
++    int16_t     di_nlink;   /*   2: File link count. */
++    uint16_t    di_oldids[2];   /*   4: Ffs: old user and group ids. */
++    uint64_t    di_size;    /*   8: File byte count. */
++    int32_t     di_atime;   /*  16: Last access time. */
++    int32_t     di_atimensec;   /*  20: Last access time. */
++    int32_t     di_mtime;   /*  24: Last modified time. */
++    int32_t     di_mtimensec;   /*  28: Last modified time. */
++    int32_t     di_ctime;   /*  32: Last inode change time. */
++    int32_t     di_ctimensec;   /*  36: Last inode change time. */
++    int32_t     di_db[UFS_NDADDR]; /*  40: Direct disk blocks. */
++    int32_t     di_ib[UFS_NIADDR]; /*  88: Indirect disk blocks. */
++    uint32_t    di_flags;   /* 100: Status flags (chflags). */
++    uint32_t    di_blocks;  /* 104: Blocks actually held. */
++    int32_t     di_gen;     /* 108: Generation number. */
++    uint32_t    di_uid;     /* 112: File owner. */
++    uint32_t    di_gid;     /* 116: File group. */
++    uint64_t    di_modrev;  /* 120: i_modrev for NFSv4 */
++};
++
++struct ufs2_dinode {
++    uint16_t    di_mode;    /*   0: IFMT, permissions; see below. */
++    int16_t     di_nlink;   /*   2: File link count. */
++    uint32_t    di_uid;     /*   4: File owner. */
++    uint32_t    di_gid;     /*   8: File group. */
++    uint32_t    di_blksize; /*  12: Inode blocksize. */
++    uint64_t    di_size;    /*  16: File byte count. */
++    uint64_t    di_blocks;  /*  24: Bytes actually held. */
++    int64_t     di_atime;   /*  32: Last access time. */
++    int64_t     di_mtime;   /*  40: Last modified time. */
++    int64_t     di_ctime;   /*  48: Last inode change time. */
++    int64_t     di_birthtime;   /*  56: Inode creation time. */
++    int32_t     di_mtimensec;   /*  64: Last modified time. */
++    int32_t     di_atimensec;   /*  68: Last access time. */
++    int32_t     di_ctimensec;   /*  72: Last inode change time. */
++    int32_t     di_birthnsec;   /*  76: Inode creation time. */
++    int32_t     di_gen;     /*  80: Generation number. */
++    uint32_t    di_kernflags;   /*  84: Kernel flags. */
++    uint32_t    di_flags;   /*  88: Status flags (chflags). */
++    int32_t     di_extsize; /*  92: External attributes block. */
++    int64_t     di_extb[UFS_NXADDR];/* 96: External attributes block. */
++    int64_t     di_db[UFS_NDADDR]; /* 112: Direct disk blocks. */
++    int64_t     di_ib[UFS_NIADDR]; /* 208: Indirect disk blocks. */
++    uint64_t    di_modrev;  /* 232: i_modrev for NFSv4 */
++    int64_t     di_spare[2];    /* 240: Reserved; currently unused */
++};
++
++struct _ufs_dinode
++{
++    struct ufs1_dinode v1;
++    struct ufs2_dinode v2;
++};
++
++struct file {
++     off_t    f_seekp;    		/* seek pointer */
++     FS      *f_fs;      		/* pointer to super-block */
++     ufs_dinode f_di;       		/* copy of on-disk inode */
++     uint    f_nishift;  		/* for blocks in indirect block */
++     indp_t  f_ind_cache_block;
++     indp_t  f_ind_cache[IND_CACHE_SZ];
++
++     char    *f_buf;     		/* buffer for data block */
++     size_t  f_buf_size; 		/* size of data block */
++     daddr_t f_buf_blkno;    		/* block number of data block */
++};
++
++struct open_file {
++    int     f_flags;    /* see F_* below */
++#if !defined(LIBSA_SINGLE_DEVICE)
++    const struct devsw  *f_dev; /* pointer to device operations */
++#endif
++    void        *f_devdata; /* device specific data */
++#if !defined(LIBSA_SINGLE_FILESYSTEM)
++    const struct fs_ops *f_ops; /* pointer to file system operations */
++#endif
++    void        *f_fsdata;  /* file system specific data */
++#if !defined(LIBSA_NO_RAW_ACCESS)
++    off_t       f_offset;   /* current file offset (F_RAW) */
++#endif
++};
++
++struct lsentry {
++    struct lsentry *e_next;
++    uint32_t e_ino;
++    const char *e_type;
++    char    e_name[1];
++};
++
++typedef struct lsentry lsentry_t;
++
++#define d_ino d_fileno
++struct  direct {
++    u_int32_t d_fileno;     /* inode number of entry */
++    u_int16_t d_reclen;     /* length of this record */
++    u_int8_t  d_type;       /* file type, see below */
++    u_int8_t  d_namlen;     /* length of string in d_name */
++    char      d_name[FFS_MAXNAMLEN + 1];/* name with length <= FFS_MAXNAMLEN */
++};
++
++#define NELEM(x) (sizeof (x) / sizeof(*x))
++
++static const char    *const typestr[] = {
++    "unknown",
++    "FIFO",
++    "CHR",
++    0,
++    "DIR",
++    0,
++    "BLK",
++    0,
++    "REG",
++    0,
++    "LNK",
++    0,
++    "SOCK",
++    0,
++    "WHT"
++};
++
++void dealloc(void *, size_t );
++void *alloc(size_t);
++void twiddle(void);
++int fnmatch(const char *, const char *);
++void lsadd(lsentry_t **, const char *, const char *, size_t, uint32_t, const char *);
++void lsprint(lsentry_t *); 
++void lsfree(lsentry_t *);
++int read_inode(ino32_t, struct open_file *);
++int block_map(struct open_file *, indp_t, indp_t *);
++int buf_read_file(struct open_file *, char **, size_t *);
++int search_directory(const char *, int, struct open_file *, ino32_t *);
++void ffs_oldfscompat(FS *);
++int ffs_find_superblock(struct open_file *, FS *);
++int64_t get_ufs_version(struct open_file*);
++#endif /* __FFS_COMMON_H__  */
Index: u-boot/patches/patch-fs_ufs_fs.h
===================================================================
RCS file: u-boot/patches/patch-fs_ufs_fs.h
diff -N u-boot/patches/patch-fs_ufs_fs.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-fs_ufs_fs.h	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,760 @@
+$NetBSD$
+
+--- fs/ufs/fs.h.orig	2018-02-22 19:29:00.717716882 +0000
++++ fs/ufs/fs.h
+@@ -0,0 +1,755 @@
++/*
++ * Copyright (c) 1982, 1986, 1993
++ *	The Regents of the University of California.  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.
++ * 3. Neither the name of the University nor the names of its contributors
++ *    may be used to endorse or promote products derived from this software
++ *    without specific prior written permission.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
++ *
++ *	@(#)fs.h	8.13 (Berkeley) 3/21/95
++ */
++
++/*
++ * NOTE: COORDINATE ON-DISK FORMAT CHANGES WITH THE FREEBSD PROJECT.
++ * SPDX-License-Identifier:>GPL-2.0+
++ */
++
++#ifndef	_UFS_FFS_FS_H_
++#define	_UFS_FFS_FS_H_
++
++/*
++ * Each disk drive contains some number of file systems.
++ * A file system consists of a number of cylinder groups.
++ * Each cylinder group has inodes and data.
++ *
++ * A file system is described by its super-block, which in turn
++ * describes the cylinder groups.  The super-block is critical
++ * data and is replicated in each cylinder group to protect against
++ * catastrophic loss.  This is done at `newfs' time and the critical
++ * super-block data does not change, so the copies need not be
++ * referenced further unless disaster strikes.
++ *
++ * For file system fs, the offsets of the various blocks of interest
++ * are given in the super block as:
++ *	[fs->fs_sblkno]		Super-block
++ *	[fs->fs_cblkno]		Cylinder group block
++ *	[fs->fs_iblkno]		Inode blocks
++ *	[fs->fs_dblkno]		Data blocks
++ * The beginning of cylinder group cg in fs, is given by
++ * the ``cgbase(fs, cg)'' macro.
++ *
++ * Depending on the architecture and the media, the superblock may
++ * reside in any one of four places. For tiny media where every block
++ * counts, it is placed at the very front of the partition. Historically,
++ * UFS1 placed it 8K from the front to leave room for the disk label and
++ * a small bootstrap. For UFS2 it got moved to 64K from the front to leave
++ * room for the disk label and a bigger bootstrap, and for really piggy
++ * systems we check at 256K from the front if the first three fail. In
++ * all cases the size of the superblock will be SBLOCKSIZE. All values are
++ * given in byte-offset form, so they do not imply a sector size. The
++ * SBLOCKSEARCH specifies the order in which the locations should be searched.
++ *
++ * Unfortunately the UFS2/FFSv2 change was done without adequate consideration
++ * of backward compatibility.  In particular 'newfs' for a FFSv2 partition
++ * must overwrite any old FFSv1 superblock at 8k, and preferably as many
++ * of the alternates as it can find - otherwise attempting to mount on a
++ * system that only supports FFSv1 is likely to succeed!.
++ * For a small FFSv1 filesystem, an old FFSv2 superblock can be left on
++ * the disk, and a system that tries to find an FFSv2 filesystem in preference
++ * to and FFSv1 one (as NetBSD does) can mount the old FFSv2 filesystem.
++ * As a added bonus, the 'first alternate' superblock of a FFSv1 filesystem
++ * with 64k blocks is at 64k - just where the code looks first when playing
++ * 'hunt the superblock'.
++ *
++ * The ffsv2 superblock layout (which might contain an ffsv1 filesystem)
++ * can be detected by checking for sb->fs_old_flags & FS_FLAGS_UPDATED.
++ * This is the default superblock type for NetBSD since ffsv2 support was added.
++ */
++#define	BBSIZE		8192
++#define	BBOFF		((off_t)(0))
++#define	BBLOCK		((daddr_t)(0))
++
++#define	SBLOCK_FLOPPY      0
++#define	SBLOCK_UFS1     8192
++#define	SBLOCK_UFS2    65536
++#define	SBLOCK_PIGGY  262144
++#define	SBLOCKSIZE      8192
++/*
++ * NB: Do not, under any circumstances, look for an ffsv1 filesystem at
++ * SBLOCK_UFS2.  Doing so will find the wrong superblock for filesystems
++ * with a 64k block size.
++ */
++#define	SBLOCKSEARCH \
++	{ SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 }
++
++/*
++ * Max number of fragments per block. This value is NOT tweakable.
++ */
++#define	MAXFRAG		8
++
++
++
++/*
++ * Addresses stored in inodes are capable of addressing fragments
++ * of `blocks'. File system blocks of at most size MAXBSIZE can
++ * be optionally broken into 2, 4, or 8 pieces, each of which is
++ * addressable; these pieces may be DEV_BSIZE, or some multiple of
++ * a DEV_BSIZE unit.
++ *
++ * Large files consist of exclusively large data blocks.  To avoid
++ * undue wasted disk space, the last data block of a small file may be
++ * allocated as only as many fragments of a large block as are
++ * necessary.  The file system format retains only a single pointer
++ * to such a fragment, which is a piece of a single large block that
++ * has been divided.  The size of such a fragment is determinable from
++ * information in the inode, using the ``ffs_blksize(fs, ip, lbn)'' macro.
++ *
++ * The file system records space availability at the fragment level;
++ * to determine block availability, aligned fragments are examined.
++ */
++
++/*
++ * MINBSIZE is the smallest allowable block size.
++ * In order to insure that it is possible to create files of size
++ * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
++ * MINBSIZE must be big enough to hold a cylinder group block,
++ * thus changes to (struct cg) must keep its size within MINBSIZE.
++ * Note that super blocks are always of size SBSIZE,
++ * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
++ */
++#define	MINBSIZE	4096
++
++/*
++ * The path name on which the file system is mounted is maintained
++ * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
++ * the super block for this name.
++ */
++#define	MAXMNTLEN	468
++
++/*
++ * The volume name for this filesystem is maintained in fs_volname.
++ * MAXVOLLEN defines the length of the buffer allocated.
++ * This space used to be part of of fs_fsmnt.
++ */
++#define	MAXVOLLEN	32
++
++/*
++ * There is a 128-byte region in the superblock reserved for in-core
++ * pointers to summary information. Originally this included an array
++ * of pointers to blocks of struct csum; now there are just four
++ * pointers and the remaining space is padded with fs_ocsp[].
++ * NOCSPTRS determines the size of this padding. One pointer (fs_csp)
++ * is taken away to point to a contiguous array of struct csum for
++ * all cylinder groups; a second (fs_maxcluster) points to an array
++ * of cluster sizes that is computed as cylinder groups are inspected;
++ * the third (fs_contigdirs) points to an array that tracks the
++ * creation of new directories; and the fourth (fs_active) is used
++ * by snapshots.
++ */
++#define	NOCSPTRS	((128 / sizeof(void *)) - 4)
++
++/*
++ * A summary of contiguous blocks of various sizes is maintained
++ * in each cylinder group. Normally this is set by the initial
++ * value of fs_maxcontig. To conserve space, a maximum summary size
++ * is set by FS_MAXCONTIG.
++ */
++#define	FS_MAXCONTIG	16
++
++/*
++ * The maximum number of snapshot nodes that can be associated
++ * with each filesystem. This limit affects only the number of
++ * snapshot files that can be recorded within the superblock so
++ * that they can be found when the filesystem is mounted. However,
++ * maintaining too many will slow the filesystem performance, so
++ * having this limit is a good idea.
++ */
++#define	FSMAXSNAP 20
++
++/*
++ * Used to identify special blocks in snapshots:
++ *
++ * BLK_NOCOPY - A block that was unallocated at the time the snapshot
++ *      was taken, hence does not need to be copied when written.
++ * BLK_SNAP - A block held by another snapshot that is not needed by this
++ *      snapshot. When the other snapshot is freed, the BLK_SNAP entries
++ *      are converted to BLK_NOCOPY. These are needed to allow fsck to
++ *      identify blocks that are in use by other snapshots (which are
++ *      expunged from this snapshot).
++ */
++#define	BLK_NOCOPY	((daddr_t)(1))
++#define	BLK_SNAP	((daddr_t)(2))
++
++/*
++ * MINFREE gives the minimum acceptable percentage of file system
++ * blocks which may be free. If the freelist drops below this level
++ * only the superuser may continue to allocate blocks. This may
++ * be set to 0 if no reserve of free blocks is deemed necessary,
++ * however throughput drops by fifty percent if the file system
++ * is run at between 95% and 100% full; thus the minimum default
++ * value of fs_minfree is 5%. However, to get good clustering
++ * performance, 10% is a better choice. This value is used only
++ * when creating a file system and can be overridden from the
++ * command line. By default we choose to optimize for time.
++ */
++#define	MINFREE		5
++#define	DEFAULTOPT	FS_OPTTIME
++
++/*
++ * Grigoriy Orlov <gluk%ptci.ru@localhost> has done some extensive work to fine
++ * tune the layout preferences for directories within a filesystem.
++ * His algorithm can be tuned by adjusting the following parameters
++ * which tell the system the average file size and the average number
++ * of files per directory. These defaults are well selected for typical
++ * filesystems, but may need to be tuned for odd cases like filesystems
++ * being used for squid caches or news spools.
++ */
++#define	AVFILESIZ	16384	/* expected average file size */
++#define	AFPDIR		64	/* expected number of files per directory */
++
++/*
++ * Per cylinder group information; summarized in blocks allocated
++ * from first cylinder group data blocks.  These blocks have to be
++ * read in from fs_csaddr (size fs_cssize) in addition to the
++ * super block.
++ */
++struct csum {
++	int32_t	cs_ndir;		/* number of directories */
++	int32_t	cs_nbfree;		/* number of free blocks */
++	int32_t	cs_nifree;		/* number of free inodes */
++	int32_t	cs_nffree;		/* number of free frags */
++};
++
++struct csum_total {
++	int64_t cs_ndir;		/* number of directories */
++	int64_t cs_nbfree;		/* number of free blocks */
++	int64_t cs_nifree;		/* number of free inodes */
++	int64_t cs_nffree;		/* number of free frags */
++	int64_t cs_spare[4];		/* future expansion */
++};
++
++
++/*
++ * Super block for an FFS file system in memory.
++ */
++struct fs {
++	int32_t	 fs_firstfield;		/* historic file system linked list, */
++	int32_t	 fs_unused_1;		/*     used for incore super blocks */
++	int32_t  fs_sblkno;		/* addr of super-block in filesys */
++	int32_t  fs_cblkno;		/* offset of cyl-block in filesys */
++	int32_t  fs_iblkno;		/* offset of inode-blocks in filesys */
++	int32_t  fs_dblkno;		/* offset of first data after cg */
++	int32_t	 fs_old_cgoffset;	/* cylinder group offset in cylinder */
++	int32_t	 fs_old_cgmask;		/* used to calc mod fs_ntrak */
++	int32_t	 fs_old_time;		/* last time written */
++	int32_t	 fs_old_size;		/* number of blocks in fs */
++	int32_t	 fs_old_dsize;		/* number of data blocks in fs */
++	int32_t	 fs_ncg;		/* number of cylinder groups */
++	int32_t	 fs_bsize;		/* size of basic blocks in fs */
++	int32_t	 fs_fsize;		/* size of frag blocks in fs */
++	int32_t	 fs_frag;		/* number of frags in a block in fs */
++/* these are configuration parameters */
++	int32_t	 fs_minfree;		/* minimum percentage of free blocks */
++	int32_t	 fs_old_rotdelay;	/* num of ms for optimal next block */
++	int32_t	 fs_old_rps;		/* disk revolutions per second */
++/* these fields can be computed from the others */
++	int32_t	 fs_bmask;		/* ``blkoff'' calc of blk offsets */
++	int32_t	 fs_fmask;		/* ``fragoff'' calc of frag offsets */
++	int32_t	 fs_bshift;		/* ``lblkno'' calc of logical blkno */
++	int32_t	 fs_fshift;		/* ``numfrags'' calc number of frags */
++/* these are configuration parameters */
++	int32_t	 fs_maxcontig;		/* max number of contiguous blks */
++	int32_t	 fs_maxbpg;		/* max number of blks per cyl group */
++/* these fields can be computed from the others */
++	int32_t	 fs_fragshift;		/* block to frag shift */
++	int32_t	 fs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
++	int32_t	 fs_sbsize;		/* actual size of super block */
++	int32_t	 fs_spare1[2];		/* old fs_csmask */
++					/* old fs_csshift */
++	int32_t	 fs_nindir;		/* value of FFS_NINDIR */
++	int32_t	 fs_inopb;		/* value of FFS_INOPB */
++	int32_t	 fs_old_nspf;		/* value of NSPF */
++/* yet another configuration parameter */
++	int32_t	 fs_optim;		/* optimization preference, see below */
++/* these fields are derived from the hardware */
++	int32_t	 fs_old_npsect;		/* # sectors/track including spares */
++	int32_t	 fs_old_interleave;	/* hardware sector interleave */
++	int32_t	 fs_old_trackskew;	/* sector 0 skew, per track */
++/* fs_id takes the space of the unused fs_headswitch and fs_trkseek fields */
++	int32_t	 fs_id[2];		/* unique file system id */
++/* sizes determined by number of cylinder groups and their sizes */
++	int32_t  fs_old_csaddr;		/* blk addr of cyl grp summary area */
++	int32_t	 fs_cssize;		/* size of cyl grp summary area */
++	int32_t	 fs_cgsize;		/* cylinder group size */
++/* these fields are derived from the hardware */
++	int32_t	 fs_spare2;		/* old fs_ntrak */
++	int32_t	 fs_old_nsect;		/* sectors per track */
++	int32_t	 fs_old_spc;		/* sectors per cylinder */
++	int32_t	 fs_old_ncyl;		/* cylinders in file system */
++	int32_t	 fs_old_cpg;		/* cylinders per group */
++	int32_t	 fs_ipg;		/* inodes per group */
++	int32_t	 fs_fpg;		/* blocks per group * fs_frag */
++/* this data must be re-computed after crashes */
++	struct	csum fs_old_cstotal;	/* cylinder summary information */
++/* these fields are cleared at mount time */
++	int8_t	 fs_fmod;		/* super block modified flag */
++	uint8_t	 fs_clean;		/* file system is clean flag */
++	int8_t	 fs_ronly;		/* mounted read-only flag */
++	uint8_t	 fs_old_flags;		/* see FS_ flags below */
++	u_char	 fs_fsmnt[MAXMNTLEN];	/* name mounted on */
++	u_char   fs_volname[MAXVOLLEN];	/* volume name */
++	uint64_t fs_swuid;		/* system-wide uid */
++	int32_t	 fs_pad;
++/* these fields retain the current block allocation info */
++	int32_t	 fs_cgrotor;		/* last cg searched (UNUSED) */
++	void 	*fs_ocsp[NOCSPTRS];	/* padding; was list of fs_cs buffers */
++	u_int8_t *fs_contigdirs;	/* # of contiguously allocated dirs */
++	struct csum *fs_csp;		/* cg summary info buffer for fs_cs */
++	int32_t	*fs_maxcluster;		/* max cluster in each cyl group */
++	u_char	*fs_active;		/* used by snapshots to track fs */
++	int32_t	 fs_old_cpc;		/* cyl per cycle in postbl */
++/* this area is otherwise allocated unless fs_old_flags & FS_FLAGS_UPDATED */
++	int32_t	 fs_maxbsize;		/* maximum blocking factor permitted */
++	uint8_t	 fs_journal_version;	/* journal format version */
++	uint8_t	 fs_journal_location;	/* journal location type */
++	uint8_t	 fs_journal_reserved[2];/* reserved for future use */
++	uint32_t fs_journal_flags;	/* journal flags */
++	uint64_t fs_journallocs[4];	/* location info for journal */
++	uint32_t fs_quota_magic;	/* see quota2.h */
++	uint8_t  fs_quota_flags;	/* see quota2.h */
++	uint8_t  fs_quota_reserved[3];	
++	uint64_t fs_quotafile[2];	/* pointer to quota inodes */
++	int64_t	 fs_sparecon64[9];	/* reserved for future use */
++	int64_t	 fs_sblockloc;		/* byte offset of standard superblock */
++	struct	csum_total fs_cstotal;	/* cylinder summary information */
++	int64_t  fs_time;		/* last time written */
++	int64_t	 fs_size;		/* number of blocks in fs */
++	int64_t	 fs_dsize;		/* number of data blocks in fs */
++	int64_t  fs_csaddr;		/* blk addr of cyl grp summary area */
++	int64_t	 fs_pendingblocks;	/* blocks in process of being freed */
++	int32_t	 fs_pendinginodes;	/* inodes in process of being freed */
++	int32_t	 fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */
++/* back to stuff that has been around a while */
++	int32_t	 fs_avgfilesize;	/* expected average file size */
++	int32_t	 fs_avgfpdir;		/* expected # of files per directory */
++	int32_t	 fs_save_cgsize;	/* save real cg size to use fs_bsize */
++	int32_t	 fs_sparecon32[26];	/* reserved for future constants */
++	uint32_t fs_flags;		/* see FS_ flags below */
++/* back to stuff that has been around a while (again) */
++	int32_t	 fs_contigsumsize;	/* size of cluster summary array */
++	int32_t	 fs_maxsymlinklen;	/* max length of an internal symlink */
++	int32_t	 fs_old_inodefmt;	/* format of on-disk inodes */
++	u_int64_t fs_maxfilesize;	/* maximum representable file size */
++	int64_t	 fs_qbmask;		/* ~fs_bmask for use with 64-bit size */
++	int64_t	 fs_qfmask;		/* ~fs_fmask for use with 64-bit size */
++	int32_t	 fs_state;		/* validate fs_clean field (UNUSED) */
++	int32_t	 fs_old_postblformat;	/* format of positional layout tables */
++	int32_t	 fs_old_nrpos;		/* number of rotational positions */
++	int32_t  fs_spare5[2];		/* old fs_postbloff */
++					/* old fs_rotbloff */
++	int32_t	 fs_magic;		/* magic number */
++};
++
++#define	fs_old_postbloff	fs_spare5[0]
++#define	fs_old_rotbloff		fs_spare5[1]
++#define	fs_old_postbl_start	fs_maxbsize
++#define	fs_old_headswitch	fs_id[0]
++#define	fs_old_trkseek	fs_id[1]
++#define	fs_old_csmask	fs_spare1[0]
++#define	fs_old_csshift	fs_spare1[1]
++
++#define	FS_42POSTBLFMT		-1	/* 4.2BSD rotational table format */
++#define	FS_DYNAMICPOSTBLFMT	1	/* dynamic rotational table format */
++
++#define	old_fs_postbl(fs_, cylno, opostblsave) \
++    ((((fs_)->fs_old_postblformat == FS_42POSTBLFMT) || \
++     ((fs_)->fs_old_postbloff == offsetof(struct fs, fs_old_postbl_start))) \
++    ? ((int16_t *)(opostblsave) + (cylno) * (fs_)->fs_old_nrpos) \
++    : ((int16_t *)((uint8_t *)(fs_) + \
++	(fs_)->fs_old_postbloff) + (cylno) * (fs_)->fs_old_nrpos))
++
++#define	old_fs_rotbl(fs) \
++    (((fs)->fs_old_postblformat == FS_42POSTBLFMT) \
++    ? ((uint8_t *)(&(fs)->fs_magic+1)) \
++    : ((uint8_t *)((uint8_t *)(fs) + (fs)->fs_old_rotbloff)))
++
++/*
++ * File system identification
++ */
++#define	FS_UFS1_MAGIC	0x011954	/* UFS1 fast file system magic number */
++#define	FS_UFS2_MAGIC	0x19540119	/* UFS2 fast file system magic number */
++#define	FS_UFS1_MAGIC_SWAPPED	0x54190100
++#define	FS_UFS2_MAGIC_SWAPPED	0x19015419
++#define	FS_OKAY		0x7c269d38	/* superblock checksum */
++#define	FS_42INODEFMT	-1		/* 4.2BSD inode format */
++#define	FS_44INODEFMT	2		/* 4.4BSD inode format */
++
++/*
++ * File system clean flags
++ */
++#define	FS_ISCLEAN	0x01
++#define	FS_WASCLEAN	0x02
++
++/*
++ * Preference for optimization.
++ */
++#define	FS_OPTTIME	0	/* minimize allocation time */
++#define	FS_OPTSPACE	1	/* minimize disk fragmentation */
++
++/*
++ * File system flags
++ */
++#define	FS_UNCLEAN	0x001	/* file system not clean at mount (unused) */
++#define	FS_DOSOFTDEP	0x002	/* file system using soft dependencies */
++#define	FS_NEEDSFSCK	0x004	/* needs sync fsck (FreeBSD compat, unused) */
++#define	FS_SUJ		0x008	/* file system using journaled softupdates */
++#define	FS_ACLS		0x010	/* file system has ACLs enabled */
++#define	FS_MULTILABEL	0x020	/* file system is MAC multi-label */
++#define	FS_GJOURNAL	0x40	/* gjournaled file system */
++#define	FS_FLAGS_UPDATED 0x80	/* flags have been moved to new location */
++#define	FS_DOWAPBL	0x100	/* Write ahead physical block logging */
++/*     	FS_NFS4ACLS	0x100	   file system has NFSv4 ACLs enabled (FBSD) */
++#define	FS_DOQUOTA2	0x200	/* in-filesystem quotas */
++/*     	FS_INDEXDIRS	0x200	   kernel supports indexed directories (FBSD)*/
++#define	FS_TRIM		0x400	/* discard deleted blocks in storage layer */
++
++/* File system flags that are ok for NetBSD if set in fs_flags */
++#define	FS_KNOWN_FLAGS	(FS_DOSOFTDEP | FS_DOWAPBL | FS_DOQUOTA2)
++
++/*
++ * File system internal flags, also in fs_flags.
++ * (Pick highest number to avoid conflicts with others)
++ */
++#define	FS_SWAPPED	0x80000000	/* file system is endian swapped */
++#define	FS_INTERNAL	0x80000000	/* mask for internal flags */
++
++/*
++ * Macros to access bits in the fs_active array.
++ */
++#define	ACTIVECG_SET(fs, cg)				\
++	do {						\
++		if ((fs)->fs_active != NULL)		\
++			setbit((fs)->fs_active, (cg));	\
++	} while (/*CONSTCOND*/ 0)
++#define	ACTIVECG_CLR(fs, cg)				\
++	do {						\
++		if ((fs)->fs_active != NULL)		\
++			clrbit((fs)->fs_active, (cg));	\
++	} while (/*CONSTCOND*/ 0)
++#define	ACTIVECG_ISSET(fs, cg)				\
++	((fs)->fs_active != NULL && isset((fs)->fs_active, (cg)))
++
++/*
++ * The size of a cylinder group is calculated by CGSIZE. The maximum size
++ * is limited by the fact that cylinder groups are at most one block.
++ * Its size is derived from the size of the maps maintained in the
++ * cylinder group and the (struct cg) size.
++ */
++#define	CGSIZE_IF(fs, ipg, fpg) \
++    /* base cg */	(sizeof(struct cg) + sizeof(int32_t) + \
++    /* old btotoff */	(fs)->fs_old_cpg * sizeof(int32_t) + \
++    /* old boff */	(fs)->fs_old_cpg * sizeof(u_int16_t) + \
++    /* inode map */	howmany((ipg), NBBY) + \
++    /* block map */	howmany((fpg), NBBY) +\
++    /* if present */	((fs)->fs_contigsumsize <= 0 ? 0 : \
++    /* cluster sum */	(fs)->fs_contigsumsize * sizeof(int32_t) + \
++    /* cluster map */	howmany(ffs_fragstoblks(fs, (fpg)), NBBY)))
++
++#define	CGSIZE(fs) CGSIZE_IF((fs), (fs)->fs_ipg, (fs)->fs_fpg)
++
++/*
++ * The minimal number of cylinder groups that should be created.
++ */
++#define	MINCYLGRPS	4
++
++
++/*
++ * Convert cylinder group to base address of its global summary info.
++ */
++#define	fs_cs(fs, indx)	fs_csp[indx]
++
++/*
++ * Cylinder group block for a file system.
++ */
++#define	CG_MAGIC	0x090255
++struct cg {
++	int32_t	 cg_firstfield;		/* historic cyl groups linked list */
++	int32_t	 cg_magic;		/* magic number */
++	int32_t	 cg_old_time;		/* time last written */
++	int32_t	 cg_cgx;		/* we are the cgx'th cylinder group */
++	int16_t	 cg_old_ncyl;		/* number of cyl's this cg */
++	int16_t	 cg_old_niblk;		/* number of inode blocks this cg */
++	int32_t	 cg_ndblk;		/* number of data blocks this cg */
++	struct	csum cg_cs;		/* cylinder summary information */
++	int32_t	 cg_rotor;		/* position of last used block */
++	int32_t	 cg_frotor;		/* position of last used frag */
++	int32_t	 cg_irotor;		/* position of last used inode */
++	int32_t	 cg_frsum[MAXFRAG];	/* counts of available frags */
++	int32_t	 cg_old_btotoff;	/* (int32) block totals per cylinder */
++	int32_t	 cg_old_boff;		/* (u_int16) free block positions */
++	int32_t	 cg_iusedoff;		/* (u_int8) used inode map */
++	int32_t	 cg_freeoff;		/* (u_int8) free block map */
++	int32_t	 cg_nextfreeoff;	/* (u_int8) next available space */
++	int32_t	 cg_clustersumoff;	/* (u_int32) counts of avail clusters */
++	int32_t	 cg_clusteroff;		/* (u_int8) free cluster map */
++	int32_t	 cg_nclusterblks;	/* number of clusters this cg */
++	int32_t  cg_niblk;		/* number of inode blocks this cg */
++	int32_t  cg_initediblk;		/* last initialized inode */
++	int32_t	 cg_sparecon32[3];	/* reserved for future use */
++	int64_t  cg_time;		/* time last written */
++	int64_t  cg_sparecon64[3];	/* reserved for future use */
++	u_int8_t cg_space[1];		/* space for cylinder group maps */
++/* actually longer */
++};
++
++/*
++ * The following structure is defined
++ * for compatibility with old file systems.
++ */
++struct ocg {
++	int32_t  cg_firstfield;		/* historic linked list of cyl groups */
++	int32_t  cg_unused_1;		/*     used for incore cyl groups */
++	int32_t  cg_time;		/* time last written */
++	int32_t  cg_cgx;		/* we are the cgx'th cylinder group */
++	int16_t  cg_ncyl;		/* number of cyl's this cg */
++	int16_t  cg_niblk;		/* number of inode blocks this cg */
++	int32_t  cg_ndblk;		/* number of data blocks this cg */
++	struct  csum cg_cs;		/* cylinder summary information */
++	int32_t  cg_rotor;		/* position of last used block */
++	int32_t  cg_frotor;		/* position of last used frag */
++	int32_t  cg_irotor;		/* position of last used inode */
++	int32_t  cg_frsum[8];		/* counts of available frags */
++	int32_t  cg_btot[32];		/* block totals per cylinder */
++	int16_t  cg_b[32][8];		/* positions of free blocks */
++	u_int8_t cg_iused[256];		/* used inode map */
++	int32_t  cg_magic;		/* magic number */
++	u_int8_t cg_free[1];		/* free block map */
++/* actually longer */
++};
++
++
++/*
++ * Macros for access to cylinder group array structures.
++ */
++#define	old_cg_blktot_old(cgp, ns) \
++    (((struct ocg *)(cgp))->cg_btot)
++#define	old_cg_blks_old(fs, cgp, cylno, ns) \
++    (((struct ocg *)(cgp))->cg_b[cylno])
++
++#define	old_cg_blktot_new(cgp, ns) \
++    ((int32_t *)((u_int8_t *)(cgp) + \
++	ufs_rw32((cgp)->cg_old_btotoff, (ns))))
++#define	old_cg_blks_new(fs, cgp, cylno, ns) \
++    ((int16_t *)((u_int8_t *)(cgp) + \
++	ufs_rw32((cgp)->cg_old_boff, (ns))) + (cylno) * (fs)->fs_old_nrpos)
++
++#define	old_cg_blktot(cgp, ns) \
++    ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
++      old_cg_blktot_old(cgp, ns) : old_cg_blktot_new(cgp, ns))
++#define	old_cg_blks(fs, cgp, cylno, ns) \
++    ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
++      old_cg_blks_old(fs, cgp, cylno, ns) : old_cg_blks_new(fs, cgp, cylno, ns))
++
++#define	cg_inosused_new(cgp, ns) \
++    ((u_int8_t *)((u_int8_t *)(cgp) + \
++	ufs_rw32((cgp)->cg_iusedoff, (ns))))
++#define	cg_blksfree_new(cgp, ns) \
++    ((u_int8_t *)((u_int8_t *)(cgp) + \
++	ufs_rw32((cgp)->cg_freeoff, (ns))))
++#define	cg_chkmagic_new(cgp, ns) \
++    (ufs_rw32((cgp)->cg_magic, (ns)) == CG_MAGIC)
++
++#define	cg_inosused_old(cgp, ns) \
++    (((struct ocg *)(cgp))->cg_iused)
++#define	cg_blksfree_old(cgp, ns) \
++    (((struct ocg *)(cgp))->cg_free)
++#define	cg_chkmagic_old(cgp, ns) \
++    (ufs_rw32(((struct ocg *)(cgp))->cg_magic, (ns)) == CG_MAGIC)
++
++#define	cg_inosused(cgp, ns) \
++    ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
++      cg_inosused_old(cgp, ns) : cg_inosused_new(cgp, ns))
++#define	cg_blksfree(cgp, ns) \
++    ((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) ? \
++      cg_blksfree_old(cgp, ns) : cg_blksfree_new(cgp, ns))
++#define	cg_chkmagic(cgp, ns) \
++    (cg_chkmagic_new(cgp, ns) || cg_chkmagic_old(cgp, ns))
++
++#define	cg_clustersfree(cgp, ns) \
++    ((u_int8_t *)((u_int8_t *)(cgp) + \
++	ufs_rw32((cgp)->cg_clusteroff, (ns))))
++#define	cg_clustersum(cgp, ns) \
++    ((int32_t *)((u_int8_t *)(cgp) + \
++	ufs_rw32((cgp)->cg_clustersumoff, (ns))))
++
++
++/*
++ * Turn file system block numbers into disk block addresses.
++ * This maps file system blocks to device size blocks.
++ */
++#if defined (_KERNEL)
++#define	FFS_FSBTODB(fs, b)	((b) << ((fs)->fs_fshift - DEV_BSHIFT))
++#define	FFS_DBTOFSB(fs, b)	((b) >> ((fs)->fs_fshift - DEV_BSHIFT))
++#else
++#define	FFS_FSBTODB(fs, b)	((b) << (fs)->fs_fsbtodb)
++#define	FFS_DBTOFSB(fs, b)	((b) >> (fs)->fs_fsbtodb)
++#endif
++
++/*
++ * Cylinder group macros to locate things in cylinder groups.
++ * They calc file system addresses of cylinder group data structures.
++ */
++#define	cgbase(fs, c)	(((daddr_t)(fs)->fs_fpg) * (c))
++#define	cgstart_ufs1(fs, c) \
++    (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask)))
++#define	cgstart_ufs2(fs, c) cgbase((fs), (c))
++#define	cgstart(fs, c) ((fs)->fs_magic == FS_UFS2_MAGIC \
++			    ? cgstart_ufs2((fs), (c)) : cgstart_ufs1((fs), (c)))
++#define	cgdmin(fs, c)	(cgstart(fs, c) + (fs)->fs_dblkno)	/* 1st data */
++#define	cgimin(fs, c)	(cgstart(fs, c) + (fs)->fs_iblkno)	/* inode blk */
++#define	cgsblock(fs, c)	(cgstart(fs, c) + (fs)->fs_sblkno)	/* super blk */
++#define	cgtod(fs, c)	(cgstart(fs, c) + (fs)->fs_cblkno)	/* cg block */
++
++/*
++ * Macros for handling inode numbers:
++ *     inode number to file system block offset.
++ *     inode number to cylinder group number.
++ *     inode number to file system block address.
++ */
++#define	ino_to_cg(fs, x)	((x) / (fs)->fs_ipg)
++#define	ino_to_fsba(fs, x)						\
++	((daddr_t)(cgimin(fs, ino_to_cg(fs, x)) +			\
++	    (ffs_blkstofrags((fs), (((x) % (fs)->fs_ipg) / FFS_INOPB(fs))))))
++#define	ino_to_fsbo(fs, x)	((x) % FFS_INOPB(fs))
++
++/*
++ * Give cylinder group number for a file system block.
++ * Give cylinder group block number for a file system block.
++ */
++#define	dtog(fs, d)	((d) / (fs)->fs_fpg)
++#define	dtogd(fs, d)	((d) % (fs)->fs_fpg)
++
++/*
++ * Extract the bits for a block from a map.
++ * Compute the cylinder and rotational position of a cyl block addr.
++ */
++#define	blkmap(fs, map, loc) \
++    (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
++#define	old_cbtocylno(fs, bno) \
++    (FFS_FSBTODB(fs, bno) / (fs)->fs_old_spc)
++#define	old_cbtorpos(fs, bno) \
++    ((fs)->fs_old_nrpos <= 1 ? 0 : \
++     (FFS_FSBTODB(fs, bno) % (fs)->fs_old_spc / (fs)->fs_old_nsect * (fs)->fs_old_trackskew + \
++      FFS_FSBTODB(fs, bno) % (fs)->fs_old_spc % (fs)->fs_old_nsect * (fs)->fs_old_interleave) % \
++     (fs)->fs_old_nsect * (fs)->fs_old_nrpos / (fs)->fs_old_npsect)
++
++/*
++ * The following macros optimize certain frequently calculated
++ * quantities by using shifts and masks in place of divisions
++ * modulos and multiplications.
++ */
++#define	ffs_blkoff(fs, loc)	/* calculates (loc % fs->fs_bsize) */ \
++	((loc) & (fs)->fs_qbmask)
++#define	ffs_fragoff(fs, loc)	/* calculates (loc % fs->fs_fsize) */ \
++	((loc) & (fs)->fs_qfmask)
++#define	ffs_lfragtosize(fs, frag) /* calculates ((off_t)frag * fs->fs_fsize) */ \
++	(((off_t)(frag)) << (fs)->fs_fshift)
++#define	ffs_lblktosize(fs, blk)	/* calculates ((off_t)blk * fs->fs_bsize) */ \
++	((uint64_t)(((off_t)(blk)) << (fs)->fs_bshift))
++#define	ffs_lblkno(fs, loc)	/* calculates (loc / fs->fs_bsize) */ \
++	((loc) >> (fs)->fs_bshift)
++#define	ffs_numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \
++	((loc) >> (fs)->fs_fshift)
++#define	ffs_blkroundup(fs, size) /* calculates roundup(size, fs->fs_bsize) */ \
++	(((size) + (fs)->fs_qbmask) & (fs)->fs_bmask)
++#define	ffs_fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \
++	(((size) + (fs)->fs_qfmask) & (fs)->fs_fmask)
++#define	ffs_fragstoblks(fs, frags) /* calculates (frags / fs->fs_frag) */ \
++	((frags) >> (fs)->fs_fragshift)
++#define	ffs_blkstofrags(fs, blks) /* calculates (blks * fs->fs_frag) */ \
++	((blks) << (fs)->fs_fragshift)
++#define	ffs_fragnum(fs, fsb)	/* calculates (fsb % fs->fs_frag) */ \
++	((fsb) & ((fs)->fs_frag - 1))
++#define	ffs_blknum(fs, fsb)	/* calculates rounddown(fsb, fs->fs_frag) */ \
++	((fsb) &~ ((fs)->fs_frag - 1))
++
++/*
++ * Determine the number of available frags given a
++ * percentage to hold in reserve.
++ */
++#define	freespace(fs, percentreserved) \
++	(ffs_blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \
++	(fs)->fs_cstotal.cs_nffree - \
++	(((off_t)((fs)->fs_dsize)) * (percentreserved) / 100))
++
++/*
++ * Determining the size of a file block in the file system.
++ */
++#define	ffs_blksize(fs, ip, lbn) \
++	(((lbn) >= UFS_NDADDR || (ip)->i_size >= ffs_lblktosize(fs, (lbn) + 1)) \
++	    ? (fs)->fs_bsize \
++	    : ((int32_t)ffs_fragroundup(fs, ffs_blkoff(fs, (ip)->i_size))))
++
++#define	ffs_sblksize(fs, size, lbn) \
++	(((lbn) >= UFS_NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \
++	  ? (fs)->fs_bsize \
++	  : ((int32_t)ffs_fragroundup(fs, ffs_blkoff(fs, (uint64_t)(size)))))
++
++
++/*
++ * Number of inodes in a secondary storage block/fragment.
++ */
++#define	FFS_INOPB(fs)	((fs)->fs_inopb)
++#define	FFS_INOPF(fs)	((fs)->fs_inopb >> (fs)->fs_fragshift)
++
++/*
++ * Number of indirects in a file system block.
++ */
++#define	FFS_NINDIR(fs)	((fs)->fs_nindir)
++
++/*
++ * Apple UFS Label:
++ *  We check for this to decide to use APPLEUFS_DIRBLKSIZ
++ */
++#define	APPLEUFS_LABEL_MAGIC		0x4c41424c /* LABL */
++#define	APPLEUFS_LABEL_SIZE		1024
++#define	APPLEUFS_LABEL_OFFSET	(BBSIZE - APPLEUFS_LABEL_SIZE) /* located at 7k */
++#define	APPLEUFS_LABEL_VERSION	1
++#define	APPLEUFS_MAX_LABEL_NAME	512
++
++struct appleufslabel {
++	u_int32_t	ul_magic;
++	u_int16_t	ul_checksum;
++	u_int16_t	ul_unused0;
++	u_int32_t	ul_version;
++	u_int32_t	ul_time;
++	u_int16_t	ul_namelen;
++	u_char	ul_name[APPLEUFS_MAX_LABEL_NAME]; /* Warning: may not be null terminated */
++	u_int16_t	ul_unused1;
++	u_int64_t	ul_uuid;	/* Note this is only 4 byte aligned */
++	u_char	ul_reserved[24];
++	u_char	ul_unused[460];
++} __packed;
++
++
++#endif /* !_UFS_FFS_FS_H_ */
Index: u-boot/patches/patch-include_fs.h
===================================================================
RCS file: u-boot/patches/patch-include_fs.h
diff -N u-boot/patches/patch-include_fs.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-include_fs.h	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- include/fs.h.orig	2017-11-14 01:08:06.000000000 +0000
++++ include/fs.h
+@@ -14,6 +14,7 @@
+ #define FS_TYPE_SANDBOX	3
+ #define FS_TYPE_UBIFS	4
+ #define FS_TYPE_BTRFS	5
++#define FS_TYPE_UFS	6
+ 
+ /*
+  * Tell the fs layer which block device an partition to use for future
Index: u-boot/patches/patch-include_ufs_ufs.h
===================================================================
RCS file: u-boot/patches/patch-include_ufs_ufs.h
diff -N u-boot/patches/patch-include_ufs_ufs.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot/patches/patch-include_ufs_ufs.h	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,24 @@
+$NetBSD$
+
+--- include/ufs/ufs.h.orig	2018-02-22 19:29:00.728284021 +0000
++++ include/ufs/ufs.h
+@@ -0,0 +1,19 @@
++/*
++ *
++ * UFS/FFSv1/FFSv2 filesystem support
++ * Created by berte <behzaterte at yandex.com>
++ * SPDX-License-Identifier:   BSD 2-Clause License
++ */
++
++#ifndef __UFS_H__
++#define __UFS_H__
++
++int  ufs_probe(struct blk_desc *, disk_partition_t *);
++int  ufs_ls(const char *);
++int  ufs_exists(const char *);
++int  ufs_size(const char *, loff_t *);
++int  ufs_read(const char *, void *, loff_t, loff_t, loff_t *);
++void ufs_close(void);
++
++#endif /* __UFS_H__  */
++
Index: u-boot-a10-olinuxino-lime/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-a10-olinuxino-lime/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-a10-olinuxino-lime/Makefile	18 Dec 2017 23:31:19 -0000	1.2
+++ u-boot-a10-olinuxino-lime/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		a10-olinuxino-lime
 UBOOT_CONFIG=		A10-OLinuXino-Lime_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-bananapi/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-bananapi/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-bananapi/Makefile	18 Dec 2017 23:31:19 -0000	1.2
+++ u-boot-bananapi/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		bananapi
 UBOOT_CONFIG=		Bananapi_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-bananapi-m3/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-bananapi-m3/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-bananapi-m3/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-bananapi-m3/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		bananapi-m3
 UBOOT_CONFIG=		Sinovoip_BPI_M3_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-beagleboard/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-beagleboard/Makefile,v
retrieving revision 1.1
diff -u -p -u -r1.1 Makefile
--- u-boot-beagleboard/Makefile	26 Aug 2017 19:56:36 -0000	1.1
+++ u-boot-beagleboard/Makefile	22 Feb 2018 20:03:30 -0000
@@ -5,4 +5,8 @@ UBOOT_CONFIG=		omap3_beagle_defconfig
 UBOOT_BIN=		u-boot.img
 UBOOT_BIN+= 		MLO
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-beagleboneblack/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-beagleboneblack/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-beagleboneblack/Makefile	26 Aug 2017 18:46:07 -0000	1.2
+++ u-boot-beagleboneblack/Makefile	22 Feb 2018 20:03:30 -0000
@@ -5,4 +5,8 @@ UBOOT_CONFIG=		am335x_boneblack_defconfi
 UBOOT_BIN=		u-boot.img
 UBOOT_BIN+= 		MLO
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-beaglebonewhite/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-beaglebonewhite/Makefile,v
retrieving revision 1.1
diff -u -p -u -r1.1 Makefile
--- u-boot-beaglebonewhite/Makefile	26 Aug 2017 18:35:33 -0000	1.1
+++ u-boot-beaglebonewhite/Makefile	22 Feb 2018 20:03:30 -0000
@@ -5,4 +5,8 @@ UBOOT_CONFIG=		am335x_evm_defconfig
 UBOOT_BIN=		u-boot.img
 UBOOT_BIN+= 		MLO
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-chip/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-chip/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-chip/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-chip/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		chip
 UBOOT_CONFIG=		CHIP_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-chip-pro/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-chip-pro/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-chip-pro/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-chip-pro/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		chip-pro
 UBOOT_CONFIG=		CHIP_pro_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-cubieboard2/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-cubieboard2/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-cubieboard2/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-cubieboard2/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		cubieboard2
 UBOOT_CONFIG=		Cubieboard2_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-cubieboard4/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-cubieboard4/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-cubieboard4/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-cubieboard4/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		cubieboard4
 UBOOT_CONFIG=		Cubieboard4_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-cubietruck/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-cubietruck/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-cubietruck/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-cubietruck/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		cubietruck
 UBOOT_CONFIG=		Cubietruck_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-hummingbird-a31/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-hummingbird-a31/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-hummingbird-a31/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-hummingbird-a31/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		hummingbird-a31
 UBOOT_CONFIG=		Hummingbird_A31_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-jetson-tk1/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-jetson-tk1/Makefile,v
retrieving revision 1.1
diff -u -p -u -r1.1 Makefile
--- u-boot-jetson-tk1/Makefile	9 Dec 2017 13:02:41 -0000	1.1
+++ u-boot-jetson-tk1/Makefile	22 Feb 2018 20:03:30 -0000
@@ -4,4 +4,8 @@ UBOOT_TARGET=		jetson-tk1
 UBOOT_CONFIG=		jetson-tk1_defconfig
 UBOOT_BIN=		u-boot u-boot-dtb.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-jetson-tx1/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-jetson-tx1/Makefile,v
retrieving revision 1.3
diff -u -p -u -r1.3 Makefile
--- u-boot-jetson-tx1/Makefile	8 Oct 2017 12:09:43 -0000	1.3
+++ u-boot-jetson-tx1/Makefile	22 Feb 2018 20:03:30 -0000
@@ -7,4 +7,8 @@ UBOOT_BIN=		u-boot u-boot-dtb.bin
 # Switch to EL1 before booting kernel (required for 32-bit support)
 PKG_DEFAULT_OPTIONS+=	el1
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm64.mk"
Index: u-boot-nanopi-m1/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-nanopi-m1/Makefile,v
retrieving revision 1.1
diff -u -p -u -r1.1 Makefile
--- u-boot-nanopi-m1/Makefile	21 Dec 2017 11:46:47 -0000	1.1
+++ u-boot-nanopi-m1/Makefile	22 Feb 2018 20:03:30 -0000
@@ -4,4 +4,8 @@ UBOOT_TARGET=		nanopi-m1
 UBOOT_CONFIG=		nanopi_m1_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-nanopi-neo/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-nanopi-neo/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-nanopi-neo/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-nanopi-neo/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		nanopi-neo
 UBOOT_CONFIG=		nanopi_neo_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-nanopi-neo-plus2/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-nanopi-neo-plus2/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-nanopi-neo-plus2/Makefile	18 Feb 2018 16:25:45 -0000	1.2
+++ u-boot-nanopi-neo-plus2/Makefile	22 Feb 2018 20:03:30 -0000
@@ -10,6 +10,10 @@ UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 #PKG_DEFAULT_OPTIONS+=	el1
 PKG_DEFAULT_OPTIONS+=	debug
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 post-extract:
 	${CP} ${PREFIX}/share/arm-trusted-firmware/sun50iw1p1/bl31.bin ${WRKSRC}
 
Index: u-boot-nanopi-neo2/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-nanopi-neo2/Makefile,v
retrieving revision 1.3
diff -u -p -u -r1.3 Makefile
--- u-boot-nanopi-neo2/Makefile	18 Feb 2018 16:25:45 -0000	1.3
+++ u-boot-nanopi-neo2/Makefile	22 Feb 2018 20:03:30 -0000
@@ -9,6 +9,10 @@ UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 # Switch to EL1 before booting kernel (required for 32-bit support)
 PKG_DEFAULT_OPTIONS+=	el1
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 post-extract:
 	${CP} ${PREFIX}/share/arm-trusted-firmware/sun50iw1p1/bl31.bin ${WRKSRC}
 
Index: u-boot-orangepi-2/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-orangepi-2/Makefile,v
retrieving revision 1.4
diff -u -p -u -r1.4 Makefile
--- u-boot-orangepi-2/Makefile	18 Dec 2017 23:31:20 -0000	1.4
+++ u-boot-orangepi-2/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		orangepi-2
 UBOOT_CONFIG=		orangepi_2_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-orangepi-one/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-orangepi-one/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- u-boot-orangepi-one/Makefile	18 Dec 2017 23:31:20 -0000	1.2
+++ u-boot-orangepi-one/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		orangepi-one
 UBOOT_CONFIG=		orangepi_one_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-orangepi-plus2e/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-orangepi-plus2e/Makefile,v
retrieving revision 1.4
diff -u -p -u -r1.4 Makefile
--- u-boot-orangepi-plus2e/Makefile	18 Dec 2017 23:31:20 -0000	1.4
+++ u-boot-orangepi-plus2e/Makefile	22 Feb 2018 20:03:30 -0000
@@ -6,4 +6,8 @@ UBOOT_TARGET=		orangepi-plus2e
 UBOOT_CONFIG=		orangepi_plus2e_defconfig
 UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"
Index: u-boot-orangepi-win/DESCR
===================================================================
RCS file: u-boot-orangepi-win/DESCR
diff -N u-boot-orangepi-win/DESCR
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot-orangepi-win/DESCR	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,5 @@
+U-Boot is a bootloader for embedded boards based on PowerPC, ARM, MIPS and
+several other processors, which can be installed in a boot ROM and used to
+initialize and test the hardware or to download and run application code.
+
+This package provides U-Boot for the Xunlong Orange Pi Win/Win Plus.
Index: u-boot-orangepi-win/Makefile
===================================================================
RCS file: u-boot-orangepi-win/Makefile
diff -N u-boot-orangepi-win/Makefile
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot-orangepi-win/Makefile	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1,21 @@
+PKGREVISION=		1
+
+UBOOT_TARGET=		orangepi-win
+UBOOT_CONFIG=		orangepi_win_defconfig
+UBOOT_BIN=		u-boot-sunxi-with-spl.bin
+
+# Switch to EL1 before booting kernel (required for 32-bit support)
+PKG_DEFAULT_OPTIONS+=	el1
+
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
+post-extract:
+	${CP} ${PREFIX}/share/arm-trusted-firmware/sun50iw1p1/bl31.bin ${WRKSRC}
+
+post-build:
+	cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${MAKE_PROGRAM} u-boot-sunxi-with-spl.bin
+
+#.include "../../sysutils/arm-trusted-firmware-sun50iw1p1/buildlink3.mk"
+.include "../../sysutils/u-boot/u-boot-arm64.mk"
Index: u-boot-orangepi-win/PLIST
===================================================================
RCS file: u-boot-orangepi-win/PLIST
diff -N u-boot-orangepi-win/PLIST
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ u-boot-orangepi-win/PLIST	22 Feb 2018 20:03:30 -0000
@@ -0,0 +1 @@
+share/u-boot/orangepi-win-orig/u-boot-sunxi-with-spl.bin
Index: u-boot-pine64/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-pine64/Makefile,v
retrieving revision 1.3
diff -u -p -u -r1.3 Makefile
--- u-boot-pine64/Makefile	18 Feb 2018 16:25:45 -0000	1.3
+++ u-boot-pine64/Makefile	22 Feb 2018 20:03:30 -0000
@@ -9,6 +9,10 @@ UBOOT_BIN=		u-boot-sunxi-with-spl.bin
 # Switch to EL1 before booting kernel (required for 32-bit support)
 PKG_DEFAULT_OPTIONS+=	el1
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 post-extract:
 	${CP} ${PREFIX}/share/arm-trusted-firmware/sun50iw1p1/bl31.bin ${WRKSRC}
 
Index: u-boot-pinebook/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-pinebook/Makefile,v
retrieving revision 1.4
diff -u -p -u -r1.4 Makefile
--- u-boot-pinebook/Makefile	18 Feb 2018 16:25:45 -0000	1.4
+++ u-boot-pinebook/Makefile	22 Feb 2018 20:03:30 -0000
@@ -15,6 +15,10 @@ EXTRACT_SUFX=		.tar.gz
 # Switch to EL1 before booting kernel (required for 32-bit support)
 PKG_DEFAULT_OPTIONS+=	el1
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 post-extract:
 	${CP} ${PREFIX}/share/arm-trusted-firmware/sun50iw1p1/bl31.bin ${WRKSRC}
 
Index: u-boot-pocketchip/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/u-boot-pocketchip/Makefile,v
retrieving revision 1.3
diff -u -p -u -r1.3 Makefile
--- u-boot-pocketchip/Makefile	18 Dec 2017 23:31:21 -0000	1.3
+++ u-boot-pocketchip/Makefile	22 Feb 2018 20:03:30 -0000
@@ -17,4 +17,8 @@ UBOOT_OPTIONS+=		CONFIG_VIDEO_LCD_BL_PWM
 UBOOT_OPTIONS+=		CONFIG_VIDEO_CHRONTEL_CH7033=y
 UBOOT_OPTIONS+=		CONFIG_VIDEO_CHRONTEL_CH7033_I2C_BUS=1
 
+# ufs filesystem & ffs command support
+PKG_DEFAULT_OPTIONS+=	cmd_ffs
+PKG_DEFAULT_OPTIONS+=	fs_ufs
+
 .include "../../sysutils/u-boot/u-boot-arm.mk"


Home | Main Index | Thread Index | Old Index