Hello Background on the issue ####################### Some time ago functionality was added to enable OMAP4 to boot over USB: https://git.pengutronix.de/cgit/barebox/commit/?id=6b4dc4d4f128bd22df4d022ad37285ce4858e1e8 That implementation uses the usb library stored in the OMAP4 ROM. The use of the OMAP4 ROM is problematic as it requires interrupts and also does not allow the MMU to be enabled. In fact there is an open issue with it: http://lists.infradead.org/pipermail/barebox/2016-August/027880.html More recently a similar functionality was added to OMAP3: https://git.pengutronix.de/cgit/barebox/commit/?id=1d7c8ec1431aec1c75c79dc17ecad0ab80435311 That implementation is using it's own way to access the usb device and has no dependencies on the ROM. Proposed changes ################ Given this scenario I modified the OMAP4 code to access the usb device directly, bypassing the ROM library, the same way the OMAP3 code does. Both OMAP3 and OMAP4 use the same usb device (musb, mentor-usb), the only change is the base address. So this modification tries to make it generic for both OMAPs, although it has not been tested on OMAP3. The patch with this modification follows. What is wrong with it ##################### Unfortunately, this modification is not working. The observed behaviour is: 1.- The console over usb works fine, as long as there is constant activity. If there are no transfers for approximately 4 seconds then the usb link is lost. 2.- The file system over usb works fine. Checked MD5 sums of kernel image and initial ram disk, all OK. 3.- Barebox reaches the start_linux function and executes the kernel function pointer, so, control is transferred to linux-land. But linux does not boot and nothing is printed on the serial console. Help needed ########### Are there any usb experts willing to help fixing this? There seems to be some "keep-alive" transactions over usb that when lost the usb link is reset. That seems to cause problem (1.-) described above. Problem (3.-) requires further investigation. The currently only known fact is that it works without this patch. Regards, Vicenç. --- arch/arm/boards/archosg9/board.c | 7 +- arch/arm/boards/archosg9/env/init/automount2 | 2 +- arch/arm/configs/archosg9_defconfig | 6 +- arch/arm/configs/archosg9_xload_defconfig | 6 +- arch/arm/cpu/cpu.c | 14 -- arch/arm/mach-omap/Kconfig | 9 +- arch/arm/mach-omap/Makefile | 2 +- arch/arm/mach-omap/include/mach/omap4_rom_usb.h | 144 ---------------- arch/arm/mach-omap/include/mach/omap_usbboot.h | 9 + arch/arm/mach-omap/omap4_generic.c | 23 +-- arch/arm/mach-omap/omap4_rom_usb.c | 197 --------------------- arch/arm/mach-omap/omap_usbboot.c | 104 +++++++++++ arch/arm/mach-omap/xload.c | 12 +- drivers/serial/Kconfig | 8 +- drivers/serial/Makefile | 2 +- drivers/serial/serial_omap4_usbboot.c | 77 --------- drivers/serial/serial_omap_usbboot.c | 54 ++++++ fs/Kconfig | 4 +- fs/Makefile | 2 +- fs/omap4_usbbootfs.c | 219 ------------------------ fs/omap_usbbootfs.c | 219 ++++++++++++++++++++++++ scripts/.gitignore | 2 +- scripts/Makefile | 6 +- scripts/{omap4_usbboot.c => omap_usbboot.c} | 0 24 files changed, 427 insertions(+), 701 deletions(-) delete mode 100644 arch/arm/mach-omap/include/mach/omap4_rom_usb.h create mode 100644 arch/arm/mach-omap/include/mach/omap_usbboot.h delete mode 100644 arch/arm/mach-omap/omap4_rom_usb.c create mode 100644 arch/arm/mach-omap/omap_usbboot.c delete mode 100644 drivers/serial/serial_omap4_usbboot.c create mode 100644 drivers/serial/serial_omap_usbboot.c delete mode 100644 fs/omap4_usbbootfs.c create mode 100644 fs/omap_usbbootfs.c rename scripts/{omap4_usbboot.c => omap_usbboot.c} (100%) diff --git a/arch/arm/boards/archosg9/board.c b/arch/arm/boards/archosg9/board.c index 52f7e86fb..cff6ba214 100644 --- a/arch/arm/boards/archosg9/board.c +++ b/arch/arm/boards/archosg9/board.c @@ -17,7 +17,7 @@ #include <generated/mach-types.h> #include <mach/omap4-silicon.h> #include <mach/omap4-devices.h> -#include <mach/omap4_rom_usb.h> +#include <mach/omap_usbboot.h> #include <mach/omap-fb.h> #include <linux/sizes.h> #include <i2c/i2c.h> @@ -46,9 +46,8 @@ static int archosg9_console_init(void) barebox_set_model("Archos G9"); barebox_set_hostname("g9"); - if (IS_ENABLED(CONFIG_DRIVER_SERIAL_OMAP4_USBBOOT) && - omap4_usbboot_ready()) { - add_generic_device("serial_omap4_usbboot", DEVICE_ID_DYNAMIC + if (IS_ENABLED(CONFIG_DRIVER_SERIAL_OMAP_USBBOOT)) { + add_generic_device("serial_omap_usbboot", DEVICE_ID_DYNAMIC , NULL, 0, 0, 0, NULL); } if (IS_ENABLED(CONFIG_DRIVER_SERIAL_NS16550)) { diff --git a/arch/arm/boards/archosg9/env/init/automount2 b/arch/arm/boards/archosg9/env/init/automount2 index fa104397e..9dc524020 100644 --- a/arch/arm/boards/archosg9/env/init/automount2 +++ b/arch/arm/boards/archosg9/env/init/automount2 @@ -4,4 +4,4 @@ mkdir -p /mnt/sd automount -d /mnt/sd '[ -e /dev/disk0.0 ] && mount /dev/disk0.0 /mnt/sd' mkdir -p /mnt/usb -automount -d /mnt/usb 'mount -t omap4_usbbootfs omap4_usbboot /mnt/usb' +automount -d /mnt/usb 'mount -t omap_usbbootfs omap_usbboot /mnt/usb' diff --git a/arch/arm/configs/archosg9_defconfig b/arch/arm/configs/archosg9_defconfig index 9a7192148..7d36fa602 100644 --- a/arch/arm/configs/archosg9_defconfig +++ b/arch/arm/configs/archosg9_defconfig @@ -1,5 +1,5 @@ CONFIG_ARCH_OMAP=y -CONFIG_OMAP4_USBBOOT=y +CONFIG_OMAP_USBBOOT=y CONFIG_MACH_ARCHOSG9=y CONFIG_THUMB2_BAREBOX=y CONFIG_ARM_BOARD_APPEND_ATAG=y @@ -69,7 +69,7 @@ CONFIG_NET_NETCONSOLE=y CONFIG_NET_RESOLV=y CONFIG_DRIVER_SERIAL_NS16550=y CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y -CONFIG_DRIVER_SERIAL_OMAP4_USBBOOT=y +CONFIG_DRIVER_SERIAL_OMAP_USBBOOT=y CONFIG_NET_USB=y CONFIG_NET_USB_SMSC95XX=y # CONFIG_SPI is not set @@ -91,7 +91,7 @@ CONFIG_LED_TRIGGERS=y CONFIG_KEYBOARD_GPIO=y CONFIG_KEYBOARD_TWL6030=y CONFIG_FS_TFTP=y -CONFIG_FS_OMAP4_USBBOOT=y +CONFIG_FS_OMAP_USBBOOT=y CONFIG_FS_NFS=y CONFIG_FS_FAT=y CONFIG_FS_FAT_WRITE=y diff --git a/arch/arm/configs/archosg9_xload_defconfig b/arch/arm/configs/archosg9_xload_defconfig index dc13f569d..bd4ac2d67 100644 --- a/arch/arm/configs/archosg9_xload_defconfig +++ b/arch/arm/configs/archosg9_xload_defconfig @@ -2,7 +2,7 @@ CONFIG_ARCH_OMAP=y CONFIG_BAREBOX_MAX_IMAGE_SIZE=0xC000 # CONFIG_OMAP_GPMC is not set CONFIG_OMAP_BUILD_IFT=y -CONFIG_OMAP4_USBBOOT=y +CONFIG_OMAP_USBBOOT=y CONFIG_MACH_ARCHOSG9=y CONFIG_THUMB2_BAREBOX=y # CONFIG_BANNER is not set @@ -15,7 +15,7 @@ CONFIG_SHELL_NONE=y CONFIG_CONSOLE_SIMPLE=y CONFIG_DRIVER_SERIAL_NS16550=y CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y -CONFIG_DRIVER_SERIAL_OMAP4_USBBOOT=y +CONFIG_DRIVER_SERIAL_OMAP_USBBOOT=y # CONFIG_SPI is not set CONFIG_MCI=y CONFIG_MCI_STARTUP=y @@ -23,5 +23,5 @@ CONFIG_MCI_STARTUP=y CONFIG_MCI_OMAP_HSMMC=y # CONFIG_FS_RAMFS is not set # CONFIG_FS_DEVFS is not set -CONFIG_FS_OMAP4_USBBOOT=y +CONFIG_FS_OMAP_USBBOOT=y CONFIG_FS_FAT=y diff --git a/arch/arm/cpu/cpu.c b/arch/arm/cpu/cpu.c index b4804634b..6e655255e 100644 --- a/arch/arm/cpu/cpu.c +++ b/arch/arm/cpu/cpu.c @@ -31,7 +31,6 @@ #include <asm-generic/memory_layout.h> #include <asm/cputype.h> #include <asm/cache.h> -#include <asm/ptrace.h> #include "mmu.h" @@ -98,23 +97,10 @@ void mmu_disable(void) */ static void arch_shutdown(void) { - uint32_t r; - #ifdef CONFIG_MMU mmu_disable(); #endif flush_icache(); - -#if __LINUX_ARM_ARCH__ <= 7 - /* - * barebox normally does not use interrupts, but some functionalities - * (eg. OMAP4_USBBOOT) require them enabled. So be sure interrupts are - * disabled before exiting. - */ - __asm__ __volatile__("mrs %0, cpsr" : "=r"(r)); - r |= PSR_I_BIT; - __asm__ __volatile__("msr cpsr, %0" : : "r"(r)); -#endif } archshutdown_exitcall(arch_shutdown); diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig index 9c41741b5..1cc0f78a0 100644 --- a/arch/arm/mach-omap/Kconfig +++ b/arch/arm/mach-omap/Kconfig @@ -120,14 +120,15 @@ config AM33XX_NET_BOOT default n depends on ARCH_AM33XX && NET -config OMAP4_USBBOOT +config OMAP_USBBOOT bool "enable booting from USB" default n - depends on ARCH_OMAP4 && !MMU + depends on ARCH_OMAP3 || ARCH_OMAP4 help Say Y here if you want to be able to boot an OMAP4 cpu from USB. - You need the utility program omap4_usbboot to boot from USB. - Please read omap4_usb_booting.txt for more information. + You need the utility program omap_usbboot to boot from USB. + For more information read: + https://git.pengutronix.de/cgit/barebox/plain/Documentation/omap4_usb_booting.txt?id=98360be0fefd58bf27df03c47d887dd676a31d73 config OMAP3_USBBOOT bool "enable booting from USB" diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile index a84e94ed7..8523633fb 100644 --- a/arch/arm/mach-omap/Makefile +++ b/arch/arm/mach-omap/Makefile @@ -30,7 +30,7 @@ pbl-$(CONFIG_ARCH_OMAP3) += omap3_clock.o obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o obj-$(CONFIG_SHELL_NONE) += xload.o obj-$(CONFIG_MFD_TWL6030) += omap4_twl6030_mmc.o -obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o +obj-$(CONFIG_OMAP_USBBOOT) += omap_usbboot.o obj-$(CONFIG_OMAP3_USBBOOT) += omap3_xload_usb.o pbl-$(CONFIG_OMAP3_USBBOOT) += omap3_xload_usb.o obj-$(CONFIG_CMD_BOOT_ORDER) += boot_order.o diff --git a/arch/arm/mach-omap/include/mach/omap4_rom_usb.h b/arch/arm/mach-omap/include/mach/omap4_rom_usb.h deleted file mode 100644 index bf8bd159a..000000000 --- a/arch/arm/mach-omap/include/mach/omap4_rom_usb.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 - * COPYRIGHT OWNER 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. - */ - -#ifndef _OMAP4_ROM_USB_H_ -#define _OMAP4_ROM_USB_H_ - -/* public api */ -#define PUBLIC_API_BASE_4430 (0x28400) -#define PUBLIC_API_BASE_4460 (0x30400) - -#define PUBLIC_GET_DRIVER_MEM_OFFSET (0x04) -#define PUBLIC_GET_DRIVER_PER_OFFSET (0x08) -#define PUBLIC_GET_DEVICE_MEM_OFFSET (0x80) -#define PUBLIC_GET_DEVICE_PER_OFFSET (0x84) - -#define DEVICE_NULL 0x40 -#define DEVICE_UART1 0x41 -#define DEVICE_UART2 0x42 -#define DEVICE_UART3 0x43 -#define DEVICE_UART4 0x44 -#define DEVICE_USB 0x45 -#define DEVICE_USBEXT 0x46 - -#define XFER_MODE_CPU 0 -#define XFER_MODE_DMA 1 - -#define STATUS_OKAY 0 -#define STATUS_FAILED 1 -#define STATUS_TIMEOUT 2 -#define STATUS_BAD_PARAM 3 -#define STATUS_WAITING 4 -#define STATUS_NO_MEMORY 5 -#define STATUS_INVALID_PTR 6 - -/* Memory ROM interface */ -struct read_desc { - u32 sector_start; - u32 sector_count; - void *destination; -}; - -struct mem_device { - u32 initialized; - u8 device_type; - u8 trials_count; - u32 xip_device; - u16 search_size; - u32 base_address; - u16 hs_toc_mask; - u16 gp_toc_mask; - void *device_data; - u16 *boot_options; -}; - -struct mem_driver { - int (*init)(struct mem_device *md); - int (*read)(struct mem_device *md, struct read_desc *rd); - int (*configure)(struct mem_device *md, void *config); -}; - - -/* Peripheral ROM interface */ -struct per_handle { - void *set_to_null; - void (*callback)(struct per_handle *rh); - void *data; - u32 length; - u16 *options; - u32 xfer_mode; - u32 device_type; - u32 status; - u16 hs_toc_mask; - u16 gp_toc_mask; - u32 config_timeout; -}; - -struct per_driver { - int (*init)(struct per_handle *rh); - int (*read)(struct per_handle *rh); - int (*write)(struct per_handle *rh); - int (*close)(struct per_handle *rh); - int (*config)(struct per_handle *rh, void *x); -}; - -#define USB_SETCONFIGDESC_ATTRIBUTES (0) -#define USB_SETCONFIGDESC_MAXPOWER (1) -#define USB_SETSUSPEND_CALLBACK (2) -struct per_usb_config { - u32 configid; - u32 value; -}; - -#define API(n) ((void *) (*((u32 *) (n)))) -/* ROM API End */ - -struct omap4_usbboot { - struct per_handle dread; - struct per_handle dwrite; - struct per_driver *io; - int ready; -}; - -int omap4_usbboot_open(void); -int omap4_usbboot_ready(void); -void omap4_usbboot_close(void); - -void omap4_usbboot_queue_read(void *data, unsigned len); -int omap4_usbboot_wait_read(void); -int omap4_usbboot_is_read_waiting(void); -int omap4_usbboot_is_read_ok(void); - -void omap4_usbboot_queue_write(void *data, unsigned len); -int omap4_usbboot_wait_write(void); - -int omap4_usbboot_read(void *data, unsigned len); -int omap4_usbboot_write(void *data, unsigned len); -void omap4_usbboot_puts(const char *s); - -#endif diff --git a/arch/arm/mach-omap/include/mach/omap_usbboot.h b/arch/arm/mach-omap/include/mach/omap_usbboot.h new file mode 100644 index 000000000..5c9ec036c --- /dev/null +++ b/arch/arm/mach-omap/include/mach/omap_usbboot.h @@ -0,0 +1,9 @@ +#ifndef OMAP_USBBOOT_H +#define OMAP_USBBOOT_H + +int omap_usbboot_available_bytes (void); +int omap_usbboot_read (void *data, unsigned len); +int omap_usbboot_write (void *data, unsigned len); +void omap_usbboot_puts (const char *s); + +#endif diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c index a3f370df8..4753b6036 100644 --- a/arch/arm/mach-omap/omap4_generic.c +++ b/arch/arm/mach-omap/omap4_generic.c @@ -9,7 +9,6 @@ #include <mach/syslib.h> #include <mach/generic.h> #include <mach/gpmc.h> -#include <mach/omap4_rom_usb.h> /* * The following several lines are taken from U-Boot to support @@ -484,21 +483,13 @@ late_initcall(watchdog_init); static int omap_vector_init(void) { - /* - * omap4 usbboot interfaces with the omap4 ROM to reuse the USB port - * used for booting. - * The ROM code uses interrupts for the transfers, so do not modify the - * interrupt vectors in this case. - */ - if (bootsource_get() != BOOTSOURCE_USB) { - __asm__ __volatile__ ( - "mov r0, #0;" - "mcr p15, #0, r0, c12, c0, #0;" - : - : - : "r0" - ); - } + __asm__ __volatile__ ( + "mov r0, #0;" + "mcr p15, #0, r0, c12, c0, #0;" + : + : + : "r0" + ); return 0; } diff --git a/arch/arm/mach-omap/omap4_rom_usb.c b/arch/arm/mach-omap/omap4_rom_usb.c deleted file mode 100644 index 31d93c34e..000000000 --- a/arch/arm/mach-omap/omap4_rom_usb.c +++ /dev/null @@ -1,197 +0,0 @@ -/* - * This code is based on: - * git://github.com/swetland/omap4boot.git - */ -/* - * Copyright (C) 2010 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 - * COPYRIGHT OWNER 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. - */ - -#include <common.h> -#include <mach/omap4-silicon.h> -#include <mach/omap4_rom_usb.h> -#include <mach/generic.h> -#include <init.h> - -static struct omap4_usbboot omap4_usbboot_data; - -int omap4_usbboot_open(void) -{ - int (*rom_get_per_driver)(struct per_driver **io, u32 device_type); - int (*rom_get_per_device)(struct per_handle **rh); - struct per_handle *boot; - int n; - u32 base; - - if (omap4_revision() >= OMAP4460_ES1_0) - base = PUBLIC_API_BASE_4460; - else - base = PUBLIC_API_BASE_4430; - - rom_get_per_driver = API(base + PUBLIC_GET_DRIVER_PER_OFFSET); - rom_get_per_device = API(base + PUBLIC_GET_DEVICE_PER_OFFSET); - - n = rom_get_per_device(&boot); - if (n) - return n; - - if ((boot->device_type != DEVICE_USB) && - (boot->device_type != DEVICE_USBEXT)) - return 0; - - memset(&omap4_usbboot_data, 0, sizeof(omap4_usbboot_data)); - n = rom_get_per_driver(&omap4_usbboot_data.io, boot->device_type); - if (n) - return n; - - omap4_usbboot_data.dread.status = -1; - omap4_usbboot_data.dread.xfer_mode = boot->xfer_mode; - omap4_usbboot_data.dread.options = boot->options; - omap4_usbboot_data.dread.device_type = boot->device_type; - - omap4_usbboot_data.dwrite.status = -1; - omap4_usbboot_data.dwrite.xfer_mode = boot->xfer_mode; - omap4_usbboot_data.dwrite.options = boot->options; - omap4_usbboot_data.dwrite.device_type = boot->device_type; - __asm__ __volatile__ ("cpsie i\n"); - omap4_usbboot_data.ready = 1; - - omap4_usbboot_puts("USB communications initialized\n"); - return 0; -} -core_initcall(omap4_usbboot_open); - -int omap4_usbboot_ready(void){ - return omap4_usbboot_data.ready; -} - -static void rom_read_callback(struct per_handle *rh) -{ - omap4_usbboot_data.dread.status = rh->status; - return; -} - -void omap4_usbboot_queue_read(void *data, unsigned len) -{ - int n; - omap4_usbboot_data.dread.data = data; - omap4_usbboot_data.dread.length = len; - omap4_usbboot_data.dread.status = STATUS_WAITING; - omap4_usbboot_data.dread.xfer_mode = 1; - omap4_usbboot_data.dread.callback = rom_read_callback; - n = omap4_usbboot_data.io->read(&omap4_usbboot_data.dread); - if (n) - omap4_usbboot_data.dread.status = n; -} - -int omap4_usbboot_wait_read(void) -{ - int ret; - while (omap4_usbboot_data.dread.status == STATUS_WAITING) - /* cpu_relax(); */ - barrier(); - ret = omap4_usbboot_data.dread.status; - omap4_usbboot_data.dread.status = -1; - return ret; -} - -int omap4_usbboot_is_read_waiting(void) -{ - barrier(); - return omap4_usbboot_data.dread.status == STATUS_WAITING; -} - -int omap4_usbboot_is_read_ok(void) -{ - barrier(); - return omap4_usbboot_data.dread.status == STATUS_OKAY; -} - -static void rom_write_callback(struct per_handle *rh) -{ - omap4_usbboot_data.dwrite.status = rh->status; - return; -} - -void omap4_usbboot_queue_write(void *data, unsigned len) -{ - int n; - omap4_usbboot_data.dwrite.data = data; - omap4_usbboot_data.dwrite.length = len; - omap4_usbboot_data.dwrite.status = STATUS_WAITING; - omap4_usbboot_data.dwrite.xfer_mode = 1; - omap4_usbboot_data.dwrite.callback = rom_write_callback; - n = omap4_usbboot_data.io->write(&omap4_usbboot_data.dwrite); - if (n) - omap4_usbboot_data.dwrite.status = n; -} - -int omap4_usbboot_wait_write(void) -{ - int ret; - while (omap4_usbboot_data.dwrite.status == STATUS_WAITING) - /* cpu_relax(); */ - barrier(); - ret = omap4_usbboot_data.dwrite.status; - omap4_usbboot_data.dwrite.status = -1; - return ret; -} - -#define USB_MAX_IO 65536 -int omap4_usbboot_read(void *data, unsigned len) -{ - unsigned xfer; - unsigned char *x = data; - int n; - while (len > 0) { - xfer = (len > USB_MAX_IO) ? USB_MAX_IO : len; - omap4_usbboot_queue_read(x, xfer); - n = omap4_usbboot_wait_read(); - if (n) - return n; - x += xfer; - len -= xfer; - } - return 0; -} - -int omap4_usbboot_write(void *data, unsigned len) -{ - omap4_usbboot_queue_write(data, len); - return omap4_usbboot_wait_write(); -} - -void omap4_usbboot_close(void) -{ - omap4_usbboot_data.io->close(&omap4_usbboot_data.dread); -} - -void omap4_usbboot_puts(const char *s) -{ - u32 c; - while ((c = *s++)) - omap4_usbboot_write(&c, 4); -} diff --git a/arch/arm/mach-omap/omap_usbboot.c b/arch/arm/mach-omap/omap_usbboot.c new file mode 100644 index 000000000..e8094a770 --- /dev/null +++ b/arch/arm/mach-omap/omap_usbboot.c @@ -0,0 +1,104 @@ +#include <common.h> +#include <io.h> +#include <mach/omap3-silicon.h> +#include <mach/omap4-silicon.h> +#include <mach/generic.h> + +#define BULK_ENDPOINT 1 +#define MUSB_TXCSR_TXPKTRDY 0x0001 +#define MUSB_RXCSR_RXPKTRDY 0x0001 + +#define L4_CORE_BASE (cpu_is_omap3() ? \ + OMAP3_L4_CORE_BASE : OMAP44XX_L4_CORE_BASE) +#define MUSB0_BASE 0xAB000 +#define MUSB_TXCSR 0x02 +#define MUSB_RXCSR 0x06 +#define MUSB_RXCOUNT 0x08 +#define USB_EP(n) (MUSB0_BASE + 0x100 + 0x10 * (n)) +#define USB_FIFO(n) (MUSB0_BASE + 0x020 + 0x04 * (n)) +#define USB_TXCSR(n) (USB_EP(n) + MUSB_TXCSR) +#define USB_RXCSR(n) (USB_EP(n) + MUSB_RXCSR) +#define USB_RXCOUNT(n) (USB_EP(n) + MUSB_RXCOUNT) + +#define USB_MAX_IO 0x10000 + +static unsigned available_bytes = 0; + +int omap_usbboot_available_bytes(void) +{ + void __iomem *const l4_core_base = (void __iomem *)L4_CORE_BASE; + void __iomem *const rxcsr = l4_core_base+USB_RXCSR (BULK_ENDPOINT); + void __iomem *const rxcount = l4_core_base+USB_RXCOUNT(BULK_ENDPOINT); + + if(available_bytes) + return available_bytes; + + if (!(readw(rxcsr) & MUSB_RXCSR_RXPKTRDY)) + return 0; + + return readw(rxcount); +} + +int omap_usbboot_read(void *data, unsigned len) +{ + void __iomem *const l4_core_base = (void __iomem *)L4_CORE_BASE; + void __iomem *const rxcsr = l4_core_base+USB_RXCSR (BULK_ENDPOINT); + void __iomem *const rxcount = l4_core_base+USB_RXCOUNT(BULK_ENDPOINT); + void __iomem *const fifo = l4_core_base+USB_FIFO (BULK_ENDPOINT); + unsigned char *buffer = data; + + while(len){ + unsigned count; + if(available_bytes){ + count = available_bytes; + available_bytes = 0; + } + else{ + while (!(readw(rxcsr) & MUSB_RXCSR_RXPKTRDY)) + barrier(); + count = readw(rxcount); + } + + if(count>len){ + available_bytes = count - len; + count = len; + } + len -= count; + for(; count; --count) + *buffer++ = readb(fifo); + + if(!available_bytes) + writew(readw(rxcsr) & ~MUSB_RXCSR_RXPKTRDY, rxcsr); + } + return 0; +} + +int omap_usbboot_write(void *data, unsigned len) +{ + void __iomem *const l4_core_base = (void __iomem *)L4_CORE_BASE; + void __iomem *const txcsr = l4_core_base+USB_TXCSR(BULK_ENDPOINT); + void __iomem *const fifo = l4_core_base+USB_FIFO (BULK_ENDPOINT); + unsigned char *buffer = data; + + while(len){ + unsigned count = len>=USB_MAX_IO ? USB_MAX_IO : len; + len -= count; + + while (readw(txcsr) & MUSB_TXCSR_TXPKTRDY) + barrier(); + + for (; count; --count) + writeb(*buffer++, fifo); + + writew(readw(txcsr) | MUSB_TXCSR_TXPKTRDY, txcsr); + } + + return 0; +} + +void omap_usbboot_puts(const char *s) +{ + u32 c; + while ((c = *s++)) + omap_usbboot_write(&c, 4); +} diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c index 822389c38..3423a5496 100644 --- a/arch/arm/mach-omap/xload.c +++ b/arch/arm/mach-omap/xload.c @@ -166,20 +166,20 @@ static void *omap_xload_boot_spi(struct omap_barebox_part *part) return read_mtd_barebox("x"); } -static void *omap4_xload_boot_usb(void){ +static void *omap_xload_boot_usb(void){ int ret; void *buf; int len; - ret = mount("omap4_usbboot", "omap4_usbbootfs", "/", NULL); + ret = mount("omap_usbboot", "omap_usbbootfs", "/", NULL); if (ret) { - printf("Unable to mount omap4_usbbootfs (%d)\n", ret); + printf("Unable to mount omap_usbbootfs (%d)\n", ret); return NULL; } buf = read_file("/barebox.bin", &len); if (!buf) - printf("could not read barebox.bin from omap4_usbbootfs\n"); + printf("could not read barebox.bin from omap_usbbootfs\n"); return buf; } @@ -307,9 +307,9 @@ static __noreturn int omap_xload(void) if (IS_ENABLED(CONFIG_OMAP3_USBBOOT) && cpu_is_omap3()) { printf("booting from USB\n"); func = omap3_xload_boot_usb(); - } else if (IS_ENABLED(CONFIG_FS_OMAP4_USBBOOT)) { + } else if (IS_ENABLED(CONFIG_FS_OMAP_USBBOOT)) { printf("booting from USB\n"); - func = omap4_xload_boot_usb(); + func = omap_xload_boot_usb(); } else { printf("booting from USB not enabled\n"); func = NULL; diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 4eab437ea..ef08f685f 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -121,12 +121,12 @@ config DRIVER_SERIAL_PXA bool "PXA serial driver" depends on ARCH_PXA -config DRIVER_SERIAL_OMAP4_USBBOOT - bool "serial driver over omap4 usb" +config DRIVER_SERIAL_OMAP_USBBOOT + bool "serial driver over omap usb" default n - depends on OMAP4_USBBOOT + depends on OMAP_USBBOOT help - Enable this to get console support over the usb bus used to boot an OMAP4 + Enable this to get console support over the usb bus used to boot an OMAP config DRIVER_SERIAL_CADENCE bool "Cadence UART driver" diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index 7d1bae195..0146e2856 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile @@ -15,7 +15,7 @@ obj-$(CONFIG_DRIVER_SERIAL_S3C) += serial_s3c.o obj-$(CONFIG_DRIVER_SERIAL_ALTERA) += serial_altera.o obj-$(CONFIG_DRIVER_SERIAL_ALTERA_JTAG) += serial_altera_jtag.o obj-$(CONFIG_DRIVER_SERIAL_PXA) += serial_pxa.o -obj-$(CONFIG_DRIVER_SERIAL_OMAP4_USBBOOT) += serial_omap4_usbboot.o +obj-$(CONFIG_DRIVER_SERIAL_OMAP_USBBOOT) += serial_omap_usbboot.o obj-$(CONFIG_DRIVER_SERIAL_AUART) += serial_auart.o obj-$(CONFIG_DRIVER_SERIAL_CADENCE) += serial_cadence.o obj-$(CONFIG_DRIVER_SERIAL_EFI_STDIO) += efi-stdio.o diff --git a/drivers/serial/serial_omap4_usbboot.c b/drivers/serial/serial_omap4_usbboot.c deleted file mode 100644 index 2ef026c24..000000000 --- a/drivers/serial/serial_omap4_usbboot.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include <common.h> -#include <init.h> -#include <malloc.h> -#include <errno.h> -#include <mach/omap4_rom_usb.h> - -struct serial_omap4_usbboot_priv { - struct console_device cdev; - u32 val; -}; - -static void serial_omap4_usbboot_putc(struct console_device *cdev, char c) -{ - unsigned b = c; - omap4_usbboot_write(&b, 4); -} - -static int serial_omap4_usbboot_tstc(struct console_device *cdev) -{ - struct serial_omap4_usbboot_priv *priv = - container_of(cdev, struct serial_omap4_usbboot_priv, cdev); - if (omap4_usbboot_is_read_waiting()) - return 0; - else if (omap4_usbboot_is_read_ok()) - return 1; - omap4_usbboot_queue_read(&priv->val, 4); - udelay(100); - if (omap4_usbboot_is_read_waiting()) - return 0; - else if (omap4_usbboot_is_read_ok()) - return 1; - return 0; -} - -static int serial_omap4_usbboot_getc(struct console_device *cdev) -{ - struct serial_omap4_usbboot_priv *priv = - container_of(cdev, struct serial_omap4_usbboot_priv, cdev); - if (omap4_usbboot_is_read_waiting() || omap4_usbboot_is_read_ok()) { - omap4_usbboot_wait_read(); - return priv->val; - } - omap4_usbboot_read(&priv->val, 4); - return priv->val; -} - -static int serial_omap4_usbboot_probe(struct device_d *dev) -{ - struct serial_omap4_usbboot_priv *priv; - priv = xzalloc(sizeof(*priv)); - - priv->cdev.dev = dev; - priv->cdev.tstc = serial_omap4_usbboot_tstc; - priv->cdev.putc = serial_omap4_usbboot_putc; - priv->cdev.getc = serial_omap4_usbboot_getc; - priv->cdev.setbrg = NULL; - - return console_register(&priv->cdev); -} - -static struct driver_d serial_omap4_usbboot_driver = { - .name = "serial_omap4_usbboot", - .probe = serial_omap4_usbboot_probe, -}; -console_platform_driver(serial_omap4_usbboot_driver); diff --git a/drivers/serial/serial_omap_usbboot.c b/drivers/serial/serial_omap_usbboot.c new file mode 100644 index 000000000..f733a43c7 --- /dev/null +++ b/drivers/serial/serial_omap_usbboot.c @@ -0,0 +1,54 @@ +/* + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <common.h> +#include <init.h> +#include <malloc.h> +#include <errno.h> +#include <mach/omap_usbboot.h> + +static void serial_omap_usbboot_putc(struct console_device *cdev, char c) +{ + unsigned b = c; + omap_usbboot_write(&b, 4); +} + +static int serial_omap_usbboot_tstc(struct console_device *cdev) +{ + return omap_usbboot_available_bytes() > 0; +} + +static int serial_omap_usbboot_getc(struct console_device *cdev) +{ + unsigned c; + omap_usbboot_read(&c, 4); + return c; +} + +static int serial_omap_usbboot_probe(struct device_d *dev) +{ + struct console_device *cdev; + cdev = xzalloc(sizeof(*cdev)); + + cdev->dev = dev; + cdev->tstc = serial_omap_usbboot_tstc; + cdev->putc = serial_omap_usbboot_putc; + cdev->getc = serial_omap_usbboot_getc; + + return console_register(cdev); +} + +static struct driver_d serial_omap_usbboot_driver = { + .name = "serial_omap_usbboot", + .probe = serial_omap_usbboot_probe, +}; +console_platform_driver(serial_omap_usbboot_driver); diff --git a/fs/Kconfig b/fs/Kconfig index c7c42acd7..79e851ed8 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -31,10 +31,10 @@ config FS_TFTP prompt "tftp support" depends on NET -config FS_OMAP4_USBBOOT +config FS_OMAP_USBBOOT bool prompt "Filesystem over usb boot" - depends on OMAP4_USBBOOT + depends on OMAP_USBBOOT config FS_NFS depends on NET diff --git a/fs/Makefile b/fs/Makefile index f2bb70285..effc64c0e 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_FS_FAT) += fat/ obj-y += fs.o obj-$(CONFIG_FS_UBIFS) += ubifs/ obj-$(CONFIG_FS_TFTP) += tftp.o -obj-$(CONFIG_FS_OMAP4_USBBOOT) += omap4_usbbootfs.o +obj-$(CONFIG_FS_OMAP_USBBOOT) += omap_usbbootfs.o obj-$(CONFIG_FS_NFS) += nfs.o parseopt.o obj-$(CONFIG_FS_BPKFS) += bpkfs.o obj-$(CONFIG_FS_UIMAGEFS) += uimagefs.o diff --git a/fs/omap4_usbbootfs.c b/fs/omap4_usbbootfs.c deleted file mode 100644 index 6085bca84..000000000 --- a/fs/omap4_usbbootfs.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include <common.h> -#include <malloc.h> -#include <fs.h> -#include <fcntl.h> -#include <init.h> -#include <linux/stat.h> -#include <linux/err.h> -#include <mach/omap4_rom_usb.h> - -#define OMAP4_USBBOOT_FS_MAGIC 0x5562464D -#define OMAP4_USBBOOT_FS_CMD_OPEN 0x46530000 -#define OMAP4_USBBOOT_FS_CMD_CLOSE 0x46530001 -#define OMAP4_USBBOOT_FS_CMD_READ 0x46530002 -#define OMAP4_USBBOOT_FS_CMD_END 0x4653FFFF - -struct file_priv { - s32 id; - u32 size; -}; -/* -static int omap4_usbbootfs_create( - struct device_d *dev, const char *pathname, mode_t mode) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_unlink(struct device_d *dev, const char *pathname) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_mkdir(struct device_d *dev, const char *pathname) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_rmdir(struct device_d *dev, const char *pathname) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_write( - struct device_d *_dev, FILE *f, const void *inbuf, size_t size) -{ - return -ENOSYS; -} - -static int omap4_usbbootfs_truncate(struct device_d *dev, FILE *f, ulong size) -{ - return -ENOSYS; -} -*/ - -static struct file_priv *omap4_usbbootfs_do_open( - struct device_d *dev, int accmode, const char *filename) -{ - struct file_priv *priv; - u32 data; - - if (accmode & O_ACCMODE) - return ERR_PTR(-ENOSYS); - - priv = xzalloc(sizeof(*priv)); - if (!priv) - return ERR_PTR(-ENOMEM); - - data = OMAP4_USBBOOT_FS_MAGIC ; omap4_usbboot_write(&data, 4); - data = OMAP4_USBBOOT_FS_CMD_OPEN; omap4_usbboot_write(&data, 4); - omap4_usbboot_puts(filename); - data = OMAP4_USBBOOT_FS_CMD_END ; omap4_usbboot_write(&data, 4); - - if (omap4_usbboot_read(&priv->id, 4) || - omap4_usbboot_read(&priv->size, 4) - ) { - free(priv); - return ERR_PTR(-EIO); - } - if (priv->id < 0) { - free(priv); - return ERR_PTR(-ENOENT); - } - - return priv; -} - -static int omap4_usbbootfs_open( - struct device_d *dev, FILE *file, const char *filename) -{ - struct file_priv *priv; - - priv = omap4_usbbootfs_do_open(dev, file->flags, filename); - if (IS_ERR(priv)) - return PTR_ERR(priv); - - file->priv = priv; - file->size = priv->size; - - return 0; -} - -static int omap4_usbbootfs_do_close(struct file_priv *priv) -{ - u32 data; - data = OMAP4_USBBOOT_FS_MAGIC ; omap4_usbboot_write(&data, 4); - data = OMAP4_USBBOOT_FS_CMD_CLOSE; omap4_usbboot_write(&data, 4); - omap4_usbboot_write(&priv->id, 4); - data = OMAP4_USBBOOT_FS_CMD_END ; omap4_usbboot_write(&data, 4); - free(priv); - return 0; -} - -static int omap4_usbbootfs_close(struct device_d *dev, FILE *f) -{ - struct file_priv *priv = f->priv; - return omap4_usbbootfs_do_close(priv); -} - -static int omap4_usbbootfs_read( - struct device_d *dev, FILE *f, void *buf, size_t size) -{ - struct file_priv *priv = f->priv; - u32 data; - - if (size > priv->size - f->pos) - size = priv->size - f->pos; - if (!size) - return 0; - - data = OMAP4_USBBOOT_FS_MAGIC ; omap4_usbboot_write(&data, 4); - data = OMAP4_USBBOOT_FS_CMD_READ; omap4_usbboot_write(&data, 4); - omap4_usbboot_write(&priv->id, 4); - omap4_usbboot_write(&f->pos, 4); - omap4_usbboot_write(&size, 4); - data = OMAP4_USBBOOT_FS_CMD_END ; omap4_usbboot_write(&data, 4); - - if (omap4_usbboot_read(buf, size)) - return -EIO; - - return size; -} - -static loff_t omap4_usbbootfs_lseek(struct device_d *dev, FILE *f, loff_t pos) -{ - f->pos = pos; - return pos; -} - -static DIR *omap4_usbbootfs_opendir(struct device_d *dev, const char *pathname) -{ - return NULL; -} - -static int omap4_usbbootfs_stat( - struct device_d *dev, const char *filename, struct stat *s) -{ - struct file_priv *priv; - - priv = omap4_usbbootfs_do_open(dev, O_RDONLY, filename); - if (IS_ERR(priv)) - return PTR_ERR(priv); - - s->st_mode = S_IFREG | - S_IRUSR | S_IRGRP | S_IROTH | - S_IXUSR | S_IXGRP | S_IXOTH ; - s->st_size = priv->size; - - omap4_usbbootfs_do_close(priv); - - return 0; -} - -static int omap4_usbbootfs_probe(struct device_d *dev) -{ - return 0; -} -static void omap4_usbbootfs_remove(struct device_d *dev) -{ -} - -static struct fs_driver_d omap4_usbbootfs_driver = { - .open = omap4_usbbootfs_open, - .close = omap4_usbbootfs_close, - .read = omap4_usbbootfs_read, - .lseek = omap4_usbbootfs_lseek, - .opendir = omap4_usbbootfs_opendir, - .stat = omap4_usbbootfs_stat, -/* - .create = omap4_usbbootfs_create, - .unlink = omap4_usbbootfs_unlink, - .mkdir = omap4_usbbootfs_mkdir, - .rmdir = omap4_usbbootfs_rmdir, - .write = omap4_usbbootfs_write, - .truncate= omap4_usbbootfs_truncate, -*/ - .flags = 0, - .drv = { - .probe = omap4_usbbootfs_probe, - .remove = omap4_usbbootfs_remove, - .name = "omap4_usbbootfs", - } -}; - -static int omap4_usbbootfs_init(void) -{ - return register_fs_driver(&omap4_usbbootfs_driver); -} -coredevice_initcall(omap4_usbbootfs_init); diff --git a/fs/omap_usbbootfs.c b/fs/omap_usbbootfs.c new file mode 100644 index 000000000..dfbd0db92 --- /dev/null +++ b/fs/omap_usbbootfs.c @@ -0,0 +1,219 @@ +/* + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <common.h> +#include <malloc.h> +#include <fs.h> +#include <fcntl.h> +#include <init.h> +#include <linux/stat.h> +#include <linux/err.h> +#include <mach/omap_usbboot.h> + +#define OMAP_USBBOOT_FS_MAGIC 0x5562464D +#define OMAP_USBBOOT_FS_CMD_OPEN 0x46530000 +#define OMAP_USBBOOT_FS_CMD_CLOSE 0x46530001 +#define OMAP_USBBOOT_FS_CMD_READ 0x46530002 +#define OMAP_USBBOOT_FS_CMD_END 0x4653FFFF + +struct file_priv { + s32 id; + u32 size; +}; +/* +static int omap_usbbootfs_create( + struct device_d *dev, const char *pathname, mode_t mode) +{ + return -ENOSYS; +} + +static int omap_usbbootfs_unlink(struct device_d *dev, const char *pathname) +{ + return -ENOSYS; +} + +static int omap_usbbootfs_mkdir(struct device_d *dev, const char *pathname) +{ + return -ENOSYS; +} + +static int omap_usbbootfs_rmdir(struct device_d *dev, const char *pathname) +{ + return -ENOSYS; +} + +static int omap_usbbootfs_write( + struct device_d *_dev, FILE *f, const void *inbuf, size_t size) +{ + return -ENOSYS; +} + +static int omap_usbbootfs_truncate(struct device_d *dev, FILE *f, ulong size) +{ + return -ENOSYS; +} +*/ + +static struct file_priv *omap_usbbootfs_do_open( + struct device_d *dev, int accmode, const char *filename) +{ + struct file_priv *priv; + u32 data; + + if (accmode & O_ACCMODE) + return ERR_PTR(-ENOSYS); + + priv = xzalloc(sizeof(*priv)); + if (!priv) + return ERR_PTR(-ENOMEM); + + data = OMAP_USBBOOT_FS_MAGIC ; omap_usbboot_write(&data, 4); + data = OMAP_USBBOOT_FS_CMD_OPEN; omap_usbboot_write(&data, 4); + omap_usbboot_puts(filename); + data = OMAP_USBBOOT_FS_CMD_END ; omap_usbboot_write(&data, 4); + + if (omap_usbboot_read(&priv->id, 4) || + omap_usbboot_read(&priv->size, 4) + ) { + free(priv); + return ERR_PTR(-EIO); + } + if (priv->id < 0) { + free(priv); + return ERR_PTR(-ENOENT); + } + + return priv; +} + +static int omap_usbbootfs_open( + struct device_d *dev, FILE *file, const char *filename) +{ + struct file_priv *priv; + + priv = omap_usbbootfs_do_open(dev, file->flags, filename); + if (IS_ERR(priv)) + return PTR_ERR(priv); + + file->priv = priv; + file->size = priv->size; + + return 0; +} + +static int omap_usbbootfs_do_close(struct file_priv *priv) +{ + u32 data; + data = OMAP_USBBOOT_FS_MAGIC ; omap_usbboot_write(&data, 4); + data = OMAP_USBBOOT_FS_CMD_CLOSE; omap_usbboot_write(&data, 4); + omap_usbboot_write(&priv->id, 4); + data = OMAP_USBBOOT_FS_CMD_END ; omap_usbboot_write(&data, 4); + free(priv); + return 0; +} + +static int omap_usbbootfs_close(struct device_d *dev, FILE *f) +{ + struct file_priv *priv = f->priv; + return omap_usbbootfs_do_close(priv); +} + +static int omap_usbbootfs_read( + struct device_d *dev, FILE *f, void *buf, size_t size) +{ + struct file_priv *priv = f->priv; + u32 data; + + if (size > priv->size - f->pos) + size = priv->size - f->pos; + if (!size) + return 0; + + data = OMAP_USBBOOT_FS_MAGIC ; omap_usbboot_write(&data, 4); + data = OMAP_USBBOOT_FS_CMD_READ; omap_usbboot_write(&data, 4); + omap_usbboot_write(&priv->id, 4); + omap_usbboot_write(&f->pos, 4); + omap_usbboot_write(&size, 4); + data = OMAP_USBBOOT_FS_CMD_END ; omap_usbboot_write(&data, 4); + + if (omap_usbboot_read(buf, size)) + return -EIO; + + return size; +} + +static loff_t omap_usbbootfs_lseek(struct device_d *dev, FILE *f, loff_t pos) +{ + f->pos = pos; + return pos; +} + +static DIR *omap_usbbootfs_opendir(struct device_d *dev, const char *pathname) +{ + return NULL; +} + +static int omap_usbbootfs_stat( + struct device_d *dev, const char *filename, struct stat *s) +{ + struct file_priv *priv; + + priv = omap_usbbootfs_do_open(dev, O_RDONLY, filename); + if (IS_ERR(priv)) + return PTR_ERR(priv); + + s->st_mode = S_IFREG | + S_IRUSR | S_IRGRP | S_IROTH | + S_IXUSR | S_IXGRP | S_IXOTH ; + s->st_size = priv->size; + + omap_usbbootfs_do_close(priv); + + return 0; +} + +static int omap_usbbootfs_probe(struct device_d *dev) +{ + return 0; +} +static void omap_usbbootfs_remove(struct device_d *dev) +{ +} + +static struct fs_driver_d omap_usbbootfs_driver = { + .open = omap_usbbootfs_open, + .close = omap_usbbootfs_close, + .read = omap_usbbootfs_read, + .lseek = omap_usbbootfs_lseek, + .opendir = omap_usbbootfs_opendir, + .stat = omap_usbbootfs_stat, +/* + .create = omap_usbbootfs_create, + .unlink = omap_usbbootfs_unlink, + .mkdir = omap_usbbootfs_mkdir, + .rmdir = omap_usbbootfs_rmdir, + .write = omap_usbbootfs_write, + .truncate= omap_usbbootfs_truncate, +*/ + .flags = 0, + .drv = { + .probe = omap_usbbootfs_probe, + .remove = omap_usbbootfs_remove, + .name = "omap_usbbootfs", + } +}; + +static int omap_usbbootfs_init(void) +{ + return register_fs_driver(&omap_usbbootfs_driver); +} +coredevice_initcall(omap_usbbootfs_init); diff --git a/scripts/.gitignore b/scripts/.gitignore index 2a9ae6bdc..8d5d9318b 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -25,4 +25,4 @@ mk-am35xx-spi-image mxsimage mxsboot mxs-usb-loader -omap4_usbboot +omap_usbboot diff --git a/scripts/Makefile b/scripts/Makefile index 7f2527d1c..e812a6369 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -28,9 +28,9 @@ hostprogs-$(CONFIG_ARCH_MXS_USBLOADER) += mxs-usb-loader HOSTCFLAGS_omap3-usb-loader.o = `pkg-config --cflags libusb-1.0` HOSTLOADLIBES_omap3-usb-loader = `pkg-config --libs libusb-1.0` hostprogs-$(CONFIG_OMAP3_USB_LOADER) += omap3-usb-loader -HOSTCFLAGS_omap4_usbboot.o = `pkg-config --cflags libusb-1.0` -HOSTLOADLIBES_omap4_usbboot = -lpthread `pkg-config --libs libusb-1.0` -hostprogs-$(CONFIG_OMAP4_USBBOOT) += omap4_usbboot +HOSTCFLAGS_omap_usbboot.o = `pkg-config --cflags libusb-1.0` +HOSTLOADLIBES_omap_usbboot = -lpthread `pkg-config --libs libusb-1.0` +hostprogs-$(CONFIG_OMAP_USBBOOT) += omap_usbboot subdir-y += mod subdir-$(CONFIG_ARCH_IMX) += imx diff --git a/scripts/omap4_usbboot.c b/scripts/omap_usbboot.c similarity index 100% rename from scripts/omap4_usbboot.c rename to scripts/omap_usbboot.c -- 2.11.1 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox