]> Git Repo - J-u-boot.git/blobdiff - common/image.c
Replace video_uc_platdata with video_uc_plat
[J-u-boot.git] / common / image.c
index 2288cff1266132529e462b8112d63796862b5c2a..a6500f5f5c7e3902953567fc996b9217a1c0b650 100644 (file)
@@ -8,8 +8,13 @@
 
 #ifndef USE_HOSTCC
 #include <common.h>
+#include <bootstage.h>
 #include <cpu_func.h>
 #include <env.h>
+#include <lmb.h>
+#include <log.h>
+#include <malloc.h>
+#include <asm/cache.h>
 #include <u-boot/crc.h>
 #include <watchdog.h>
 
@@ -31,6 +36,7 @@
 #include <xilinx.h>
 #endif
 
+#include <asm/global_data.h>
 #include <u-boot/md5.h>
 #include <u-boot/sha1.h>
 #include <linux/errno.h>
 #include <lzma/LzmaTypes.h>
 #include <lzma/LzmaDec.h>
 #include <lzma/LzmaTools.h>
+#include <linux/zstd.h>
 
 #ifdef CONFIG_CMD_BDI
-extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+extern int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc,
+                    char *const argv[]);
 #endif
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -182,6 +190,7 @@ static const table_entry_t uimage_type[] = {
        {       IH_TYPE_STM32IMAGE, "stm32image", "STMicroelectronics STM32 Image" },
        {       IH_TYPE_MTKIMAGE,   "mtk_image",   "MediaTek BootROM loadable Image" },
        {       IH_TYPE_COPRO, "copro", "Coprocessor Image"},
+       {       IH_TYPE_SUNXI_EGON, "sunxi_egon",  "Allwinner eGON Boot Image" },
        {       -1,                 "",           "",                   },
 };
 
@@ -192,6 +201,7 @@ static const table_entry_t uimage_comp[] = {
        {       IH_COMP_LZMA,   "lzma",         "lzma compressed",      },
        {       IH_COMP_LZO,    "lzo",          "lzo compressed",       },
        {       IH_COMP_LZ4,    "lz4",          "lz4 compressed",       },
+       {       IH_COMP_ZSTD,   "zstd",         "zstd compressed",      },
        {       -1,             "",             "",                     },
 };
 
@@ -201,6 +211,14 @@ struct table_info {
        const table_entry_t *table;
 };
 
+static const struct comp_magic_map image_comp[] = {
+       {       IH_COMP_BZIP2,  "bzip2",        {0x42, 0x5a},},
+       {       IH_COMP_GZIP,   "gzip",         {0x1f, 0x8b},},
+       {       IH_COMP_LZMA,   "lzma",         {0x5d, 0x00},},
+       {       IH_COMP_LZO,    "lzo",          {0x89, 0x4c},},
+       {       IH_COMP_NONE,   "none",         {},     },
+};
+
 static const struct table_info table_info[IH_COUNT] = {
        { "architecture", IH_ARCH_COUNT, uimage_arch },
        { "compression", IH_COMP_COUNT, uimage_comp },
@@ -406,6 +424,21 @@ static void print_decomp_msg(int comp_type, int type, bool is_xip)
                printf("   Uncompressing %s\n", name);
 }
 
+int image_decomp_type(const unsigned char *buf, ulong len)
+{
+       const struct comp_magic_map *cmagic = image_comp;
+
+       if (len < 2)
+               return -EINVAL;
+
+       for (; cmagic->comp_id > 0; cmagic++) {
+               if (!memcmp(buf, cmagic->magic, 2))
+                       break;
+       }
+
+       return cmagic->comp_id;
+}
+
 int image_decomp(int comp, ulong load, ulong image_start, int type,
                 void *load_buf, void *image_buf, ulong image_len,
                 uint unc_len, ulong *load_end)
@@ -479,6 +512,56 @@ int image_decomp(int comp, ulong load, ulong image_start, int type,
                break;
        }
 #endif /* CONFIG_LZ4 */
+#ifdef CONFIG_ZSTD
+       case IH_COMP_ZSTD: {
+               size_t size = unc_len;
+               ZSTD_DStream *dstream;
+               ZSTD_inBuffer in_buf;
+               ZSTD_outBuffer out_buf;
+               void *workspace;
+               size_t wsize;
+
+               wsize = ZSTD_DStreamWorkspaceBound(image_len);
+               workspace = malloc(wsize);
+               if (!workspace) {
+                       debug("%s: cannot allocate workspace of size %zu\n", __func__,
+                             wsize);
+                       return -1;
+               }
+
+               dstream = ZSTD_initDStream(image_len, workspace, wsize);
+               if (!dstream) {
+                       printf("%s: ZSTD_initDStream failed\n", __func__);
+                       return ZSTD_getErrorCode(ret);
+               }
+
+               in_buf.src = image_buf;
+               in_buf.pos = 0;
+               in_buf.size = image_len;
+
+               out_buf.dst = load_buf;
+               out_buf.pos = 0;
+               out_buf.size = size;
+
+               while (1) {
+                       size_t ret;
+
+                       ret = ZSTD_decompressStream(dstream, &out_buf, &in_buf);
+                       if (ZSTD_isError(ret)) {
+                               printf("%s: ZSTD_decompressStream error %d\n", __func__,
+                                      ZSTD_getErrorCode(ret));
+                               return ZSTD_getErrorCode(ret);
+                       }
+
+                       if (in_buf.pos >= image_len || !ret)
+                               break;
+               }
+
+               image_len = out_buf.pos;
+
+               break;
+       }
+#endif /* CONFIG_ZSTD */
        default:
                printf("Unimplemented compression type %d\n", comp);
                return -ENOSYS;
