diff --git a/arch/arm/boards/crystalfontz-cfa10036/env/init/automount b/arch/arm/boards/crystalfontz-cfa10036/env/init/automount index fe67e55..668775d 100644 --- a/arch/arm/boards/crystalfontz-cfa10036/env/init/automount +++ b/arch/arm/boards/crystalfontz-cfa10036/env/init/automount @@ -6,4 +6,4 @@ fi mkdir -p /mnt/disk0.1 -automount -d /mnt/disk0.1 '[ -e /dev/disk0.1 ] && mount /dev/disk0.1 fat /mnt/disk0.1' +automount -d /mnt/disk0.1 '[ -e /dev/disk0.1 ] && mount /dev/disk0.1 /mnt/disk0.1' diff --git a/arch/arm/boards/mioa701/env/bin/sdcard_override b/arch/arm/boards/mioa701/env/bin/sdcard_override index 4b2ad51..ab83534 100644 --- a/arch/arm/boards/mioa701/env/bin/sdcard_override +++ b/arch/arm/boards/mioa701/env/bin/sdcard_override @@ -8,7 +8,7 @@ mci0.probe=1 if [ $mci0.probe = 1 ]; then mkdir /sdcard - mount /dev/disk0.0 fat /sdcard + mount /dev/disk0.0 /sdcard if [ -f /sdcard/barebox.env ]; then loadenv /sdcard/barebox.env /env.sd /env.sd/bin/init diff --git a/arch/arm/boards/pcm049/env/bin/nand_bootstrap b/arch/arm/boards/pcm049/env/bin/nand_bootstrap index acd00dc..f8873fa 100644 --- a/arch/arm/boards/pcm049/env/bin/nand_bootstrap +++ b/arch/arm/boards/pcm049/env/bin/nand_bootstrap @@ -4,7 +4,7 @@ mci0.probe=1 mkdir mnt -mount /dev/disk0.0 fat /mnt +mount /dev/disk0.0 /mnt if [ $? != 0 ]; then echo "failed to mount mmc card" exit 1 diff --git a/arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap b/arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap index acd00dc..f8873fa 100644 --- a/arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap +++ b/arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap @@ -4,7 +4,7 @@ mci0.probe=1 mkdir mnt -mount /dev/disk0.0 fat /mnt +mount /dev/disk0.0 /mnt if [ $? != 0 ]; then echo "failed to mount mmc card" exit 1 diff --git a/arch/blackfin/include/asm/unaligned.h b/arch/blackfin/include/asm/unaligned.h new file mode 100644 index 0000000..0f6c098 --- /dev/null +++ b/arch/blackfin/include/asm/unaligned.h @@ -0,0 +1,11 @@ +#ifndef _ASM_BLACKFIN_UNALIGNED_H +#define _ASM_BLACKFIN_UNALIGNED_H + +#include +#include +#include + +#define get_unaligned __get_unaligned_le +#define put_unaligned __put_unaligned_le + +#endif /* _ASM_BLACKFIN_UNALIGNED_H */ diff --git a/arch/openrisc/include/asm/unaligned.h b/arch/openrisc/include/asm/unaligned.h new file mode 100644 index 0000000..1141cbd --- /dev/null +++ b/arch/openrisc/include/asm/unaligned.h @@ -0,0 +1,51 @@ +/* + * OpenRISC Linux + * + * Linux architectural port borrowing liberally from similar works of + * others. All original copyrights apply as per the original source + * declaration. + * + * OpenRISC implementation: + * Copyright (C) 2003 Matjaz Breskvar + * Copyright (C) 2010-2011 Jonas Bonn + * et al. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __ASM_OPENRISC_UNALIGNED_H +#define __ASM_OPENRISC_UNALIGNED_H + +/* + * This is copied from the generic implementation and the C-struct + * variant replaced with the memmove variant. The GCC compiler + * for the OR32 arch optimizes too aggressively for the C-struct + * variant to work, so use the memmove variant instead. + * + * It may be worth considering implementing the unaligned access + * exception handler and allowing unaligned accesses (access_ok.h)... + * not sure if it would be much of a performance win without further + * investigation. + */ +#include + +#if defined(__LITTLE_ENDIAN) +# include +# include +# include +# define get_unaligned __get_unaligned_le +# define put_unaligned __put_unaligned_le +#elif defined(__BIG_ENDIAN) +# include +# include +# include +# define get_unaligned __get_unaligned_be +# define put_unaligned __put_unaligned_be +#else +# error need to define endianess +#endif + +#endif /* __ASM_OPENRISC_UNALIGNED_H */ diff --git a/arch/ppc/include/asm/unaligned.h b/arch/ppc/include/asm/unaligned.h new file mode 100644 index 0000000..a41fa8c --- /dev/null +++ b/arch/ppc/include/asm/unaligned.h @@ -0,0 +1,16 @@ +#ifndef _ASM_PPC_UNALIGNED_H +#define _ASM_PPC_UNALIGNED_H + +#ifdef __KERNEL__ + +/* + * The PowerPC can do unaligned accesses itself in big endian mode. + */ +#include +#include + +#define get_unaligned __get_unaligned_be +#define put_unaligned __put_unaligned_be + +#endif /* __KERNEL__ */ +#endif /* _ASM_PPC_UNALIGNED_H */ diff --git a/commands/mount.c b/commands/mount.c index b32faef..5b12ad4 100644 --- a/commands/mount.c +++ b/commands/mount.c @@ -29,11 +29,14 @@ #include #include #include +#include static int do_mount(int argc, char *argv[]) { + int opt; int ret = 0; struct fs_device_d *fsdev; + char *type = NULL; if (argc == 1) { for_each_fs_device(fsdev) { @@ -45,10 +48,18 @@ return 0; } - if (argc != 4) + while ((opt = getopt(argc, argv, "t:")) > 0) { + switch (opt) { + case 't': + type = optarg; + break; + } + } + + if (argc < optind + 2) return COMMAND_ERROR_USAGE; - if ((ret = mount(argv[1], argv[2], argv[3]))) { + if ((ret = mount(argv[optind], type, argv[optind + 1]))) { perror("mount"); return 1; } @@ -56,8 +67,9 @@ } BAREBOX_CMD_HELP_START(mount) -BAREBOX_CMD_HELP_USAGE("mount [ ]\n") +BAREBOX_CMD_HELP_USAGE("mount [[-t ]\n") BAREBOX_CMD_HELP_SHORT("Mount a filesystem of a given type to a mountpoint.\n") +BAREBOX_CMD_HELP_SHORT("If no fstpye is specified detected it.\n") BAREBOX_CMD_HELP_SHORT("If no argument is given, list mounted filesystems.\n") BAREBOX_CMD_HELP_END diff --git a/common/filetype.c b/common/filetype.c index 1a5b82d..e736d43 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ [filetype_aimage] = "Android boot image", [filetype_sh] = "Bourne Shell", [filetype_mips_barebox] = "MIPS barebox image", + [filetype_fat] = "FAT filesytem", }; const char *file_type_to_string(enum filetype f) @@ -50,6 +52,22 @@ return NULL; } +static int is_fat(u8 *buf) +{ + if (get_unaligned_le16(&buf[510]) != 0xAA55) + return 0; + + /* FAT */ + if ((get_unaligned_le32(&buf[54]) & 0xFFFFFF) == 0x544146) + return 1; + + /* FAT32 */ + if ((get_unaligned_le32(&buf[82]) & 0xFFFFFF) == 0x544146) + return 1; + + return 0; +} + enum filetype file_detect_type(void *_buf) { u32 *buf = _buf; @@ -81,6 +99,8 @@ return filetype_aimage; if (strncmp(buf8 + 0x10, "barebox", 7) == 0) return filetype_mips_barebox; + if (is_fat(buf8)) + return filetype_fat; return filetype_unknown; } diff --git a/defaultenv-2/base/init/automount b/defaultenv-2/base/init/automount index 7b53309..fe56d92 100644 --- a/defaultenv-2/base/init/automount +++ b/defaultenv-2/base/init/automount @@ -8,15 +8,15 @@ # automount tftp server based on $eth0.serverip mkdir -p /mnt/tftp -automount /mnt/tftp 'ifup eth0 && mount $eth0.serverip tftp /mnt/tftp' +automount /mnt/tftp 'ifup eth0 && mount -t tftp $eth0.serverip /mnt/tftp' # automount nfs server example #nfshost=somehost #mkdir -p /mnt/${nfshost} -#automount /mnt/$nfshost "ifup eth0 && mount ${nfshost}:/tftpboot nfs /mnt/${nfshost}" +#automount /mnt/$nfshost "ifup eth0 && mount -t nfs ${nfshost}:/tftpboot /mnt/${nfshost}" # FAT on usb disk example #mkdir -p /mnt/fat -#automount -d /mnt/fat 'usb && [ -e /dev/disk0.0 ] && mount /dev/disk0.0 fat /mnt/fat' +#automount -d /mnt/fat 'usb && [ -e /dev/disk0.0 ] && mount /dev/disk0.0 /mnt/fat' diff --git a/fs/Kconfig b/fs/Kconfig index b75820f..4c66543 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -1,6 +1,11 @@ menu "Filesystem support " +config FS + bool + default y + select FILETYPE + config FS_AUTOMOUNT bool diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 5e6c81c..01724a2 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -430,6 +430,7 @@ .write = fat_write, .truncate = fat_truncate, #endif + .type = filetype_fat, .flags = 0, .drv = { .probe = fat_probe, diff --git a/fs/fs.c b/fs/fs.c index 0b376a5..8ab1a3a 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -954,6 +954,28 @@ } EXPORT_SYMBOL(register_fs_driver); +static const char *detect_fs(const char *filename) +{ + enum filetype type = file_name_detect_type(filename); + struct driver_d *drv; + struct fs_driver_d *fdrv; + + if (type == filetype_unknown) + return NULL; + + for_each_driver(drv) { + if (drv->bus != &fs_bus) + continue; + + fdrv = drv_to_fs_driver(drv); + + if (type == fdrv->type) + return drv->name; + } + + return NULL; +} + /* * Mount a device to a directory. * We do this by registering a new device on which the filesystem @@ -985,6 +1007,12 @@ } } + if (!fsname) + fsname = detect_fs(device); + + if (!fsname) + return -ENOENT; + fsdev = xzalloc(sizeof(struct fs_device_d)); fsdev->backingstore = xstrdup(device); safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME); @@ -1222,7 +1250,7 @@ fsdev = get_fs_device_and_root_path(&p); if (!fsdev) { - ret = -ENOENT; + ret = -ENODEV; goto out; } fsdrv = fsdev->driver; diff --git a/include/filetype.h b/include/filetype.h index f5de8ed..179ec0f 100644 --- a/include/filetype.h +++ b/include/filetype.h @@ -18,6 +18,7 @@ filetype_aimage, filetype_sh, filetype_mips_barebox, + filetype_fat, }; const char *file_type_to_string(enum filetype f); diff --git a/include/fs.h b/include/fs.h index c0b9f71..22470e6 100644 --- a/include/fs.h +++ b/include/fs.h @@ -2,6 +2,7 @@ #define __FS_H #include +#include #define PATH_MAX 1024 /* include/linux/limits.h */ @@ -72,6 +73,8 @@ struct driver_d drv; + enum filetype type; + unsigned long flags; }; @@ -93,6 +96,8 @@ struct list_head list; }; +#define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv) + /* * standard posix file functions */