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 23447ae4f7SBin Meng #include <vbe.h> 242e192b24SSimon Glass #include <asm/e820.h> 252e192b24SSimon Glass #include <linux/linkage.h> 262e192b24SSimon Glass #endif 272e192b24SSimon Glass 282e192b24SSimon Glass /* 29839c4e9cSBin Meng * A very simple ELF64 loader, assumes the image is valid, returns the 302e192b24SSimon Glass * entry point address. 31839c4e9cSBin Meng * 32839c4e9cSBin Meng * Note if U-Boot is 32-bit, the loader assumes the to segment's 33839c4e9cSBin Meng * physical address and size is within the lower 32-bit address space. 34839c4e9cSBin Meng */ 35839c4e9cSBin Meng static unsigned long load_elf64_image_phdr(unsigned long addr) 36839c4e9cSBin Meng { 37839c4e9cSBin Meng Elf64_Ehdr *ehdr; /* Elf header structure pointer */ 38839c4e9cSBin Meng Elf64_Phdr *phdr; /* Program header structure pointer */ 39839c4e9cSBin Meng int i; 40839c4e9cSBin Meng 41839c4e9cSBin Meng ehdr = (Elf64_Ehdr *)addr; 42839c4e9cSBin Meng phdr = (Elf64_Phdr *)(addr + (ulong)ehdr->e_phoff); 43839c4e9cSBin Meng 44839c4e9cSBin Meng /* Load each program header */ 45839c4e9cSBin Meng for (i = 0; i < ehdr->e_phnum; ++i) { 46839c4e9cSBin Meng void *dst = (void *)(ulong)phdr->p_paddr; 47839c4e9cSBin Meng void *src = (void *)addr + phdr->p_offset; 48839c4e9cSBin Meng 49839c4e9cSBin Meng debug("Loading phdr %i to 0x%p (%lu bytes)\n", 50839c4e9cSBin Meng i, dst, (ulong)phdr->p_filesz); 51839c4e9cSBin Meng if (phdr->p_filesz) 52839c4e9cSBin Meng memcpy(dst, src, phdr->p_filesz); 53839c4e9cSBin Meng if (phdr->p_filesz != phdr->p_memsz) 54839c4e9cSBin Meng memset(dst + phdr->p_filesz, 0x00, 55839c4e9cSBin Meng phdr->p_memsz - phdr->p_filesz); 56839c4e9cSBin Meng flush_cache((unsigned long)dst, phdr->p_filesz); 57839c4e9cSBin Meng ++phdr; 58839c4e9cSBin Meng } 59839c4e9cSBin Meng 60839c4e9cSBin Meng return ehdr->e_entry; 61839c4e9cSBin Meng } 62839c4e9cSBin Meng 63839c4e9cSBin Meng /* 64839c4e9cSBin Meng * A very simple ELF loader, assumes the image is valid, returns the 65839c4e9cSBin Meng * entry point address. 66839c4e9cSBin Meng * 67839c4e9cSBin Meng * The loader firstly reads the EFI class to see if it's a 64-bit image. 68839c4e9cSBin Meng * If yes, call the ELF64 loader. Otherwise continue with the ELF32 loader. 692e192b24SSimon Glass */ 702e192b24SSimon Glass static unsigned long load_elf_image_phdr(unsigned long addr) 712e192b24SSimon Glass { 722e192b24SSimon Glass Elf32_Ehdr *ehdr; /* Elf header structure pointer */ 732e192b24SSimon Glass Elf32_Phdr *phdr; /* Program header structure pointer */ 742e192b24SSimon Glass int i; 752e192b24SSimon Glass 762e192b24SSimon Glass ehdr = (Elf32_Ehdr *)addr; 77839c4e9cSBin Meng if (ehdr->e_ident[EI_CLASS] == ELFCLASS64) 78839c4e9cSBin Meng return load_elf64_image_phdr(addr); 79839c4e9cSBin Meng 802e192b24SSimon Glass phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff); 812e192b24SSimon Glass 822e192b24SSimon Glass /* Load each program header */ 832e192b24SSimon Glass for (i = 0; i < ehdr->e_phnum; ++i) { 842e192b24SSimon Glass void *dst = (void *)(uintptr_t)phdr->p_paddr; 852e192b24SSimon Glass void *src = (void *)addr + phdr->p_offset; 86839c4e9cSBin Meng 872e192b24SSimon Glass debug("Loading phdr %i to 0x%p (%i bytes)\n", 882e192b24SSimon Glass i, dst, phdr->p_filesz); 892e192b24SSimon Glass if (phdr->p_filesz) 902e192b24SSimon Glass memcpy(dst, src, phdr->p_filesz); 912e192b24SSimon Glass if (phdr->p_filesz != phdr->p_memsz) 922e192b24SSimon Glass memset(dst + phdr->p_filesz, 0x00, 932e192b24SSimon Glass phdr->p_memsz - phdr->p_filesz); 942e192b24SSimon Glass flush_cache((unsigned long)dst, phdr->p_filesz); 952e192b24SSimon Glass ++phdr; 962e192b24SSimon Glass } 972e192b24SSimon Glass 982e192b24SSimon Glass return ehdr->e_entry; 992e192b24SSimon Glass } 1002e192b24SSimon Glass 1012e192b24SSimon Glass static unsigned long load_elf_image_shdr(unsigned long addr) 1022e192b24SSimon Glass { 1032e192b24SSimon Glass Elf32_Ehdr *ehdr; /* Elf header structure pointer */ 1042e192b24SSimon Glass Elf32_Shdr *shdr; /* Section header structure pointer */ 1052e192b24SSimon Glass unsigned char *strtab = 0; /* String table pointer */ 1062e192b24SSimon Glass unsigned char *image; /* Binary image pointer */ 1072e192b24SSimon Glass int i; /* Loop counter */ 1082e192b24SSimon Glass 1092e192b24SSimon Glass ehdr = (Elf32_Ehdr *)addr; 1102e192b24SSimon Glass 1112e192b24SSimon Glass /* Find the section header string table for output info */ 1122e192b24SSimon Glass shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff + 1132e192b24SSimon Glass (ehdr->e_shstrndx * sizeof(Elf32_Shdr))); 1142e192b24SSimon Glass 1152e192b24SSimon Glass if (shdr->sh_type == SHT_STRTAB) 1162e192b24SSimon Glass strtab = (unsigned char *)(addr + shdr->sh_offset); 1172e192b24SSimon Glass 1182e192b24SSimon Glass /* Load each appropriate section */ 1192e192b24SSimon Glass for (i = 0; i < ehdr->e_shnum; ++i) { 1202e192b24SSimon Glass shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff + 1212e192b24SSimon Glass (i * sizeof(Elf32_Shdr))); 1222e192b24SSimon Glass 1232e192b24SSimon Glass if (!(shdr->sh_flags & SHF_ALLOC) || 1242e192b24SSimon Glass shdr->sh_addr == 0 || shdr->sh_size == 0) { 1252e192b24SSimon Glass continue; 1262e192b24SSimon Glass } 1272e192b24SSimon Glass 1282e192b24SSimon Glass if (strtab) { 1292e192b24SSimon Glass debug("%sing %s @ 0x%08lx (%ld bytes)\n", 1302e192b24SSimon Glass (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load", 1312e192b24SSimon Glass &strtab[shdr->sh_name], 1322e192b24SSimon Glass (unsigned long)shdr->sh_addr, 1332e192b24SSimon Glass (long)shdr->sh_size); 1342e192b24SSimon Glass } 1352e192b24SSimon Glass 1362e192b24SSimon Glass if (shdr->sh_type == SHT_NOBITS) { 1372e192b24SSimon Glass memset((void *)(uintptr_t)shdr->sh_addr, 0, 1382e192b24SSimon Glass shdr->sh_size); 1392e192b24SSimon Glass } else { 1402e192b24SSimon Glass image = (unsigned char *)addr + shdr->sh_offset; 1412e192b24SSimon Glass memcpy((void *)(uintptr_t)shdr->sh_addr, 1422e192b24SSimon Glass (const void *)image, shdr->sh_size); 1432e192b24SSimon Glass } 1442e192b24SSimon Glass flush_cache(shdr->sh_addr, shdr->sh_size); 1452e192b24SSimon Glass } 1462e192b24SSimon Glass 1472e192b24SSimon Glass return ehdr->e_entry; 1482e192b24SSimon Glass } 1492e192b24SSimon Glass 1502e192b24SSimon Glass /* Allow ports to override the default behavior */ 1512e192b24SSimon Glass static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), 1522e192b24SSimon Glass int argc, char * const argv[]) 1532e192b24SSimon Glass { 1542e192b24SSimon Glass unsigned long ret; 1552e192b24SSimon Glass 1562e192b24SSimon Glass /* 1572e192b24SSimon Glass * pass address parameter as argv[0] (aka command name), 1582e192b24SSimon Glass * and all remaining args 1592e192b24SSimon Glass */ 1602e192b24SSimon Glass ret = entry(argc, argv); 1612e192b24SSimon Glass 1622e192b24SSimon Glass return ret; 1632e192b24SSimon Glass } 1642e192b24SSimon Glass 1652e192b24SSimon Glass /* 1662e192b24SSimon Glass * Determine if a valid ELF image exists at the given memory location. 1672e192b24SSimon Glass * First look at the ELF header magic field, then make sure that it is 1682e192b24SSimon Glass * executable. 1692e192b24SSimon Glass */ 1702e192b24SSimon Glass int valid_elf_image(unsigned long addr) 1712e192b24SSimon Glass { 1722e192b24SSimon Glass Elf32_Ehdr *ehdr; /* Elf header structure pointer */ 1732e192b24SSimon Glass 1742e192b24SSimon Glass ehdr = (Elf32_Ehdr *)addr; 1752e192b24SSimon Glass 1762e192b24SSimon Glass if (!IS_ELF(*ehdr)) { 1772e192b24SSimon Glass printf("## No elf image at address 0x%08lx\n", addr); 1782e192b24SSimon Glass return 0; 1792e192b24SSimon Glass } 1802e192b24SSimon Glass 1812e192b24SSimon Glass if (ehdr->e_type != ET_EXEC) { 1822e192b24SSimon Glass printf("## Not a 32-bit elf image at address 0x%08lx\n", addr); 1832e192b24SSimon Glass return 0; 1842e192b24SSimon Glass } 1852e192b24SSimon Glass 1862e192b24SSimon Glass return 1; 1872e192b24SSimon Glass } 1882e192b24SSimon Glass 1892e192b24SSimon Glass /* Interpreter command to boot an arbitrary ELF image from memory */ 1902e192b24SSimon Glass int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 1912e192b24SSimon Glass { 1922e192b24SSimon Glass unsigned long addr; /* Address of the ELF image */ 1932e192b24SSimon Glass unsigned long rc; /* Return value from user code */ 194be1b8679STom Rini char *sload = NULL; 19500caae6dSSimon Glass const char *ep = env_get("autostart"); 1962e192b24SSimon Glass int rcode = 0; 1972e192b24SSimon Glass 198be1b8679STom Rini /* Consume 'bootelf' */ 199be1b8679STom Rini argc--; argv++; 2002e192b24SSimon Glass 201be1b8679STom Rini /* Check for flag. */ 202be1b8679STom Rini if (argc >= 1 && (argv[0][0] == '-' && \ 203be1b8679STom Rini (argv[0][1] == 'p' || argv[0][1] == 's'))) { 204be1b8679STom Rini sload = argv[0]; 205be1b8679STom Rini /* Consume flag. */ 206be1b8679STom Rini argc--; argv++; 207be1b8679STom Rini } 208be1b8679STom Rini /* Check for address. */ 209be1b8679STom Rini if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) { 210be1b8679STom Rini /* Consume address */ 211be1b8679STom Rini argc--; argv++; 212be1b8679STom Rini } else 2132e192b24SSimon Glass addr = load_addr; 2142e192b24SSimon Glass 2152e192b24SSimon Glass if (!valid_elf_image(addr)) 2162e192b24SSimon Glass return 1; 2172e192b24SSimon Glass 2182e192b24SSimon Glass if (sload && sload[1] == 'p') 2192e192b24SSimon Glass addr = load_elf_image_phdr(addr); 2202e192b24SSimon Glass else 2212e192b24SSimon Glass addr = load_elf_image_shdr(addr); 2222e192b24SSimon Glass 2232e192b24SSimon Glass if (ep && !strcmp(ep, "no")) 2242e192b24SSimon Glass return rcode; 2252e192b24SSimon Glass 2262e192b24SSimon Glass printf("## Starting application at 0x%08lx ...\n", addr); 2272e192b24SSimon Glass 2282e192b24SSimon Glass /* 2292e192b24SSimon Glass * pass address parameter as argv[0] (aka command name), 2302e192b24SSimon Glass * and all remaining args 2312e192b24SSimon Glass */ 232be1b8679STom Rini rc = do_bootelf_exec((void *)addr, argc, argv); 2332e192b24SSimon Glass if (rc != 0) 2342e192b24SSimon Glass rcode = 1; 2352e192b24SSimon Glass 2362e192b24SSimon Glass printf("## Application terminated, rc = 0x%lx\n", rc); 2372e192b24SSimon Glass 2382e192b24SSimon Glass return rcode; 2392e192b24SSimon Glass } 2402e192b24SSimon Glass 2412e192b24SSimon Glass /* 2422e192b24SSimon Glass * Interpreter command to boot VxWorks from a memory image. The image can 2432e192b24SSimon Glass * be either an ELF image or a raw binary. Will attempt to setup the 2442e192b24SSimon Glass * bootline and other parameters correctly. 2452e192b24SSimon Glass */ 2462e192b24SSimon Glass int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 2472e192b24SSimon Glass { 2482e192b24SSimon Glass unsigned long addr; /* Address of image */ 2492e192b24SSimon Glass unsigned long bootaddr; /* Address to put the bootline */ 2502e192b24SSimon Glass char *bootline; /* Text of the bootline */ 2512e192b24SSimon Glass char *tmp; /* Temporary char pointer */ 2522e192b24SSimon Glass char build_buf[128]; /* Buffer for building the bootline */ 2532e192b24SSimon Glass int ptr = 0; 2542e192b24SSimon Glass #ifdef CONFIG_X86 2552902be86SBin Meng ulong base; 256fa5e91f7SBin Meng struct e820_info *info; 25745519924SBin Meng struct e820_entry *data; 258447ae4f7SBin Meng struct efi_gop_info *gop; 259447ae4f7SBin Meng struct vesa_mode_info *vesa = &mode_info.vesa; 2602e192b24SSimon Glass #endif 2612e192b24SSimon Glass 2622e192b24SSimon Glass /* 2632e192b24SSimon Glass * Check the loadaddr variable. 2642e192b24SSimon Glass * If we don't know where the image is then we're done. 2652e192b24SSimon Glass */ 2662e192b24SSimon Glass if (argc < 2) 2672e192b24SSimon Glass addr = load_addr; 2682e192b24SSimon Glass else 2692e192b24SSimon Glass addr = simple_strtoul(argv[1], NULL, 16); 2702e192b24SSimon Glass 2712e192b24SSimon Glass #if defined(CONFIG_CMD_NET) 2722e192b24SSimon Glass /* 2732e192b24SSimon Glass * Check to see if we need to tftp the image ourselves 2742e192b24SSimon Glass * before starting 2752e192b24SSimon Glass */ 2762e192b24SSimon Glass if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) { 2772e192b24SSimon Glass if (net_loop(TFTPGET) <= 0) 2782e192b24SSimon Glass return 1; 2792e192b24SSimon Glass printf("Automatic boot of VxWorks image at address 0x%08lx ...\n", 2802e192b24SSimon Glass addr); 2812e192b24SSimon Glass } 2822e192b24SSimon Glass #endif 2832e192b24SSimon Glass 2842e192b24SSimon Glass /* 2852e192b24SSimon Glass * This should equate to 2862e192b24SSimon Glass * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET 2872e192b24SSimon Glass * from the VxWorks BSP header files. 2882e192b24SSimon Glass * This will vary from board to board 2892e192b24SSimon Glass */ 2908996975fSTuomas Tynkkynen #if defined(CONFIG_SYS_VXWORKS_MAC_PTR) 2912e192b24SSimon Glass tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR; 29235affd7aSSimon Glass eth_env_get_enetaddr("ethaddr", (uchar *)build_buf); 2932e192b24SSimon Glass memcpy(tmp, build_buf, 6); 2942e192b24SSimon Glass #else 2952e192b24SSimon Glass puts("## Ethernet MAC address not copied to NV RAM\n"); 2962e192b24SSimon Glass #endif 2972e192b24SSimon Glass 2982e192b24SSimon Glass /* 2992e192b24SSimon Glass * Use bootaddr to find the location in memory that VxWorks 3002e192b24SSimon Glass * will look for the bootline string. The default value is 3012e192b24SSimon Glass * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by 3022e192b24SSimon Glass * VxWorks BSP. For example, on PowerPC it defaults to 0x4200. 3032e192b24SSimon Glass */ 30400caae6dSSimon Glass tmp = env_get("bootaddr"); 3052e192b24SSimon Glass if (!tmp) { 3062e192b24SSimon Glass printf("## VxWorks bootline address not specified\n"); 3072e192b24SSimon Glass } else { 3082e192b24SSimon Glass bootaddr = simple_strtoul(tmp, NULL, 16); 3092e192b24SSimon Glass 3102e192b24SSimon Glass /* 3112e192b24SSimon Glass * Check to see if the bootline is defined in the 'bootargs' 3122e192b24SSimon Glass * parameter. If it is not defined, we may be able to 3132e192b24SSimon Glass * construct the info. 3142e192b24SSimon Glass */ 31500caae6dSSimon Glass bootline = env_get("bootargs"); 316*7824ad6aSBin Meng if (!bootline) { 31700caae6dSSimon Glass tmp = env_get("bootdev"); 3182e192b24SSimon Glass if (tmp) { 3192e192b24SSimon Glass strcpy(build_buf, tmp); 3202e192b24SSimon Glass ptr = strlen(tmp); 3212e192b24SSimon Glass } else 3222e192b24SSimon Glass printf("## VxWorks boot device not specified\n"); 3232e192b24SSimon Glass 32400caae6dSSimon Glass tmp = env_get("bootfile"); 3252e192b24SSimon Glass if (tmp) 3262e192b24SSimon Glass ptr += sprintf(build_buf + ptr, 3272e192b24SSimon Glass "host:%s ", tmp); 3282e192b24SSimon Glass else 3292e192b24SSimon Glass ptr += sprintf(build_buf + ptr, 3302e192b24SSimon Glass "host:vxWorks "); 3312e192b24SSimon Glass 3322e192b24SSimon Glass /* 3332e192b24SSimon Glass * The following parameters are only needed if 'bootdev' 3342e192b24SSimon Glass * is an ethernet device, otherwise they are optional. 3352e192b24SSimon Glass */ 33600caae6dSSimon Glass tmp = env_get("ipaddr"); 3372e192b24SSimon Glass if (tmp) { 3382e192b24SSimon Glass ptr += sprintf(build_buf + ptr, "e=%s", tmp); 33900caae6dSSimon Glass tmp = env_get("netmask"); 3402e192b24SSimon Glass if (tmp) { 341723806ccSSimon Glass u32 mask = env_get_ip("netmask").s_addr; 3422e192b24SSimon Glass ptr += sprintf(build_buf + ptr, 3432e192b24SSimon Glass ":%08x ", ntohl(mask)); 3442e192b24SSimon Glass } else { 3452e192b24SSimon Glass ptr += sprintf(build_buf + ptr, " "); 3462e192b24SSimon Glass } 3472e192b24SSimon Glass } 3482e192b24SSimon Glass 34900caae6dSSimon Glass tmp = env_get("serverip"); 3502e192b24SSimon Glass if (tmp) 3512e192b24SSimon Glass ptr += sprintf(build_buf + ptr, "h=%s ", tmp); 3522e192b24SSimon Glass 35300caae6dSSimon Glass tmp = env_get("gatewayip"); 3542e192b24SSimon Glass if (tmp) 3552e192b24SSimon Glass ptr += sprintf(build_buf + ptr, "g=%s ", tmp); 3562e192b24SSimon Glass 35700caae6dSSimon Glass tmp = env_get("hostname"); 3582e192b24SSimon Glass if (tmp) 3592e192b24SSimon Glass ptr += sprintf(build_buf + ptr, "tn=%s ", tmp); 3602e192b24SSimon Glass 36100caae6dSSimon Glass tmp = env_get("othbootargs"); 3622e192b24SSimon Glass if (tmp) { 3632e192b24SSimon Glass strcpy(build_buf + ptr, tmp); 3642e192b24SSimon Glass ptr += strlen(tmp); 3652e192b24SSimon Glass } 3662e192b24SSimon Glass 367*7824ad6aSBin Meng bootline = build_buf; 3682e192b24SSimon Glass } 3692e192b24SSimon Glass 370*7824ad6aSBin Meng memcpy((void *)bootaddr, bootline, 371*7824ad6aSBin Meng max(strlen(bootline), (size_t)255)); 372*7824ad6aSBin Meng flush_cache(bootaddr, max(strlen(bootline), (size_t)255)); 3732e192b24SSimon Glass printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, 3742e192b24SSimon Glass (char *)bootaddr); 3752e192b24SSimon Glass } 3762e192b24SSimon Glass 3772e192b24SSimon Glass #ifdef CONFIG_X86 3782e192b24SSimon Glass /* 3792902be86SBin Meng * Get VxWorks's physical memory base address from environment, 3802902be86SBin Meng * if we don't specify it in the environment, use a default one. 3812e192b24SSimon Glass */ 3822902be86SBin Meng base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE); 38345519924SBin Meng data = (struct e820_entry *)(base + E820_DATA_OFFSET); 384fa5e91f7SBin Meng info = (struct e820_info *)(base + E820_INFO_OFFSET); 3852e192b24SSimon Glass 386fa5e91f7SBin Meng memset(info, 0, sizeof(struct e820_info)); 3872e192b24SSimon Glass info->sign = E820_SIGNATURE; 3882e192b24SSimon Glass info->entries = install_e820_map(E820MAX, data); 38945519924SBin Meng info->addr = (info->entries - 1) * sizeof(struct e820_entry) + 3902902be86SBin Meng E820_DATA_OFFSET; 3911351700cSBin Meng 3921351700cSBin Meng /* 3931351700cSBin Meng * Explicitly clear the bootloader image size otherwise if memory 3941351700cSBin Meng * at this offset happens to contain some garbage data, the final 3951351700cSBin Meng * available memory size for the kernel is insane. 3961351700cSBin Meng */ 3971351700cSBin Meng *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0; 398447ae4f7SBin Meng 399447ae4f7SBin Meng /* 400447ae4f7SBin Meng * Prepare compatible framebuffer information block. 401447ae4f7SBin Meng * The VESA mode has to be 32-bit RGBA. 402447ae4f7SBin Meng */ 403447ae4f7SBin Meng if (vesa->x_resolution && vesa->y_resolution) { 404447ae4f7SBin Meng gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET); 405447ae4f7SBin Meng gop->magic = EFI_GOP_INFO_MAGIC; 406447ae4f7SBin Meng gop->info.version = 0; 407447ae4f7SBin Meng gop->info.width = vesa->x_resolution; 408447ae4f7SBin Meng gop->info.height = vesa->y_resolution; 409447ae4f7SBin Meng gop->info.pixel_format = EFI_GOT_RGBA8; 410447ae4f7SBin Meng gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4; 411447ae4f7SBin Meng gop->fb_base = vesa->phys_base_ptr; 412447ae4f7SBin Meng gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution; 413447ae4f7SBin Meng } 4142e192b24SSimon Glass #endif 4152e192b24SSimon Glass 4162e192b24SSimon Glass /* 4172e192b24SSimon Glass * If the data at the load address is an elf image, then 4182e192b24SSimon Glass * treat it like an elf image. Otherwise, assume that it is a 4192e192b24SSimon Glass * binary image. 4202e192b24SSimon Glass */ 4212e192b24SSimon Glass if (valid_elf_image(addr)) 422476c2fcdSChristian Gmeiner addr = load_elf_image_phdr(addr); 4232e192b24SSimon Glass else 4242e192b24SSimon Glass puts("## Not an ELF image, assuming binary\n"); 4252e192b24SSimon Glass 4262e192b24SSimon Glass printf("## Starting vxWorks at 0x%08lx ...\n", addr); 4272e192b24SSimon Glass 4282e192b24SSimon Glass dcache_disable(); 4293194daa1SVasyl Vavrychuk #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI) 4303194daa1SVasyl Vavrychuk armv8_setup_psci(); 4313194daa1SVasyl Vavrychuk smp_kick_all_cpus(); 4323194daa1SVasyl Vavrychuk #endif 4333194daa1SVasyl Vavrychuk 4342e192b24SSimon Glass #ifdef CONFIG_X86 4352e192b24SSimon Glass /* VxWorks on x86 uses stack to pass parameters */ 4362e192b24SSimon Glass ((asmlinkage void (*)(int))addr)(0); 4372e192b24SSimon Glass #else 4382e192b24SSimon Glass ((void (*)(int))addr)(0); 4392e192b24SSimon Glass #endif 4402e192b24SSimon Glass 4412e192b24SSimon Glass puts("## vxWorks terminated\n"); 4422e192b24SSimon Glass 4432e192b24SSimon Glass return 1; 4442e192b24SSimon Glass } 4452e192b24SSimon Glass 4462e192b24SSimon Glass U_BOOT_CMD( 447be1b8679STom Rini bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf, 4482e192b24SSimon Glass "Boot from an ELF image in memory", 4492e192b24SSimon Glass "[-p|-s] [address]\n" 4502e192b24SSimon Glass "\t- load ELF image at [address] via program headers (-p)\n" 4512e192b24SSimon Glass "\t or via section headers (-s)" 4522e192b24SSimon Glass ); 4532e192b24SSimon Glass 4542e192b24SSimon Glass U_BOOT_CMD( 4552e192b24SSimon Glass bootvx, 2, 0, do_bootvx, 4562e192b24SSimon Glass "Boot vxWorks from an ELF image", 4572e192b24SSimon Glass " [address] - load address of vxWorks ELF image." 4582e192b24SSimon Glass ); 459