@@ -604,14 +687,11 @@ phys_size_t env_get_bootm_size(void)
                return tmp;
        }
 
-#if (defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)) && \
-     defined(CONFIG_NR_DRAM_BANKS)
-       start = gd->bd->bi_dram[0].start;
-       size = gd->bd->bi_dram[0].size;
-#else
-       start = gd->bd->bi_memstart;
-       size = gd->bd->bi_memsize;
-#endif
+       start = gd->ram_base;
+       size = gd->ram_size;
+
+       if (start + size > gd->ram_top)
+               size = gd->ram_top - start;
 
        s = env_get("bootm_low");
        if (s)
@@ -723,14 +803,14 @@ static const char *unknown_msg(enum ih_category category)
 }
 
 /**
- * get_cat_table_entry_name - translate entry id to long name
+ * genimg_get_cat_name - translate entry id to long name
  * @category: category to look up (enum ih_category)
  * @id: entry id to be translated
  *
  * This will scan the translation table trying to find the entry that matches
  * the given id.
  *
- * @retur long entry name if translation succeeds; error string on failure
+ * @return long entry name if translation succeeds; error string on failure
  */
 const char *genimg_get_cat_name(enum ih_category category, uint id)
 {
@@ -747,14 +827,14 @@ const char *genimg_get_cat_name(enum ih_category category, uint id)
 }
 
 /**
- * get_cat_table_entry_short_name - translate entry id to short name
+ * genimg_get_cat_short_name - translate entry id to short name
  * @category: category to look up (enum ih_category)
  * @id: entry id to be translated
  *
  * This will scan the translation table trying to find the entry that matches
  * the given id.
  *
- * @retur short entry name if translation succeeds; error string on failure
+ * @return short entry name if translation succeeds; error string on failure
  */
 const char *genimg_get_cat_short_name(enum ih_category category, uint id)
 {
@@ -780,6 +860,24 @@ const char *genimg_get_cat_desc(enum ih_category category)
        return table_info[category].desc;
 }
 
+/**
+ * genimg_cat_has_id - check whether category has entry id
+ * @category: category to look up (enum ih_category)
+ * @id: entry id to be checked
+ *
+ * This will scan the translation table trying to find the entry that matches
+ * the given id.
+ *
+ * @return true if category has entry id; false if not
+ */
+bool genimg_cat_has_id(enum ih_category category, uint id)
+{
+       if (get_table_entry(table_info[category].table, id))
+               return true;
+
+       return false;
+}
+
 /**
  * get_table_entry_name - translate entry id to long name
  * @table: pointer to a translation table for entries of a specific type
@@ -822,6 +920,12 @@ const char *genimg_get_type_name(uint8_t type)
        return (get_table_entry_name(uimage_type, "Unknown Image", type));
 }
 
+const char *genimg_get_comp_name(uint8_t comp)
+{
+       return (get_table_entry_name(uimage_comp, "Unknown Compression",
+                                       comp));
+}
+
 static const char *genimg_get_short_name(const table_entry_t *table, int val)
 {
        table = get_table_entry(table, val);
@@ -839,12 +943,6 @@ const char *genimg_get_type_short_name(uint8_t type)
        return genimg_get_short_name(uimage_type, type);
 }
 
-const char *genimg_get_comp_name(uint8_t comp)
-{
-       return (get_table_entry_name(uimage_comp, "Unknown Compression",
-                                       comp));
-}
-
 const char *genimg_get_comp_short_name(uint8_t comp)
 {
        return genimg_get_short_name(uimage_comp, comp);
@@ -1048,8 +1146,8 @@ int genimg_has_config(bootm_headers_t *images)
  *     1, if ramdisk image is found but corrupted, or invalid
  *     rd_start and rd_end are set to 0 if no ramdisk exists
  */
-int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
-               uint8_t arch, ulong *rd_start, ulong *rd_end)
+int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
+                    uint8_t arch, ulong *rd_start, ulong *rd_end)
 {
        ulong rd_addr, rd_load;
        ulong rd_data, rd_len;
@@ -1344,7 +1442,7 @@ int boot_get_setup(bootm_headers_t *images, uint8_t arch,
 
 #if IMAGE_ENABLE_FIT
 #if defined(CONFIG_FPGA)
-int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
+int boot_get_fpga(int argc, char *const argv[], bootm_headers_t *images,
                  uint8_t arch, const ulong *ld_start, ulong * const ld_len)
 {
        ulong tmp_img_addr, img_data, img_len;
@@ -1445,8 +1543,8 @@ static void fit_loadable_process(uint8_t img_type,
                        fit_loadable_handler->handler(img_data, img_len);
 }
 
-int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
-               uint8_t arch, const ulong *ld_start, ulong * const ld_len)
+int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images,
+                     uint8_t arch, const ulong *ld_start, ulong * const ld_len)
 {
        /*
         * These variables are used to hold the current image location
@@ -1584,10 +1682,12 @@ int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
  *      0 - success
  *     -1 - failure
  */
-int boot_get_kbd(struct lmb *lmb, bd_t **kbd)
+int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd)
 {
-       *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
-                               env_get_bootm_mapsize() + env_get_bootm_low());
+       *kbd = (struct bd_info *)(ulong)lmb_alloc_base(lmb,
+                                                      sizeof(struct bd_info),
+                                                      0xf,
+                                                      env_get_bootm_mapsize() + env_get_bootm_low());
        if (*kbd == NULL)
                return -1;
 
This page took 0.042268 seconds and 4 git commands to generate.