]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - common/cmd_bootm.c
rename CFG_ macros to CONFIG_SYS
[karo-tx-uboot.git] / common / cmd_bootm.c
index 08a014f4484d3035835b937fd7200aa9e1e14140..2a9c59f2a266c6281c88081d23db4cc62a75c703 100644 (file)
@@ -40,7 +40,7 @@
 #include <usb.h>
 #endif
 
-#ifdef CFG_HUSH_PARSER
+#ifdef CONFIG_SYS_HUSH_PARSER
 #include <hush.h>
 #endif
 
 #include <fdt_support.h>
 #endif
 
+#ifdef CONFIG_LZMA
+#define _7ZIP_BYTE_DEFINED /* Byte already defined by zlib */
+#include <lzma/LzmaTypes.h>
+#include <lzma/LzmaDecode.h>
+#include <lzma/LzmaTools.h>
+#endif /* CONFIG_LZMA */
+
 DECLARE_GLOBAL_DATA_PTR;
 
 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
-#ifndef CFG_BOOTM_LEN
-#define CFG_BOOTM_LEN  0x800000        /* use 8MByte as default max gunzip size */
+#ifndef CONFIG_SYS_BOOTM_LEN
+#define CONFIG_SYS_BOOTM_LEN   0x800000        /* use 8MByte as default max gunzip size */
 #endif
 
 #ifdef CONFIG_BZIP2
@@ -108,8 +115,11 @@ static boot_os_fn do_bootm_qnxelf;
 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 #endif
+#if defined(CONFIG_INTEGRITY)
+static boot_os_fn do_bootm_integrity;
+#endif
 
-ulong load_addr = CFG_LOAD_ADDR;       /* Default Load Address */
+ulong load_addr = CONFIG_SYS_LOAD_ADDR;        /* Default Load Address */
 static bootm_headers_t images;         /* pointers to os/initrd/fdt images */
 
 void __board_lmb_reserve(struct lmb *lmb)
@@ -248,6 +258,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                }
 
 #if defined(CONFIG_OF_LIBFDT)
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
                /* find flattened device tree */
                ret = boot_get_fdt (flag, argc, argv, &images,
                                    &images.ft_addr, &images.ft_len);
@@ -257,6 +268,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                }
 
                set_working_fdt_addr(images.ft_addr);
+#endif
 #endif
        }
 
@@ -277,7 +289,7 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
        ulong blob_end = os.end;
        ulong image_start = os.image_start;
        ulong image_len = os.image_len;
-       uint unc_len = CFG_BOOTM_LEN;
+       uint unc_len = CONFIG_SYS_BOOTM_LEN;
 
        const char *type_name = genimg_get_type_name (os.type);
 
@@ -317,7 +329,7 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
                 */
                int i = BZ2_bzBuffToBuffDecompress ((char*)load,
                                        &unc_len, (char *)image_start, image_len,
-                                       CFG_MALLOC_LEN < (4096 * 1024), 0);
+                                       CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
                if (i != BZ_OK) {
                        printf ("BUNZIP2: uncompress or overwrite error %d "
                                "- must RESET board to recover\n", i);
@@ -329,18 +341,34 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
                *load_end = load + unc_len;
                break;
 #endif /* CONFIG_BZIP2 */
+#ifdef CONFIG_LZMA
+       case IH_COMP_LZMA:
+               printf ("   Uncompressing %s ... ", type_name);
+
+               int ret = lzmaBuffToBuffDecompress(
+                       (unsigned char *)load, &unc_len,
+                       (unsigned char *)image_start, image_len);
+               if (ret != LZMA_RESULT_OK) {
+                       printf ("LZMA: uncompress or overwrite error %d "
+                               "- must RESET board to recover\n", ret);
+                       show_boot_progress (-6);
+                       return BOOTM_ERR_RESET;
+               }
+               *load_end = load + unc_len;
+               break;
+#endif /* CONFIG_LZMA */
        default:
                printf ("Unimplemented compression type %d\n", comp);
                return BOOTM_ERR_UNIMPLEMENTED;
        }
        puts ("OK\n");
-       debug ("   kernel loaded at 0x%08lx, end = 0x%8p\n", load, load_end);
+       debug ("   kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
        if (boot_progress)
                show_boot_progress (7);
 
        if ((load < blob_end) && (*load_end > blob_start)) {
                debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
-               debug ("images.os.load = 0x%lx, load_end = 0x%p\n", load, load_end);
+               debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
 
                return BOOTM_ERR_OVERLAP;
        }
@@ -452,6 +480,11 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
            break;
 #endif
 
+#ifdef CONFIG_INTEGRITY
+       case IH_OS_INTEGRITY:
+           do_bootm_integrity (0, argc, argv, &images);
+           break;
+#endif
        }
 
        show_boot_progress (-9);
@@ -729,7 +762,7 @@ static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]
 }
 
 U_BOOT_CMD(
-       bootm,  CFG_MAXARGS,    1,      do_bootm,
+       bootm,  CONFIG_SYS_MAXARGS,     1,      do_bootm,
        "bootm   - boot application image from memory\n",
        "[addr [arg ...]]\n    - boot application image stored in memory\n"
        "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
@@ -759,7 +792,7 @@ int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        int rcode = 0;
 
-#ifndef CFG_HUSH_PARSER
+#ifndef CONFIG_SYS_HUSH_PARSER
        if (run_command (getenv ("bootcmd"), flag) < 0)
                rcode = 1;
 #else
@@ -846,6 +879,12 @@ static int image_info (ulong addr)
                }
 
                fit_print_contents (hdr);
+
+               if (!fit_all_image_check_hashes (hdr)) {
+                       puts ("Bad hash in FIT image!\n");
+                       return 1;
+               }
+
                return 0;
 #endif
        default:
@@ -857,7 +896,7 @@ static int image_info (ulong addr)
 }
 
 U_BOOT_CMD(
-       iminfo, CFG_MAXARGS,    1,      do_iminfo,
+       iminfo, CONFIG_SYS_MAXARGS,     1,      do_iminfo,
        "iminfo  - print header information for application image\n",
        "addr [addr ...]\n"
        "    - print header information for application image starting at\n"
@@ -878,7 +917,7 @@ int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        void *hdr;
 
        for (i = 0, info = &flash_info[0];
-               i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
+               i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
 
                if (info->flash_id == FLASH_UNKNOWN)
                        goto next_bank;
@@ -1144,3 +1183,33 @@ static int do_bootm_qnxelf(int flag, int argc, char *argv[],
        return 1;
 }
 #endif
+
+#ifdef CONFIG_INTEGRITY
+static int do_bootm_integrity (int flag, int argc, char *argv[],
+                          bootm_headers_t *images)
+{
+       void (*entry_point)(void);
+
+#if defined(CONFIG_FIT)
+       if (!images->legacy_hdr_valid) {
+               fit_unsupported_reset ("INTEGRITY");
+               return 1;
+       }
+#endif
+
+       entry_point = (void (*)(void))images->ep;
+
+       printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
+               (ulong)entry_point);
+
+       show_boot_progress (15);
+
+       /*
+        * INTEGRITY Parameters:
+        *   None
+        */
+       (*entry_point)();
+
+       return 1;
+}
+#endif