]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
Merge branch 'master' of git://git.denx.de/u-boot-arm
authorTom Rini <trini@ti.com>
Sat, 7 Sep 2013 00:25:35 +0000 (20:25 -0400)
committerTom Rini <trini@ti.com>
Sat, 7 Sep 2013 00:25:35 +0000 (20:25 -0400)
30 files changed:
Makefile
README
arch/nios2/lib/longlong.h
board/ait/cam_enc_4xx/config.mk
common/cmd_bootm.c
common/cmd_ximg.c
config.mk
doc/git-mailrc
drivers/block/ahci.c
examples/standalone/Makefile
fs/fat/fat_write.c
include/ahci.h
include/configs/MPC8544DS.h
include/configs/MPC8572DS.h
include/configs/MPC8610HPCD.h
include/configs/MPC8641HPCN.h
include/configs/P2020DS.h
include/configs/am335x_evm.h
include/configs/cam_enc_4xx.h
include/configs/coreboot.h
include/configs/highbank.h
include/configs/sandbox.h
include/linux/compiler-gcc.h
include/linux/compiler-gcc4.h
lib/gunzip.c
lib/lzma/LzmaTools.c
lib/lzo/lzo1x_decompress.c
test/Makefile
test/compression.c [new file with mode: 0644]
tools/env/fw_env.c

index ed48279acd130613dc2a684ece2265a42b999f84..8aa80399afa0e084cb98e42eb3e615651881e013 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -398,6 +398,7 @@ ALL-y += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map
 ALL-$(CONFIG_NAND_U_BOOT) += $(obj)u-boot-nand.bin
 ALL-$(CONFIG_ONENAND_U_BOOT) += $(obj)u-boot-onenand.bin
 ALL-$(CONFIG_SPL) += $(obj)spl/u-boot-spl.bin
+ALL-$(CONFIG_SPL_FRAMEWORK) += $(obj)u-boot.img
 ALL-$(CONFIG_TPL) += $(obj)tpl/u-boot-tpl.bin
 ALL-$(CONFIG_OF_SEPARATE) += $(obj)u-boot.dtb $(obj)u-boot-dtb.bin
 ifneq ($(CONFIG_SPL_TARGET),)
diff --git a/README b/README
index 677c3dc252174f62dacc13bb93ab4aad702e63a6..63706be81db2d11c7713af5e458c2c037a9992d5 100644 (file)
--- a/README
+++ b/README
@@ -1680,6 +1680,10 @@ CBFS (Coreboot Filesystem) support
                to compress the specified memory at its best effort.
 
 - Compression support:
+               CONFIG_GZIP
+
+               Enabled by default to support gzip compressed images.
+
                CONFIG_BZIP2
 
                If this option is set, support for bzip2 compressed
@@ -1713,6 +1717,11 @@ CBFS (Coreboot Filesystem) support
                then calculate the amount of needed dynamic memory (ensuring
                the appropriate CONFIG_SYS_MALLOC_LEN value).
 
+               CONFIG_LZO
+
+               If this option is set, support for LZO compressed images
+               is included.
+
 - MII/PHY support:
                CONFIG_PHY_ADDR
 
index 63c64ed74d5dafd97e1eb6e54e40fdd2cc7efa76..45ec5f0f193937e3c17bd7a8342bc9cc38fa1b75 100644 (file)
@@ -3,6 +3,7 @@
    2005  Free Software Foundation, Inc.
 
  * SPDX-License-Identifier:    GPL-2.0+
+ */
 
 /* You have to define the following before including this file:
 
index c280029a36fee47c35aaa02f559457b746c1956e..d7e7894831d090d2f78de734c1f4a7c4eb1041e1 100644 (file)
@@ -7,8 +7,6 @@
 # (mem base + reserved)
 #
 
-#Provide at least 16MB spacing between us and the Linux Kernel image
-CONFIG_SPL_PAD_TO := 12320
 UBL_CONFIG = $(SRCTREE)/board/$(BOARDDIR)/ublimage.cfg
 ifndef CONFIG_SPL_BUILD
 ALL-y += $(obj)u-boot.ubl
index 1685c14a5261eba30d21ea29c9eb87a65fbe50e5..b07b0f48b20a9053ecef1d0cf9a3282fba17bd17 100644 (file)
@@ -368,7 +368,7 @@ static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
 
        const char *type_name = genimg_get_type_name(os.type);
 
-       load_buf = map_sysmem(load, image_len);
+       load_buf = map_sysmem(load, unc_len);
        image_buf = map_sysmem(image_start, image_len);
        switch (comp) {
        case IH_COMP_NONE:
@@ -436,11 +436,12 @@ static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
        }
 #endif /* CONFIG_LZMA */
 #ifdef CONFIG_LZO
-       case IH_COMP_LZO:
+       case IH_COMP_LZO: {
+               size_t size;
+
                printf("   Uncompressing %s ... ", type_name);
 
-               ret = lzop_decompress(image_buf, image_len, load_buf,
-                                     &unc_len);
+               ret = lzop_decompress(image_buf, image_len, load_buf, &size);
                if (ret != LZO_E_OK) {
                        printf("LZO: uncompress or overwrite error %d "
                              "- must RESET board to recover\n", ret);
@@ -449,8 +450,9 @@ static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
                        return BOOTM_ERR_RESET;
                }
 
-               *load_end = load + unc_len;
+               *load_end = load + size;
                break;
+       }
 #endif /* CONFIG_LZO */
        default:
                printf("Unimplemented compression type %d\n", comp);
index b439be3d088526eb48c0fb9c95cd6f805203728f..65a8319662f13a18450f9c03a77b885590ee45ff 100644 (file)
@@ -20,6 +20,7 @@
 #include <bzlib.h>
 #endif
 #include <asm/byteorder.h>
+#include <asm/io.h>
 
 #ifndef CONFIG_SYS_XIMG_LEN
 /* use 8MByte as default max gunzip size */
@@ -34,7 +35,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
        ulong           data, len, count;
        int             verify;
        int             part = 0;
-       image_header_t  *hdr;
+       image_header_t  *hdr = NULL;
 #if defined(CONFIG_FIT)
        const char      *uname = NULL;
        const void*     fit_hdr;
@@ -222,7 +223,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
                                 * which requires at most 2300 KB of memory.
                                 */
                                i = BZ2_bzBuffToBuffDecompress(
-                                       (char *)ntohl(hdr->ih_load),
+                                       map_sysmem(ntohl(hdr->ih_load), 0),
                                        &unc_len, (char *)data, len,
                                        CONFIG_SYS_MALLOC_LEN < (4096 * 1024),
                                        0);
index 39b20baf0857755ce86a4f96c44ff2165f1a1978..48913f6659f101e9009d54b5886bab44f0fafccd 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -241,22 +241,6 @@ ifneq ($(CONFIG_SYS_TEXT_BASE),)
 CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
 endif
 
-ifneq ($(CONFIG_SPL_TEXT_BASE),)
-CPPFLAGS += -DCONFIG_SPL_TEXT_BASE=$(CONFIG_SPL_TEXT_BASE)
-endif
-
-ifneq ($(CONFIG_SPL_PAD_TO),)
-CPPFLAGS += -DCONFIG_SPL_PAD_TO=$(CONFIG_SPL_PAD_TO)
-endif
-
-ifneq ($(CONFIG_TPL_PAD_TO),)
-CPPFLAGS += -DCONFIG_TPL_PAD_TO=$(CONFIG_TPL_PAD_TO)
-endif
-
-ifneq ($(CONFIG_UBOOT_PAD_TO),)
-CPPFLAGS += -DCONFIG_UBOOT_PAD_TO=$(CONFIG_UBOOT_PAD_TO)
-endif
-
 ifeq ($(CONFIG_SPL_BUILD),y)
 CPPFLAGS += -DCONFIG_SPL_BUILD
 ifeq ($(CONFIG_TPL_BUILD),y)
