12e192b24SSimon Glass /* 22e192b24SSimon Glass * Copyright (c) 2001 William L. Pitts 32e192b24SSimon Glass * All rights reserved. 42e192b24SSimon Glass * 52e192b24SSimon Glass * Redistribution and use in source and binary forms are freely 62e192b24SSimon Glass * permitted provided that the above copyright notice and this 72e192b24SSimon Glass * paragraph and the following disclaimer are duplicated in all 82e192b24SSimon Glass * such forms. 92e192b24SSimon Glass * 102e192b24SSimon Glass * This software is provided "AS IS" and without any express or 112e192b24SSimon Glass * implied warranties, including, without limitation, the implied 122e192b24SSimon Glass * warranties of merchantability and fitness for a particular 132e192b24SSimon Glass * purpose. 142e192b24SSimon Glass */ 152e192b24SSimon Glass 162e192b24SSimon Glass #include <common.h> 172e192b24SSimon Glass #include <command.h> 182e192b24SSimon Glass #include <elf.h> 199925f1dbSAlex Kiernan #include <environment.h> 202e192b24SSimon Glass #include <net.h> 212e192b24SSimon Glass #include <vxworks.h> 222e192b24SSimon Glass #ifdef CONFIG_X86 232e192b24SSimon Glass #include <asm/e820.h> 242e192b24SSimon Glass #include <linux/linkage.h> 252e192b24SSimon Glass #endif 262e192b24SSimon Glass 272e192b24SSimon Glass /* 28*839c4e9cSBin Meng * A very simple ELF64 loader, assumes the image is valid, returns the 292e192b24SSimon Glass * entry point address. 30*839c4e9cSBin Meng * 31*839c4e9cSBin Meng * Note if U-Boot is 32-bit, the loader assumes the to segment's 32*839c4e9cSBin Meng * physical address and size is within the lower 32-bit address space. 33*839c4e9cSBin Meng */ 34*839c4e9cSBin Meng static unsigned long load_elf64_image_phdr(unsigned long addr) 35*839c4e9cSBin Meng { 36*839c4e9cSBin Meng Elf64_Ehdr *ehdr; /* Elf header structure pointer */ 37*839c4e9cSBin Meng Elf64_Phdr *phdr; /* Program header structure pointer */ 38*839c4e9cSBin Meng int i; 39*839c4e9cSBin Meng 40*839c4e9cSBin Meng ehdr = (Elf64_Ehdr *)addr; 41*839c4e9cSBin Meng phdr = (Elf64_Phdr *)(addr + (ulong)ehdr->e_phoff); 42*839c4e9cSBin Meng 43*839c4e9cSBin Meng /* Load each program header */ 44*839c4e9cSBin Meng for (i = 0; i < ehdr->e_phnum; ++i) { 45*839c4e9cSBin Meng void *dst = (void *)(ulong)phdr->p_paddr; 46*839c4e9cSBin Meng void *src = (void *)addr + phdr->p_offset; 47*839c4e9cSBin Meng 48*839c4e9cSBin Meng debug("Loading phdr %i to 0x%p (%lu bytes)\n", 49*839c4e9cSBin Meng i, dst, (ulong)phdr->p_filesz); 50*839c4e9cSBin Meng if (phdr->p_filesz) 51*839c4e9cSBin Meng memcpy(dst, src, phdr->p_filesz); 52*839c4e9cSBin Meng if (phdr->p_filesz != phdr->p_memsz) 53*839c4e9cSBin Meng memset(dst + phdr->p_filesz, 0x00, 54*839c4e9cSBin Meng phdr->p_memsz - phdr->p_filesz); 55*839c4e9cSBin Meng flush_cache((unsigned long)dst, phdr->p_filesz); 56*839c4e9cSBin Meng ++phdr; 57*839c4e9cSBin Meng } 58*839c4e9cSBin Meng 59*839c4e9cSBin Meng return ehdr->e_entry; 60*839c4e9cSBin Meng } 61*839c4e9cSBin Meng 62*839c4e9cSBin Meng /* 63*839c4e9cSBin Meng * A very simple ELF loader, assumes the image is valid, returns the 64*839c4e9cSBin Meng * entry point address. 65*839c4e9cSBin Meng * 66*839c4e9cSBin Meng * The loader firstly reads the EFI class to see if it's a 64-bit image. 67*839c4e9cSBin Meng * If yes, call the ELF64 loader. Otherwise continue with the ELF32 loader. 682e192b24SSimon Glass */ 692e192b24SSimon Glass static unsigned long load_elf_image_phdr(unsigned long addr) 702e192b24SSimon Glass { 712e192b24SSimon Glass Elf32_Ehdr *ehdr; /* Elf header structure pointer */ 722e192b24SSimon Glass Elf32_Phdr *phdr; /* Program header structure pointer */ 732e192b24SSimon Glass int i; 742e192b24SSimon Glass 752e192b24SSimon Glass ehdr = (Elf32_Ehdr *)addr; 76*839c4e9cSBin Meng if (ehdr->e_ident[EI_CLASS] == ELFCLASS64) 77*839c4e9cSBin Meng return load_elf64_image_phdr(addr); 78*839c4e9cSBin Meng 792e192b24SSimon Glass phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff); 802e192b24SSimon Glass 812e192b24SSimon Glass /* Load each program header */ 822e192b24SSimon Glass for (i = 0; i < ehdr->e_phnum; ++i) { 832e192b24SSimon Glass void *dst = (void *)(uintptr_t)phdr->p_paddr; 842e192b24SSimon Glass void *src = (void *)addr + phdr->p_offset; 85*839c4e9cSBin Meng 862e192b24SSimon Glass debug("Loading phdr %i to 0x%p (%i bytes)\n", 872e192b24SSimon Glass i, dst, phdr->p_filesz); 882e192b24SSimon Glass if (phdr->p_filesz) 892e192b24SSimon Glass memcpy(dst, src, phdr->p_filesz); 902e192b24SSimon Glass if (phdr->p_filesz != phdr->p_memsz) 912e192b24SSimon Glass memset(dst + phdr->p_filesz, 0x00, 922e192b24SSimon Glass phdr->p_memsz - phdr->p_filesz); 932e192b24SSimon Glass flush_cache((unsigned long)dst, phdr->p_filesz); 942e192b24SSimon Glass ++phdr; 952e192b24SSimon Glass } 962e192b24SSimon Glass 972e192b24SSimon Glass return ehdr->e_entry; 982e192b24SSimon Glass } 992e192b24SSimon Glass 1002e192b24SSimon Glass static unsigned long load_elf_image_shdr(unsigned long addr) 1012e192b24SSimon Glass { 1022e192b24SSimon Glass Elf32_Ehdr *ehdr; /* Elf header structure pointer */ 1032e192b24SSimon Glass Elf32_Shdr *shdr; /* Section header structure pointer */ 1042e192b24SSimon Glass unsigned char *strtab = 0; /* String table pointer */ 1052e192b24SSimon Glass unsigned char *image; /* Binary image pointer */ 1062e192b24SSimon Glass int i; /* Loop counter */ 1072e192b24SSimon Glass 1082e192b24SSimon Glass ehdr = (Elf32_Ehdr *)addr; 1092e192b24SSimon Glass 1102e192b24SSimon Glass /* Find the section header string table for output info */ 1112e192b24SSimon Glass shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff + 1122e192b24SSimon Glass (ehdr->e_shstrndx * sizeof(Elf32_Shdr))); 1132e192b24SSimon Glass 1142e192b24SSimon Glass if (shdr->sh_type == SHT_STRTAB) 1152e192b24SSimon Glass strtab = (unsigned char *)(addr + shdr->sh_offset); 1162e192b24SSimon Glass 1172e192b24SSimon Glass /* Load each appropriate section */ 1182e192b24SSimon Glass for (i = 0; i < ehdr->e_shnum; ++i) { 1192e192b24SSimon Glass shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff + 1202e192b24SSimon Glass (i * sizeof(Elf32_Shdr))); 1212e192b24SSimon Glass 1222e192b24SSimon Glass if (!(shdr->sh_flags & SHF_ALLOC) || 1232e192b24SSimon Glass shdr->sh_addr == 0 || shdr->sh_size == 0) { 1242e192b24SSimon Glass continue; 1252e192b24SSimon Glass } 1262e192b24SSimon Glass 1272e192b24SSimon Glass if (strtab) { 1282e192b24SSimon Glass debug("%sing %s @ 0x%08lx (%ld bytes)\n", 1292e192b24SSimon Glass (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load", 1302e192b24SSimon Glass &strtab[shdr->sh_name], 1312e192b24SSimon Glass (unsigned long)shdr->sh_addr, 1322e192b24SSimon Glass (long)shdr->sh_size); 1332e192b24SSimon Glass } 1342e192b24SSimon Glass 1352e192b24SSimon Glass if (shdr->sh_type == SHT_NOBITS) { 1362e192b24SSimon Glass memset((void *)(uintptr_t)shdr->sh_addr, 0, 1372e192b24SSimon Glass shdr->sh_size); 1382e192b24SSimon Glass } else { 1392e192b24SSimon Glass image = (unsigned char *)addr + shdr->sh_offset; 1402e192b24SSimon Glass memcpy((void *)(uintptr_t)shdr->sh_addr, 1412e192b24SSimon Glass (const void *)image, shdr->sh_size); 1422e192b24SSimon Glass } 1432e192b24SSimon Glass flush_cache(shdr->sh_addr, shdr->sh_size); 1442e192b24SSimon Glass } 1452e192b24SSimon Glass 1462e192b24SSimon Glass return ehdr->e_entry; 1472e192b24SSimon Glass } 1482e192b24SSimon Glass 1492e192b24SSimon Glass /* Allow ports to override the default behavior */ 1502e192b24SSimon Glass static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), 1512e192b24SSimon Glass int argc, char * const argv[]) 1522e192b24SSimon Glass { 1532e192b24SSimon Glass unsigned long ret; 1542e192b24SSimon Glass 1552e192b24SSimon Glass /* 1562e192b24SSimon Glass * pass address parameter as argv[0] (aka command name), 1572e192b24SSimon Glass * and all remaining args 1582e192b24SSimon Glass */ 1592e192b24SSimon Glass ret = entry(argc, argv); 1602e192b24SSimon Glass 1612e192b24SSimon Glass return ret; 1622e192b24SSimon Glass } 1632e192b24SSimon Glass 1642e192b24SSimon Glass /* 1652e192b24SSimon Glass * Determine if a valid ELF image exists at the given memory location. 1662e192b24SSimon Glass * First look at the ELF header magic field, then make sure that it is 1672e192b24SSimon Glass * executable. 1682e192b24SSimon Glass */ 1692e192b24SSimon Glass int valid_elf_image(unsigned long addr) 1702e192b24SSimon Glass { 1712e192b24SSimon Glass Elf32_Ehdr *ehdr; /* Elf header structure pointer */ 1722e192b24SSimon Glass 1732e192b24SSimon Glass ehdr = (Elf32_Ehdr *)addr; 1742e192b24SSimon Glass 1752e192b24SSimon Glass if (!IS_ELF(*ehdr)) { 1762e192b24SSimon Glass printf("## No elf image at address 0x%08lx\n", addr); 1772e192b24SSimon Glass return 0; 1782e192b24SSimon Glass } 1792e192b24SSimon Glass 1802e192b24SSimon Glass if (ehdr->e_type != ET_EXEC) { 1812e192b24SSimon Glass printf("## Not a 32-bit elf image at address 0x%08lx\n", addr); 1822e192b24SSimon Glass return 0; 1832e192b24SSimon Glass } 1842e192b24SSimon Glass 1852e192b24SSimon Glass return 1; 1862e192b24SSimon Glass } 1872e192b24SSimon Glass 1882e192b24SSimon Glass /* Interpreter command to boot an arbitrary ELF image from memory */ 1892e192b24SSimon Glass int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 1902e192b24SSimon Glass { 1912e192b24SSimon Glass unsigned long addr; /* Address of the ELF image */ 1922e192b24SSimon Glass unsigned long rc; /* Return value from user code */ 193be1b8679STom Rini char *sload = NULL; 19400caae6dSSimon Glass const char *ep = env_get("autostart"); 1952e192b24SSimon Glass int rcode = 0; 1962e192b24SSimon Glass 197be1b8679STom Rini /* Consume 'bootelf' */ 198be1b8679STom Rini argc--; argv++; 1992e192b24SSimon Glass 200be1b8679STom Rini /* Check for flag. */ 201be1b8679STom Rini if (argc >= 1 && (argv[0][0] == '-' && \ 202be1b8679STom Rini (argv[0][1] == 'p' || argv[0][1] == 's'))) { 203be1b8679STom Rini sload = argv[0]; 204be1b8679STom Rini /* Consume flag. */ 205be1b8679STom Rini argc--; argv++; 206be1b8679STom Rini } 207be1b8679STom Rini /* Check for address. */ 208be1b8679STom Rini if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) { 209be1b8679STom Rini /* Consume address */ 210be1b8679STom Rini argc--; argv++; 211be1b8679STom Rini } else 2122e192b24SSimon Glass addr = load_addr; 2132e192b24SSimon Glass 2142e192b24SSimon Glass if (!valid_elf_image(addr)) 2152e192b24SSimon Glass return 1; 2162e192b24SSimon Glass 2172e192b24SSimon Glass if (sload && sload[1] == 'p') 2182e192b24SSimon Glass addr = load_elf_image_phdr(addr); 2192e192b24SSimon Glass else 2202e192b24SSimon Glass addr = load_elf_image_shdr(addr); 2212e192b24SSimon Glass 2222e192b24SSimon Glass if (ep && !strcmp(ep, "no")) 2232e192b24SSimon Glass return rcode; 2242e192b24SSimon Glass 2252e192b24SSimon Glass printf("## Starting application at 0x%08lx ...\n", addr); 2262e192b24SSimon Glass 2272e192b24SSimon Glass /* 2282e192b24SSimon Glass * pass address parameter as argv[0] (aka command name), 2292e192b24SSimon Glass * and all remaining args 2302e192b24SSimon Glass */ 231be1b8679STom Rini rc = do_bootelf_exec((void *)addr, argc, argv); 2322e192b24SSimon Glass if (rc != 0) 2332e192b24SSimon Glass rcode = 1; 2342e192b24SSimon Glass 2352e192b24SSimon Glass printf("## Application terminated, rc = 0x%lx\n", rc); 2362e192b24SSimon Glass 2372e192b24SSimon Glass return rcode; 2382e192b24SSimon Glass } 2392e192b24SSimon Glass 2402e192b24SSimon Glass /* 2412e192b24SSimon Glass * Interpreter command to boot VxWorks from a memory image. The image can 2422e192b24SSimon Glass * be either an ELF image or a raw binary. Will attempt to setup the 2432e192b24SSimon Glass * bootline and other parameters correctly. 2442e192b24SSimon Glass */ 2452e192b24SSimon Glass int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 2462e192b24SSimon Glass { 2472e192b24SSimon Glass unsigned long addr; /* Address of image */ 2482e192b24SSimon Glass unsigned long bootaddr; /* Address to put the bootline */ 2492e192b24SSimon Glass char *bootline; /* Text of the bootline */ 2502e192b24SSimon Glass char *tmp; /* Temporary char pointer */ 2512e192b24SSimon Glass char build_buf[128]; /* Buffer for building the bootline */ 2522e192b24SSimon Glass int ptr = 0; 2532e192b24SSimon Glass #ifdef CONFIG_X86 2542902be86SBin Meng ulong base; 255fa5e91f7SBin Meng struct e820_info *info; 25645519924SBin Meng struct e820_entry *data; 2572e192b24SSimon Glass #endif 2582e192b24SSimon Glass 2592e192b24SSimon Glass /* 2602e192b24SSimon Glass * Check the loadaddr variable. 2612e192b24SSimon Glass * If we don't know where the image is then we're done. 2622e192b24SSimon Glass */ 2632e192b24SSimon Glass if (argc < 2) 2642e192b24SSimon Glass addr = load_addr; 2652e192b24SSimon Glass else 2662e192b24SSimon Glass addr = simple_strtoul(argv[1], NULL, 16); 2672e192b24SSimon Glass 2682e192b24SSimon Glass #if defined(CONFIG_CMD_NET) 2692e192b24SSimon Glass /* 2702e192b24SSimon Glass * Check to see if we need to tftp the image ourselves 2712e192b24SSimon Glass * before starting 2722e192b24SSimon Glass */ 2732e192b24SSimon Glass if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) { 2742e192b24SSimon Glass if (net_loop(TFTPGET) <= 0) 2752e192b24SSimon Glass return 1; 2762e192b24SSimon Glass printf("Automatic boot of VxWorks image at address 0x%08lx ...\n", 2772e192b24SSimon Glass addr); 2782e192b24SSimon Glass } 2792e192b24SSimon Glass #endif 2802e192b24SSimon Glass 2812e192b24SSimon Glass /* 2822e192b24SSimon Glass * This should equate to 2832e192b24SSimon Glass * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET 2842e192b24SSimon Glass * from the VxWorks BSP header files. 2852e192b24SSimon Glass * This will vary from board to board 2862e192b24SSimon Glass */ 2878996975fSTuomas Tynkkynen #if defined(CONFIG_SYS_VXWORKS_MAC_PTR) 2882e192b24SSimon Glass tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR; 28935affd7aSSimon Glass eth_env_get_enetaddr("ethaddr", (uchar *)build_buf); 2902e192b24SSimon Glass memcpy(tmp, build_buf, 6); 2912e192b24SSimon Glass #else 2922e192b24SSimon Glass puts("## Ethernet MAC address not copied to NV RAM\n"); 2932e192b24SSimon Glass #endif 2942e192b24SSimon Glass 2952e192b24SSimon Glass /* 2962e192b24SSimon Glass * Use bootaddr to find the location in memory that VxWorks 2972e192b24SSimon Glass * will look for the bootline string. The default value is 2982e192b24SSimon Glass * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by 2992e192b24SSimon Glass * VxWorks BSP. For example, on PowerPC it defaults to 0x4200. 3002e192b24SSimon Glass */ 30100caae6dSSimon Glass tmp = env_get("bootaddr"); 3022e192b24SSimon Glass if (!tmp) { 3032e192b24SSimon Glass printf("## VxWorks bootline address not specified\n"); 3042e192b24SSimon Glass } else { 3052e192b24SSimon Glass bootaddr = simple_strtoul(tmp, NULL, 16); 3062e192b24SSimon Glass 3072e192b24SSimon Glass /* 3082e192b24SSimon Glass * Check to see if the bootline is defined in the 'bootargs' 3092e192b24SSimon Glass * parameter. If it is not defined, we may be able to 3102e192b24SSimon Glass * construct the info. 3112e192b24SSimon Glass */ 31200caae6dSSimon Glass bootline = env_get("bootargs"); 3132e192b24SSimon Glass if (bootline) { 3142e192b24SSimon Glass memcpy((void *)bootaddr, bootline, 3152e192b24SSimon Glass max(strlen(bootline), (size_t)255)); 3162e192b24SSimon Glass flush_cache(bootaddr, max(strlen(bootline), 3172e192b24SSimon Glass (size_t)255)); 3182e192b24SSimon Glass } else { 31900caae6dSSimon Glass tmp = env_get("bootdev"); 3202e192b24SSimon Glass if (tmp) { 3212e192b24SSimon Glass strcpy(build_buf, tmp); 3222e192b24SSimon Glass ptr = strlen(tmp); 3232e192b24SSimon Glass } else 3242e192b24SSimon Glass printf("## VxWorks boot device not specified\n"); 3252e192b24SSimon Glass 32600caae6dSSimon Glass tmp = env_get("bootfile"); 3272e192b24SSimon Glass if (tmp) 3282e192b24SSimon Glass ptr += sprintf(build_buf + ptr, 3292e192b24SSimon Glass "host:%s ", tmp); 3302e192b24SSimon Glass else 3312e192b24SSimon Glass ptr += sprintf(build_buf + ptr, 3322e192b24SSimon Glass "host:vxWorks "); 3332e192b24SSimon Glass 3342e192b24SSimon Glass /* 3352e192b24SSimon Glass * The following parameters are only needed if 'bootdev' 3362e192b24SSimon Glass * is an ethernet device, otherwise they are optional. 3372e192b24SSimon Glass */ 33800caae6dSSimon Glass tmp = env_get("ipaddr"); 3392e192b24SSimon Glass if (tmp) { 3402e192b24SSimon Glass ptr += sprintf(build_buf + ptr, "e=%s", tmp); 34100caae6dSSimon Glass tmp = env_get("netmask"); 3422e192b24SSimon Glass if (tmp) { 343723806ccSSimon Glass u32 mask = env_get_ip("netmask").s_addr; 3442e192b24SSimon Glass ptr += sprintf(build_buf + ptr, 3452e192b24SSimon Glass ":%08x ", ntohl(mask)); 3462e192b24SSimon Glass } else { 3472e192b24SSimon Glass ptr += sprintf(build_buf + ptr, " "); 3482e192b24SSimon Glass } 3492e192b24SSimon Glass } 3502e192b24SSimon Glass 35100caae6dSSimon Glass tmp = env_get("serverip"); 3522e192b24SSimon Glass if (tmp) 3532e192b24SSimon Glass ptr += sprintf(build_buf + ptr, "h=%s ", tmp); 3542e192b24SSimon Glass 35500caae6dSSimon Glass tmp = env_get("gatewayip"); 3562e192b24SSimon Glass if (tmp) 3572e192b24SSimon Glass ptr += sprintf(build_buf + ptr, "g=%s ", tmp); 3582e192b24SSimon Glass 35900caae6dSSimon Glass tmp = env_get("hostname"); 3602e192b24SSimon Glass if (tmp) 3612e192b24SSimon Glass ptr += sprintf(build_buf + ptr, "tn=%s ", tmp); 3622e192b24SSimon Glass 36300caae6dSSimon Glass tmp = env_get("othbootargs"); 3642e192b24SSimon Glass if (tmp) { 3652e192b24SSimon Glass strcpy(build_buf + ptr, tmp); 3662e192b24SSimon Glass ptr += strlen(tmp); 3672e192b24SSimon Glass } 3682e192b24SSimon Glass 3692e192b24SSimon Glass memcpy((void *)bootaddr, build_buf, 3702e192b24SSimon Glass max(strlen(build_buf), (size_t)255)); 3712e192b24SSimon Glass flush_cache(bootaddr, max(strlen(build_buf), 3722e192b24SSimon Glass (size_t)255)); 3732e192b24SSimon Glass } 3742e192b24SSimon Glass 3752e192b24SSimon Glass printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, 3762e192b24SSimon Glass (char *)bootaddr); 3772e192b24SSimon Glass } 3782e192b24SSimon Glass 3792e192b24SSimon Glass #ifdef CONFIG_X86 3802e192b24SSimon Glass /* 3812902be86SBin Meng * Get VxWorks's physical memory base address from environment, 3822902be86SBin Meng * if we don't specify it in the environment, use a default one. 3832e192b24SSimon Glass */ 3842902be86SBin Meng base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE); 38545519924SBin Meng data = (struct e820_entry *)(base + E820_DATA_OFFSET); 386fa5e91f7SBin Meng info = (struct e820_info *)(base + E820_INFO_OFFSET); 3872e192b24SSimon Glass 388fa5e91f7SBin Meng memset(info, 0, sizeof(struct e820_info)); 3892e192b24SSimon Glass info->sign = E820_SIGNATURE; 3902e192b24SSimon Glass info->entries = install_e820_map(E820MAX, data); 39145519924SBin Meng info->addr = (info->entries - 1) * sizeof(struct e820_entry) + 3922902be86SBin Meng E820_DATA_OFFSET; 3931351700cSBin Meng 3941351700cSBin Meng /* 3951351700cSBin Meng * Explicitly clear the bootloader image size otherwise if memory 3961351700cSBin Meng * at this offset happens to contain some garbage data, the final 3971351700cSBin Meng * available memory size for the kernel is insane. 3981351700cSBin Meng */ 3991351700cSBin Meng *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0; 4002e192b24SSimon Glass #endif 4012e192b24SSimon Glass 4022e192b24SSimon Glass /* 4032e192b24SSimon Glass * If the data at the load address is an elf image, then 4042e192b24SSimon Glass * treat it like an elf image. Otherwise, assume that it is a 4052e192b24SSimon Glass * binary image. 4062e192b24SSimon Glass */ 4072e192b24SSimon Glass if (valid_elf_image(addr)) 408476c2fcdSChristian Gmeiner addr = load_elf_image_phdr(addr); 4092e192b24SSimon Glass else 4102e192b24SSimon Glass puts("## Not an ELF image, assuming binary\n"); 4112e192b24SSimon Glass 4122e192b24SSimon Glass printf("## Starting vxWorks at 0x%08lx ...\n", addr); 4132e192b24SSimon Glass 4142e192b24SSimon Glass dcache_disable(); 4153194daa1SVasyl Vavrychuk #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI) 4163194daa1SVasyl Vavrychuk armv8_setup_psci(); 4173194daa1SVasyl Vavrychuk smp_kick_all_cpus(); 4183194daa1SVasyl Vavrychuk #endif 4193194daa1SVasyl Vavrychuk 4202e192b24SSimon Glass #ifdef CONFIG_X86 4212e192b24SSimon Glass /* VxWorks on x86 uses stack to pass parameters */ 4222e192b24SSimon Glass ((asmlinkage void (*)(int))addr)(0); 4232e192b24SSimon Glass #else 4242e192b24SSimon Glass ((void (*)(int))addr)(0); 4252e192b24SSimon Glass #endif 4262e192b24SSimon Glass 4272e192b24SSimon Glass puts("## vxWorks terminated\n"); 4282e192b24SSimon Glass 4292e192b24SSimon Glass return 1; 4302e192b24SSimon Glass } 4312e192b24SSimon Glass 4322e192b24SSimon Glass U_BOOT_CMD( 433be1b8679STom Rini bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf, 4342e192b24SSimon Glass "Boot from an ELF image in memory", 4352e192b24SSimon Glass "[-p|-s] [address]\n" 4362e192b24SSimon Glass "\t- load ELF image at [address] via program headers (-p)\n" 4372e192b24SSimon Glass "\t or via section headers (-s)" 4382e192b24SSimon Glass ); 4392e192b24SSimon Glass 4402e192b24SSimon Glass U_BOOT_CMD( 4412e192b24SSimon Glass bootvx, 2, 0, do_bootvx, 4422e192b24SSimon Glass "Boot vxWorks from an ELF image", 4432e192b24SSimon Glass " [address] - load address of vxWorks ELF image." 4442e192b24SSimon Glass ); 445