diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2011-11-29 20:45:23 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-11-29 20:45:23 +0100 |
commit | e0f4fb2c982d66210dfd5ffaf92912bf1c6c6586 (patch) | |
tree | 6095eff90c4f335e47dc2454be6edc671dfe5e1b | |
parent | 97e0b488a94c6f8c9bac5100b0f8542264d555be (diff) | |
parent | 6fa8c93a5ecefe4effa0e0425441a8ff6b2ce6ab (diff) | |
download | barebox-e0f4fb2c982d66210dfd5ffaf92912bf1c6c6586.tar.gz barebox-e0f4fb2c982d66210dfd5ffaf92912bf1c6c6586.tar.xz |
Merge branch 'master' into next
Conflicts:
drivers/ata/disk_drive.c
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | arch/arm/boards/freescale-mx53-loco/board.c | 2 | ||||
-rw-r--r-- | arch/arm/boards/mini2440/config.h | 9 | ||||
-rw-r--r-- | arch/arm/boards/mini2440/mini2440.c | 3 | ||||
-rw-r--r-- | arch/arm/configs/pcm043_defconfig | 1 | ||||
-rw-r--r-- | arch/arm/mach-imx/nand.c | 2 | ||||
-rw-r--r-- | arch/nios2/include/asm/unaligned.h | 15 | ||||
-rw-r--r-- | arch/x86/boot/pmjump.S | 3 | ||||
-rw-r--r-- | arch/x86/include/asm/types.h | 2 | ||||
-rw-r--r-- | arch/x86/include/asm/unaligned.h | 14 | ||||
-rw-r--r-- | arch/x86/lib/traveler.S | 11 | ||||
-rw-r--r-- | commands/mkdir.c | 7 | ||||
-rw-r--r-- | commands/mount.c | 2 | ||||
-rw-r--r-- | common/console.c | 19 | ||||
-rw-r--r-- | common/env.c | 3 | ||||
-rw-r--r-- | common/password.c | 3 | ||||
-rw-r--r-- | drivers/nor/m25p80.c | 6 | ||||
-rw-r--r-- | drivers/serial/serial_s3c24x0.c | 2 | ||||
-rw-r--r-- | drivers/spi/atmel_spi.c | 2 | ||||
-rw-r--r-- | drivers/usb/host/Kconfig | 4 | ||||
-rw-r--r-- | drivers/usb/host/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/host/ehci-hcd.c | 4 | ||||
-rw-r--r-- | fs/fat/fat.c | 2 | ||||
-rw-r--r-- | fs/fs.c | 7 | ||||
-rw-r--r-- | include/stdio.h | 8 | ||||
-rw-r--r-- | lib/decompress_unlzo.c | 216 | ||||
-rw-r--r-- | lib/readkey.c | 2 | ||||
-rw-r--r-- | scripts/setupmbr/.gitignore | 1 |
28 files changed, 263 insertions, 91 deletions
@@ -1,5 +1,5 @@ VERSION = 2011 -PATCHLEVEL = 10 +PATCHLEVEL = 11 SUBLEVEL = 0 EXTRAVERSION = NAME = Amissive Actinocutious Kiwi diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c index c00b3bb942..6a5ef37adf 100644 --- a/arch/arm/boards/freescale-mx53-loco/board.c +++ b/arch/arm/boards/freescale-mx53-loco/board.c @@ -103,8 +103,6 @@ static int loco_devices_init(void) armlinux_set_bootparams((void *)0x70000100); armlinux_set_architecture(MACH_TYPE_MX53_LOCO); - loco_fec_reset(); - return 0; } diff --git a/arch/arm/boards/mini2440/config.h b/arch/arm/boards/mini2440/config.h index 1f2fb4c4f5..8d36193c1d 100644 --- a/arch/arm/boards/mini2440/config.h +++ b/arch/arm/boards/mini2440/config.h @@ -61,13 +61,14 @@ * Twrph1 = 1 (-> 20ns) * Cycle time = 80ns */ -#define A9M2440_TACLS 1 -#define A9M2440_TWRPH0 3 -#define A9M2440_TWRPH1 1 +#define MINI2440_TACLS 1 +#define MINI2440_TWRPH0 3 +#define MINI2440_TWRPH1 1 /* needed in the generic NAND boot code only */ #ifdef CONFIG_S3C24XX_NAND_BOOT -# define BOARD_DEFAULT_NAND_TIMING CALC_NFCONF_TIMING(A9M2440_TACLS, A9M2440_TWRPH0, A9M2440_TWRPH1) +# define BOARD_DEFAULT_NAND_TIMING \ + CALC_NFCONF_TIMING(MINI2440_TACLS, MINI2440_TWRPH0, MINI2440_TWRPH1) #endif /* diff --git a/arch/arm/boards/mini2440/mini2440.c b/arch/arm/boards/mini2440/mini2440.c index 56e2668540..b4cc0f89e8 100644 --- a/arch/arm/boards/mini2440/mini2440.c +++ b/arch/arm/boards/mini2440/mini2440.c @@ -45,7 +45,8 @@ #include <mach/fb.h> static struct s3c24x0_nand_platform_data nand_info = { - .nand_timing = CALC_NFCONF_TIMING(A9M2440_TACLS, A9M2440_TWRPH0, A9M2440_TWRPH1), + .nand_timing = CALC_NFCONF_TIMING(MINI2440_TACLS, MINI2440_TWRPH0, + MINI2440_TWRPH1), .flash_bbt = 1, /* same as the kernel */ }; diff --git a/arch/arm/configs/pcm043_defconfig b/arch/arm/configs/pcm043_defconfig index 3bf21c8660..3c728ed3fc 100644 --- a/arch/arm/configs/pcm043_defconfig +++ b/arch/arm/configs/pcm043_defconfig @@ -1,5 +1,6 @@ CONFIG_ARCH_IMX=y CONFIG_CACHE_L2X0=y +CONFIG_ARCH_IMX_EXTERNAL_BOOT=y CONFIG_ARCH_IMX35=y CONFIG_MACH_PCM043=y CONFIG_IMX_CLKO=y diff --git a/arch/arm/mach-imx/nand.c b/arch/arm/mach-imx/nand.c index fcbb85ef68..27b72a0d80 100644 --- a/arch/arm/mach-imx/nand.c +++ b/arch/arm/mach-imx/nand.c @@ -95,7 +95,7 @@ void imx_nand_set_layout(int writesize, int datawidth) FMCR = fmcr; } -#elif defined CONFIG_ARCH_IMX51 +#elif defined CONFIG_ARCH_IMX51 || defined CONFIG_ARCH_IMX53 void imx_nand_set_layout(int writesize, int datawidth) { diff --git a/arch/nios2/include/asm/unaligned.h b/arch/nios2/include/asm/unaligned.h new file mode 100644 index 0000000000..7615e8a85d --- /dev/null +++ b/arch/nios2/include/asm/unaligned.h @@ -0,0 +1,15 @@ +#ifndef _ASM_NIOS_UNALIGNED_H +#define _ASM_NIOS_UNALIGNED_H + +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/be_byteshift.h> +#include <linux/unaligned/generic.h> + +/* + * Select endianness + */ + +#define get_unaligned __get_unaligned_le +#define put_unaligned __put_unaligned_le + +#endif /* _ASM_NIOS_UNALIGNED_H */ diff --git a/arch/x86/boot/pmjump.S b/arch/x86/boot/pmjump.S index d2fb8f0ebc..09bfc6ea86 100644 --- a/arch/x86/boot/pmjump.S +++ b/arch/x86/boot/pmjump.S @@ -44,6 +44,7 @@ protected_mode_jump: /* Transition to 32-bit flat mode */ data32 ljmp $__BOOT_CS, $in_pm32 + .size protected_mode_jump, .-protected_mode_jump /* ------------------------------------------------------------------------ */ @@ -83,5 +84,5 @@ in_pm32: jmp uboot_entry - .size protected_mode_jump, .-protected_mode_jump + .size in_pm32, .-in_pm32 diff --git a/arch/x86/include/asm/types.h b/arch/x86/include/asm/types.h index 17c5fd7b9c..d5208699a9 100644 --- a/arch/x86/include/asm/types.h +++ b/arch/x86/include/asm/types.h @@ -39,6 +39,8 @@ typedef unsigned short u16; typedef unsigned int u32; +typedef unsigned long long u64; + #endif /* __ASSEMBLY__ */ #endif /* __ASM_X86_TYPES_H */ diff --git a/arch/x86/include/asm/unaligned.h b/arch/x86/include/asm/unaligned.h new file mode 100644 index 0000000000..a7bd416b47 --- /dev/null +++ b/arch/x86/include/asm/unaligned.h @@ -0,0 +1,14 @@ +#ifndef _ASM_X86_UNALIGNED_H +#define _ASM_X86_UNALIGNED_H + +/* + * The x86 can do unaligned accesses itself. + */ + +#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/generic.h> + +#define get_unaligned __get_unaligned_le +#define put_unaligned __put_unaligned_le + +#endif /* _ASM_X86_UNALIGNED_H */ diff --git a/arch/x86/lib/traveler.S b/arch/x86/lib/traveler.S index 06141955fd..4f7a9e399a 100644 --- a/arch/x86/lib/traveler.S +++ b/arch/x86/lib/traveler.S @@ -72,6 +72,7 @@ real_to_prot: /* jump to relocation, flush prefetch queue, and reload %cs */ DATA32 ljmp $__BOOT_CS, $return_to_flatmode + .size real_to_prot, .-real_to_prot /* ----------------------------------------------------------------------- */ .section .boot.text.return_to_flatmode, "ax" @@ -102,8 +103,7 @@ return_to_flatmode: /* flag we returned happy here */ xorl %eax, %eax ret - - .size real_to_prot, .-real_to_prot + .size return_to_flatmode, .-return_to_flatmode /* ------------------------------------------------------------------------ */ @@ -140,13 +140,16 @@ prot_to_real: /* at last, also limit the code segment to 16 bit */ ljmp $__REAL_CS, $return_to_realmode + .size prot_to_real, .-prot_to_real /* ----------------------------------------------------------------------- */ .section .boot.text.return_to_realmode, "ax" -return_to_realmode: + .globl return_to_realmode + .type return_to_realmode, @function .code16 +return_to_realmode: /* disable protected mode */ movl %cr0, %eax andl $(~0x00000001), %eax @@ -176,5 +179,5 @@ enter_realmode: /* return on realmode stack! */ DATA32 ret - .size prot_to_real, .-prot_to_real + .size return_to_realmode, .-return_to_realmode diff --git a/commands/mkdir.c b/commands/mkdir.c index b66795b6e2..45e7408cb6 100644 --- a/commands/mkdir.c +++ b/commands/mkdir.c @@ -45,10 +45,13 @@ static int do_mkdir(struct command *cmdtp, int argc, char *argv[]) return COMMAND_ERROR_USAGE; while (optind < argc) { - if (parent) + if (parent) { ret = make_directory(argv[optind]); - else + if (ret == -EEXIST) + ret = 0; + } else { ret = mkdir(argv[optind], 0); + } if (ret) { printf("could not create %s: %s\n", argv[optind], errno_str()); return 1; diff --git a/commands/mount.c b/commands/mount.c index 52d1700a78..7cefdbea24 100644 --- a/commands/mount.c +++ b/commands/mount.c @@ -40,7 +40,7 @@ static int do_mount(struct command *cmdtp, int argc, char *argv[]) entry = mtab_next_entry(entry); if (entry) { printf("%s on %s type %s\n", - entry->parent_device ? entry->parent_device->name : "none", + entry->parent_device ? dev_name(entry->parent_device) : "none", entry->path, entry->dev->name); } diff --git a/common/console.c b/common/console.c index 06e9c29e8c..944dd07197 100644 --- a/common/console.c +++ b/common/console.c @@ -292,27 +292,32 @@ int fputc(int fd, char c) } EXPORT_SYMBOL(fputc); -void console_puts(unsigned int ch, const char *str) +int console_puts(unsigned int ch, const char *str) { const char *s = str; + int n = 0; + while (*s) { - if (*s == '\n') + if (*s == '\n') { console_putc(ch, '\r'); + n++; + } console_putc(ch, *s); + n++; s++; } + return n; } EXPORT_SYMBOL(console_puts); int fputs(int fd, const char *s) { if (fd == 1) - puts(s); + return puts(s); else if (fd == 2) - eputs(s); + return eputs(s); else return write(fd, s, strlen(s)); - return 0; } EXPORT_SYMBOL(fputs); @@ -327,7 +332,7 @@ void console_flush(void) } EXPORT_SYMBOL(console_flush); -void fprintf (int file, const char *fmt, ...) +int fprintf(int file, const char *fmt, ...) { va_list args; uint i; @@ -342,7 +347,7 @@ void fprintf (int file, const char *fmt, ...) va_end (args); /* Print the string */ - fputs (file, printbuffer); + return fputs(file, printbuffer); } EXPORT_SYMBOL(fprintf); diff --git a/common/env.c b/common/env.c index defb26b3b7..05ed71418e 100644 --- a/common/env.c +++ b/common/env.c @@ -247,8 +247,7 @@ int export(const char *varname) if (val) { setenv_raw(context->global, varname, val); setenv_raw(context->local, varname, NULL); - return 0; } - return -1; + return 0; } EXPORT_SYMBOL(export); diff --git a/common/password.c b/common/password.c index ece7704786..311f9cb8a7 100644 --- a/common/password.c +++ b/common/password.c @@ -42,13 +42,12 @@ int password(unsigned char *passwd, size_t length, int flags, int timeout) unsigned char *buf = passwd; int pos = 0; unsigned char ch; - uint64_t start, second; + uint64_t start; if (!passwd) return -EINVAL; start = get_time_ns(); - second = start; do { if (tstc()) { diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c index e6fe75e9bf..92b07af7f7 100644 --- a/drivers/nor/m25p80.c +++ b/drivers/nor/m25p80.c @@ -778,10 +778,12 @@ static int m25p_probe(struct device_d *dev) m25p80_ops.write = m25p80_write; /* prefer "small sector" erase if possible */ - if (info->flags & SECT_4K) + if (info->flags & SECT_4K) { flash->erase_opcode = OPCODE_BE_4K; - else + flash->erasesize = 4096; + } else { flash->erase_opcode = OPCODE_SE; + } flash->page_size = info->page_size; diff --git a/drivers/serial/serial_s3c24x0.c b/drivers/serial/serial_s3c24x0.c index 3a703b6fe8..abc08e0e41 100644 --- a/drivers/serial/serial_s3c24x0.c +++ b/drivers/serial/serial_s3c24x0.c @@ -72,6 +72,8 @@ static int s3c24x0_serial_init_port(struct console_device *cdev) writew(0x0245, base + UCON); #ifdef CONFIG_DRIVER_SERIAL_S3C24X0_AUTOSYNC + writeb(0x10, base + UMCON); /* enable auto flow control */ +#else writeb(0x01, base + UMCON); /* RTS up */ #endif diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c index faa03b1c9e..47e6756731 100644 --- a/drivers/spi/atmel_spi.c +++ b/drivers/spi/atmel_spi.c @@ -190,6 +190,7 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *mesg) struct spi_transfer *t = NULL; unsigned int bits = spi->bits_per_word; + mesg->actual_length = 0; ret = master->setup(spi); if (ret < 0) { dev_dbg(master->dev, "transfer: master setup failed\n"); @@ -210,6 +211,7 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *mesg) u32 tx_val; int i = 0, rx_val; + mesg->actual_length += t->len; if (bits <= 8) { const u8 *txbuf = t->tx_buf; u8 *rxbuf = t->rx_buf; diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 929eb89a3a..96e09e28a0 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -7,3 +7,7 @@ config USB_EHCI_OMAP config USB_OHCI bool "OHCI driver" + +config USB_OHCI_AT91 + depends on ARCH_AT91 + bool "AT91 OHCI driver" diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 1c7e18f75f..00f5e24943 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -1,4 +1,4 @@ obj-$(CONFIG_USB_EHCI) += ehci-hcd.o obj-$(CONFIG_USB_EHCI_OMAP) += ehci-omap.o obj-$(CONFIG_USB_OHCI) += ohci-hcd.o -obj-$(CONFIG_ARCH_AT91) += ohci-at91.o +obj-$(CONFIG_USB_OHCI_AT91) += ohci-at91.o diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 72f1c14359..81e3a42539 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -714,7 +714,7 @@ ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer, goto unknown; } /* unblock posted writes */ - ehci_readl(&ehci->hcor->or_usbcmd); + (void) ehci_readl(&ehci->hcor->or_usbcmd); break; case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): reg = ehci_readl(status_reg); @@ -743,7 +743,7 @@ ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer, } ehci_writel(status_reg, reg); /* unblock posted write */ - ehci_readl(&ehci->hcor->or_usbcmd); + (void) ehci_readl(&ehci->hcor->or_usbcmd); break; default: debug("Unknown request\n"); diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 4219801bde..8420f3a097 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -354,6 +354,8 @@ static int fat_stat(struct device_d *dev, const char *filename, struct stat *s) FILINFO finfo; int ret; + memset(&finfo, 0, sizeof(FILINFO)); + ret = f_stat(&priv->fat, filename, &finfo); if (ret) return ret; @@ -743,6 +743,7 @@ int mount(const char *device, const char *fsname, const char *_path) struct mtab_entry *entry; struct fs_device_d *fsdev; struct device_d *dev, *parent_device = NULL; + struct cdev *cdev = NULL; int ret; char *path = normalise_path(_path); @@ -808,6 +809,12 @@ int mount(const char *device, const char *fsname, const char *_path) goto out2; } + if (!strncmp(device, "/dev/", 5)) { + cdev = cdev_by_name(device + 5); + if(cdev) + parent_device = cdev->dev; + } + if (parent_device) dev_add_child(parent_device, &fsdev->dev); diff --git a/include/stdio.h b/include/stdio.h index a0d81d3b74..4901bc7182 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -17,12 +17,12 @@ int tstc(void); /* stdout */ void console_putc(unsigned int ch, const char c); int getc(void); -void console_puts(unsigned int ch, const char *s); +int console_puts(unsigned int ch, const char *s); void console_flush(void); -static inline void puts(const char *s) +static inline int puts(const char *s) { - console_puts(CONSOLE_STDOUT, s); + return console_puts(CONSOLE_STDOUT, s); } static inline void putchar(char c) @@ -54,7 +54,7 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); #define stderr 2 #define MAX_FILES 128 -void fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); +int fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); int fputs(int file, const char *s); int fputc(int file, const char c); int ftstc(int file); diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c index fc5c49f455..0ae3d4d049 100644 --- a/lib/decompress_unlzo.c +++ b/lib/decompress_unlzo.c @@ -46,14 +46,25 @@ static const unsigned char lzop_magic[] = { #define LZO_BLOCK_SIZE (256*1024l) #define HEADER_HAS_FILTER 0x00000800L +#define HEADER_SIZE_MIN (9 + 7 + 4 + 8 + 1 + 4) +#define HEADER_SIZE_MAX (9 + 7 + 1 + 8 + 8 + 4 + 1 + 255 + 4) -static inline int parse_header(u8 *input, u8 *skip) +static inline int parse_header(u8 *input, int *skip, int in_len) { int l; u8 *parse = input; + u8 *end = input + in_len; u8 level = 0; u16 version; + /* + * Check that there's enough input to possibly have a valid header. + * Then it is possible to parse several fields until the minimum + * size may have been used. + */ + if (in_len < HEADER_SIZE_MIN) + return 0; + /* read magic: 9 first bits */ for (l = 0; l < 9; l++) { if (*parse++ != lzop_magic[l]) @@ -71,6 +82,15 @@ static inline int parse_header(u8 *input, u8 *skip) else parse += 4; /* flags */ + /* + * At least mode, mtime_low, filename length, and checksum must + * be left to be parsed. If also mtime_high is present, it's OK + * because the next input buffer check is after reading the + * filename length. + */ + if (end - parse < 8 + 1 + 4) + return 0; + /* skip mode and mtime_low */ parse += 8; if (version >= 0x0940) @@ -78,108 +98,191 @@ static inline int parse_header(u8 *input, u8 *skip) l = *parse++; /* don't care about the file name, and skip checksum */ + if (end - parse < l + 4) + return 0; parse += l + 4; *skip = parse - input; return 1; } -static int __unlzo(int *dest_len, - int (*fill) (void *, unsigned int), - int (*flush) (void *, unsigned int)) +static inline int __unlzo(u8 *input, int in_len, + int (*fill) (void *, unsigned int), + int (*flush) (void *, unsigned int), + u8 *output, int *posp, + void (*error) (char *x)) { - u8 skip = 0, r = 0; + u8 r = 0; + int skip = 0; u32 src_len, dst_len; size_t tmp; - u8 *in_buf, *in_buf_save, *out_buf, *out_buf_save; - int obytes_processed = 0; + u8 *in_buf, *in_buf_save, *out_buf; int ret = -1; - out_buf = xmalloc(LZO_BLOCK_SIZE); - in_buf = xmalloc(lzo1x_worst_compress(LZO_BLOCK_SIZE)); + if (output) { + out_buf = output; + } else if (!flush) { + error("NULL output pointer and no flush function provided"); + goto exit; + } else { + out_buf = malloc(LZO_BLOCK_SIZE); + if (!out_buf) { + error("Could not allocate output buffer"); + goto exit; + } + } + if (input && fill) { + error("Both input pointer and fill function provided, don't know what to do"); + goto exit_1; + } else if (input) { + in_buf = input; + } else if (!fill) { + error("NULL input pointer and missing fill function"); + goto exit_1; + } else { + in_buf = malloc(lzo1x_worst_compress(LZO_BLOCK_SIZE)); + if (!in_buf) { + error("Could not allocate input buffer"); + goto exit_1; + } + } in_buf_save = in_buf; - out_buf_save = out_buf; - ret = fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE)); - if (ret < 0) - goto exit_free; - - if (!parse_header(in_buf, &skip)) - return -EINVAL; + if (posp) + *posp = 0; + + if (fill) { + /* + * Start from in_buf + HEADER_SIZE_MAX to make it possible + * to use memcpy() to copy the unused data to the beginning + * of the buffer. This way memmove() isn't needed which + * is missing from pre-boot environments of most archs. + */ + in_buf += HEADER_SIZE_MAX; + in_len = fill(in_buf, HEADER_SIZE_MAX); + } + if (!parse_header(in_buf, &skip, in_len)) { + error("invalid header"); + goto exit_2; + } in_buf += skip; + in_len -= skip; + + if (fill) { + /* Move the unused data to the beginning of the buffer. */ + memcpy(in_buf_save, in_buf, in_len); + in_buf = in_buf_save; + } + + if (posp) + *posp = skip; for (;;) { /* read uncompressed block size */ + if (fill && in_len < 4) { + skip = fill(in_buf + in_len, 4 - in_len); + if (skip > 0) + in_len += skip; + } + if (in_len < 4) { + error("file corrupted"); + goto exit_2; + } dst_len = get_unaligned_be32(in_buf); in_buf += 4; + in_len -= 4; /* exit if last block */ - if (dst_len == 0) + if (dst_len == 0) { + if (posp) + *posp += 4; break; + } if (dst_len > LZO_BLOCK_SIZE) { - printf("dest len longer than block size"); - goto exit_free; + error("dest len longer than block size"); + goto exit_2; } /* read compressed block size, and skip block checksum info */ + if (fill && in_len < 8) { + skip = fill(in_buf + in_len, 8 - in_len); + if (skip > 0) + in_len += skip; + } + if (in_len < 8) { + error("file corrupted"); + goto exit_2; + } src_len = get_unaligned_be32(in_buf); in_buf += 8; + in_len -= 8; if (src_len <= 0 || src_len > dst_len) { - printf("file corrupted"); - goto exit_free; + error("file corrupted"); + goto exit_2; } /* decompress */ + if (fill && in_len < src_len) { + skip = fill(in_buf + in_len, src_len - in_len); + if (skip > 0) + in_len += skip; + } + if (in_len < src_len) { + error("file corrupted"); + goto exit_2; + } tmp = dst_len; /* When the input data is not compressed at all, * lzo1x_decompress_safe will fail, so call memcpy() * instead */ - if (unlikely(dst_len == src_len)) { - if (src_len != dst_len) { - printf("Compressed data violation"); - goto exit_free; - } - out_buf = in_buf; - } else { + if (unlikely(dst_len == src_len)) + memcpy(out_buf, in_buf, src_len); + else { r = lzo1x_decompress_safe((u8 *) in_buf, src_len, out_buf, &tmp); if (r != LZO_E_OK || dst_len != tmp) { - printf("Compressed data violation"); - goto exit_free; + error("Compressed data violation"); + goto exit_2; } } - ret = flush(out_buf, dst_len); - if (ret < 0) - goto exit_free; - - out_buf = in_buf + src_len; - in_buf = in_buf_save; - ret = fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE)); - if (ret < 0) - goto exit_free; - - if (ret == 0) - in_buf = out_buf; - - out_buf = out_buf_save; - - obytes_processed += dst_len; - + if (flush && flush(out_buf, dst_len) != dst_len) + goto exit_2; + if (output) + out_buf += dst_len; + if (posp) + *posp += src_len + 12; + + in_buf += src_len; + in_len -= src_len; + if (fill) { + /* + * If there happens to still be unused data left in + * in_buf, move it to the beginning of the buffer. + * Use a loop to avoid memmove() dependency. + */ + if (in_len > 0) + for (skip = 0; skip < in_len; ++skip) + in_buf_save[skip] = in_buf[skip]; + in_buf = in_buf_save; + } } -exit_free: - free(in_buf); - free(out_buf); - - *dest_len = obytes_processed; - return 0; + ret = 0; +exit_2: + if (!input) + free(in_buf_save); +exit_1: + if (!output) + free(out_buf); +exit: + return ret; } static int in_fd; @@ -195,9 +298,14 @@ static int unlzo_flush(void *buf, unsigned int len) return write(out_fd, buf, len); } +static void unlzo_error(char *s) +{ + printf("%s\n", s); +} + int unlzo(int _in_fd, int _out_fd, int *dest_len) { in_fd = _in_fd; out_fd = _out_fd; - return __unlzo(dest_len, unlzo_fill, unlzo_flush); + return __unlzo(NULL, 0, unlzo_fill, unlzo_flush, NULL, NULL, unlzo_error); } diff --git a/lib/readkey.c b/lib/readkey.c index a42d1cb8ff..1117c30ac2 100644 --- a/lib/readkey.c +++ b/lib/readkey.c @@ -67,6 +67,8 @@ int read_key(void) esc[i] = getc(); if (esc[i++] == '~') break; + if (i == ARRAY_SIZE(esc)) + return -1; } } esc[i] = 0; diff --git a/scripts/setupmbr/.gitignore b/scripts/setupmbr/.gitignore new file mode 100644 index 0000000000..a7301f9111 --- /dev/null +++ b/scripts/setupmbr/.gitignore @@ -0,0 +1 @@ +setupmbr |