@@ -272,10 +256,6 @@ Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
 endif
 endif
 
-ifneq ($(RESET_VECTOR_ADDRESS),)
-CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
-endif
-
 ifneq ($(OBJTREE),$(SRCTREE))
 CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
 endif
index e3a47c46f34c545e5bfe3856b2ffb6334501527e..2cacaa034145fe8f0311c641a78a548dba0e4584 100644 (file)
@@ -22,8 +22,9 @@ alias jasonjin       Jason Jin <jason.jin@freescale.com>
 alias jhersh         Joe Hershberger <joe.hershberger@gmail.com>
 alias kimphill       Kim Phillips <kim.phillips@freescale.com>
 alias macpaul        Macpaul Lin <macpaul@andestech.com>
-alias marex          Marek Vasut <marek.vasut@gmail.com>
+alias marex          Marek Vasut <marex@denx.de>
 alias monstr         Michal Simek <monstr@monstr.eu>
+alias panto          Pantelis Antoniou <panto@antoniou-consulting.com>
 alias prafulla       Prafulla Wadaskar <prafulla@marvell.com>
 alias prom           Minkyu Kang <mk7.kang@samsung.com>
 alias rbohmer        Remy Bohmer <linux@bohmer.net>
@@ -102,7 +103,7 @@ alias cfi            uboot, stroese
 alias kerneldoc      uboot, marex
 alias fdt            uboot, Jerry Van Baren <vanbaren@cideas.com>
 alias i2c            uboot, hs
-alias mmc            uboot, afleming
+alias mmc            uboot, panto
 alias nand           uboot, scottwood
 alias net            uboot, jhersh
 alias usb            uboot, marex
index e455ba5fb6507f1b1f435804fdf84836a27e8096..8cc9379b82c406ff4245a800c26520c2f79bff64 100644 (file)
 #include <asm/io.h>
 #include <malloc.h>
 #include <scsi.h>
-#include <ata.h>
+#include <libata.h>
 #include <linux/ctype.h>
 #include <ahci.h>
 
 static int ata_io_flush(u8 port);
 
 struct ahci_probe_ent *probe_ent = NULL;
-hd_driveid_t *ataid[AHCI_MAX_PORTS];
+u16 *ataid[AHCI_MAX_PORTS];
 
 #define writel_with_flush(a,b) do { writel(a,b); readl(b); } while (0)
 
@@ -38,7 +38,7 @@ hd_driveid_t *ataid[AHCI_MAX_PORTS];
 #endif
 
 /* Maximum timeouts for each event */
-#define WAIT_MS_SPINUP 10000
+#define WAIT_MS_SPINUP 20000
 #define WAIT_MS_DATAIO 5000
 #define WAIT_MS_FLUSH  5000
 #define WAIT_MS_LINKUP 4
@@ -107,6 +107,27 @@ static int waiting_for_cmd_completed(volatile u8 *offset,
        return (i < timeout_msec) ? 0 : -1;
 }
 
