[U-Boot] [PATCH 1/3] sysboot: Add support for ubifs to the sysboot command

ubifs does not go though the generic block layer because mtd devices are special, so the "any" filesystem option to sysboot does not work, this adds support for a "ubifs" filesystem to the sysboot command which makes it possible to boot from ubifs using an extlinux.conf file.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- common/cmd_pxe.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c index 080b376..b4f2e3e 100644 --- a/common/cmd_pxe.c +++ b/common/cmd_pxe.c @@ -16,6 +16,10 @@ #include <fs.h> #include <asm/io.h>
+#ifdef CONFIG_CMD_UBIFS +#include "../fs/ubifs/ubifs.h" +#endif + #include "menu.h" #include "cli.h"
@@ -156,6 +160,17 @@ static int do_get_ext2(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr) return -ENOENT; }
+static int do_get_ubifs(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr) +{ +#ifdef CONFIG_CMD_UBIFS + u32 addr = simple_strtoul(file_addr, NULL, 16); + + if (!ubifs_load((char *)file_path, addr, 0)) + return 1; +#endif + return -ENOENT; +} + static int do_get_fat(cmd_tbl_t *cmdtp, const char *file_path, char *file_addr) { #ifdef CONFIG_CMD_FAT @@ -1680,6 +1695,8 @@ static int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) do_getfile = do_get_ext2; else if (strstr(argv[3], "fat")) do_getfile = do_get_fat; + else if (strstr(argv[3], "ubifs")) + do_getfile = do_get_ubifs; else if (strstr(argv[3], "any")) do_getfile = do_get_any; else {

Add a ubifsexists command to check whether a file exists on an ubifs volume.
This is useful for use in standardized bootscripts, such as the scripts from include/config_distro_bootcmd.h.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- common/cmd_ubifs.c | 23 +++++++++++++++++++++++ fs/ubifs/ubifs.c | 12 ++++++++++++ fs/ubifs/ubifs.h | 1 + 3 files changed, 36 insertions(+)
diff --git a/common/cmd_ubifs.c b/common/cmd_ubifs.c index 8e9a4e5..1a54ba0 100644 --- a/common/cmd_ubifs.c +++ b/common/cmd_ubifs.c @@ -145,6 +145,22 @@ static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, return ret; }
+int do_ubifs_exists(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + if (!ubifs_mounted) { + printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); + return -1; + } + + if (argc != 2) + return CMD_RET_USAGE; + + if (!ubifs_exists(argv[1])) + return CMD_RET_FAILURE; + + return 0; +} + U_BOOT_CMD( ubifsmount, 2, 0, do_ubifs_mount, "mount UBIFS volume", @@ -171,3 +187,10 @@ U_BOOT_CMD( "<addr> <filename> [bytes]\n" " - load file 'filename' to address 'addr'" ); + +U_BOOT_CMD( + ubifsexists, 2, 0, do_ubifs_exists, + "check file exists on an UBIFS filesystem", + "<filename>\n" + " - check 'filename' exists" +); diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index 6dd6174..2ef6ab8 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -857,3 +857,15 @@ out: ubi_close_volume(c->ubi); return err; } + +int ubifs_exists(char *filename) +{ + struct ubifs_info *c = ubifs_sb->s_fs_info; + unsigned long inum; + + c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY); + inum = ubifs_findfile(ubifs_sb, filename); + ubi_close_volume(c->ubi); + + return inum != 0; +} diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index a51b237..070fcde 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -2385,5 +2385,6 @@ int uboot_ubifs_mount(char *vol_name); void ubifs_umount(struct ubifs_info *c); int ubifs_ls(char *dir_name); int ubifs_load(char *filename, u32 addr, u32 size); +int ubifs_exists(char *filename); #endif #endif /* !__UBIFS_H__ */

