diff options
Diffstat (limited to 'common')
41 files changed, 642 insertions, 287 deletions
diff --git a/common/Makefile b/common/Makefile index b19d3793b4..6cc4de8a73 100644 --- a/common/Makefile +++ b/common/Makefile @@ -233,6 +233,7 @@ obj-$(CONFIG_SPL_ENV_SUPPORT) += env_flags.o obj-$(CONFIG_SPL_ENV_SUPPORT) += env_callback.o obj-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o obj-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o +obj-$(CONFIG_ENV_IS_IN_FAT) += env_fat.o obj-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o obj-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o @@ -265,4 +266,6 @@ obj-y += aboot.o obj-y += fb_mmc.o endif +obj-$(CONFIG_CMD_BLOB) += cmd_blob.o + CFLAGS_env_embedded.o := -Wa,--no-warn -DENV_CRC=$(shell tools/envcrc 2>/dev/null) diff --git a/common/aboot.c b/common/aboot.c index d5c464bd7d..fba8e3e683 100644 --- a/common/aboot.c +++ b/common/aboot.c @@ -208,6 +208,7 @@ void write_sparse_image(block_dev_desc_t *dev_desc, break; case CHUNK_TYPE_DONT_CARE: + blk += blkcnt; total_blocks += chunk_header->chunk_sz; break; diff --git a/common/board_f.c b/common/board_f.c index e6aa298d5a..b5bebc9dc8 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -128,14 +128,11 @@ int init_func_watchdog_reset(void) } #endif /* CONFIG_WATCHDOG */ -void __board_add_ram_info(int use_default) +__weak void board_add_ram_info(int use_default) { /* please define platform specific board_add_ram_info() */ } -void board_add_ram_info(int) - __attribute__ ((weak, alias("__board_add_ram_info"))); - static int init_baud_rate(void) { gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); @@ -221,7 +218,7 @@ static int show_dram_config(void) return 0; } -void __dram_init_banksize(void) +__weak void dram_init_banksize(void) { #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE) gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; @@ -229,9 +226,6 @@ void __dram_init_banksize(void) #endif } -void dram_init_banksize(void) - __attribute__((weak, alias("__dram_init_banksize"))); - #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C) static int init_func_i2c(void) { diff --git a/common/board_r.c b/common/board_r.c index 7e1a76d97f..7c339008ed 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -60,7 +60,7 @@ DECLARE_GLOBAL_DATA_PTR; ulong monitor_flash_len; -int __board_flash_wp_on(void) +__weak int board_flash_wp_on(void) { /* * Most flashes can't be detected when write protection is enabled, @@ -70,16 +70,10 @@ int __board_flash_wp_on(void) return 0; } -int board_flash_wp_on(void) - __attribute__ ((weak, alias("__board_flash_wp_on"))); - -void __cpu_secondary_init_r(void) +__weak void cpu_secondary_init_r(void) { } -void cpu_secondary_init_r(void) - __attribute__ ((weak, alias("__cpu_secondary_init_r"))); - static int initr_secondary_cpu(void) { /* @@ -354,7 +348,7 @@ static int initr_flash(void) } #endif -#ifdef CONFIG_PPC +#if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI) static int initr_spi(void) { /* PPC does this here */ @@ -370,7 +364,7 @@ static int initr_spi(void) #ifdef CONFIG_CMD_NAND /* go init the NAND */ -int initr_nand(void) +static int initr_nand(void) { puts("NAND: "); nand_init(); @@ -380,7 +374,7 @@ int initr_nand(void) #if defined(CONFIG_CMD_ONENAND) /* go init the NAND */ -int initr_onenand(void) +static int initr_onenand(void) { puts("NAND: "); onenand_init(); @@ -389,7 +383,7 @@ int initr_onenand(void) #endif #ifdef CONFIG_GENERIC_MMC -int initr_mmc(void) +static int initr_mmc(void) { puts("MMC: "); mmc_initialize(gd->bd); @@ -398,7 +392,7 @@ int initr_mmc(void) #endif #ifdef CONFIG_HAS_DATAFLASH -int initr_dataflash(void) +static int initr_dataflash(void) { AT91F_DataflashInit(); dataflash_print_info(); diff --git a/common/bootm.c b/common/bootm.c index ff81a271a5..6b3ea8c61b 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -9,6 +9,7 @@ #include <common.h> #include <bootstage.h> #include <bzlib.h> +#include <errno.h> #include <fdt_support.h> #include <lmb.h> #include <malloc.h> @@ -83,6 +84,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc, { const void *os_hdr; bool ep_found = false; + int ret; /* get kernel image header, start address and length */ os_hdr = boot_get_kernel(cmdtp, flag, argc, argv, @@ -102,6 +104,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc, images.os.end = image_get_image_end(os_hdr); images.os.load = image_get_load(os_hdr); + images.os.arch = image_get_arch(os_hdr); break; #endif #if defined(CONFIG_FIT) @@ -129,6 +132,13 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc, return 1; } + if (fit_image_get_arch(images.fit_hdr_os, + images.fit_noffset_os, + &images.os.arch)) { + puts("Can't get image ARCH!\n"); + return 1; + } + images.os.end = fit_get_end(images.fit_hdr_os); if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os, @@ -144,11 +154,11 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc, images.os.type = IH_TYPE_KERNEL; images.os.comp = IH_COMP_NONE; images.os.os = IH_OS_LINUX; - images.ep = images.os.load; - ep_found = true; images.os.end = android_image_get_end(os_hdr); images.os.load = android_image_get_kload(os_hdr); + images.ep = images.os.load; + ep_found = true; break; #endif default: @@ -156,8 +166,18 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc, return 1; } - /* find kernel entry point */ - if (images.legacy_hdr_valid) { + /* If we have a valid setup.bin, we will use that for entry (x86) */ + if (images.os.arch == IH_ARCH_I386 || + images.os.arch == IH_ARCH_X86_64) { + ulong len; + + ret = boot_get_setup(&images, IH_ARCH_I386, &images.ep, &len); + if (ret < 0 && ret != -ENOENT) { + puts("Could not find a valid setup.bin for x86\n"); + return 1; + } + /* Kernel entry point is the setup.bin */ + } else if (images.legacy_hdr_valid) { images.ep = image_get_ep(&images.legacy_hdr_os_copy); #if defined(CONFIG_FIT) } else if (images.fit_uname_os) { diff --git a/common/cli.c b/common/cli.c index 272b0288d7..075ae9dc4a 100644 --- a/common/cli.c +++ b/common/cli.c @@ -36,8 +36,11 @@ int run_command(const char *cmd, int flag) return 0; #else - return parse_string_outer(cmd, - FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP); + int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP; + + if (flag & CMD_FLAG_ENV) + hush_flags |= FLAG_CONT_ON_NEWLINE; + return parse_string_outer(cmd, hush_flags); #endif } @@ -125,7 +128,7 @@ int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; } - if (run_command(arg, flag) != 0) + if (run_command(arg, flag | CMD_FLAG_ENV) != 0) return 1; } return 0; diff --git a/common/cli_hush.c b/common/cli_hush.c index 38da5a09fa..2b654b754f 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -3170,7 +3170,8 @@ static int parse_stream_outer(struct in_str *inp, int flag) update_ifs_map(); if (!(flag & FLAG_PARSE_SEMICOLON) || (flag & FLAG_REPARSING)) mapset((uchar *)";$&|", 0); inp->promptmode=1; - rcode = parse_stream(&temp, &ctx, inp, '\n'); + rcode = parse_stream(&temp, &ctx, inp, + flag & FLAG_CONT_ON_NEWLINE ? -1 : '\n'); #ifdef __U_BOOT__ if (rcode == 1) flag_repeat = 0; #endif diff --git a/common/cmd_blob.c b/common/cmd_blob.c new file mode 100644 index 0000000000..82ecaf09e5 --- /dev/null +++ b/common/cmd_blob.c @@ -0,0 +1,109 @@ +/* + * + * Command for encapsulating/decapsulating blob of memory. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <command.h> +#include <environment.h> +#include <malloc.h> +#include <asm/byteorder.h> +#include <linux/compiler.h> + +DECLARE_GLOBAL_DATA_PTR; + +/** + * blob_decap() - Decapsulate the data as a blob + * @key_mod: - Pointer to key modifier/key + * @src: - Address of data to be decapsulated + * @dst: - Address of data to be decapsulated + * @len: - Size of data to be decapsulated + * + * Returns zero on success,and negative on error. + */ +__weak int blob_decap(u8 *key_mod, u8 *src, u8 *dst, u32 len) +{ + return 0; +} + +/** + * blob_encap() - Encapsulate the data as a blob + * @key_mod: - Pointer to key modifier/key + * @src: - Address of data to be encapsulated + * @dst: - Address of data to be encapsulated + * @len: - Size of data to be encapsulated + * + * Returns zero on success,and negative on error. + */ +__weak int blob_encap(u8 *key_mod, u8 *src, u8 *dst, u32 len) +{ + return 0; +} + +/** + * do_blob() - Handle the "blob" command-line command + * @cmdtp: Command data struct pointer + * @flag: Command flag + * @argc: Command-line argument count + * @argv: Array of command-line arguments + * + * Returns zero on success, CMD_RET_USAGE in case of misuse and negative + * on error. + */ +static int do_blob(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + uint32_t key_addr, src_addr, dst_addr, len; + uint8_t *km_ptr, *src_ptr, *dst_ptr; + int enc, ret = 0; + + if (argc != 6) + return CMD_RET_USAGE; + + if (!strncmp(argv[1], "enc", 3)) + enc = 1; + else if (!strncmp(argv[1], "dec", 3)) + enc = 0; + else + return CMD_RET_USAGE; + + src_addr = simple_strtoul(argv[2], NULL, 16); + dst_addr = simple_strtoul(argv[3], NULL, 16); + len = simple_strtoul(argv[4], NULL, 16); + key_addr = simple_strtoul(argv[5], NULL, 16); + + km_ptr = (uint8_t *)key_addr; + src_ptr = (uint8_t *)src_addr; + dst_ptr = (uint8_t *)dst_addr; + + if (enc) + ret = blob_encap(km_ptr, src_ptr, dst_ptr, len); + else + ret = blob_decap(km_ptr, src_ptr, dst_ptr, len); + + return ret; +} + +/***************************************************/ +static char blob_help_text[] = + "enc src dst len km - Encapsulate and create blob of data\n" + " $len bytes long at address $src and\n" + " store the result at address $dst.\n" + " $km is the 16 byte key modifier\n" + " is also required for generation/use as\n" + " key for cryptographic operation. Key\n" + " modifier should be 16 byte long.\n" + "blob dec src dst len km - Decapsulate the blob of data at address\n" + " $src and store result of $len byte at\n" + " addr $dst.\n" + " $km is the 16 byte key modifier\n" + " is also required for generation/use as\n" + " key for cryptographic operation. Key\n" + " modifier should be 16 byte long.\n"; + +U_BOOT_CMD( + blob, 6, 1, do_blob, + "Blob encapsulation/decryption", + blob_help_text +); diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 843ec6e0c2..67233600b1 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -12,6 +12,7 @@ #include <bootm.h> #include <command.h> #include <environment.h> +#include <errno.h> #include <image.h> #include <lmb.h> #include <malloc.h> diff --git a/common/cmd_eeprom.c b/common/cmd_eeprom.c index a02f0cb0bb..29f0f1f784 100644 --- a/common/cmd_eeprom.c +++ b/common/cmd_eeprom.c @@ -389,13 +389,8 @@ void eeprom_init (void) #if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) spi_init_f (); #endif -#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT) || \ - defined(CONFIG_SYS_I2C) -#ifdef CONFIG_SYS_I2C - i2c_init_all(); -#else - i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); -#endif +#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT) + i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); #endif } diff --git a/common/cmd_elf.c b/common/cmd_elf.c index ab9c7e332d..42a52965c2 100644 --- a/common/cmd_elf.c +++ b/common/cmd_elf.c @@ -14,6 +14,7 @@ */ #include <common.h> +#include <bootm.h> #include <command.h> #include <linux/ctype.h> #include <net.h> @@ -28,8 +29,7 @@ static unsigned long load_elf_image_phdr(unsigned long addr); static unsigned long load_elf_image_shdr(unsigned long addr); /* Allow ports to override the default behavior */ -__attribute__((weak)) -unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), +static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), int argc, char * const argv[]) { unsigned long ret; diff --git a/common/cmd_gpio.c b/common/cmd_gpio.c index 11f4e4031d..65d6df451c 100644 --- a/common/cmd_gpio.c +++ b/common/cmd_gpio.c @@ -12,7 +12,7 @@ #include <dm.h> #include <asm/gpio.h> -int __weak name_to_gpio(const char *name) +__weak int name_to_gpio(const char *name) { return simple_strtoul(name, NULL, 10); } @@ -25,13 +25,6 @@ enum gpio_cmd { }; #if defined(CONFIG_DM_GPIO) && !defined(gpio_status) -static const char * const gpio_function[GPIOF_COUNT] = { - "input", - "output", - "unused", - "unknown", - "func", -}; /* A few flags used by show_gpio() */ enum { @@ -40,22 +33,16 @@ enum { FLAG_SHOW_NEWLINE = 1 << 2, }; -static void show_gpio(struct udevice *dev, const char *bank_name, int offset, - int *flagsp) +static void gpio_get_description(struct udevice *dev, const char *bank_name, + int offset, int *flagsp) { - struct dm_gpio_ops *ops = gpio_get_ops(dev); - int func = GPIOF_UNKNOWN; char buf[80]; int ret; - BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function)); - - if (ops->get_function) { - ret = ops->get_function(dev, offset); - if (ret >= 0 && ret < ARRAY_SIZE(gpio_function)) - func = ret; - } - if (!(*flagsp & FLAG_SHOW_ALL) && func == GPIOF_UNUSED) + ret = gpio_get_function(dev, offset, NULL); + if (ret < 0) + goto err; + if (!(*flagsp & FLAG_SHOW_ALL) && ret == GPIOF_UNUSED) return; if ((*flagsp & FLAG_SHOW_BANK) && bank_name) { if (*flagsp & FLAG_SHOW_NEWLINE) { @@ -65,20 +52,15 @@ static void show_gpio(struct udevice *dev, const char *bank_name, int offset, printf("Bank %s:\n", bank_name); *flagsp &= ~FLAG_SHOW_BANK; } - *buf = '\0'; - if (ops->get_state) { - ret = ops->get_state(dev, offset, buf, sizeof(buf)); - if (ret) { - puts("<unknown>"); - return; - } - } else { - sprintf(buf, "%s%u: %8s %d", bank_name, offset, - gpio_function[func], ops->get_value(dev, offset)); - } - puts(buf); - puts("\n"); + ret = gpio_get_status(dev, offset, buf, sizeof(buf)); + if (ret) + goto err; + + printf("%s\n", buf); + return; +err: + printf("Error %d\n", ret); } static int do_gpio_status(bool all, const char *gpio_name) @@ -101,8 +83,10 @@ static int do_gpio_status(bool all, const char *gpio_name) if (all) flags |= FLAG_SHOW_ALL; bank_name = gpio_get_bank_info(dev, &num_bits); - if (!num_bits) + if (!num_bits) { + debug("GPIO device %s has no bits\n", dev->name); continue; + } banklen = bank_name ? strlen(bank_name) : 0; if (!gpio_name || !bank_name || @@ -113,11 +97,12 @@ static int do_gpio_status(bool all, const char *gpio_name) p = gpio_name + banklen; if (gpio_name && *p) { offset = simple_strtoul(p, NULL, 10); - show_gpio(dev, bank_name, offset, &flags); + gpio_get_description(dev, bank_name, offset, + &flags); } else { for (offset = 0; offset < num_bits; offset++) { - show_gpio(dev, bank_name, offset, - &flags); + gpio_get_description(dev, bank_name, + offset, &flags); } } } diff --git a/common/cmd_io.c b/common/cmd_io.c index eefac36f87..c59148f413 100644 --- a/common/cmd_io.c +++ b/common/cmd_io.c @@ -70,8 +70,8 @@ int do_io_iow(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) /**************************************************/ U_BOOT_CMD(iod, 2, 0, do_io_iod, - "IO space display", "[.b, .w, .l] address [# of objects]"); + "IO space display", "[.b, .w, .l] address"); U_BOOT_CMD(iow, 3, 0, do_io_iow, - "IO space modify (auto-incrementing address)", - "[.b, .w, .l] address"); + "IO space modify", + "[.b, .w, .l] address value"); diff --git a/common/cmd_mem.c b/common/cmd_mem.c index bfca59e351..0d50dcfe9c 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -480,6 +480,9 @@ static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if ((count % (64 << 10)) == 0) WATCHDOG_RESET(); } + unmap_sysmem(buf); + unmap_sysmem(src); + return 0; } diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c index b3f7687aee..cbc107ea50 100644 --- a/common/cmd_scsi.c +++ b/common/cmd_scsi.c @@ -10,6 +10,7 @@ */ #include <common.h> #include <command.h> +#include <inttypes.h> #include <asm/processor.h> #include <scsi.h> #include <image.h> @@ -391,7 +392,7 @@ static ulong scsi_read(int device, lbaint_t blknr, lbaint_t blkcnt, blks=0; } debug("scsi_read_ext: startblk " LBAF - ", blccnt %x buffer %lx\n", + ", blccnt %x buffer %" PRIXPTR "\n", start, smallblks, buf_addr); if (scsi_exec(pccb) != true) { scsi_print_error(pccb); @@ -401,7 +402,7 @@ static ulong scsi_read(int device, lbaint_t blknr, lbaint_t blkcnt, buf_addr+=pccb->datalen; } while(blks!=0); debug("scsi_read_ext: end startblk " LBAF - ", blccnt %x buffer %lx\n", start, smallblks, buf_addr); + ", blccnt %x buffer %" PRIXPTR "\n", start, smallblks, buf_addr); return(blkcnt); } @@ -445,7 +446,7 @@ static ulong scsi_write(int device, lbaint_t blknr, start += blks; blks = 0; } - debug("%s: startblk " LBAF ", blccnt %x buffer %lx\n", + debug("%s: startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n", __func__, start, smallblks, buf_addr); if (scsi_exec(pccb) != true) { scsi_print_error(pccb); @@ -454,7 +455,7 @@ static ulong scsi_write(int device, lbaint_t blknr, } buf_addr += pccb->datalen; } while (blks != 0); - debug("%s: end startblk " LBAF ", blccnt %x buffer %lx\n", + debug("%s: end startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n", __func__, start, smallblks, buf_addr); return blkcnt; } diff --git a/common/cmd_sf.c b/common/cmd_sf.c index c60e8d10df..95a6f89a84 100644 --- a/common/cmd_sf.c +++ b/common/cmd_sf.c @@ -8,10 +8,13 @@ #include <common.h> #include <div64.h> +#include <dm.h> #include <malloc.h> +#include <spi.h> #include <spi_flash.h> #include <asm/io.h> +#include <dm/device-internal.h> static struct spi_flash *flash; @@ -80,7 +83,12 @@ static int do_spi_flash_probe(int argc, char * const argv[]) unsigned int speed = CONFIG_SF_DEFAULT_SPEED; unsigned int mode = CONFIG_SF_DEFAULT_MODE; char *endp; +#ifdef CONFIG_DM_SPI_FLASH + struct udevice *new, *bus_dev; + int ret; +#else struct spi_flash *new; +#endif if (argc >= 2) { cs = simple_strtoul(argv[1], &endp, 0); @@ -108,6 +116,23 @@ static int do_spi_flash_probe(int argc, char * const argv[]) return -1; } +#ifdef CONFIG_DM_SPI_FLASH + /* Remove the old device, otherwise probe will just be a nop */ + ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new); + if (!ret) { + device_remove(new); + device_unbind(new); + } + flash = NULL; + ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new); + if (ret) { + printf("Failed to initialize SPI flash at %u:%u (error %d)\n", + bus, cs, ret); + return 1; + } + + flash = new->uclass_priv; +#else new = spi_flash_probe(bus, cs, speed, mode); if (!new) { printf("Failed to initialize SPI flash at %u:%u\n", bus, cs); @@ -117,6 +142,7 @@ static int do_spi_flash_probe(int argc, char * const argv[]) if (flash) spi_flash_free(flash); flash = new; +#endif return 0; } diff --git a/common/cmd_spi.c b/common/cmd_spi.c index be5709c617..64c3ffcf42 100644 --- a/common/cmd_spi.c +++ b/common/cmd_spi.c @@ -11,6 +11,7 @@ #include <common.h> #include <command.h> +#include <dm.h> #include <errno.h> #include <spi.h> @@ -42,19 +43,38 @@ static uchar din[MAX_SPI_BYTES]; static int do_spi_xfer(int bus, int cs) { struct spi_slave *slave; - int rcode = 0; - + int ret = 0; + +#ifdef CONFIG_DM_SPI + char name[30], *str; + struct udevice *dev; + + snprintf(name, sizeof(name), "generic_%d:%d", bus, cs); + str = strdup(name); + ret = spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv", + str, &dev, &slave); + if (ret) + return ret; +#else slave = spi_setup_slave(bus, cs, 1000000, mode); if (!slave) { printf("Invalid device %d:%d\n", bus, cs); return -EINVAL; } +#endif - spi_claim_bus(slave); - if (spi_xfer(slave, bitlen, dout, din, - SPI_XFER_BEGIN | SPI_XFER_END) != 0) { - printf("Error during SPI transaction\n"); - rcode = -EIO; + ret = spi_claim_bus(slave); + if (ret) + goto done; + ret = spi_xfer(slave, bitlen, dout, din, + SPI_XFER_BEGIN | SPI_XFER_END); +#ifndef CONFIG_DM_SPI + /* We don't get an error code in this case */ + if (ret) + ret = -EIO; +#endif + if (ret) { + printf("Error %d during SPI transaction\n", ret); } else { int j; @@ -62,10 +82,13 @@ static int do_spi_xfer(int bus, int cs) printf("%02X", din[j]); printf("\n"); } +done: spi_release_bus(slave); +#ifndef CONFIG_DM_SPI spi_free_slave(slave); +#endif - return rcode; + return ret; } /* diff --git a/common/command.c b/common/command.c index 746b7e3f0e..4719f4978b 100644 --- a/common/command.c +++ b/common/command.c @@ -18,13 +18,13 @@ * for long help messages */ -int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int - flag, int argc, char * const argv[]) +int _do_help(cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) { int i; int rcode = 0; - if (argc == 1) { /*show list of commands */ + if (argc == 1) { /* show list of commands */ cmd_tbl_t *cmd_array[cmd_items]; int i, j, swaps; @@ -38,8 +38,8 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int for (i = cmd_items - 1; i > 0; --i) { swaps = 0; for (j = 0; j < i; ++j) { - if (strcmp (cmd_array[j]->name, - cmd_array[j + 1]->name) > 0) { + if (strcmp(cmd_array[j]->name, + cmd_array[j + 1]->name) > 0) { cmd_tbl_t *tmp; tmp = cmd_array[j]; cmd_array[j] = cmd_array[j + 1]; @@ -56,7 +56,7 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int const char *usage = cmd_array[i]->usage; /* allow user abort */ - if (ctrlc ()) + if (ctrlc()) return 1; if (usage == NULL) continue; @@ -69,26 +69,23 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int * command help (long version) */ for (i = 1; i < argc; ++i) { - if ((cmdtp = find_cmd_tbl (argv[i], cmd_start, cmd_items )) != NULL) { + cmdtp = find_cmd_tbl(argv[i], cmd_start, cmd_items); + if (cmdtp != NULL) { rcode |= cmd_usage(cmdtp); } else { - printf ("Unknown command '%s' - try 'help'" - " without arguments for list of all" - " known commands\n\n", argv[i] - ); + printf("Unknown command '%s' - try 'help' without arguments for list of all known commands\n\n", + argv[i]); rcode = 1; } } return rcode; } -/*************************************************************************** - * find command table entry for a command - */ -cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) +/* find command table entry for a command */ +cmd_tbl_t *find_cmd_tbl(const char *cmd, cmd_tbl_t *table, int table_len) { cmd_tbl_t *cmdtp; - cmd_tbl_t *cmdtp_temp = table; /*Init value */ + cmd_tbl_t *cmdtp_temp = table; /* Init value */ const char *p; int len; int n_found = 0; @@ -101,11 +98,9 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) */ len = ((p = strchr(cmd, '.')) == NULL) ? strlen (cmd) : (p - cmd); - for (cmdtp = table; - cmdtp != table + table_len; - cmdtp++) { - if (strncmp (cmd, cmdtp->name, len) == 0) { - if (len == strlen (cmdtp->name)) + for (cmdtp = table; cmdtp != table + table_len; cmdtp++) { + if (strncmp(cmd, cmdtp->name, len) == 0) { + if (len == strlen(cmdtp->name)) return cmdtp; /* full match */ cmdtp_temp = cmdtp; /* abbreviated command ? */ @@ -119,7 +114,7 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len) return NULL; /* not found or ambiguous command */ } -cmd_tbl_t *find_cmd (const char *cmd) +cmd_tbl_t *find_cmd(const char *cmd) { cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd); const int len = ll_entry_count(cmd_tbl_t, cmd); @@ -138,8 +133,8 @@ int cmd_usage(const cmd_tbl_t *cmdtp) return 1; } - puts (cmdtp->help); - putc ('\n'); + puts(cmdtp->help); + putc('\n'); #endif /* CONFIG_SYS_LONGHELP */ return 1; } @@ -194,7 +189,7 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv } /* more than one arg or one but the start of the next */ - if (argc > 1 || (last_char == '\0' || isblank(last_char))) { + if (argc > 1 || last_char == '\0' || isblank(last_char)) { cmdtp = find_cmd(argv[0]); if (cmdtp == NULL || cmdtp->complete == NULL) { cmdv[0] = NULL; @@ -345,7 +340,8 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp) argc = make_argv(tmp_buf, sizeof(argv)/sizeof(argv[0]), argv); /* do the completion and return the possible completions */ - i = complete_cmdv(argc, argv, last_char, sizeof(cmdv)/sizeof(cmdv[0]), cmdv); + i = complete_cmdv(argc, argv, last_char, + sizeof(cmdv) / sizeof(cmdv[0]), cmdv); /* no match; bell and out */ if (i == 0) { @@ -365,7 +361,7 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp) len = strlen(s); sep = " "; seplen = 1; - } else if (i > 1 && (j = find_common_prefix(cmdv)) != 0) { /* more */ + } else if (i > 1 && (j = find_common_prefix(cmdv)) != 0) { /* more */ k = strlen(argv[argc - 1]); j -= k; if (j > 0) { @@ -414,7 +410,7 @@ int cmd_get_data_size(char* arg, int default_size) */ int len = strlen(arg); if (len > 2 && arg[len-2] == '.') { - switch(arg[len-1]) { + switch (arg[len-1]) { case 'b': return 1; case 'w': @@ -448,10 +444,10 @@ void fixup_cmdtable(cmd_tbl_t *cmdtp, int size) for (i = 0; i < size; i++) { ulong addr; - addr = (ulong) (cmdtp->cmd) + gd->reloc_off; + addr = (ulong)(cmdtp->cmd) + gd->reloc_off; #if DEBUG_COMMANDS printf("Command \"%s\": 0x%08lx => 0x%08lx\n", - cmdtp->name, (ulong) (cmdtp->cmd), addr); + cmdtp->name, (ulong)(cmdtp->cmd), addr); #endif cmdtp->cmd = (int (*)(struct cmd_tbl_s *, int, int, char * const []))addr; diff --git a/common/console.c b/common/console.c index 5a2f411600..4695386a33 100644 --- a/common/console.c +++ b/common/console.c @@ -7,6 +7,7 @@ #include <common.h> #include <stdarg.h> +#include <iomux.h> #include <malloc.h> #include <os.h> #include <serial.h> @@ -621,7 +622,7 @@ inline void dbg(const char *fmt, ...) } #else -inline void dbg(const char *fmt, ...) +static inline void dbg(const char *fmt, ...) { } #endif diff --git a/common/cros_ec.c b/common/cros_ec.c index b8ce1b581a..bb299bccff 100644 --- a/common/cros_ec.c +++ b/common/cros_ec.c @@ -10,25 +10,44 @@ #include <common.h> #include <cros_ec.h> +#include <dm.h> +#include <errno.h> + DECLARE_GLOBAL_DATA_PTR; +#ifndef CONFIG_DM_CROS_EC struct local_info { struct cros_ec_dev *cros_ec_dev; /* Pointer to cros_ec device */ int cros_ec_err; /* Error for cros_ec, 0 if ok */ }; static struct local_info local; +#endif struct cros_ec_dev *board_get_cros_ec_dev(void) { +#ifdef CONFIG_DM_CROS_EC + struct udevice *dev; + int ret; + + ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev); + if (ret) { + debug("%s: Error %d\n", __func__, ret); + return NULL; + } + return dev->uclass_priv; +#else return local.cros_ec_dev; +#endif } static int board_init_cros_ec_devices(const void *blob) { +#ifndef CONFIG_DM_CROS_EC local.cros_ec_err = cros_ec_init(blob, &local.cros_ec_dev); if (local.cros_ec_err) return -1; /* Will report in board_late_init() */ +#endif return 0; } @@ -40,5 +59,16 @@ int cros_ec_board_init(void) int cros_ec_get_error(void) { +#ifdef CONFIG_DM_CROS_EC + struct udevice *dev; + int ret; + + ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev); + if (ret && ret != -ENODEV) + return ret; + + return 0; +#else return local.cros_ec_err; +#endif } diff --git a/common/env_nand.c b/common/env_nand.c index 5a734a9321..749605fe3f 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -124,7 +124,7 @@ int env_init(void) * The legacy NAND code saved the environment in the first NAND device i.e., * nand_dev_desc + 0. This is also the behaviour using the new NAND code. */ -int writeenv(size_t offset, u_char *buf) +static int writeenv(size_t offset, u_char *buf) { size_t end = offset + CONFIG_ENV_RANGE; size_t amount_saved = 0; @@ -233,7 +233,7 @@ int saveenv(void) } #endif /* CMD_SAVEENV */ -int readenv(size_t offset, u_char *buf) +static int readenv(size_t offset, u_char *buf) { size_t end = offset + CONFIG_ENV_RANGE; size_t amount_loaded = 0; diff --git a/common/env_sf.c b/common/env_sf.c index 37ab13ae17..5e3729c2c2 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -12,6 +12,7 @@ #include <common.h> #include <environment.h> #include <malloc.h> +#include <spi.h> #include <spi_flash.h> #include <search.h> #include <errno.h> diff --git a/common/exports.c b/common/exports.c index b97ca48307..88fcfc8cb6 100644 --- a/common/exports.c +++ b/common/exports.c @@ -27,10 +27,12 @@ unsigned long get_version(void) # define i2c_write dummy # define i2c_read dummy #endif -#ifndef CONFIG_CMD_SPI +#if !defined(CONFIG_CMD_SPI) || defined(CONFIG_DM_SPI) # define spi_init dummy # define spi_setup_slave dummy # define spi_free_slave dummy +#endif +#ifndef CONFIG_CMD_SPI # define spi_claim_bus dummy # define spi_release_bus dummy # define spi_xfer dummy diff --git a/common/image-android.c b/common/image-android.c index 6ded7e2c97..59079fc32b 100644 --- a/common/image-android.c +++ b/common/image-android.c @@ -7,9 +7,26 @@ #include <common.h> #include <image.h> #include <android_image.h> +#include <malloc.h> +#include <errno.h> static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1]; +/** + * android_image_get_kernel() - processes kernel part of Android boot images + * @hdr: Pointer to image header, which is at the start + * of the image. + * @verify: Checksum verification flag. Currently unimplemented. + * @os_data: Pointer to a ulong variable, will hold os data start + * address. + * @os_len: Pointer to a ulong variable, will hold os data length. + * + * This function returns the os image's start address and length. Also, + * it appends the kernel command line to the bootargs env variable. + * + * Return: Zero, os start address and length on success, + * otherwise on failure. + */ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, ulong *os_data, ulong *os_len) { @@ -25,16 +42,32 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, printf("Kernel load addr 0x%08x size %u KiB\n", hdr->kernel_addr, DIV_ROUND_UP(hdr->kernel_size, 1024)); - strncpy(andr_tmp_str, hdr->cmdline, ANDR_BOOT_ARGS_SIZE); - andr_tmp_str[ANDR_BOOT_ARGS_SIZE] = '\0'; - if (strlen(andr_tmp_str)) { - printf("Kernel command line: %s\n", andr_tmp_str); - setenv("bootargs", andr_tmp_str); + + int len = 0; + if (*hdr->cmdline) { + printf("Kernel command line: %s\n", hdr->cmdline); + len += strlen(hdr->cmdline); + } + + char *bootargs = getenv("bootargs"); + if (bootargs) + len += strlen(bootargs); + + char *newbootargs = malloc(len + 2); + if (!newbootargs) { + puts("Error: malloc in android_image_get_kernel failed!\n"); + return -ENOMEM; + } + *newbootargs = '\0'; + + if (bootargs) { + strcpy(newbootargs, bootargs); + strcat(newbootargs, " "); } - if (hdr->ramdisk_size) - printf("RAM disk load addr 0x%08x size %u KiB\n", - hdr->ramdisk_addr, - DIV_ROUND_UP(hdr->ramdisk_size, 1024)); + if (*hdr->cmdline) + strcat(newbootargs, hdr->cmdline); + + setenv("bootargs", newbootargs); if (os_data) { *os_data = (ulong)hdr; @@ -52,17 +85,18 @@ int android_image_check_header(const struct andr_img_hdr *hdr) ulong android_image_get_end(const struct andr_img_hdr *hdr) { - u32 size = 0; + ulong end; /* * The header takes a full page, the remaining components are aligned * on page boundary */ - size += hdr->page_size; - size += ALIGN(hdr->kernel_size, hdr->page_size); - size += ALIGN(hdr->ramdisk_size, hdr->page_size); - size += ALIGN(hdr->second_size, hdr->page_size); + end = (ulong)hdr; + end += hdr->page_size; + end += ALIGN(hdr->kernel_size, hdr->page_size); + end += ALIGN(hdr->ramdisk_size, hdr->page_size); + end += ALIGN(hdr->second_size, hdr->page_size); - return size; + return end; } ulong android_image_get_kload(const struct andr_img_hdr *hdr) @@ -75,6 +109,10 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr, { if (!hdr->ramdisk_size) return -1; + + printf("RAM disk load addr 0x%08x size %u KiB\n", + hdr->ramdisk_addr, DIV_ROUND_UP(hdr->ramdisk_size, 1024)); + *rd_data = (unsigned long)hdr; *rd_data += hdr->page_size; *rd_data += ALIGN(hdr->kernel_size, hdr->page_size); diff --git a/common/image-fit.c b/common/image-fit.c index 255c4cac9c..4ffc5aaa51 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1114,7 +1114,8 @@ int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) if (fit_image_get_arch(fit, noffset, &image_arch)) return 0; - return (arch == image_arch); + return (arch == image_arch) || + (arch == IH_ARCH_I386 && image_arch == IH_ARCH_X86_64); } /** @@ -1434,7 +1435,7 @@ void fit_conf_print(const void *fit, int noffset, const char *p) printf("%s FDT: %s\n", p, uname); } -int fit_image_select(const void *fit, int rd_noffset, int verify) +static int fit_image_select(const void *fit, int rd_noffset, int verify) { fit_image_print(fit, rd_noffset, " "); @@ -1497,6 +1498,8 @@ static const char *fit_get_image_type_property(int type) return FIT_KERNEL_PROP; case IH_TYPE_RAMDISK: return FIT_RAMDISK_PROP; + case IH_TYPE_X86_SETUP: + return FIT_SETUP_PROP; } return "unknown"; @@ -1591,7 +1594,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr, } bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH); -#ifndef USE_HOSTCC +#if !defined(USE_HOSTCC) && !defined(CONFIG_SANDBOX) if (!fit_image_check_target_arch(fit, noffset)) { puts("Unsupported Architecture\n"); bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH); @@ -1693,3 +1696,23 @@ int fit_image_load(bootm_headers_t *images, ulong addr, return noffset; } + +int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch, + ulong *setup_start, ulong *setup_len) +{ + int noffset; + ulong addr; + ulong len; + int ret; + + addr = map_to_sysmem(images->fit_hdr_os); + noffset = fit_get_node_from_config(images, FIT_SETUP_PROP, addr); + if (noffset < 0) + return noffset; + + ret = fit_image_load(images, addr, NULL, NULL, arch, + IH_TYPE_X86_SETUP, BOOTSTAGE_ID_FIT_SETUP_START, + FIT_LOAD_REQUIRED, setup_start, &len); + + return ret; +} diff --git a/common/image.c b/common/image.c index 085771c763..b75a5ce29a 100644 --- a/common/image.c +++ b/common/image.c @@ -85,6 +85,7 @@ static const table_entry_t uimage_arch[] = { { IH_ARCH_SANDBOX, "sandbox", "Sandbox", }, { IH_ARCH_ARM64, "arm64", "AArch64", }, { IH_ARCH_ARC, "arc", "ARC", }, + { IH_ARCH_X86_64, "x86_64", "AMD x86_64", }, { -1, "", "", }, }; @@ -143,6 +144,7 @@ static const table_entry_t uimage_type[] = { { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",}, { IH_TYPE_MXSIMAGE, "mxsimage", "Freescale MXS Boot Image",}, { IH_TYPE_ATMELIMAGE, "atmelimage", "ATMEL ROM-Boot Image",}, + { IH_TYPE_X86_SETUP, "x86_setup", "x86 setup.bin", }, { -1, "", "", }, }; @@ -1009,7 +1011,8 @@ int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images, image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len); } #ifdef CONFIG_ANDROID_BOOT_IMAGE - else if ((genimg_get_format(images) == IMAGE_FORMAT_ANDROID) && + else if ((genimg_get_format((void *)images->os.start) + == IMAGE_FORMAT_ANDROID) && (!android_image_get_ramdisk((void *)images->os.start, &rd_data, &rd_len))) { /* empty */ @@ -1136,6 +1139,16 @@ error: } #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */ +int boot_get_setup(bootm_headers_t *images, uint8_t arch, + ulong *setup_start, ulong *setup_len) +{ +#if defined(CONFIG_FIT) + return boot_get_setup_fit(images, arch, setup_start, setup_len); +#else + return -ENOENT; +#endif +} + #ifdef CONFIG_SYS_BOOT_GET_CMDLINE /** * boot_get_cmdline - allocate and initialize kernel cmdline diff --git a/common/lcd.c b/common/lcd.c index 217ec9dbd2..787d80e3cb 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -33,7 +33,6 @@ #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \ defined(CONFIG_CPU_MONAHANS) -#define CONFIG_CPU_PXA #include <asm/byteorder.h> #endif @@ -1023,7 +1022,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y) switch (bmp_bpix) { case 1: /* pass through */ - case 8: + case 8: { #ifdef CONFIG_LCD_BMP_RLE8 u32 compression = get_unaligned_le32(&bmp->header.compression); if (compression == BMP_BI_RLE8) { @@ -1056,7 +1055,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y) fb -= byte_width + lcd_line_length; } break; - + } #if defined(CONFIG_BMP_16BPP) case 16: for (i = 0; i < height; ++i) { diff --git a/common/menu.c b/common/menu.c index 94afeb2900..e81c074f36 100644 --- a/common/menu.c +++ b/common/menu.c @@ -105,12 +105,9 @@ static inline void *menu_item_destroy(struct menu *m, return NULL; } -void __menu_display_statusline(struct menu *m) +__weak void menu_display_statusline(struct menu *m) { - return; } -void menu_display_statusline(struct menu *m) - __attribute__ ((weak, alias("__menu_display_statusline"))); /* * Display a menu so the user can make a choice of an item. First display its diff --git a/common/modem.c b/common/modem.c index be54b10110..96b10648d8 100644 --- a/common/modem.c +++ b/common/modem.c @@ -19,7 +19,7 @@ static inline void mdm_readline(char *buf, int bufsiz) for(;;) { c = serial_getc(); - /* dbg("(%c)", c); */ + debug("(%c)", c); switch(c) { case '\r': @@ -40,7 +40,6 @@ static inline void mdm_readline(char *buf, int bufsiz) } } -extern void dbg(const char *fmt, ...); int mdm_init (void) { char env_str[16]; @@ -66,15 +65,15 @@ int mdm_init (void) serial_puts("\n"); for(;;) { mdm_readline(console_buffer, CONFIG_SYS_CBSIZE); - dbg("ini%d: [%s]", i, console_buffer); + debug("ini%d: [%s]", i, console_buffer); if ((strcmp(console_buffer, "OK") == 0) || (strcmp(console_buffer, "ERROR") == 0)) { - dbg("ini%d: cmd done", i); + debug("ini%d: cmd done", i); break; } else /* in case we are originating call ... */ if (strncmp(console_buffer, "CONNECT", 7) == 0) { - dbg("ini%d: connect", i); + debug("ini%d: connect", i); return 0; } } @@ -90,9 +89,9 @@ int mdm_init (void) for(;i > 1;) { /* if 'i' > 1 - wait for connection message from modem */ mdm_readline(console_buffer, CONFIG_SYS_CBSIZE); - dbg("ini_f: [%s]", console_buffer); + debug("ini_f: [%s]", console_buffer); if (strncmp(console_buffer, "CONNECT", 7) == 0) { - dbg("ini_f: connected"); + debug("ini_f: connected"); return 0; } } diff --git a/common/spl/Makefile b/common/spl/Makefile index 64569c2cc6..10a4589969 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -18,5 +18,6 @@ obj-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o obj-$(CONFIG_SPL_MMC_SUPPORT) += spl_mmc.o obj-$(CONFIG_SPL_USB_SUPPORT) += spl_usb.o obj-$(CONFIG_SPL_FAT_SUPPORT) += spl_fat.o +obj-$(CONFIG_SPL_EXT_SUPPORT) += spl_ext.o obj-$(CONFIG_SPL_SATA_SUPPORT) += spl_sata.o endif diff --git a/common/spl/spl.c b/common/spl/spl.c index b16664f845..d85bab3928 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -23,6 +23,7 @@ DECLARE_GLOBAL_DATA_PTR; #define CONFIG_SYS_UBOOT_START CONFIG_SYS_TEXT_BASE #endif #ifndef CONFIG_SYS_MONITOR_LEN +/* Unknown U-Boot size, let's assume it will not be more than 200 KB */ #define CONFIG_SYS_MONITOR_LEN (200 * 1024) #endif @@ -92,7 +93,6 @@ void spl_parse_image_header(const struct image_header *header) /* Signature not found - assume u-boot.bin */ debug("mkimage signature not found - ih_magic = %x\n", header->ih_magic); - /* Let's assume U-Boot will not be more than 200 KB */ spl_image.size = CONFIG_SYS_MONITOR_LEN; spl_image.entry_point = CONFIG_SYS_UBOOT_START; spl_image.load_addr = CONFIG_SYS_TEXT_BASE; diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c new file mode 100644 index 0000000000..d9eba5aef3 --- /dev/null +++ b/common/spl/spl_ext.c @@ -0,0 +1,139 @@ +/* + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <spl.h> +#include <asm/u-boot.h> +#include <ext4fs.h> +#include <image.h> + +#ifdef CONFIG_SPL_EXT_SUPPORT +int spl_load_image_ext(block_dev_desc_t *block_dev, + int partition, + const char *filename) +{ + s32 err; + struct image_header *header; + int filelen; + disk_partition_t part_info = {}; + + header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - + sizeof(struct image_header)); + + if (get_partition_info(block_dev, + partition, &part_info)) { + printf("spl: no partition table found\n"); + return -1; + } + + ext4fs_set_blk_dev(block_dev, &part_info); + + err = ext4fs_mount(0); + if (!err) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + printf("%s: ext4fs mount err - %d\n", __func__, err); +#endif + goto end; + } + + filelen = err = ext4fs_open(filename); + if (err < 0) { + puts("spl: ext4fs_open failed\n"); + goto end; + } + err = ext4fs_read((char *)header, sizeof(struct image_header)); + if (err <= 0) { + puts("spl: ext4fs_read failed\n"); + goto end; + } + + spl_parse_image_header(header); + + err = ext4fs_read((char *)spl_image.load_addr, filelen); + +end: +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + if (err <= 0) + printf("%s: error reading image %s, err - %d\n", + __func__, filename, err); +#endif + + return err <= 0; +} + +#ifdef CONFIG_SPL_OS_BOOT +int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition) +{ + int err; + int filelen; + disk_partition_t part_info = {}; + __maybe_unused char *file; + + if (get_partition_info(block_dev, + partition, &part_info)) { + printf("spl: no partition table found\n"); + return -1; + } + + ext4fs_set_blk_dev(block_dev, &part_info); + + err = ext4fs_mount(0); + if (!err) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + printf("%s: ext4fs mount err - %d\n", __func__, err); +#endif + return -1; + } + +#if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT) + file = getenv("falcon_args_file"); + if (file) { + filelen = err = ext4fs_open(file); + if (err < 0) { + puts("spl: ext4fs_open failed\n"); + goto defaults; + } + err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen); + if (err <= 0) { + printf("spl: error reading image %s, err - %d, falling back to default\n", + file, err); + goto defaults; + } + file = getenv("falcon_image_file"); + if (file) { + err = spl_load_image_ext(block_dev, partition, file); + if (err != 0) { + puts("spl: falling back to default\n"); + goto defaults; + } + + return 0; + } else { + puts("spl: falcon_image_file not set in environment, falling back to default\n"); + } + } else { + puts("spl: falcon_args_file not set in environment, falling back to default\n"); + } + +defaults: +#endif + + filelen = err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME); + if (err < 0) + puts("spl: ext4fs_open failed\n"); + + err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen); + if (err <= 0) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + printf("%s: error reading image %s, err - %d\n", + __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err); +#endif + return -1; + } + + return spl_load_image_ext(block_dev, partition, + CONFIG_SPL_FS_LOAD_KERNEL_NAME); +} +#endif +#endif diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 56be943881..350f7d9fd6 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -30,7 +30,7 @@ static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition) #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf("%s: fat register err - %d\n", __func__, err); #endif - hang(); + return err; } fat_registered = 1; @@ -106,18 +106,18 @@ int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition) defaults: #endif - err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME, + err = file_fat_read(CONFIG_SPL_FS_LOAD_ARGS_NAME, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0); if (err <= 0) { #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf("%s: error reading image %s, err - %d\n", - __func__, CONFIG_SPL_FAT_LOAD_ARGS_NAME, err); + __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err); #endif return -1; } return spl_load_image_fat(block_dev, partition, - CONFIG_SPL_FAT_LOAD_KERNEL_NAME); + CONFIG_SPL_FS_LOAD_KERNEL_NAME); } #endif #endif diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index fa6f891bc8..ee71f793a6 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -100,17 +100,31 @@ void spl_mmc_load_image(void) #endif err = mmc_load_image_raw(mmc, CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); +#if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT) + } else if (boot_mode == MMCSD_MODE_FS) { + debug("boot mode - FS\n"); #ifdef CONFIG_SPL_FAT_SUPPORT - } else if (boot_mode == MMCSD_MODE_FAT) { - debug("boot mode - FAT\n"); #ifdef CONFIG_SPL_OS_BOOT if (spl_start_uboot() || spl_load_image_fat_os(&mmc->block_dev, - CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION)) + CONFIG_SYS_MMC_SD_FS_BOOT_PARTITION)) #endif err = spl_load_image_fat(&mmc->block_dev, - CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION, - CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME); + CONFIG_SYS_MMC_SD_FS_BOOT_PARTITION, + CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); + if(err) +#endif /* CONFIG_SPL_FAT_SUPPORT */ + { +#ifdef CONFIG_SPL_EXT_SUPPORT +#ifdef CONFIG_SPL_OS_BOOT + if (spl_start_uboot() || spl_load_image_ext_os(&mmc->block_dev, + CONFIG_SYS_MMC_SD_FS_BOOT_PARTITION)) #endif + err = spl_load_image_ext(&mmc->block_dev, + CONFIG_SYS_MMC_SD_FS_BOOT_PARTITION, + CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); +#endif /* CONFIG_SPL_EXT_SUPPORT */ + } +#endif /* defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT) */ #ifdef CONFIG_SUPPORT_EMMC_BOOT } else if (boot_mode == MMCSD_MODE_EMMCBOOT) { /* diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index 12e16d9603..aeea79315e 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -42,7 +42,7 @@ void spl_sata_load_image(void) #endif err = spl_load_image_fat(stor_dev, CONFIG_SYS_SATA_FAT_BOOT_PARTITION, - CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME); + CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); if (err) { puts("Error loading sata device\n"); hang(); diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c index 53a9043795..c81672b798 100644 --- a/common/spl/spl_usb.c +++ b/common/spl/spl_usb.c @@ -49,7 +49,7 @@ void spl_usb_load_image(void) #endif err = spl_load_image_fat(stor_dev, CONFIG_SYS_USB_FAT_BOOT_PARTITION, - CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME); + CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); if (err) { puts("Error loading USB device\n"); diff --git a/common/stdio.c b/common/stdio.c index 82328150cb..adbfc890dd 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -39,39 +39,39 @@ char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; #endif #ifdef CONFIG_SYS_DEVICE_NULLDEV -void nulldev_putc(struct stdio_dev *dev, const char c) +static void nulldev_putc(struct stdio_dev *dev, const char c) { /* nulldev is empty! */ } -void nulldev_puts(struct stdio_dev *dev, const char *s) +static void nulldev_puts(struct stdio_dev *dev, const char *s) { /* nulldev is empty! */ } -int nulldev_input(struct stdio_dev *dev) +static int nulldev_input(struct stdio_dev *dev) { /* nulldev is empty! */ return 0; } #endif -void stdio_serial_putc(struct stdio_dev *dev, const char c) +static void stdio_serial_putc(struct stdio_dev *dev, const char c) { serial_putc(c); } -void stdio_serial_puts(struct stdio_dev *dev, const char *s) +static void stdio_serial_puts(struct stdio_dev *dev, const char *s) { serial_puts(s); } -int stdio_serial_getc(struct stdio_dev *dev) +static int stdio_serial_getc(struct stdio_dev *dev) { return serial_getc(); } -int stdio_serial_tstc(struct stdio_dev *dev) +static int stdio_serial_tstc(struct stdio_dev *dev) { return serial_tstc(); } @@ -197,6 +197,7 @@ int stdio_deregister_dev(struct stdio_dev *dev, int force) } list_del(&(dev->list)); + free(dev); /* reassign Device list */ list_for_each(pos, &(devs.list)) { diff --git a/common/usb.c b/common/usb.c index bd0f8d5d18..7d33a0f086 100644 --- a/common/usb.c +++ b/common/usb.c @@ -927,7 +927,6 @@ int usb_new_device(struct usb_device *dev) * thread_id=5729457&forum_id=5398 */ __maybe_unused struct usb_device_descriptor *desc; - int port = -1; struct usb_device *parent = dev->parent; unsigned short portstatus; @@ -965,24 +964,10 @@ int usb_new_device(struct usb_device *dev) #endif if (parent) { - int j; - - /* find the port number we're at */ - for (j = 0; j < parent->maxchild; j++) { - if (parent->children[j] == dev) { - port = j; - break; - } - } - if (port < 0) { - printf("usb_new_device:cannot locate device's port.\n"); - return 1; - } - /* reset the port for the second time */ - err = hub_port_reset(dev->parent, port, &portstatus); + err = hub_port_reset(dev->parent, dev->portnr - 1, &portstatus); if (err < 0) { - printf("\n Couldn't reset port %i\n", port); + printf("\n Couldn't reset port %i\n", dev->portnr); return 1; } } diff --git a/common/usb_hub.c b/common/usb_hub.c index c416e5e0b3..0f1eab4486 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -86,50 +86,11 @@ static void usb_hub_power_on(struct usb_hub_device *hub) int i; struct usb_device *dev; unsigned pgood_delay = hub->desc.bPwrOn2PwrGood * 2; - ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1); - unsigned short portstatus; - int ret; dev = hub->pusb_dev; - /* - * Enable power to the ports: - * Here we Power-cycle the ports: aka, - * turning them off and turning on again. - */ debug("enabling power on all ports\n"); for (i = 0; i < dev->maxchild; i++) { - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); - debug("port %d returns %lX\n", i + 1, dev->status); - } - - /* Wait at least 2*bPwrOn2PwrGood for PP to change */ - mdelay(pgood_delay); - - for (i = 0; i < dev->maxchild; i++) { - ret = usb_get_port_status(dev, i + 1, portsts); - if (ret < 0) { - debug("port %d: get_port_status failed\n", i + 1); - continue; - } - - /* - * Check to confirm the state of Port Power: - * xHCI says "After modifying PP, s/w shall read - * PP and confirm that it has reached the desired state - * before modifying it again, undefined behavior may occur - * if this procedure is not followed". - * EHCI doesn't say anything like this, but no harm in keeping - * this. - */ - portstatus = le16_to_cpu(portsts->wPortStatus); - if (portstatus & (USB_PORT_STAT_POWER << 1)) { - debug("port %d: Port power change failed\n", i + 1); - continue; - } - } - - for (i = 0; i < dev->maxchild; i++) { usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); debug("port %d returns %lX\n", i + 1, dev->status); } diff --git a/common/usb_kbd.c b/common/usb_kbd.c index fdc083c70c..bc7145ea79 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -99,6 +99,11 @@ static const unsigned char usb_kbd_arrow[] = { #define USB_KBD_BOOT_REPORT_SIZE 8 struct usb_kbd_pdata { + unsigned long intpipe; + int intpktsize; + int intinterval; + struct int_queue *intq; + uint32_t repeat_delay; uint32_t usb_in_pointer; @@ -116,32 +121,6 @@ extern int __maybe_unused net_busy_flag; /* The period of time between two calls of usb_kbd_testc(). */ static unsigned long __maybe_unused kbd_testc_tms; -/* Generic keyboard event polling. */ -void usb_kbd_generic_poll(void) -{ - struct stdio_dev *dev; - struct usb_device *usb_kbd_dev; - struct usb_kbd_pdata *data; - struct usb_interface *iface; - struct usb_endpoint_descriptor *ep; - int pipe; - int maxp; - - /* Get the pointer to USB Keyboard device pointer */ - dev = stdio_get_by_name(DEVNAME); - usb_kbd_dev = (struct usb_device *)dev->priv; - data = usb_kbd_dev->privptr; - iface = &usb_kbd_dev->config.if_desc[0]; - ep = &iface->ep_desc[0]; - pipe = usb_rcvintpipe(usb_kbd_dev, ep->bEndpointAddress); - - /* Submit a interrupt transfer request */ - maxp = usb_maxpacket(usb_kbd_dev, pipe); - usb_submit_int_msg(usb_kbd_dev, pipe, data->new, - min(maxp, USB_KBD_BOOT_REPORT_SIZE), - ep->bInterval); -} - /* Puts character in the queue and sets up the in and out pointer. */ static void usb_kbd_put_queue(struct usb_kbd_pdata *data, char c) { @@ -331,23 +310,11 @@ static int usb_kbd_irq(struct usb_device *dev) static inline void usb_kbd_poll_for_event(struct usb_device *dev) { #if defined(CONFIG_SYS_USB_EVENT_POLL) - struct usb_interface *iface; - struct usb_endpoint_descriptor *ep; - struct usb_kbd_pdata *data; - int pipe; - int maxp; - - /* Get the pointer to USB Keyboard device pointer */ - data = dev->privptr; - iface = &dev->config.if_desc[0]; - ep = &iface->ep_desc[0]; - pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); + struct usb_kbd_pdata *data = dev->privptr; /* Submit a interrupt transfer request */ - maxp = usb_maxpacket(dev, pipe); - usb_submit_int_msg(dev, pipe, &data->new[0], - min(maxp, USB_KBD_BOOT_REPORT_SIZE), - ep->bInterval); + usb_submit_int_msg(dev, data->intpipe, &data->new[0], data->intpktsize, + data->intinterval); usb_kbd_irq_worker(dev); #elif defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP) @@ -358,6 +325,15 @@ static inline void usb_kbd_poll_for_event(struct usb_device *dev) 1, 0, data->new, USB_KBD_BOOT_REPORT_SIZE); if (memcmp(data->old, data->new, USB_KBD_BOOT_REPORT_SIZE)) usb_kbd_irq_worker(dev); +#elif defined(CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE) + struct usb_kbd_pdata *data = dev->privptr; + if (poll_int_queue(dev, data->intq)) { + usb_kbd_irq_worker(dev); + /* We've consumed all queued int packets, create new */ + destroy_int_queue(dev, data->intq); + data->intq = create_int_queue(dev, data->intpipe, 1, + USB_KBD_BOOT_REPORT_SIZE, data->new); + } #endif } @@ -415,7 +391,6 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum) struct usb_interface *iface; struct usb_endpoint_descriptor *ep; struct usb_kbd_pdata *data; - int pipe, maxp; if (dev->descriptor.bNumConfigurations != 1) return 0; @@ -464,8 +439,10 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum) /* Set IRQ handler */ dev->irq_handle = usb_kbd_irq; - pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); - maxp = usb_maxpacket(dev, pipe); + data->intpipe = usb_rcvintpipe(dev, ep->bEndpointAddress); + data->intpktsize = min(usb_maxpacket(dev, data->intpipe), + USB_KBD_BOOT_REPORT_SIZE); + data->intinterval = ep->bInterval; /* We found a USB Keyboard, install it. */ usb_set_protocol(dev, iface->desc.bInterfaceNumber, 0); @@ -474,9 +451,14 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum) usb_set_idle(dev, iface->desc.bInterfaceNumber, REPEAT_RATE, 0); debug("USB KBD: enable interrupt pipe...\n"); - if (usb_submit_int_msg(dev, pipe, data->new, - min(maxp, USB_KBD_BOOT_REPORT_SIZE), - ep->bInterval) < 0) { +#ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE + data->intq = create_int_queue(dev, data->intpipe, 1, + USB_KBD_BOOT_REPORT_SIZE, data->new); + if (!data->intq) { +#else + if (usb_submit_int_msg(dev, data->intpipe, data->new, data->intpktsize, + data->intinterval) < 0) { +#endif printf("Failed to get keyboard state from device %04x:%04x\n", dev->descriptor.idVendor, dev->descriptor.idProduct); /* Abort, we don't want to use that non-functional keyboard. */ @@ -550,9 +532,22 @@ int drv_usb_kbd_init(void) int usb_kbd_deregister(int force) { #ifdef CONFIG_SYS_STDIO_DEREGISTER - int ret = stdio_deregister(DEVNAME, force); - if (ret && ret != -ENODEV) - return ret; + struct stdio_dev *dev; + struct usb_device *usb_kbd_dev; + struct usb_kbd_pdata *data; + + dev = stdio_get_by_name(DEVNAME); + if (dev) { + usb_kbd_dev = (struct usb_device *)dev->priv; + data = usb_kbd_dev->privptr; + if (stdio_deregister_dev(dev, force) != 0) + return 1; +#ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE + destroy_int_queue(usb_kbd_dev, data->intq); +#endif + free(data->new); + free(data); + } return 0; #else diff --git a/common/usb_storage.c b/common/usb_storage.c index 6ac358d5e2..eb7706c100 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -33,6 +33,7 @@ #include <common.h> #include <command.h> +#include <inttypes.h> #include <asm/byteorder.h> #include <asm/processor.h> @@ -1071,7 +1072,7 @@ unsigned long usb_stor_read(int device, lbaint_t blknr, blks = blkcnt; debug("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF - " buffer %lx\n", device, start, blks, buf_addr); + " buffer %" PRIxPTR "\n", device, start, blks, buf_addr); do { /* XXX need some comment here */ @@ -1101,7 +1102,7 @@ retry_it: ss->flags &= ~USB_READY; debug("usb_read: end startblk " LBAF - ", blccnt %x buffer %lx\n", + ", blccnt %x buffer %" PRIxPTR "\n", start, smallblks, buf_addr); usb_disable_asynch(0); /* asynch transfer allowed */ @@ -1145,7 +1146,7 @@ unsigned long usb_stor_write(int device, lbaint_t blknr, blks = blkcnt; debug("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF - " buffer %lx\n", device, start, blks, buf_addr); + " buffer %" PRIxPTR "\n", device, start, blks, buf_addr); do { /* If write fails retry for max retry count else @@ -1176,8 +1177,8 @@ retry_it: } while (blks != 0); ss->flags &= ~USB_READY; - debug("usb_write: end startblk " LBAF ", blccnt %x buffer %lx\n", - start, smallblks, buf_addr); + debug("usb_write: end startblk " LBAF ", blccnt %x buffer %" + PRIxPTR "\n", start, smallblks, buf_addr); usb_disable_asynch(0); /* asynch transfer allowed */ if (blkcnt >= USB_MAX_XFER_BLK) |