+int __weak ahci_link_up(struct ahci_probe_ent *probe_ent, u8 port)
+{
+       u32 tmp;
+       int j = 0;
+       u8 *port_mmio = (u8 *)probe_ent->port[port].port_mmio;
+
+       /* 
+        * Bring up SATA link.
+        * SATA link bringup time is usually less than 1 ms; only very
+        * rarely has it taken between 1-2 ms. Never seen it above 2 ms.
+        */
+       while (j < WAIT_MS_LINKUP) {
+               tmp = readl(port_mmio + PORT_SCR_STAT);
+               tmp &= PORT_SCR_STAT_DET_MASK;
+               if (tmp == PORT_SCR_STAT_DET_PHYRDY)
+                       return 0;
+               udelay(1000);
+               j++;
+       }
+       return 1;
+}
 
 static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 {
@@ -117,8 +138,9 @@ static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 #endif
        volatile u8 *mmio = (volatile u8 *)probe_ent->mmio_base;
        u32 tmp, cap_save, cmd;
-       int i, j;
+       int i, j, ret;
        volatile u8 *port_mmio;
+       u32 port_map;
 
        debug("ahci_host_init: start\n");
 
@@ -160,6 +182,7 @@ static int ahci_host_init(struct ahci_probe_ent *probe_ent)
 #endif
        probe_ent->cap = readl(mmio + HOST_CAP);
        probe_ent->port_map = readl(mmio + HOST_PORTS_IMPL);
+       port_map = probe_ent->port_map;
        probe_ent->n_ports = (probe_ent->cap & 0x1f) + 1;
 
        debug("cap 0x%x  port_map 0x%x  n_ports %d\n",
@@ -169,6 +192,8 @@ static int ahci_host_init(struct ahci_probe_ent *probe_ent)
                probe_ent->n_ports = CONFIG_SYS_SCSI_MAX_SCSI_ID;
 
        for (i = 0; i < probe_ent->n_ports; i++) {
+               if (!(port_map & (1 << i)))
+                       continue;
                probe_ent->port[i].port_mmio = ahci_port_base((u32) mmio, i);
                port_mmio = (u8 *) probe_ent->port[i].port_mmio;
                ahci_setup_port(&probe_ent->port[i], (unsigned long)mmio, i);
@@ -196,19 +221,9 @@ static int ahci_host_init(struct ahci_probe_ent *probe_ent)
                cmd |= PORT_CMD_SPIN_UP;
                writel_with_flush(cmd, port_mmio + PORT_CMD);
 
-               /* Bring up SATA link.
-                * SATA link bringup time is usually less than 1 ms; only very
-                * rarely has it taken between 1-2 ms. Never seen it above 2 ms.
-                */
-               j = 0;
-               while (j < WAIT_MS_LINKUP) {
-                       tmp = readl(port_mmio + PORT_SCR_STAT);
-                       if ((tmp & 0xf) == 0x3)
-                               break;
-                       udelay(1000);
-                       j++;
-               }
-               if (j == WAIT_MS_LINKUP) {
+               /* Bring up SATA link. */
+               ret = ahci_link_up(probe_ent, i);
+               if (ret) {
                        printf("SATA link %d timeout.\n", i);
                        continue;
                } else {
@@ -225,11 +240,23 @@ static int ahci_host_init(struct ahci_probe_ent *probe_ent)
                j = 0;
                while (j < WAIT_MS_SPINUP) {
                        tmp = readl(port_mmio + PORT_TFDATA);
-                       if (!(tmp & (ATA_STAT_BUSY | ATA_STAT_DRQ)))
+                       if (!(tmp & (ATA_BUSY | ATA_DRQ)))
                                break;
                        udelay(1000);
+                       tmp = readl(port_mmio + PORT_SCR_STAT);
+                       tmp &= PORT_SCR_STAT_DET_MASK;
+                       if (tmp == PORT_SCR_STAT_DET_PHYRDY)
+                               break;
                        j++;
                }
+
+               tmp = readl(port_mmio + PORT_SCR_STAT) & PORT_SCR_STAT_DET_MASK;
+               if (tmp == PORT_SCR_STAT_DET_COMINIT) {
+                       debug("SATA link %d down (COMINIT received), retrying...\n", i);
+                       i--;
+                       continue;
+               }
+
                printf("Target spinup took %d ms.\n", j);
                if (j == WAIT_MS_SPINUP)
                        debug("timeout.\n");
@@ -254,7 +281,7 @@ static int ahci_host_init(struct ahci_probe_ent *probe_ent)
                /* register linkup ports */
                tmp = readl(port_mmio + PORT_SCR_STAT);
                debug("SATA port %d status: 0x%x\n", i, tmp);
-               if ((tmp & 0xf) == 0x03)
+               if ((tmp & PORT_SCR_STAT_DET_MASK) == PORT_SCR_STAT_DET_PHYRDY)
                        probe_ent->link_port_map |= (0x01 << i);
        }
 
@@ -351,8 +378,6 @@ static int ahci_init_one(pci_dev_t pdev)
        u16 vendor;
        int rc;
 
-       memset((void *)ataid, 0, sizeof(hd_driveid_t *) * AHCI_MAX_PORTS);
-
        probe_ent = malloc(sizeof(struct ahci_probe_ent));
        memset(probe_ent, 0, sizeof(struct ahci_probe_ent));
        probe_ent->dev = pdev;
@@ -442,7 +467,7 @@ static void ahci_set_feature(u8 port)
        memset(fis, 0, sizeof(fis));
        fis[0] = 0x27;
        fis[1] = 1 << 7;
-       fis[2] = ATA_CMD_SETF;
+       fis[2] = ATA_CMD_SET_FEATURES;
        fis[3] = SETFEATURES_XFER;
        fis[12] = __ilog2(probe_ent->udma_mask + 1) + 0x40 - 0x01;
 
@@ -580,33 +605,12 @@ static char *ata_id_strcpy(u16 *target, u16 *src, int len)
        return (char *)target;
 }
 
-
-static void dump_ataid(hd_driveid_t *ataid)
-{
-       debug("(49)ataid->capability = 0x%x\n", ataid->capability);
-       debug("(53)ataid->field_valid =0x%x\n", ataid->field_valid);
-       debug("(63)ataid->dma_mword = 0x%x\n", ataid->dma_mword);
-       debug("(64)ataid->eide_pio_modes = 0x%x\n", ataid->eide_pio_modes);
-       debug("(75)ataid->queue_depth = 0x%x\n", ataid->queue_depth);
-       debug("(80)ataid->major_rev_num = 0x%x\n", ataid->major_rev_num);
-       debug("(81)ataid->minor_rev_num = 0x%x\n", ataid->minor_rev_num);
-       debug("(82)ataid->command_set_1 = 0x%x\n", ataid->command_set_1);
-       debug("(83)ataid->command_set_2 = 0x%x\n", ataid->command_set_2);
-       debug("(84)ataid->cfsse = 0x%x\n", ataid->cfsse);
-       debug("(85)ataid->cfs_enable_1 = 0x%x\n", ataid->cfs_enable_1);
-       debug("(86)ataid->cfs_enable_2 = 0x%x\n", ataid->cfs_enable_2);
-       debug("(87)ataid->csf_default = 0x%x\n", ataid->csf_default);
-       debug("(88)ataid->dma_ultra = 0x%x\n", ataid->dma_ultra);
-       debug("(93)ataid->hw_config = 0x%x\n", ataid->hw_config);
-}
-
-
 /*
  * SCSI INQUIRY command operation.
  */
 static int ata_scsiop_inquiry(ccb *pccb)
 {
-       u8 hdr[] = {
+       static const u8 hdr[] = {
                0,
                0,
                0x5,            /* claim SPC-3 version compatibility */
@@ -614,7 +618,7 @@ static int ata_scsiop_inquiry(ccb *pccb)
                95 - 4,
        };
        u8 fis[20];
-       u8 *tmpid;
+       u16 *tmpid;
        u8 port;
 
        /* Clean ccb data buffer */
@@ -629,28 +633,33 @@ static int ata_scsiop_inquiry(ccb *pccb)
        /* Construct the FIS */
        fis[0] = 0x27;          /* Host to device FIS. */
        fis[1] = 1 << 7;        /* Command FIS. */
-       fis[2] = ATA_CMD_IDENT; /* Command byte. */
+       fis[2] = ATA_CMD_ID_ATA; /* Command byte. */
 
        /* Read id from sata */
        port = pccb->target;
-       if (!(tmpid = malloc(sizeof(hd_driveid_t))))
+       tmpid = malloc(ATA_ID_WORDS * 2);
+       if (!tmpid)
                return -ENOMEM;
 
-       if (ahci_device_data_io(port, (u8 *) &fis, sizeof(fis), tmpid,
-                               sizeof(hd_driveid_t), 0)) {
+       if (ahci_device_data_io(port, (u8 *) &fis, sizeof(fis), (u8 *)tmpid,
+                               ATA_ID_WORDS * 2, 0)) {
                debug("scsi_ahci: SCSI inquiry command failure.\n");
+               free(tmpid);
                return -EIO;
        }
 
        if (ataid[port])
                free(ataid[port]);
-       ataid[port] = (hd_driveid_t *) tmpid;
+       ataid[port] = tmpid;
+       ata_swap_buf_le16(tmpid, ATA_ID_WORDS);
 
        memcpy(&pccb->pdata[8], "ATA     ", 8);
-       ata_id_strcpy((u16 *) &pccb->pdata[16], (u16 *)ataid[port]->model, 16);
-       ata_id_strcpy((u16 *) &pccb->pdata[32], (u16 *)ataid[port]->fw_rev, 4);
+       ata_id_strcpy((u16 *) &pccb->pdata[16], &tmpid[ATA_ID_PROD], 16);
+       ata_id_strcpy((u16 *) &pccb->pdata[32], &tmpid[ATA_ID_FW_REV], 4);
 
-       dump_ataid(ataid[port]);
+#ifdef DEBUG
+       ata_dump_id(tmpid);
+#endif
        return 0;
 }
 
@@ -698,7 +707,7 @@ static int ata_scsiop_read_write(ccb *pccb, u8 is_write)
 
                now_blocks = min(MAX_SATA_BLOCKS_READ_WRITE, blocks);
 
-               transfer_size = ATA_BLOCKSIZE * now_blocks;
+               transfer_size = ATA_SECT_SIZE * now_blocks;
                if (transfer_size > user_buffer_size) {
                        printf("scsi_ahci: Error: buffer too small.\n");
                        return -EIO;
@@ -753,6 +762,7 @@ static int ata_scsiop_read_write(ccb *pccb, u8 is_write)
 static int ata_scsiop_read_capacity10(ccb *pccb)
 {
        u32 cap;
+       u64 cap64;
        u32 block_size;
 
        if (!ataid[pccb->target]) {
@@ -762,18 +772,11 @@ static int ata_scsiop_read_capacity10(ccb *pccb)
                return -EPERM;
        }
 
-       cap = le32_to_cpu(ataid[pccb->target]->lba_capacity);
-       if (cap == 0xfffffff) {
-               unsigned short *cap48 = ataid[pccb->target]->lba48_capacity;
-               if (cap48[2] || cap48[3]) {
-                       cap = 0xffffffff;
-               } else {
-                       cap = (le16_to_cpu(cap48[1]) << 16) |
-                             (le16_to_cpu(cap48[0]));
-               }
-       }
+       cap64 = ata_id_n_sectors(ataid[pccb->target]);
+       if (cap64 > 0x100000000ULL)
+               cap64 = 0xffffffff;
 
-       cap = cpu_to_be32(cap);
+       cap = cpu_to_be32(cap64);
        memcpy(pccb->pdata, &cap, sizeof(cap));
 
        block_size = cpu_to_be32((u32)512);
@@ -798,12 +801,7 @@ static int ata_scsiop_read_capacity16(ccb *pccb)
                return -EPERM;
        }
 
-       cap = le32_to_cpu(ataid[pccb->target]->lba_capacity);
-       if (cap == 0xfffffff) {
-               memcpy(&cap, ataid[pccb->target]->lba48_capacity, sizeof(cap));
-               cap = le64_to_cpu(cap);
-       }
-
+       cap = ata_id_n_sectors(ataid[pccb->target]);
        cap = cpu_to_be64(cap);
        memcpy(pccb->pdata, &cap, sizeof(cap));
 
@@ -890,8 +888,6 @@ int ahci_init(u32 base)
        int i, rc = 0;
        u32 linkmap;
 
-       memset(ataid, 0, sizeof(ataid));
-
        probe_ent = malloc(sizeof(struct ahci_probe_ent));
        memset(probe_ent, 0, sizeof(struct ahci_probe_ent));
 
index 4afedea065dd9e8da7c4bccfeaf4af109d1f7bc8..45b0fdc1615f4208e62ea7155b81998b62d2cfe2 100644 (file)
@@ -52,7 +52,18 @@ ELF  := $(addprefix $(obj),$(ELF))
 BIN    := $(addprefix $(obj),$(BIN))
 SREC   := $(addprefix $(obj),$(SREC))
 
-gcclibdir := $(shell dirname `$(CC) -print-libgcc-file-name`)
+# Add GCC lib
+ifdef USE_PRIVATE_LIBGCC
+ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
+PLATFORM_LIBGCC = $(OBJTREE)/arch/$(ARCH)/lib/libgcc.o
+else
+PLATFORM_LIBGCC = -L $(USE_PRIVATE_LIBGCC) -lgcc
+endif
+else
+PLATFORM_LIBGCC := -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc
+endif
+PLATFORM_LIBS += $(PLATFORM_LIBGCC)
+export PLATFORM_LIBS
 
 CPPFLAGS += -I..
 
@@ -82,7 +93,7 @@ $(ELF):
 $(obj)%:       $(obj)%.o $(LIB)
                $(LD) $(LDFLAGS) -g -Ttext $(CONFIG_STANDALONE_LOAD_ADDR) \
                        -o $@ -e $(SYM_PREFIX)$(notdir $(<:.o=)) $< $(LIB) \
-                       -L$(gcclibdir) -lgcc
+                       $(PLATFORM_LIBS)
 
 $(SREC):
 $(obj)%.srec:  $(obj)%
index b78026a81f97da50f53cf3e2468c2f6d1dfb84dd..b7a21e05bf77754f223e96451260ee95471329a2 100644 (file)
@@ -552,9 +552,11 @@ set_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer,
 
        debug("clustnum: %d, startsect: %d\n", clustnum, startsect);
 
-       if (disk_write(startsect, size / mydata->sect_size, buffer) < 0) {
-               debug("Error writing data\n");
-               return -1;
+       if ((size / mydata->sect_size) > 0) {
+               if (disk_write(startsect, size / mydata->sect_size, buffer) < 0) {
+                       debug("Error writing data\n");
+                       return -1;
+               }
        }
 
        if (size % mydata->sect_size) {
index 78a8c55f7ba736355e425b28a3adf5f14d563534..90e850929b7d4c625dee3baeb7ed4307af2fe0cc 100644 (file)
                                | PORT_IRQ_DMAS_FIS | PORT_IRQ_PIOS_FIS \
                                | PORT_IRQ_D2H_REG_FIS
 
+/* PORT_SCR_STAT bits */
+#define PORT_SCR_STAT_DET_MASK 0x3
+#define PORT_SCR_STAT_DET_COMINIT 0x1
+#define PORT_SCR_STAT_DET_PHYRDY 0x3
+
 /* PORT_CMD bits */
 #define PORT_CMD_ATAPI         (1 << 24) /* Device is ATAPI */
 #define PORT_CMD_LIST_ON       (1 << 15) /* cmd list DMA engine running */
 
 #define AHCI_MAX_PORTS         32
 
-/* SETFEATURES stuff */
-#define SETFEATURES_XFER       0x03
-#define XFER_UDMA_7            0x47
-#define XFER_UDMA_6            0x46
-#define XFER_UDMA_5            0x45
-#define XFER_UDMA_4            0x44
-#define XFER_UDMA_3            0x43
-#define XFER_UDMA_2            0x42
-#define XFER_UDMA_1            0x41
-#define XFER_UDMA_0            0x40
-#define XFER_MW_DMA_2          0x22
-#define XFER_MW_DMA_1          0x21
-#define XFER_MW_DMA_0          0x20
-#define XFER_SW_DMA_2          0x12
-#define XFER_SW_DMA_1          0x11
-#define XFER_SW_DMA_0          0x10
-#define XFER_PIO_4             0x0C
-#define XFER_PIO_3             0x0B
-#define XFER_PIO_2             0x0A
-#define XFER_PIO_1             0x09
-#define XFER_PIO_0             0x08
-#define XFER_PIO_SLOW          0x00
-
 #define ATA_FLAG_SATA          (1 << 3)
 #define ATA_FLAG_NO_LEGACY     (1 << 4) /* no legacy mode check */
 #define ATA_FLAG_MMIO          (1 << 6) /* use MMIO, not PIO */
index 2a5e5d4ed9df39546ace24152f49dd3dc4fcc153..7f1628592fd09c5105ba5539db3bd99419d81e50 100644 (file)
@@ -318,6 +318,7 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);
 #define CONFIG_SCSI_AHCI
 
 #ifdef CONFIG_SCSI_AHCI
+#define CONFIG_LIBATA
 #define CONFIG_SATA_ULI5288
 #define CONFIG_SYS_SCSI_MAX_SCSI_ID    4
 #define CONFIG_SYS_SCSI_MAX_LUN        1
index 05d887050046eeb23f46c3fcda43837f44f29551..acd39816bea4d8c2db0aff2bce969f9af6aab57a 100644 (file)
 #define CONFIG_SCSI_AHCI
 
 #ifdef CONFIG_SCSI_AHCI
+#define CONFIG_LIBATA
 #define CONFIG_SATA_ULI5288
 #define CONFIG_SYS_SCSI_MAX_SCSI_ID    4
 #define CONFIG_SYS_SCSI_MAX_LUN        1
index 1553a746c8a55b3d54ffb3fc20bbf81a476ead46..0b2cf87016ddcb905feb19188e980536dc82a6c3 100644 (file)
 #define CONFIG_SCSI_AHCI
 
 #ifdef CONFIG_SCSI_AHCI
+#define CONFIG_LIBATA
 #define CONFIG_SATA_ULI5288
 #define CONFIG_SYS_SCSI_MAX_SCSI_ID    4
 #define CONFIG_SYS_SCSI_MAX_LUN        1
index 6ca6f6b807e2e960959cf0808ba9d7ead0fd71a8..0945ae155d4ba7c4bc35759c43e018bdf4188583 100644 (file)
@@ -412,6 +412,7 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);
 #define CONFIG_SCSI_AHCI
 
 #ifdef CONFIG_SCSI_AHCI
+#define CONFIG_LIBATA
 #define CONFIG_SATA_ULI5288
 #define CONFIG_SYS_SCSI_MAX_SCSI_ID    4
 #define CONFIG_SYS_SCSI_MAX_LUN        1
index b5078cdb524e991c43715daa7f7c52132760b2e6..785e497f20ff69e3f97287e9bc7215fa69c5b6aa 100644 (file)
 #define CONFIG_SCSI_AHCI
 
 #ifdef CONFIG_SCSI_AHCI
+#define CONFIG_LIBATA
 #define CONFIG_SATA_ULI5288
 #define CONFIG_SYS_SCSI_MAX_SCSI_ID    4
 #define CONFIG_SYS_SCSI_MAX_LUN        1
index eae5a19f2ab391911107e6ab1a31c9d39e1d4a98..3de30fc28019f37a52d97bb4806a45d65a7f4384 100644 (file)
                                "echo Running uenvcmd ...;" \
                                "run uenvcmd;" \
                        "fi;" \
-                       "run mmcloados;" \
+                       "if run loaduimage; then " \
+                               "run mmcloados;" \
+                       "fi;" \
                "fi;\0" \
        "spiboot=echo Booting from spi ...; " \
                "run spiargs; " \
index ac7ed812d68b6cd3118948633f56e4c22a2a65fe..db9eb0f159fbd17dcb99676b4526fca24179d007 100644 (file)
 #define CONFIG_SPL_STACK               (0x00010000 + 0x7f00)
 
 #define CONFIG_SPL_TEXT_BASE           0x00000020 /*CONFIG_SYS_SRAM_START*/
+/* Provide at least 16MB spacing between us and the Linux Kernel image */
+#define CONFIG_SPL_PAD_TO              12320
 #define CONFIG_SPL_MAX_FOOTPRINT       12288
 
 #ifndef CONFIG_SPL_BUILD
index c2dcef89c6e526c70a14d69d9cc444a0d7606355..47215e59aa8983d6a5bec75533816f6db5124b6f 100644 (file)
@@ -56,6 +56,7 @@
 #define CONFIG_SCSI_AHCI
 
 #ifdef CONFIG_SCSI_AHCI
+#define CONFIG_LIBATA
 #define CONFIG_SYS_64BIT_LBA
 #define CONFIG_SATA_INTEL              1
 #define CONFIG_SCSI_DEV_LIST           {PCI_VENDOR_ID_INTEL, \
index a5743d63df5174f8e9baceb0c7f2df45993a276a..afb6e64e1b0464c6d9ec521a8b701e1711b766aa 100644 (file)
@@ -39,6 +39,7 @@
 #define CONFIG_SYS_BOOTCOUNT_ADDR      0xfff3cf0c
 
 #define CONFIG_MISC_INIT_R
+#define CONFIG_LIBATA
 #define CONFIG_SCSI_AHCI
 #define CONFIG_SCSI_AHCI_PLAT
 #define CONFIG_SYS_SCSI_MAX_SCSI_ID    5
index af3d6ad4e7977b1017e346c86d768ea232ae3c55..402703038454edca9a67c9071fdbed8b127b0cf3 100644 (file)
                                        "stdout=serial\0" \
                                        "stderr=serial\0"
 
+#define CONFIG_GZIP_COMPRESSED
+#define CONFIG_BZIP2
+#define CONFIG_LZO
+#define CONFIG_LZMA
+
 #endif
index 73dcf804bc940e6738f5f0f553f3cf2045f78fd7..9896e547b94ec0120863700dc3dde914c93c5bb5 100644 (file)
@@ -50,7 +50,9 @@
 #endif
 
 #define __deprecated                   __attribute__((deprecated))
-#define __packed                       __attribute__((packed))
+#ifndef __packed
+# define __packed                      __attribute__((packed))
+#endif
 #define __weak                         __attribute__((weak))
 
 /*
  * would be.
  * [...]
  */
-#define __pure                         __attribute__((pure))
-#define __aligned(x)                   __attribute__((aligned(x)))
+#ifndef __pure
+# define __pure                                __attribute__((pure))
+#endif
+#ifndef __aligned
+# define __aligned(x)                  __attribute__((aligned(x)))
+#endif
 #define __printf(a,b)                  __attribute__((format(printf,a,b)))
 #define  noinline                      __attribute__((noinline))
 #define __attribute_const__            __attribute__((__const__))
index 94dea3ffbfa19576e2cd8bb59b56658465101b49..27d11ca7b08f398b68a372104748384248d0b1db 100644 (file)
@@ -12,7 +12,9 @@
 #define __used                 __attribute__((__used__))
 #define __must_check           __attribute__((warn_unused_result))
 #define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
-#define __always_inline                inline __attribute__((always_inline))
+#ifndef __always_inline
+# define __always_inline               inline __attribute__((always_inline))
+#endif
 
 /*
  * A trick to suppress uninitialized variable warning without generating any
index 9959781b0004096fe542d950f0cea3f98f066fd3..35abfb38e176ff64b621fbe9d91b3542ce8150cd 100644 (file)
@@ -89,13 +89,13 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
        s.avail_out = dstlen;
        do {
                r = inflate(&s, Z_FINISH);
-               if (r != Z_STREAM_END && r != Z_BUF_ERROR && stoponerr == 1) {
+               if (stoponerr == 1 && r != Z_STREAM_END &&
+                   (s.avail_out == 0 || r != Z_BUF_ERROR)) {
                        printf("Error: inflate() returned %d\n", r);
                        inflateEnd(&s);
                        return -1;
                }
                s.avail_in = *lenp - offset - (int)(s.next_out - (unsigned char*)dst);
-               s.avail_out = dstlen;
        } while (r == Z_BUF_ERROR);
        *lenp = s.next_out - (unsigned char *) dst;
        inflateEnd(&s);
index 8d1165e11bddf12c52a3c75bf72220333601daa7..0aec2f9c76b2199117082ca6ddf64426eb6ddb61 100644 (file)
@@ -97,15 +97,19 @@ int lzmaBuffToBuffDecompress (unsigned char *outStream, SizeT *uncompressedSize,
     g_Alloc.Alloc = SzAlloc;
     g_Alloc.Free = SzFree;
 
+    /* Short-circuit early if we know the buffer can't hold the results. */
+    if (outSizeFull != (SizeT)-1 && *uncompressedSize < outSizeFull)
+        return SZ_ERROR_OUTPUT_EOF;
+
     /* Decompress */
-    outProcessed = outSizeFull;
+    outProcessed = *uncompressedSize;
 
     WATCHDOG_RESET();
 
     res = LzmaDecode(
         outStream, &outProcessed,
         inStream + LZMA_DATA_OFFSET, &compressedSize,
-        inStream, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &state, &g_Alloc);
+        inStream, LZMA_PROPS_SIZE, LZMA_FINISH_END, &state, &g_Alloc);
     *uncompressedSize = outProcessed;
     if (res != SZ_OK)  {
         return res;
index e6ff708f11999e0ddf96efe06818d61c15fa382c..35f3793f31c61e045df3c634b5299d7c735fc623 100644 (file)
@@ -68,13 +68,14 @@ int lzop_decompress(const unsigned char *src, size_t src_len,
        unsigned char *start = dst;
        const unsigned char *send = src + src_len;
        u32 slen, dlen;
-       size_t tmp;
+       size_t tmp, remaining;
        int r;
 
        src = parse_header(src);
        if (!src)
                return LZO_E_ERROR;
 
+       remaining = *dst_len;
        while (src < send) {
                /* read uncompressed block size */
                dlen = get_unaligned_be32(src);
@@ -93,6 +94,10 @@ int lzop_decompress(const unsigned char *src, size_t src_len,
                if (slen <= 0 || slen > dlen)
                        return LZO_E_ERROR;
 
+               /* abort if buffer ran out of room */
+               if (dlen > remaining)
+                       return LZO_E_OUTPUT_OVERRUN;
+
                /* decompress */
                tmp = dlen;
                r = lzo1x_decompress_safe((u8 *) src, slen, dst, &tmp);
@@ -105,6 +110,7 @@ int lzop_decompress(const unsigned char *src, size_t src_len,
 
                src += slen;
                dst += dlen;
+               remaining -= dlen;
        }
 
        return LZO_E_INPUT_OVERRUN;
index 99ce890e596f9b9970c62546ec402b4f582eeeed..a68613df729c34dd72211122f12993743575d293 100644 (file)
@@ -9,6 +9,7 @@ include $(TOPDIR)/config.mk
 LIB    = $(obj)libtest.o
 
 COBJS-$(CONFIG_SANDBOX) += command_ut.o
+COBJS-$(CONFIG_SANDBOX) += compression.o
 
 COBJS  := $(sort $(COBJS-y))
 SRCS   := $(COBJS:.o=.c)
diff --git a/test/compression.c b/test/compression.c
new file mode 100644 (file)
index 0000000..8834d5e
--- /dev/null
@@ -0,0 +1,335 @@
+/*
+ * Copyright (c) 2013, The Chromium Authors
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#define DEBUG
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+
+#include <u-boot/zlib.h>
+#include <bzlib.h>
+
+#include <lzma/LzmaTypes.h>
+#include <lzma/LzmaDec.h>
+#include <lzma/LzmaTools.h>
+
+#include <linux/lzo.h>
+
+static const char plain[] =
+       "I am a highly compressable bit of text.\n"
+       "I am a highly compressable bit of text.\n"
+       "I am a highly compressable bit of text.\n"
+       "There are many like me, but this one is mine.\n"
+       "If I were any shorter, there wouldn't be much sense in\n"
+       "compressing me in the first place. At least with lzo, anyway,\n"
+       "which appears to behave poorly in the face of short text\n"
+       "messages.\n";
+
+/* bzip2 -c /tmp/plain.txt > /tmp/plain.bz2 */
+static const char bzip2_compressed[] =
+       "\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\xe5\x63\xdd\x09\x00\x00"
+       "\x28\x57\x80\x00\x10\x40\x85\x20\x20\x04\x00\x3f\xef\xdf\xf0\x30"
+       "\x00\xd6\xd0\x34\x91\x89\xa6\xf5\x4d\x19\x1a\x19\x0d\x02\x34\xd4"
+       "\xc9\x00\x34\x34\x00\x02\x48\x41\x35\x4f\xd4\xc6\x88\xd3\x50\x3d"
+       "\x4f\x51\x82\x4f\x88\xc3\x0d\x05\x62\x4f\x91\xa3\x52\x1b\xd0\x52"
+       "\x41\x4a\xa3\x98\xc2\x6b\xca\xa3\x82\xa5\xac\x8b\x15\x99\x68\xad"
+       "\xdf\x29\xd6\xf1\xf7\x5a\x10\xcd\x8c\x26\x61\x94\x95\xfe\x9e\x16"
+       "\x18\x28\x69\xd4\x23\x64\xcc\x2b\xe5\xe8\x5f\x00\xa4\x70\x26\x2c"
+       "\xee\xbd\x59\x6d\x6a\xec\xfc\x31\xda\x59\x0a\x14\x2a\x60\x1c\xf0"
+       "\x04\x86\x73\x9a\xc5\x5b\x87\x3f\x5b\x4c\x93\xe6\xb5\x35\x0d\xa6"
+       "\xb1\x2e\x62\x7b\xab\x67\xe7\x99\x2a\x14\x5e\x9f\x64\xcb\x96\xf4"
+       "\x0d\x65\xd4\x39\xe6\x8b\x7e\xea\x1c\x03\x69\x97\x83\x58\x91\x96"
+       "\xe1\xf0\x9d\xa4\x15\x8b\xb8\xc6\x93\xdc\x3d\xd9\x3c\x22\x55\xef"
+       "\xfb\xbb\x2a\xd3\x87\xa2\x8b\x04\xd9\x19\xf8\xe2\xfd\x4f\xdb\x1a"
+       "\x07\xc8\x60\xa3\x3f\xf8\xbb\x92\x29\xc2\x84\x87\x2b\x1e\xe8\x48";
+static const unsigned long bzip2_compressed_size = 240;
+
+/* lzma -z -c /tmp/plain.txt > /tmp/plain.lzma */
+static const char lzma_compressed[] =
+       "\x5d\x00\x00\x80\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x24\x88"
+       "\x08\x26\xd8\x41\xff\x99\xc8\xcf\x66\x3d\x80\xac\xba\x17\xf1\xc8"
+       "\xb9\xdf\x49\x37\xb1\x68\xa0\x2a\xdd\x63\xd1\xa7\xa3\x66\xf8\x15"
+       "\xef\xa6\x67\x8a\x14\x18\x80\xcb\xc7\xb1\xcb\x84\x6a\xb2\x51\x16"
+       "\xa1\x45\xa0\xd6\x3e\x55\x44\x8a\x5c\xa0\x7c\xe5\xa8\xbd\x04\x57"
+       "\x8f\x24\xfd\xb9\x34\x50\x83\x2f\xf3\x46\x3e\xb9\xb0\x00\x1a\xf5"
+       "\xd3\x86\x7e\x8f\x77\xd1\x5d\x0e\x7c\xe1\xac\xde\xf8\x65\x1f\x4d"
+       "\xce\x7f\xa7\x3d\xaa\xcf\x26\xa7\x58\x69\x1e\x4c\xea\x68\x8a\xe5"
+       "\x89\xd1\xdc\x4d\xc7\xe0\x07\x42\xbf\x0c\x9d\x06\xd7\x51\xa2\x0b"
+       "\x7c\x83\x35\xe1\x85\xdf\xee\xfb\xa3\xee\x2f\x47\x5f\x8b\x70\x2b"
+       "\xe1\x37\xf3\x16\xf6\x27\x54\x8a\x33\x72\x49\xea\x53\x7d\x60\x0b"
+       "\x21\x90\x66\xe7\x9e\x56\x61\x5d\xd8\xdc\x59\xf0\xac\x2f\xd6\x49"
+       "\x6b\x85\x40\x08\x1f\xdf\x26\x25\x3b\x72\x44\xb0\xb8\x21\x2f\xb3"
+       "\xd7\x9b\x24\x30\x78\x26\x44\x07\xc3\x33\xd1\x4d\x03\x1b\xe1\xff"
+       "\xfd\xf5\x50\x8d\xca";
+static const unsigned long lzma_compressed_size = 229;
+
+/* lzop -c /tmp/plain.txt > /tmp/plain.lzo */
+static const char lzo_compressed[] =
+       "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a\x10\x30\x20\x60\x09\x40\x01"
+       "\x05\x03\x00\x00\x09\x00\x00\x81\xb4\x52\x09\x54\xf1\x00\x00\x00"
+       "\x00\x09\x70\x6c\x61\x69\x6e\x2e\x74\x78\x74\x65\xb1\x07\x9c\x00"
+       "\x00\x01\x5e\x00\x00\x01\x0f\xc3\xc7\x7a\xe0\x00\x16\x49\x20\x61"
+       "\x6d\x20\x61\x20\x68\x69\x67\x68\x6c\x79\x20\x63\x6f\x6d\x70\x72"
+       "\x65\x73\x73\x61\x62\x6c\x65\x20\x62\x69\x74\x20\x6f\x66\x20\x74"
+       "\x65\x78\x74\x2e\x0a\x20\x2f\x9c\x00\x00\x22\x54\x68\x65\x72\x65"
+       "\x20\x61\x72\x65\x20\x6d\x61\x6e\x79\x20\x6c\x69\x6b\x65\x20\x6d"
+       "\x65\x2c\x20\x62\x75\x74\x20\x74\x68\x69\x73\x20\x6f\x6e\x65\x20"
+       "\x69\x73\x20\x6d\x69\x6e\x65\x2e\x0a\x49\x66\x20\x49\x20\x77\x84"
+       "\x06\x0a\x6e\x79\x20\x73\x68\x6f\x72\x74\x65\x72\x2c\x20\x74\x90"
+       "\x08\x00\x08\x77\x6f\x75\x6c\x64\x6e\x27\x74\x20\x62\x65\x20\x6d"
+       "\x75\x63\x68\x20\x73\x65\x6e\x73\x65\x20\x69\x6e\x0a\xf8\x19\x02"
+       "\x69\x6e\x67\x20\x6d\x64\x02\x64\x06\x00\x5a\x20\x66\x69\x72\x73"
+       "\x74\x20\x70\x6c\x61\x63\x65\x2e\x20\x41\x74\x20\x6c\x65\x61\x73"
+       "\x74\x20\x77\x69\x74\x68\x20\x6c\x7a\x6f\x2c\x20\x61\x6e\x79\x77"
+       "\x61\x79\x2c\x0a\x77\x68\x69\x63\x68\x20\x61\x70\x70\x65\x61\x72"
+       "\x73\x20\x74\x6f\x20\x62\x65\x68\x61\x76\x65\x20\x70\x6f\x6f\x72"
+       "\x6c\x79\x20\x69\x6e\x20\x74\x68\x65\x20\x66\x61\x63\x65\x20\x6f"
+       "\x66\x20\x73\x68\x6f\x72\x74\x20\x74\x65\x78\x74\x0a\x6d\x65\x73"
+       "\x73\x61\x67\x65\x73\x2e\x0a\x11\x00\x00\x00\x00\x00\x00";
+static const unsigned long lzo_compressed_size = 334;
+
+
+#define TEST_BUFFER_SIZE       512
+
+typedef int (*mutate_func)(void *, unsigned long, void *, unsigned long,
+                          unsigned long *);
+
+static int compress_using_gzip(void *in, unsigned long in_size,
+                              void *out, unsigned long out_max,
+                              unsigned long *out_size)
+{
+       int ret;
+       unsigned long inout_size = out_max;
+
+       ret = gzip(out, &inout_size, in, in_size);
+       if (out_size)
+               *out_size = inout_size;
+
+       return ret;
+}
+
+static int uncompress_using_gzip(void *in, unsigned long in_size,
+                                void *out, unsigned long out_max,
+                                unsigned long *out_size)
+{
+       int ret;
+       unsigned long inout_size = in_size;
+
+       ret = gunzip(out, out_max, in, &inout_size);
+       if (out_size)
+               *out_size = inout_size;
+
+       return ret;
+}
+
+static int compress_using_bzip2(void *in, unsigned long in_size,
+                               void *out, unsigned long out_max,
+                               unsigned long *out_size)
+{
+       /* There is no bzip2 compression in u-boot, so fake it. */
+       assert(in_size == strlen(plain));
+       assert(memcmp(plain, in, in_size) == 0);
+
+       if (bzip2_compressed_size > out_max)
+               return -1;
+
+       memcpy(out, bzip2_compressed, bzip2_compressed_size);
+       if (out_size)
+               *out_size = bzip2_compressed_size;
+
+       return 0;
+}
+
+static int uncompress_using_bzip2(void *in, unsigned long in_size,
+                                 void *out, unsigned long out_max,
+                                 unsigned long *out_size)
+{
+       int ret;
+       unsigned int inout_size = out_max;
+
+       ret = BZ2_bzBuffToBuffDecompress(out, &inout_size, in, in_size,
+                       CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
+       if (out_size)
+               *out_size = inout_size;
+
+       return (ret != BZ_OK);
+}
+
+static int compress_using_lzma(void *in, unsigned long in_size,
+                              void *out, unsigned long out_max,
+                              unsigned long *out_size)
+{
+       /* There is no lzma compression in u-boot, so fake it. */
+       assert(in_size == strlen(plain));
+       assert(memcmp(plain, in, in_size) == 0);
+
+       if (lzma_compressed_size > out_max)
+               return -1;
+
+       memcpy(out, lzma_compressed, lzma_compressed_size);
+       if (out_size)
+               *out_size = lzma_compressed_size;
+
+       return 0;
+}
+
+static int uncompress_using_lzma(void *in, unsigned long in_size,
+                                void *out, unsigned long out_max,
+                                unsigned long *out_size)
+{
+       int ret;
+       SizeT inout_size = out_max;
+
+       ret = lzmaBuffToBuffDecompress(out, &inout_size, in, in_size);
+       if (out_size)
+               *out_size = inout_size;
+
+       return (ret != SZ_OK);
+}
+
+static int compress_using_lzo(void *in, unsigned long in_size,
+                             void *out, unsigned long out_max,
+                             unsigned long *out_size)
+{
+       /* There is no lzo compression in u-boot, so fake it. */
+       assert(in_size == strlen(plain));
+       assert(memcmp(plain, in, in_size) == 0);
+
+       if (lzo_compressed_size > out_max)
+               return -1;
+
+       memcpy(out, lzo_compressed, lzo_compressed_size);
+       if (out_size)
+               *out_size = lzo_compressed_size;
+
+       return 0;
+}
+
+static int uncompress_using_lzo(void *in, unsigned long in_size,
+                               void *out, unsigned long out_max,
+                               unsigned long *out_size)
+{
+       int ret;
+       size_t input_size = in_size;
+       size_t output_size = out_max;
+
+       ret = lzop_decompress(in, input_size, out, &output_size);
+       if (out_size)
+               *out_size = output_size;
+
+       return (ret != LZO_E_OK);
+}
+
+#define errcheck(statement) if (!(statement)) { \
+       fprintf(stderr, "\tFailed: %s\n", #statement); \
+       ret = 1; \
+       goto out; \
+}
+
+static int run_test(char *name, mutate_func compress, mutate_func uncompress)
+{
+       ulong orig_size, compressed_size, uncompressed_size;
+       void *orig_buf;
+       void *compressed_buf = NULL;
+       void *uncompressed_buf = NULL;
+       void *compare_buf = NULL;
+       int ret;
+
+       printf(" testing %s ...\n", name);
+
+       orig_buf = (void *)plain;
+       orig_size = strlen(orig_buf); /* Trailing NULL not included. */
+       errcheck(orig_size > 0);
+
+       compressed_size = uncompressed_size = TEST_BUFFER_SIZE;
+       compressed_buf = malloc(compressed_size);
+       errcheck(compressed_buf != NULL);
+       uncompressed_buf = malloc(uncompressed_size);
+       errcheck(uncompressed_buf != NULL);
+       compare_buf = malloc(uncompressed_size);
+       errcheck(compare_buf != NULL);
+
+       /* Compress works as expected. */
+       printf("\torig_size:%lu\n", orig_size);
+       memset(compressed_buf, 'A', TEST_BUFFER_SIZE);
+       errcheck(compress(orig_buf, orig_size,
+                       compressed_buf, compressed_size,
+                       &compressed_size) == 0);
+       printf("\tcompressed_size:%lu\n", compressed_size);
+       errcheck(compressed_size > 0);
+       errcheck(compressed_size < orig_size);
+       errcheck(((char *)compressed_buf)[compressed_size-1] != 'A');
+       errcheck(((char *)compressed_buf)[compressed_size] == 'A');
+
+       /* Uncompresses with space remaining. */
+       errcheck(uncompress(compressed_buf, compressed_size,
+                         uncompressed_buf, uncompressed_size,
+                         &uncompressed_size) == 0);
+       printf("\tuncompressed_size:%lu\n", uncompressed_size);
+       errcheck(uncompressed_size == orig_size);
+       errcheck(memcmp(orig_buf, uncompressed_buf, orig_size) == 0);
+
+       /* Uncompresses with exactly the right size output buffer. */
+       memset(uncompressed_buf, 'A', TEST_BUFFER_SIZE);
+       errcheck(uncompress(compressed_buf, compressed_size,
+                         uncompressed_buf, orig_size,
+                         &uncompressed_size) == 0);
+       errcheck(uncompressed_size == orig_size);
+       errcheck(memcmp(orig_buf, uncompressed_buf, orig_size) == 0);
+       errcheck(((char *)uncompressed_buf)[orig_size] == 'A');
+
+       /* Make sure compression does not over-run. */
+       memset(compare_buf, 'A', TEST_BUFFER_SIZE);
+       ret = compress(orig_buf, orig_size,
+                      compare_buf, compressed_size - 1,
+                      NULL);
+       errcheck(((char *)compare_buf)[compressed_size] == 'A');
+       errcheck(ret != 0);
+       printf("\tcompress does not overrun\n");
+
+       /* Make sure decompression does not over-run. */
+       memset(compare_buf, 'A', TEST_BUFFER_SIZE);
+       ret = uncompress(compressed_buf, compressed_size,
+                        compare_buf, uncompressed_size - 1,
+                        NULL);
+       errcheck(((char *)compare_buf)[uncompressed_size - 1] == 'A');
+       errcheck(ret != 0);
+       printf("\tuncompress does not overrun\n");
+
+       /* Got here, everything is fine. */
+       ret = 0;
+
+out:
+       printf(" %s: %s\n", name, ret == 0 ? "ok" : "FAILED");
+
+       free(compare_buf);
+       free(uncompressed_buf);
+       free(compressed_buf);
+
+       return ret;
+}
+
+
+static int do_test_compression(cmd_tbl_t *cmdtp, int flag, int argc,
+                              char * const argv[])
+{
+       int err = 0;
+
+       err += run_test("gzip", compress_using_gzip, uncompress_using_gzip);
+       err += run_test("bzip2", compress_using_bzip2, uncompress_using_bzip2);
+       err += run_test("lzma", compress_using_lzma, uncompress_using_lzma);
+       err += run_test("lzo", compress_using_lzo, uncompress_using_lzo);
+
+       printf("test_compression %s\n", err == 0 ? "ok" : "FAILED");
+
+       return err;
+}
+
+U_BOOT_CMD(
+       test_compression,       5,      1,      do_test_compression,
+       "Basic test of compressors: gzip bzip2 lzma lzo", ""
+);
index 44607b164a7024501360d206b90b1b6d419e6a29..577ce2de4725249ba4989d02f78c57595d6f93c6 100644 (file)
@@ -727,27 +727,39 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count,
                                   MEMGETBADBLOCK needs 64 bits */
        int rc;
 
-       blocklen = DEVESIZE (dev);
+       /*
+        * For mtd devices only offset and size of the environment do matter
+        */
+       if (mtd_type == MTD_ABSENT) {
+               blocklen = count;
+               top_of_range = offset + count;
+               erase_len = blocklen;
+               blockstart = offset;
+               block_seek = 0;
+               write_total = blocklen;
+       } else {
+               blocklen = DEVESIZE(dev);
 
-       top_of_range = ((DEVOFFSET(dev) / blocklen) +
-                                       ENVSECTORS (dev)) * blocklen;
+               top_of_range = ((DEVOFFSET(dev) / blocklen) +
+                                       ENVSECTORS(dev)) * blocklen;
 
-       erase_offset = (offset / blocklen) * blocklen;
+               erase_offset = (offset / blocklen) * blocklen;
 
-       /* Maximum area we may use */
-       erase_len = top_of_range - erase_offset;
+               /* Maximum area we may use */
+               erase_len = top_of_range - erase_offset;
 
-       blockstart = erase_offset;
-       /* Offset inside a block */
-       block_seek = offset - erase_offset;
+               blockstart = erase_offset;
+               /* Offset inside a block */
+               block_seek = offset - erase_offset;
 
-       /*
-        * Data size we actually have to write: from the start of the block
-        * to the start of the data, then count bytes of data, and to the
-        * end of the block
-        */
-       write_total = ((block_seek + count + blocklen - 1) /
-                                               blocklen) * blocklen;
+               /*
+                * Data size we actually write: from the start of the block
+                * to the start of the data, then count bytes of data, and
+                * to the end of the block
+                */
+               write_total = ((block_seek + count + blocklen - 1) /
+                                                       blocklen) * blocklen;
+       }
 
        /*
         * Support data anywhere within erase sectors: read out the complete
@@ -818,17 +830,18 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count,
                        continue;
                }
 
-               erase.start = blockstart;
-               ioctl (fd, MEMUNLOCK, &erase);
-               /* These do not need an explicit erase cycle */
-               if (mtd_type != MTD_ABSENT &&
-                   mtd_type != MTD_DATAFLASH)
-                       if (ioctl (fd, MEMERASE, &erase) != 0) {
-                               fprintf (stderr, "MTD erase error on %s: %s\n",
-                                        DEVNAME (dev),
-                                        strerror (errno));
-                               return -1;
-                       }
+               if (mtd_type != MTD_ABSENT) {
+                       erase.start = blockstart;
+                       ioctl(fd, MEMUNLOCK, &erase);
+                       /* These do not need an explicit erase cycle */
+                       if (mtd_type != MTD_DATAFLASH)
+                               if (ioctl(fd, MEMERASE, &erase) != 0) {
+                                       fprintf(stderr,
+                                               "MTD erase error on %s: %s\n",
+                                               DEVNAME(dev), strerror(errno));
+                                       return -1;
+                               }
+               }
 
                if (lseek (fd, blockstart, SEEK_SET) == -1) {
                        fprintf (stderr,
@@ -847,7 +860,8 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count,
                        return -1;
                }
 
-               ioctl (fd, MEMLOCK, &erase);
+               if (mtd_type != MTD_ABSENT)
+                       ioctl(fd, MEMLOCK, &erase);
 
                processed  += blocklen;
                block_seek = 0;
@@ -1136,6 +1150,9 @@ int fw_env_open(void)
                } else if (DEVTYPE(dev_current) == MTD_UBIVOLUME &&
                           DEVTYPE(!dev_current) == MTD_UBIVOLUME) {
                        environment.flag_scheme = FLAG_INCREMENTAL;
+               } else if (DEVTYPE(dev_current) == MTD_ABSENT &&
+                          DEVTYPE(!dev_current) == MTD_ABSENT) {
+                       environment.flag_scheme = FLAG_INCREMENTAL;
                } else {
                        fprintf (stderr, "Incompatible flash types!\n");
                        return -1;