From: Roy Spliet r.spliet@ultimaker.com
Under the assumptions of having a UBI partition called boot
Signed-off-by: Hans de Goede hdegoede@redhat.com --- include/config_distro_bootcmd.h | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h index 3a360ca4..bbc2e1a 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -72,6 +72,47 @@ BOOT_TARGET_DEVICES_references_MMC_without_CONFIG_CMD_MMC #endif
+#ifdef CONFIG_CMD_UBIFS +#define BOOTENV_SHARED_UBIFS \ + "scan_ubifs_for_extlinux=" \ + "if ubifsexists ${prefix}extlinux/extlinux.conf; then " \ + "echo Found ${prefix}extlinux/extlinux.conf; " \ + "sysboot ubi0 0:0 ubifs ${scriptaddr} " \ + "${prefix}extlinux/extlinux.conf; " \ + "echo SCRIPT FAILED: continuing...; " \ + "fi\0" \ + \ + "scan_ubifs_for_scripts=" \ + "for script in ${boot_scripts}; do " \ + "if ubifsexists ${prefix}${script}; then " \ + "echo Found U-Boot script " \ + "${prefix}${script}; " \ + "ubifsload ${scriptaddr} " \ + "${prefix}${script}; " \ + "source ${scriptaddr}; " \ + "echo SCRIPT FAILED: continuing...; " \ + "fi; " \ + "done\0" +#define BOOTENV_DEV_UBIFS(devtypeu, devtypel, instance) \ + "bootcmd_ubifs=" \ + "if ubi part " #devtypel #instance "_main &&" \ + "ubifsmount ubi:boot; then " \ + "echo Scanning " #devtypel #instance "_main:boot;"\ + "for prefix in ${boot_prefixes}; do " \ + "run scan_ubifs_for_extlinux; " \ + "run scan_ubifs_for_scripts; " \ + "done; " \ + "fi\0" +#define BOOTENV_DEV_NAME_UBIFS(devtypeu, devtypel, instance) \ + "ubifs " +#else +#define BOOTENV_SHARED_UBIFS +#define BOOTENV_DEV_UBIFS \ + BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS +#define BOOTENV_DEV_NAME_UBIFS \ + BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS +#endif + #ifdef CONFIG_CMD_SATA #define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata) #define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV @@ -185,6 +226,7 @@ BOOTENV_SHARED_SATA \ BOOTENV_SHARED_SCSI \ BOOTENV_SHARED_IDE \ + BOOTENV_SHARED_UBIFS \ "boot_prefixes=/ /boot/\0" \ "boot_scripts=boot.scr.uimg boot.scr\0" \ "boot_script_dhcp=boot.scr.uimg\0" \

On 08/20/2015 10:04 AM, Hans de Goede wrote:
ubifs does not go though the generic block layer because mtd devices are special, so the "any" filesystem option to sysboot does not work, this adds support for a "ubifs" filesystem to the sysboot command which makes it possible to boot from ubifs using an extlinux.conf file.
Why are they special? Surely ubifs support can be integrated into the filesystem layer, thus removing the need for patches 1 and 3 in this series?
The problem here is that in patch 3,BOOTENV_DEV_UBIFS and BOOTENV_SHARED_UBIFS duplicate the file looping logic that already exist in other block device scanning macros. Naively it looks like it should be possible to avoid that completely. One change I vaguely had in mind for the distro boot scripts was to add a user-configurable environment variable to specify which of extlinux, script (and later perhaps Android, ...) support each partition was scanned for. Any time a change like that is made, with this patch applied first, that change would have to be replicated twice (and potentially n times if we continue down this path).

Hi,
On 20-08-15 21:53, Stephen Warren wrote:
On 20-08-15 18:04, Hans de Goede wrote:
ubifs does not go though the generic block layer because mtd devices are special, so the "any" filesystem option to sysboot does not work, this adds support for a "ubifs" filesystem to the sysboot command which makes it possible to boot from ubifs using an extlinux.conf file.
Why are they special? Surely ubifs support can be integrated into the filesystem layer, thus removing the need for patches 1 and 3 in this series?
I looked into that before going that root, the problem is that the filesystem layer assumes that files sit on top of block devices, and all the filesystem layer code operates on block_dev_desc_t devices.
But ubifs operates on ubi volumes which in turn operate on raw nand, this has vastly different characteristics then regular block devices.
ubifs deals with erase-blocks, finding or creating a free erase block when it needs to write stuff, then erasing an entire block and writing part of it a page-size at a time where erase-block-size != page-size, and both are typically of values much larger then disk sector-sizes. There is no notion of erase blocks in the fs / block layer.
Working with raw flash just is vastly different from working with block devices, so ubifs can not be shoe-horned to fit into the filesystem layer. I agree this would have been the logical thing to do, and I've looked into doing this, but the 2 simply do not fit.
The problem here is that in patch 3,BOOTENV_DEV_UBIFS and BOOTENV_SHARED_UBIFS duplicate the file looping logic that already exist in other block device scanning macros. Naively it looks like it should be possible to avoid that completely. One change I vaguely had in mind for the distro boot scripts was to add a user-configurable environment variable to specify which of extlinux, script (and later perhaps Android, ...) support each partition was scanned for. Any time a change like that is made, with this patch applied first, that change would have to be replicated twice (and potentially n times if we continue down this path).
As I said in my commit msg: "mtd devices are special", so I'm afraid we will just have to live with a little duplication here.
Regards,
Hans

On 08/21/2015 03:56 AM, Hans de Goede wrote:
Hi,
On 20-08-15 21:53, Stephen Warren wrote:
On 20-08-15 18:04, Hans de Goede wrote:
ubifs does not go though the generic block layer because mtd devices are special, so the "any" filesystem option to sysboot does not work, this adds support for a "ubifs" filesystem to the sysboot command which makes it possible to boot from ubifs using an extlinux.conf file.
Why are they special? Surely ubifs support can be integrated into the filesystem layer, thus removing the need for patches 1 and 3 in this
series?
I looked into that before going that root, the problem is that the filesystem layer assumes that files sit on top of block devices, and all the filesystem layer code operates on block_dev_desc_t devices.
But ubifs operates on ubi volumes which in turn operate on raw nand, this has vastly different characteristics then regular block devices.
ubifs deals with erase-blocks, finding or creating a free erase block when it needs to write stuff, then erasing an entire block and writing part of it a page-size at a time where erase-block-size != page-size, and both are typically of values much larger then disk sector-sizes. There is no notion of erase blocks in the fs / block layer.
Can't the filesystem layer simply be taught how to look up block devices for most filesystems, but look up volumes for other filesystems? I still see no fundamental reason we can't abstract this so higher level SW doesn't have to have special cases.

Hi,
On 22-08-15 00:01, Stephen Warren wrote:
On 08/21/2015 03:56 AM, Hans de Goede wrote:
Hi,
On 20-08-15 21:53, Stephen Warren wrote:
On 20-08-15 18:04, Hans de Goede wrote:
ubifs does not go though the generic block layer because mtd devices are special, so the "any" filesystem option to sysboot does not work, this adds support for a "ubifs" filesystem to the sysboot command which makes it possible to boot from ubifs using an extlinux.conf file.
Why are they special? Surely ubifs support can be integrated into the filesystem layer, thus removing the need for patches 1 and 3 in this
series?
I looked into that before going that root, the problem is that the filesystem layer assumes that files sit on top of block devices, and all the filesystem layer code operates on block_dev_desc_t devices.
But ubifs operates on ubi volumes which in turn operate on raw nand, this has vastly different characteristics then regular block devices.
ubifs deals with erase-blocks, finding or creating a free erase block when it needs to write stuff, then erasing an entire block and writing part of it a page-size at a time where erase-block-size != page-size, and both are typically of values much larger then disk sector-sizes. There is no notion of erase blocks in the fs / block layer.
Can't the filesystem layer simply be taught how to look up block devices for most filesystems, but look up volumes for other filesystems? I still see no fundamental reason we can't abstract this so higher level SW doesn't have to have special cases.
Ok, so I've given this a second shot, and you are right, it is possible to make ubifs work with the generic filesystem code.
I'll post a v2 using that.
Regards,
Hans
participants (2)
-
Hans de Goede
-
Stephen Warren