diff options
66 files changed, 1487 insertions, 570 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index a7a62dff814..e7a6dd9ce2d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -951,6 +951,7 @@ S: Maintained T: git https://gitlab.denx.de/u-boot/custodians/u-boot-riscv.git F: arch/riscv/ F: cmd/riscv/ +F: doc/usage/sbi.rst F: drivers/timer/andes_plmt_timer.c F: drivers/timer/sifive_clint_timer.c F: tools/prelink-riscv.c diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index a36b8c7fff9..5ff1a31b38d 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -908,7 +908,8 @@ dtb-$(CONFIG_TARGET_SAMA5D2_XPLAINED) += \ at91-sama5d2_xplained.dtb dtb-$(CONFIG_TARGET_SAMA5D27_SOM1_EK) += \ - at91-sama5d27_som1_ek.dtb + at91-sama5d27_som1_ek.dtb \ + at91-sama5d27_giantboard.dtb dtb-$(CONFIG_TARGET_SAMA5D27_WLSOM1_EK) += \ at91-sama5d27_wlsom1_ek.dtb diff --git a/arch/arm/dts/at91-sama5d27_giantboard.dts b/arch/arm/dts/at91-sama5d27_giantboard.dts new file mode 100644 index 00000000000..e81ca60ca0a --- /dev/null +++ b/arch/arm/dts/at91-sama5d27_giantboard.dts @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * at91-sama5d27_giantboard.dts - Device Tree file for Giant Board + * + * Copyright (C) 2020 Greg Gallagher <greg@embeddedgreg.com> + * + * Derived from at91-sama5d27_som1_ek.dts + * + * Copyright (C) 2017 Microchip Corporation + * Wenyou Yang <wenyou.yang@microchip.com> + */ +/dts-v1/; +#include "sama5d2.dtsi" +#include "sama5d2-pinfunc.h" + +/ { + model = "Giant Board"; + compatible = "atmel,sama5d27-giantboard", "atmel,sama5d2", "atmel,sama5"; + + memory { + reg = <0x20000000 0x8000000>; + }; + + chosen { + u-boot,dm-pre-reloc; + stdout-path = &uart1; + }; + + ahb { + sdmmc1: sdio-host@b0000000 { + bus-width = <4>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_sdmmc1_cmd_dat_default &pinctrl_sdmmc1_ck_cd_default>; + status = "okay"; + u-boot,dm-pre-reloc; + }; + + apb { + + uart1: serial@f8020000 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_uart1_default>; + status = "okay"; + u-boot,dm-pre-reloc; + }; + + i2c0: i2c@f8028000 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_i2c0_default>; + status = "okay"; + }; + + i2c1: i2c@fc028000 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_i2c1_default>; + status = "okay"; + + pmic@5b { + compatible = "active-semi,act8945a"; + reg = <0x5b>; + active-semi,vsel-low; + status = "okay"; + }; + }; + + pit: timer@f8048030 { + status = "okay"; + u-boot,dm-pre-reloc; + }; + + sfr: sfr@f8030000 { + status = "okay"; + u-boot,dm-pre-reloc; + }; + + pioA: gpio@fc038000 { + pinctrl { + + pinctrl_sdmmc1_cmd_dat_default: sdmmc1_cmd_dat_default { + pinmux = <PIN_PA28__SDMMC1_CMD>, + <PIN_PA18__SDMMC1_DAT0>, + <PIN_PA19__SDMMC1_DAT1>, + <PIN_PA20__SDMMC1_DAT2>, + <PIN_PA21__SDMMC1_DAT3>; + bias-pull-up; + u-boot,dm-pre-reloc; + }; + + pinctrl_sdmmc1_ck_cd_default: sdmmc1_ck_cd_default { + pinmux = <PIN_PA22__SDMMC1_CK>, + <PIN_PA30__SDMMC1_CD>; + bias-disable; + u-boot,dm-pre-reloc; + }; + + pinctrl_uart1_default: uart1_default { + pinmux = <PIN_PD2__URXD1>, + <PIN_PD3__UTXD1>; + bias-disable; + u-boot,dm-pre-reloc; + }; + + pinctrl_i2c0_default: i2c0_default { + pinmux = <PIN_PD21__TWD0>, + <PIN_PD22__TWCK0>; + bias-disable; + }; + + pinctrl_i2c1_default: i2c1_default { + pinmux = <PIN_PD4__TWD1>, + <PIN_PD5__TWCK1>; + bias-disable; + }; + + pinctrl_usb_default: usb_default { + pinmux = <PIN_PB10__GPIO>; + bias-disable; + }; + + pinctrl_usba_vbus: usba_vbus { + pinmux = <PIN_PA31__GPIO>; + bias-disable; + }; + }; + }; + }; + }; +}; diff --git a/arch/arm/mach-at91/include/mach/atmel_pio4.h b/arch/arm/mach-at91/include/mach/atmel_pio4.h index f348b05bc85..35ac7b2d40e 100644 --- a/arch/arm/mach-at91/include/mach/atmel_pio4.h +++ b/arch/arm/mach-at91/include/mach/atmel_pio4.h @@ -52,6 +52,7 @@ struct atmel_pio4_port { #define ATMEL_PIO_DRVSTR_LO (1 << 16) #define ATMEL_PIO_DRVSTR_ME (2 << 16) #define ATMEL_PIO_DRVSTR_HI (3 << 16) +#define ATMEL_PIO_DRVSTR_OFFSET 16 #define ATMEL_PIO_CFGR_EVTSEL_MASK GENMASK(26, 24) #define ATMEL_PIO_CFGR_EVTSEL_FALLING (0 << 24) #define ATMEL_PIO_CFGR_EVTSEL_RISING (1 << 24) diff --git a/arch/arm/mach-at91/include/mach/sam9x60.h b/arch/arm/mach-at91/include/mach/sam9x60.h index b7f43226b7e..c08d19c6917 100644 --- a/arch/arm/mach-at91/include/mach/sam9x60.h +++ b/arch/arm/mach-at91/include/mach/sam9x60.h @@ -154,8 +154,8 @@ /* * PMECC table in ROM */ -#define ATMEL_PMECC_INDEX_OFFSET_512 0x8000 -#define ATMEL_PMECC_INDEX_OFFSET_1024 0x10000 +#define ATMEL_PMECC_INDEX_OFFSET_512 0x0000 +#define ATMEL_PMECC_INDEX_OFFSET_1024 0x8000 /* * SAM9X60 specific prototypes diff --git a/arch/arm/mach-at91/include/mach/sama5d3.h b/arch/arm/mach-at91/include/mach/sama5d3.h index 83f18a8148f..f4f05676f72 100644 --- a/arch/arm/mach-at91/include/mach/sama5d3.h +++ b/arch/arm/mach-at91/include/mach/sama5d3.h @@ -190,8 +190,8 @@ /* * PMECC table in ROM */ -#define ATMEL_PMECC_INDEX_OFFSET_512 0x10000 -#define ATMEL_PMECC_INDEX_OFFSET_1024 0x18000 +#define ATMEL_PMECC_INDEX_OFFSET_512 0x8000 +#define ATMEL_PMECC_INDEX_OFFSET_1024 0x10000 /* * SAMA5D3 specific prototypes diff --git a/arch/arm/mach-at91/spl_atmel.c b/arch/arm/mach-at91/spl_atmel.c index 23588e79f94..217ed12e31e 100644 --- a/arch/arm/mach-at91/spl_atmel.c +++ b/arch/arm/mach-at91/spl_atmel.c @@ -103,6 +103,13 @@ void board_init_f(ulong dummy) { int ret; + if (IS_ENABLED(CONFIG_OF_CONTROL)) { + ret = spl_early_init(); + if (ret) { + debug("spl_early_init() failed: %d\n", ret); + hang(); + } + } switch_to_main_crystal_osc(); #ifdef CONFIG_SAMA5D2 diff --git a/arch/arm/mach-exynos/include/mach/dwmmc.h b/arch/arm/mach-exynos/include/mach/dwmmc.h index 5654a0ea6b2..59c28ed54c5 100644 --- a/arch/arm/mach-exynos/include/mach/dwmmc.h +++ b/arch/arm/mach-exynos/include/mach/dwmmc.h @@ -25,5 +25,3 @@ /* CLKSEL Register */ #define DWMCI_DIVRATIO_BIT 24 #define DWMCI_DIVRATIO_MASK 0x7 - -int exynos_dwmmc_init(const void *blob); diff --git a/board/atmel/sama5d27_som1_ek/MAINTAINERS b/board/atmel/sama5d27_som1_ek/MAINTAINERS index f2d2f49db30..ba2f31e6c4d 100644 --- a/board/atmel/sama5d27_som1_ek/MAINTAINERS +++ b/board/atmel/sama5d27_som1_ek/MAINTAINERS @@ -6,3 +6,9 @@ F: include/configs/sama5d27_som1_ek.h F: configs/sama5d27_som1_ek_mmc_defconfig F: configs/sama5d27_som1_ek_mmc1_defconfig F: configs/sama5d27_som1_ek_qspiflash_defconfig + +SAMA5D27 GIANT BOARD +M: Greg Gallagher <greg@embeddedgreg.com> +S: Maintained +F: configs/sama5d27_giantboard_defconfig +F: arch/arm/dts/at91-sama5d27_giantboard.dts diff --git a/board/samsung/arndale/arndale.c b/board/samsung/arndale/arndale.c index 91813763cec..d283ef6275a 100644 --- a/board/samsung/arndale/arndale.c +++ b/board/samsung/arndale/arndale.c @@ -73,19 +73,6 @@ int dram_init_banksize(void) return 0; } -#ifdef CONFIG_MMC -int board_mmc_init(struct bd_info *bis) -{ - int ret; - /* dwmmc initializattion for available channels */ - ret = exynos_dwmmc_init(gd->fdt_blob); - if (ret) - debug("dwmmc init failed\n"); - - return ret; -} -#endif - static int board_uart_init(void) { int err = 0, uart_id; diff --git a/cmd/echo.c b/cmd/echo.c index d02a4cfd586..fda844ee9d3 100644 --- a/cmd/echo.c +++ b/cmd/echo.c @@ -10,47 +10,34 @@ static int do_echo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - int i; - int putnl = 1; - - for (i = 1; i < argc; i++) { - char *p = argv[i]; - char *nls; /* new-line suppression */ + int i = 1; + bool space = false; + bool newline = true; + + if (argc > 1) { + if (!strcmp(argv[1], "-n")) { + newline = false; + ++i; + } + } - if (i > 1) + for (; i < argc; ++i) { + if (space) { putc(' '); - - nls = strstr(p, "\\c"); - if (nls) { - char *prenls = p; - - putnl = 0; - /* - * be paranoid and guess that someone might - * say \c more than once - */ - while (nls) { - *nls = '\0'; - puts(prenls); - *nls = '\\'; - prenls = nls + 2; - nls = strstr(prenls, "\\c"); - } - puts(prenls); - } else { - puts(p); } + puts(argv[i]); + space = true; } - if (putnl) + if (newline) putc('\n'); return 0; } U_BOOT_CMD( - echo, CONFIG_SYS_MAXARGS, 1, do_echo, + echo, CONFIG_SYS_MAXARGS, 1, do_echo, "echo args to console", - "[args..]\n" - " - echo args to console; \\c suppresses newline" + "[-n] [args..]\n" + " - echo args to console; -n suppresses newline" ); diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 9a2d4ddd5ef..83bc2196a5a 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -189,14 +189,16 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag, ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL)); if (ret == EFI_BUFFER_TOO_SMALL) { result = malloc(size); + if (!result) + return CMD_RET_FAILURE; ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, result)); - if (ret != EFI_SUCCESS) { - free(result); - printf("Failed to get %ls\n", var_name16); + } + if (ret != EFI_SUCCESS) { + free(result); + printf("Failed to get %ls\n", var_name16); - return CMD_RET_FAILURE; - } + return CMD_RET_FAILURE; } printf("Result total size: 0x%x\n", result->variable_total_size); diff --git a/cmd/load.c b/cmd/load.c index c6a7cc46515..f252c748948 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -1065,25 +1065,25 @@ U_BOOT_CMD( U_BOOT_CMD( loadb, 3, 0, do_load_serial_bin, "load binary file over serial line (kermit mode)", - "[ off ] [ baud ]\n" + "[ addr [ baud ] ]\n" " - load binary file over serial line" - " with offset 'off' and baudrate 'baud'" + " at address 'addr' with baudrate 'baud'" ); U_BOOT_CMD( loadx, 3, 0, do_load_serial_bin, "load binary file over serial line (xmodem mode)", - "[ off ] [ baud ]\n" + "[ addr [ baud ] ]\n" " - load binary file over serial line" - " with offset 'off' and baudrate 'baud'" + " at address 'addr' with baudrate 'baud'" ); U_BOOT_CMD( loady, 3, 0, do_load_serial_bin, "load binary file over serial line (ymodem mode)", - "[ off ] [ baud ]\n" + "[ addr [ baud ] ]\n" " - load binary file over serial line" - " with offset 'off' and baudrate 'baud'" + " at address 'addr' with baudrate 'baud'" ); #endif /* CONFIG_CMD_LOADB */ diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c index 5401d9411b9..d39741e9058 100644 --- a/common/image-fit-sig.c +++ b/common/image-fit-sig.c @@ -19,20 +19,6 @@ DECLARE_GLOBAL_DATA_PTR; #define IMAGE_MAX_HASHED_NODES 100 -#ifdef USE_HOSTCC -void *host_blob; - -void image_set_host_blob(void *blob) -{ - host_blob = blob; -} - -void *image_get_host_blob(void) -{ - return host_blob; -} -#endif - /** * fit_region_make_list() - Make a list of image regions * diff --git a/common/image-fit.c b/common/image-fit.c index 21c44bdf691..8660c3fd819 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -112,6 +112,21 @@ int fit_parse_subimage(const char *spec, ulong addr_curr, } #endif /* !USE_HOSTCC */ +#ifdef USE_HOSTCC +/* Host tools use these implementations for Cipher and Signature support */ +static void *host_blob; + +void image_set_host_blob(void *blob) +{ + host_blob = blob; +} + +void *image_get_host_blob(void) +{ + return host_blob; +} +#endif /* USE_HOSTCC */ + static void fit_get_debug(const void *fit, int noffset, char *prop_name, int err) { diff --git a/configs/at91sam9n12ek_mmc_defconfig b/configs/at91sam9n12ek_mmc_defconfig index 74a28a30296..ad6ab851531 100644 --- a/configs/at91sam9n12ek_mmc_defconfig +++ b/configs/at91sam9n12ek_mmc_defconfig @@ -42,6 +42,7 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/at91sam9n12ek_spiflash_defconfig b/configs/at91sam9n12ek_spiflash_defconfig index 6a340f5a01a..c6ac36652b3 100644 --- a/configs/at91sam9n12ek_spiflash_defconfig +++ b/configs/at91sam9n12ek_spiflash_defconfig @@ -44,6 +44,7 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/at91sam9x5ek_mmc_defconfig b/configs/at91sam9x5ek_mmc_defconfig index d48d2d73331..9acdbb84455 100644 --- a/configs/at91sam9x5ek_mmc_defconfig +++ b/configs/at91sam9x5ek_mmc_defconfig @@ -45,6 +45,7 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/at91sam9x5ek_spiflash_defconfig b/configs/at91sam9x5ek_spiflash_defconfig index eb935d6ddcd..25de37f4960 100644 --- a/configs/at91sam9x5ek_spiflash_defconfig +++ b/configs/at91sam9x5ek_spiflash_defconfig @@ -47,6 +47,7 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/sama5d27_giantboard_defconfig b/configs/sama5d27_giantboard_defconfig new file mode 100644 index 00000000000..4e55a626258 --- /dev/null +++ b/configs/sama5d27_giantboard_defconfig @@ -0,0 +1,97 @@ +CONFIG_ARM=y +CONFIG_ARCH_CPU_INIT=y +CONFIG_ARCH_AT91=y +CONFIG_CMDLINE=y +CONFIG_SYS_TEXT_BASE=0x23f00000 +CONFIG_TARGET_SAMA5D27_SOM1_EK=y +CONFIG_SAMA5D27_GIANTBOARD=y +CONFIG_SPL_GPIO_SUPPORT=y +CONFIG_SPL_LIBCOMMON_SUPPORT=y +CONFIG_SPL_LIBGENERIC_SUPPORT=y +CONFIG_SYS_MALLOC_F_LEN=0x2000 +CONFIG_SPL_MMC_SUPPORT=y +CONFIG_SPL_SERIAL_SUPPORT=y +CONFIG_SPL_DRIVERS_MISC_SUPPORT=y +CONFIG_ENV_SIZE=0x4000 +CONFIG_NR_DRAM_BANKS=1 +CONFIG_SPL=y +CONFIG_DEBUG_UART_BOARD_INIT=y +CONFIG_DEBUG_UART_BASE=0xf8020000 +CONFIG_DEBUG_UART_CLOCK=82000000 +CONFIG_SPL_FAT_SUPPORT=y +CONFIG_SPL_FS_FAT=y +CONFIG_SYS_BOARD="giantboard" +CONFIG_SYS_BOARD_NAME="giantboard" +CONFIG_SPL_LIBDISK_SUPPORT=y +CONFIG_DEBUG_UART=y +CONFIG_ENV_VARS_UBOOT_CONFIG=y +CONFIG_FIT=y +CONFIG_SYS_EXTRA_OPTIONS="SAMA5D2" +CONFIG_SD_BOOT=y +CONFIG_BOOTDELAY=3 +CONFIG_USE_BOOTARGS=y +CONFIG_MISC_INIT_R=y +CONFIG_BOARD_EARLY_INIT_F=y +# CONFIG_DISPLAY_BOARDINFO is not set +CONFIG_SPL_TEXT_BASE=0x200000 +CONFIG_SPL_SEPARATE_BSS=y +CONFIG_HUSH_PARSER=y +CONFIG_AUTOBOOT_KEYED=y +CONFIG_AUTOBOOT_PROMPT="Hit SPACE in %d seconds to stop autoboot.\n" +CONFIG_AUTOBOOT_STOP_STR=" " +CONFIG_AUTOBOOT_KEYED_CTRLC=y +CONFIG_CMD_BOOTZ=y +# CONFIG_CMD_FLASH is not set +CONFIG_CMD_I2C=y +# CONFIG_CMD_LOADS is not set +CONFIG_CMD_MMC=y +CONFIG_CMD_PART=y +CONFIG_CMD_SF=y +CONFIG_CMD_USB=y +CONFIG_CMD_EXT4=y +CONFIG_CMD_FAT=y +CONFIG_CMD_FS_GENERIC=y +CONFIG_OF_CONTROL=y +CONFIG_SPL_OF_CONTROL=y +CONFIG_OF_LIBFDT=y +CONFIG_OF_LIBFDT_OVERLAY=y +CONFIG_DEFAULT_DEVICE_TREE="at91-sama5d27_giantboard" +CONFIG_OF_SPL_REMOVE_PROPS="interrupts interrupt-parent dmas dma-names" +CONFIG_ENV_IS_IN_FAT=y +CONFIG_DM=y +CONFIG_SPL_DM=y +CONFIG_SPL_DM_SEQ_ALIAS=y +CONFIG_CLK=y +CONFIG_SPL_CLK=y +CONFIG_CLK_AT91=y +CONFIG_AT91_UTMI=y +CONFIG_AT91_H32MX=y +CONFIG_AT91_GENERIC_CLK=y +CONFIG_DM_GPIO=y +CONFIG_ATMEL_PIO4=y +CONFIG_DM_I2C=y +CONFIG_SYS_I2C_AT91=y +CONFIG_DM_MMC=y +CONFIG_MMC_SDHCI=y +CONFIG_MMC_SDHCI_ATMEL=y +CONFIG_DM_SPI_FLASH=y +CONFIG_SPI_FLASH=y +# CONFIG_NET is not set +CONFIG_PINCTRL=y +CONFIG_SPL_PINCTRL=y +CONFIG_PINCTRL_AT91PIO4=y +CONFIG_DM_SERIAL=y +CONFIG_DEBUG_UART_ATMEL=y +CONFIG_DEBUG_UART_ANNOUNCE=y +CONFIG_ATMEL_USART=y +CONFIG_SPI=y +CONFIG_DM_SPI=y +CONFIG_TIMER=y +CONFIG_SPL_TIMER=y +CONFIG_ATMEL_PIT_TIMER=y +CONFIG_USB=y +CONFIG_DM_USB=y +CONFIG_USB_EHCI_HCD=y +CONFIG_USB_STORAGE=y +CONFIG_USB_GADGET=y +CONFIG_USB_GADGET_ATMEL_USBA=y diff --git a/configs/sama5d36ek_cmp_mmc_defconfig b/configs/sama5d36ek_cmp_mmc_defconfig index 22c1134658f..7b6cbb1e248 100644 --- a/configs/sama5d36ek_cmp_mmc_defconfig +++ b/configs/sama5d36ek_cmp_mmc_defconfig @@ -46,6 +46,8 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y +CONFIG_PMECC_CAP=4 CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/sama5d36ek_cmp_nandflash_defconfig b/configs/sama5d36ek_cmp_nandflash_defconfig index ed78f4ed487..a3b2fac8532 100644 --- a/configs/sama5d36ek_cmp_nandflash_defconfig +++ b/configs/sama5d36ek_cmp_nandflash_defconfig @@ -46,6 +46,7 @@ CONFIG_DM_MMC=y CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_NAND_ATMEL=y +CONFIG_PMECC_CAP=4 CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER=y CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 diff --git a/configs/sama5d36ek_cmp_spiflash_defconfig b/configs/sama5d36ek_cmp_spiflash_defconfig index 8fc183faa20..4d604a2dea9 100644 --- a/configs/sama5d36ek_cmp_spiflash_defconfig +++ b/configs/sama5d36ek_cmp_spiflash_defconfig @@ -48,6 +48,8 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y +CONFIG_PMECC_CAP=4 CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/sama5d3_xplained_mmc_defconfig b/configs/sama5d3_xplained_mmc_defconfig index c839b4fe6e2..e35a5752662 100644 --- a/configs/sama5d3_xplained_mmc_defconfig +++ b/configs/sama5d3_xplained_mmc_defconfig @@ -65,6 +65,8 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y +CONFIG_PMECC_CAP=4 CONFIG_DM_ETH=y CONFIG_MACB=y CONFIG_PINCTRL=y diff --git a/configs/sama5d3xek_mmc_defconfig b/configs/sama5d3xek_mmc_defconfig index 70c6e30718e..5c0c5cb6b50 100644 --- a/configs/sama5d3xek_mmc_defconfig +++ b/configs/sama5d3xek_mmc_defconfig @@ -70,6 +70,8 @@ CONFIG_SYS_FLASH_PROTECTION=y CONFIG_SYS_FLASH_CFI=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y +CONFIG_PMECC_CAP=4 CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/sama5d3xek_spiflash_defconfig b/configs/sama5d3xek_spiflash_defconfig index 5a06518c9c4..109ac9f522f 100644 --- a/configs/sama5d3xek_spiflash_defconfig +++ b/configs/sama5d3xek_spiflash_defconfig @@ -71,6 +71,8 @@ CONFIG_SYS_FLASH_PROTECTION=y CONFIG_SYS_FLASH_CFI=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y +CONFIG_PMECC_CAP=4 CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/sama5d4_xplained_spiflash_defconfig b/configs/sama5d4_xplained_spiflash_defconfig index d9ad9cc522d..a29bbaed635 100644 --- a/configs/sama5d4_xplained_spiflash_defconfig +++ b/configs/sama5d4_xplained_spiflash_defconfig @@ -67,6 +67,8 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y +CONFIG_PMECC_CAP=8 CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/sama5d4ek_mmc_defconfig b/configs/sama5d4ek_mmc_defconfig index d91a6f66445..3aa1fd4bdd8 100644 --- a/configs/sama5d4ek_mmc_defconfig +++ b/configs/sama5d4ek_mmc_defconfig @@ -61,6 +61,8 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y +CONFIG_PMECC_CAP=8 CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/configs/sama5d4ek_spiflash_defconfig b/configs/sama5d4ek_spiflash_defconfig index 5ebd1cc9b1f..e62619f2ced 100644 --- a/configs/sama5d4ek_spiflash_defconfig +++ b/configs/sama5d4ek_spiflash_defconfig @@ -64,6 +64,8 @@ CONFIG_GENERIC_ATMEL_MCI=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ATMEL=y +CONFIG_ATMEL_NAND_HW_PMECC=y +CONFIG_PMECC_CAP=8 CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_SPEED=30000000 CONFIG_SPI_FLASH_ATMEL=y diff --git a/doc/Makefile b/doc/Makefile index 0e0da5666f8..a686d4728ec 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -106,7 +106,7 @@ cleandocs: $(Q)$(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=doc/media clean dochelp: - @echo ' Linux kernel internal documentation in different formats from ReST:' + @echo ' U-Boot documentation in different formats from ReST:' @echo ' htmldocs - HTML' @echo ' latexdocs - LaTeX' @echo ' pdfdocs - PDF' diff --git a/doc/README.menu b/doc/README.menu deleted file mode 100644 index 0f3d7416055..00000000000 --- a/doc/README.menu +++ /dev/null @@ -1,124 +0,0 @@ -SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright 2010-2011 Calxeda, Inc. - */ - -U-Boot provides a set of interfaces for creating and using simple, text -based menus. Menus are displayed as lists of labeled entries on the -console, and an entry can be selected by entering its label. - -To use the menu code, enable CONFIG_MENU, and include "menu.h" where -the interfaces should be available. - -Menus are composed of items. Each item has a key used to identify it in -the menu, and an opaque pointer to data controlled by the consumer. - -If you want to show a menu, instead starting the shell, define -CONFIG_AUTOBOOT_MENU_SHOW. You have to code the int menu_show(int bootdelay) -function, which handle your menu. This function returns the remaining -bootdelay. - -Interfaces ----------- -#include "menu.h" - -/* - * Consumers of the menu interfaces will use a struct menu * as the - * handle for a menu. struct menu is only fully defined in menu.c, - * preventing consumers of the menu interfaces from accessing its - * contents directly. - */ -struct menu; - -/* - * NOTE: See comments in common/menu.c for more detailed documentation on - * these interfaces. - */ - -/* - * menu_create() - Creates a menu handle with default settings - */ -struct menu *menu_create(char *title, int timeout, int prompt, - void (*item_data_print)(void *), - char *(*item_choice)(void *), - void *item_choice_data); - -/* - * menu_item_add() - Adds or replaces a menu item - */ -int menu_item_add(struct menu *m, char *item_key, void *item_data); - -/* - * menu_default_set() - Sets the default choice for the menu - */ -int menu_default_set(struct menu *m, char *item_key); - -/* - * menu_default_choice() - Set *choice to point to the default item's data - */ -int menu_default_choice(struct menu *m, void **choice); - -/* - * menu_get_choice() - Returns the user's selected menu entry, or the - * default if the menu is set to not prompt or the timeout expires. - */ -int menu_get_choice(struct menu *m, void **choice); - -/* - * menu_destroy() - frees the memory used by a menu and its items. - */ -int menu_destroy(struct menu *m); - -/* - * menu_display_statusline(struct menu *m); - * shows a statusline for every menu_display call. - */ -void menu_display_statusline(struct menu *m); - -Example Code ------------- -This example creates a menu that always prompts, and allows the user -to pick from a list of tools. The item key and data are the same. - -#include "menu.h" - -char *tools[] = { - "Hammer", - "Screwdriver", - "Nail gun", - NULL -}; - -char *pick_a_tool(void) -{ - struct menu *m; - int i; - char *tool = NULL; - - m = menu_create("Tools", 0, 1, NULL); - - for(i = 0; tools[i]; i++) { - if (menu_item_add(m, tools[i], tools[i]) != 1) { - printf("failed to add item!"); - menu_destroy(m); - return NULL; - } - } - - if (menu_get_choice(m, (void **)&tool) != 1) - printf("Problem picking tool!\n"); - - menu_destroy(m); - - return tool; -} - -void caller(void) -{ - char *tool = pick_a_tool(); - - if (tool) { - printf("picked a tool: %s\n", tool); - use_tool(tool); - } -} diff --git a/doc/develop/index.rst b/doc/develop/index.rst index 0a7e204b343..beaa64d8d90 100644 --- a/doc/develop/index.rst +++ b/doc/develop/index.rst @@ -3,13 +3,32 @@ Develop U-Boot ============== +Implementation +-------------- .. toctree:: - :maxdepth: 2 + :maxdepth: 1 - coccinelle commands - crash_dumps global_data logging + menus + +Debugging +--------- + +.. toctree:: + :maxdepth: 1 + + crash_dumps trace + +Testing +------- + +.. toctree:: + :maxdepth: 1 + + coccinelle + testing + py_testing diff --git a/doc/develop/menus.rst b/doc/develop/menus.rst new file mode 100644 index 00000000000..dda8f963fb5 --- /dev/null +++ b/doc/develop/menus.rst @@ -0,0 +1,131 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright 2010-2011 Calxeda, Inc. + +Menus +===== + +U-Boot provides a set of interfaces for creating and using simple, text +based menus. Menus are displayed as lists of labeled entries on the +console, and an entry can be selected by entering its label. + +To use the menu code, enable CONFIG_MENU, and include "menu.h" where +the interfaces should be available. + +Menus are composed of items. Each item has a key used to identify it in +the menu, and an opaque pointer to data controlled by the consumer. + +If you want to show a menu, instead starting the shell, define +CONFIG_AUTOBOOT_MENU_SHOW. You have to code the int menu_show(int bootdelay) +function, which handle your menu. This function returns the remaining +bootdelay. + +Interfaces +---------- + +.. code-block:: c + + #include "menu.h" + + /* + * Consumers of the menu interfaces will use a struct menu * as the + * handle for a menu. struct menu is only fully defined in menu.c, + * preventing consumers of the menu interfaces from accessing its + * contents directly. + */ + struct menu; + + /* + * NOTE: See comments in common/menu.c for more detailed documentation on + * these interfaces. + */ + + /* + * menu_create() - Creates a menu handle with default settings + */ + struct menu *menu_create(char *title, int timeout, int prompt, + void (*item_data_print)(void *), + char *(*item_choice)(void *), + void *item_choice_data); + + /* + * menu_item_add() - Adds or replaces a menu item + */ + int menu_item_add(struct menu *m, char *item_key, void *item_data); + + /* + * menu_default_set() - Sets the default choice for the menu + */ + int menu_default_set(struct menu *m, char *item_key); + + /* + * menu_default_choice() - Set *choice to point to the default item's data + */ + int menu_default_choice(struct menu *m, void **choice); + + /* + * menu_get_choice() - Returns the user's selected menu entry, or the + * default if the menu is set to not prompt or the timeout expires. + */ + int menu_get_choice(struct menu *m, void **choice); + + /* + * menu_destroy() - frees the memory used by a menu and its items. + */ + int menu_destroy(struct menu *m); + + /* + * menu_display_statusline(struct menu *m); + * shows a statusline for every menu_display call. + */ + void menu_display_statusline(struct menu *m); + +Example Code +------------ + +This example creates a menu that always prompts, and allows the user +to pick from a list of tools. The item key and data are the same. + +.. code-block:: c + + #include "menu.h" + + char *tools[] = { + "Hammer", + "Screwdriver", + "Nail gun", + NULL + }; + + char *pick_a_tool(void) + { + struct menu *m; + int i; + char *tool = NULL; + + m = menu_create("Tools", 0, 1, NULL); + + for(i = 0; tools[i]; i++) { + if (menu_item_add(m, tools[i], tools[i]) != 1) { + printf("failed to add item!"); + menu_destroy(m); + return NULL; + } + } + + if (menu_get_choice(m, (void **)&tool) != 1) + printf("Problem picking tool!\n"); + + menu_destroy(m); + + return tool; + } + + void caller(void) + { + char *tool = pick_a_tool(); + + if (tool) { + printf("picked a tool: %s\n", tool); + use_tool(tool); + } + } diff --git a/test/py/README.md b/doc/develop/py_testing.rst index fddc104b266..f71e837aa96 100644 --- a/test/py/README.md +++ b/doc/develop/py_testing.rst @@ -1,6 +1,8 @@ -# U-Boot pytest suite +U-Boot pytest suite +=================== -## Introduction +Introduction +------------ This tool aims to test U-Boot by executing U-Boot shell commands using the console interface. A single top-level script exists to execute or attach to the @@ -14,40 +16,42 @@ results. Advantages of this approach are: flexible than writing it all in C. - It is reasonably simple to interact with U-Boot in this way. -## Requirements +Requirements +------------ The test suite is implemented using pytest. Interaction with the U-Boot console involves executing some binary and interacting with its stdin/stdout. You will need to implement various "hook" scripts that are called by the test suite at the appropriate time. -In order to run the testsuite at a minimum we require that both python3 and -pip for python3 be installed. All of the required python modules are -described in the requirements.txt file in this directory and can be installed -with the command ```pip install -r requirements.txt``` +In order to run the test suite at a minimum we require that both Python 3 and +pip for Python 3 are installed. All of the required python modules are +described in the requirements.txt file in the /test/py/ directory and can be +installed via the command + +.. code-block:: bash + + pip install -r requirements.txt In order to execute certain tests on their supported platforms other tools -will be required. The following is an incomplete list: - -| Package | -| -------------- | -| gdisk | -| dfu-util | -| dtc | -| openssl | -| sudo OR guestmount | -| e2fsprogs | -| util-linux | -| coreutils | -| dosfstools | -| efitools | -| mount | -| mtools | -| sbsigntool | -| udisks2 | - - -Please use the apporirate commands for your distribution to match these tools +will be required. The following is an incomplete list: + +* gdisk +* dfu-util +* dtc +* openssl +* sudo OR guestmount +* e2fsprogs +* util-linux +* coreutils +* dosfstools +* efitools +* mount +* mtools +* sbsigntool +* udisks2 + +Please use the appropriate commands for your distribution to match these tools up with the package that provides them. The test script supports either: @@ -58,28 +62,31 @@ The test script supports either: physical board, attach to the board's console stream, and reset the board. Further details are described later. -### Using `virtualenv` to provide requirements +Using `virtualenv` to provide requirements +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The recommended way to run the test suite, in order to ensure reproducibility is to use `virtualenv` to set up the necessary environment. This can be done via the following commands: -```bash -$ cd /path/to/u-boot -$ sudo apt-get install python3 python3-virtualenv -$ virtualenv -p /usr/bin/python3 venv -$ . ./venv/bin/activate -$ pip install -r test/py/requirements.txt -``` -## Testing sandbox +.. code-block:: console + + $ cd /path/to/u-boot + $ sudo apt-get install python3 python3-virtualenv + $ virtualenv -p /usr/bin/python3 venv + $ . ./venv/bin/activate + $ pip install -r test/py/requirements.txt -To run the testsuite on the sandbox port (U-Boot built as a native user-space +Testing sandbox +--------------- + +To run the test suite on the sandbox port (U-Boot built as a native user-space application), simply execute: -``` -./test/py/test.py --bd sandbox --build -``` +.. code-block:: bash + + ./test/py/test.py --bd sandbox --build The `--bd` option tells the test suite which board type is being tested. This lets the test suite know which features the board has, and hence exactly what @@ -95,7 +102,8 @@ will be written to `${build_dir}/test-log.html`. This is best viewed in a web browser, but may be read directly as plain text, perhaps with the aid of the `html2text` utility. -### Testing under a debugger +Testing under a debugger +~~~~~~~~~~~~~~~~~~~~~~~~ If you need to run sandbox under a debugger, you may pass the command-line option `--gdbserver COMM`. This causes two things to happens: @@ -111,19 +119,21 @@ option `--gdbserver COMM`. This causes two things to happens: A usage example is: Window 1: -```shell -./test/py/test.py --bd sandbox --gdbserver localhost:1234 -``` + +.. code-block:: bash + + ./test/py/test.py --bd sandbox --gdbserver localhost:1234 Window 2: -```shell -gdb ./build-sandbox/u-boot -ex 'target remote localhost:1234' -``` + +.. code-block:: bash + + gdb ./build-sandbox/u-boot -ex 'target remote localhost:1234' Alternatively, you could leave off the `-ex` option and type the command manually into gdb once it starts. -You can use any debugger you wish, so long as it speaks the gdb remote +You can use any debugger you wish, as long as it speaks the gdb remote protocol, or any graphical wrapper around gdb. Some tests deliberately cause the sandbox process to exit, e.g. to test the @@ -132,30 +142,39 @@ to attach the debugger to the new sandbox instance. If these tests are not relevant to your debugging session, you can skip them using pytest's -k command-line option; see the next section. -## Command-line options - -- `--board-type`, `--bd`, `-B` set the type of the board to be tested. For - example, `sandbox` or `seaboard`. -- `--board-identity`, `--id` set the identity of the board to be tested. - This allows differentiation between multiple instances of the same type of - physical board that are attached to the same host machine. This parameter is - not interpreted by the test script in any way, but rather is simply passed - to the hook scripts described below, and may be used in any site-specific - way deemed necessary. -- `--build` indicates that the test script should compile U-Boot itself - before running the tests. If using this option, make sure that any - environment variables required by the build process are already set, such as - `$CROSS_COMPILE`. -- `--buildman` indicates that `--build` should use buildman to build U-Boot. - There is no need to set $CROSS_COMPILE` in this case since buildman handles - it. -- `--build-dir` sets the directory containing the compiled U-Boot binaries. - If omitted, this is `${source_dir}/build-${board_type}`. -- `--result-dir` sets the directory to write results, such as log files, - into. If omitted, the build directory is used. -- `--persistent-data-dir` sets the directory used to store persistent test - data. This is test data that may be re-used across test runs, such as file- - system images. +Command-line options +-------------------- + +--board-type, --bd, -B + set the type of the board to be tested. For example, `sandbox` or `seaboard`. + +--board-identity`, --id + sets the identity of the board to be tested. This allows differentiation + between multiple instances of the same type of physical board that are + attached to the same host machine. This parameter is not interpreted by th + test script in any way, but rather is simply passed to the hook scripts + described below, and may be used in any site-specific way deemed necessary. + +--build + indicates that the test script should compile U-Boot itself before running + the tests. If using this option, make sure that any environment variables + required by the build process are already set, such as `$CROSS_COMPILE`. + +--buildman + indicates that `--build` should use buildman to build U-Boot. There is no need + to set $CROSS_COMPILE` in this case since buildman handles it. + +--build-dir + sets the directory containing the compiled U-Boot binaries. If omitted, this + is `${source_dir}/build-${board_type}`. + +--result-dir + sets the directory to write results, such as log files, into. + If omitted, the build directory is used. + +--persistent-data-dir + sets the directory used to store persistent test data. This is test data that + may be re-used across test runs, such as file-system images. `pytest` also implements a number of its own command-line options. Commonly used options are mentioned below. Please see `pytest` documentation for complete @@ -163,21 +182,26 @@ details. Execute `py.test --version` for a brief summary. Note that U-Boot's test.py script passes all command-line arguments directly to `pytest` for processing. -- `-k` selects which tests to run. The default is to run all known tests. This +-k + selects which tests to run. The default is to run all known tests. This option takes a single argument which is used to filter test names. Simple logical operators are supported. For example: - - `'ums'` runs only tests with "ums" in their name. - - `'ut_dm'` runs only tests with "ut_dm" in their name. Note that in this + + - `'-k ums'` runs only tests with "ums" in their name. + - `'-k ut_dm'` runs only tests with "ut_dm" in their name. Note that in this case, "ut_dm" is a parameter to a test rather than the test name. The full test name is e.g. "test_ut[ut_dm_leak]". - - `'not reset'` runs everything except tests with "reset" in their name. - - `'ut or hush'` runs only tests with "ut" or "hush" in their name. - - `'not (ut or hush)'` runs everything except tests with "ut" or "hush" in + - `'-k not reset'` runs everything except tests with "reset" in their name. + - `'-k ut or hush'` runs only tests with "ut" or "hush" in their name. + - `'-k not (ut or hush)'` runs everything except tests with "ut" or "hush" in their name. -- `-s` prevents pytest from hiding a test's stdout. This allows you to see + +-s + prevents pytest from hiding a test's stdout. This allows you to see U-Boot's console log in real time on pytest's stdout. -## Testing real hardware +Testing real hardware +--------------------- The tools and techniques used to interact with real hardware will vary radically between different host and target systems, and the whims of the user. @@ -187,9 +211,11 @@ via `$PATH`. These scripts implement certain actions on behalf of the test suite. This keeps the test suite simple and isolated from system variances unrelated to U-Boot features. -### Hook scripts +Hook scripts +~~~~~~~~~~~~ -#### Environment variables +Environment variables +''''''''''''''''''''' The following environment variables are set when running hook scripts: @@ -202,16 +228,18 @@ The following environment variables are set when running hook scripts: - `UBOOT_RESULT_DIR` the test result directory. - `UBOOT_PERSISTENT_DATA_DIR` the test persistent data directory. -#### `u-boot-test-console` +u-boot-test-console +''''''''''''''''''' This script provides access to the U-Boot console. The script's stdin/stdout should be connected to the board's console. This process should continue to run indefinitely, until killed. The test suite will run this script in parallel with all other hooks. -This script may be implemented e.g. by exec()ing `cu`, `kermit`, `conmux`, etc. +This script may be implemented e.g. by executing `cu`, `kermit`, `conmux`, etc. +via exec(). -If you are able to run U-Boot under a hardware simulator such as qemu, then +If you are able to run U-Boot under a hardware simulator such as QEMU, then you would likely spawn that simulator from this script. However, note that `u-boot-test-reset` may be called multiple times per test script run, and must cause U-Boot to start execution from scratch each time. Hopefully your @@ -219,10 +247,11 @@ simulator includes a virtual reset button! If not, you can launch the simulator from `u-boot-test-reset` instead, while arranging for this console process to always communicate with the current simulator instance. -#### `u-boot-test-flash` +u-boot-test-flash +''''''''''''''''' Prior to running the test suite against a board, some arrangement must be made -so that the board executes the particular U-Boot binary to be tested. Often, +so that the board executes the particular U-Boot binary to be tested. Often this involves writing the U-Boot binary to the board's flash ROM. The test suite calls this hook script for that purpose. @@ -248,7 +277,8 @@ hook script appropriately. This script will typically be implemented by calling out to some SoC- or board-specific vendor flashing utility. -#### `u-boot-test-reset` +u-boot-test-reset +''''''''''''''''' Whenever the test suite needs to reset the target board, this script is executed. This is guaranteed to happen at least once, prior to executing the @@ -261,20 +291,22 @@ relay or electronic switch attached to the board's reset signal. The semantics of this script require that when it is executed, U-Boot will start running from scratch. If the U-Boot binary to be tested has been written -to flash, pulsing the board's reset signal is likely all this script need do. -However, in some scenarios, this script may perform other actions. For +to flash, pulsing the board's reset signal is likely all this script needs to +do. However, in some scenarios, this script may perform other actions. For example, it may call out to some SoC- or board-specific vendor utility in order to download the U-Boot binary directly into RAM and execute it. This would avoid the need for `u-boot-test-flash` to actually write U-Boot to flash, thus saving wear on the flash chip(s). -#### Examples +Examples +'''''''' https://github.com/swarren/uboot-test-hooks contains some working example hook scripts, and may be useful as a reference when implementing hook scripts for your platform. These scripts are not considered part of U-Boot itself. -### Board-type-specific configuration +Board-type-specific configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Each board has a different configuration and behaviour. Many of these differences can be automatically detected by parsing the `.config` file in the @@ -286,7 +318,8 @@ defined in these modules is available for use by any test function. The data contained in these scripts must be purely derived from U-Boot source code. Hence, these configuration files are part of the U-Boot source tree too. -### Execution environment configuration +Execution environment configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Each user's hardware setup may enable testing different subsets of the features implemented by a particular board's configuration of U-Boot. For example, a @@ -304,14 +337,16 @@ U-Boot source tree, and should be installed outside of the source tree. Users should set `$PYTHONPATH` prior to running the test script to allow these modules to be loaded. -### Board module parameter usage +Board module parameter usage +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The test scripts rely on the following variables being defined by the board module: -- None at present. +- none at present -### U-Boot `.config` feature usage +U-Boot `.config` feature usage +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The test scripts rely on various U-Boot `.config` features, either directly in order to test those features, or indirectly in order to query information from @@ -328,7 +363,8 @@ instances of: - `@pytest.mark.buildconfigspec(...` - `@pytest.mark.notbuildconfigspec(...` -### Complete invocation example +Complete invocation example +~~~~~~~~~~~~~~~~~~~~~~~~~~~ Assuming that you have installed the hook scripts into $HOME/ubtest/bin, and any required environment configuration Python modules into $HOME/ubtest/py, @@ -336,32 +372,33 @@ then you would likely invoke the test script as follows: If U-Boot has already been built: -```bash -PATH=$HOME/ubtest/bin:$PATH \ +.. code-block:: bash + + PATH=$HOME/ubtest/bin:$PATH \ PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \ ./test/py/test.py --bd seaboard -``` If you want the test script to compile U-Boot for you too, then you likely need to set `$CROSS_COMPILE` to allow this, and invoke the test script as follows: -```bash -CROSS_COMPILE=arm-none-eabi- \ +.. code-block:: bash + + CROSS_COMPILE=arm-none-eabi- \ PATH=$HOME/ubtest/bin:$PATH \ PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \ ./test/py/test.py --bd seaboard --build -``` or, using buildman to handle it: -```bash +.. code-block:: bash + PATH=$HOME/ubtest/bin:$PATH \ PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \ ./test/py/test.py --bd seaboard --build --buildman -``` -## Writing tests +Writing tests +------------- Please refer to the pytest documentation for details of writing pytest tests. Details specific to the U-Boot test suite are described below. diff --git a/test/README b/doc/develop/testing.rst index 4bc9ca3a6ae..4bc9ca3a6ae 100644 --- a/test/README +++ b/doc/develop/testing.rst diff --git a/doc/device-tree-bindings/pinctrl/atmel,at91-pio4-pinctrl.txt b/doc/device-tree-bindings/pinctrl/atmel,at91-pio4-pinctrl.txt index a376c6fba5d..9252dc154e9 100644 --- a/doc/device-tree-bindings/pinctrl/atmel,at91-pio4-pinctrl.txt +++ b/doc/device-tree-bindings/pinctrl/atmel,at91-pio4-pinctrl.txt @@ -28,6 +28,8 @@ Optional properties: - GENERIC_PINCONFIG: generic pinconfig options to use, bias-disable, bias-pull-down, bias-pull-up, drive-open-drain, input-schmitt-enable, input-debounce. +- atmel,drive-strength: 0 or 1 for low drive, 2 for medium drive and 3 for +high drive. The default value is low drive. Example: diff --git a/doc/uImage.FIT/source_file_format.txt b/doc/uImage.FIT/source_file_format.txt index 633f227c59c..00ed3ebe935 100644 --- a/doc/uImage.FIT/source_file_format.txt +++ b/doc/uImage.FIT/source_file_format.txt @@ -126,12 +126,10 @@ Root node of the uImage Tree should have the following layout: load addresses supplied within sub-image nodes. May be omitted when no entry or load addresses are used. - Mandatory node: + Mandatory nodes: - images : This node contains a set of sub-nodes, each of them representing single component sub-image (like kernel, ramdisk, etc.). At least one sub-image is required. - - Optional node: - configurations : Contains a set of available configuration nodes and defines a default configuration. @@ -169,8 +167,8 @@ the '/images' node should have the following layout: to "none". Conditionally mandatory property: - - os : OS name, mandatory for types "kernel" and "ramdisk". Valid OS names - are: "openbsd", "netbsd", "freebsd", "4_4bsd", "linux", "svr4", "esix", + - os : OS name, mandatory for types "kernel". Valid OS names are: + "openbsd", "netbsd", "freebsd", "4_4bsd", "linux", "svr4", "esix", "solaris", "irix", "sco", "dell", "ncr", "lynxos", "vxworks", "psos", "qnx", "u-boot", "rtems", "unity", "integrity". - arch : Architecture name, mandatory for types: "standalone", "kernel", @@ -179,10 +177,13 @@ the '/images' node should have the following layout: "sparc64", "m68k", "microblaze", "nios2", "blackfin", "avr32", "st200", "sandbox". - entry : entry point address, address size is determined by - '#address-cells' property of the root node. Mandatory for for types: - "standalone" and "kernel". + '#address-cells' property of the root node. + Mandatory for types: "firmware", and "kernel". - load : load address, address size is determined by '#address-cells' - property of the root node. Mandatory for types: "standalone" and "kernel". + property of the root node. + Mandatory for types: "firmware", and "kernel". + - compatible : compatible method for loading image. + Mandatory for types: "fpga", and images that do not specify a load address. Optional nodes: - hash-1 : Each hash sub-node represents separate hash or checksum @@ -205,9 +206,8 @@ o hash-1 6) '/configurations' node ------------------------- -The 'configurations' node is optional. If present, it allows to create a -convenient, labeled boot configurations, which combine together kernel images -with their ramdisks and fdt blobs. +The 'configurations' node creates convenient, labeled boot configurations, +which combine together kernel images with their ramdisks and fdt blobs. The 'configurations' node has has the following structure: @@ -236,27 +236,22 @@ Each configuration has the following structure: o config-1 |- description = "configuration description" |- kernel = "kernel sub-node unit name" - |- ramdisk = "ramdisk sub-node unit name" |- fdt = "fdt sub-node unit-name" [, "fdt overlay sub-node unit-name", ...] - |- fpga = "fpga sub-node unit-name" |- loadables = "loadables sub-node unit-name" |- compatible = "vendor,board-style device tree compatible string" Mandatory properties: - description : Textual configuration description. - - kernel : Unit name of the corresponding kernel image (image sub-node of a - "kernel" type). + - kernel or firmware: Unit name of the corresponding kernel or firmware + (u-boot, op-tee, etc) image. If both "kernel" and "firmware" are specified, + control is passed to the firmware image. Optional properties: - - ramdisk : Unit name of the corresponding ramdisk image (component image - node of a "ramdisk" type). - fdt : Unit name of the corresponding fdt blob (component image node of a "fdt type"). Additional fdt overlay nodes can be supplied which signify that the resulting device tree blob is generated by the first base fdt blob with all subsequent overlays applied. - - setup : Unit name of the corresponding setup binary (used for booting - an x86 kernel). This contains the setup.bin file built by the kernel. - fpga : Unit name of the corresponding fpga bitstream blob (component image node of a "fpga type"). - loadables : Unit name containing a list of additional binaries to be diff --git a/doc/usage/conitrace.rst b/doc/usage/conitrace.rst new file mode 100644 index 00000000000..d9916c865ee --- /dev/null +++ b/doc/usage/conitrace.rst @@ -0,0 +1,54 @@ +conitrace command +================= + +Synopsis +-------- + +:: + + conitrace + +Description +----------- + +The conitrace command is used to test the correct function of the console input +driver. It is especially valuable for checking the support for special keys like +<F1> or <POS1>. + +To display escape sequences on a single line the output only advances to the +next line after detecting a pause of a few milliseconds. + +The output is hexadecimal. + +Examples +-------- + +Entering keys <B><SHIFT-B><CTRL-B><X> + +:: + + => conitrace + Waiting for your input + To terminate type 'x' + 62 + 42 + 02 + => + +Entering keys <F1><POS1><DEL><BACKSPACE><X> + +:: + + => conitrace + Waiting for your input + To terminate type 'x' + 1b 4f 50 + 1b 5b 48 + 1b 5b 33 7e + 7f + => + +Configuration +------------- + +The conitrace command is only available if CONFIG_CMD_CONITRACE=y. diff --git a/doc/usage/echo.rst b/doc/usage/echo.rst new file mode 100644 index 00000000000..861abdfd1eb --- /dev/null +++ b/doc/usage/echo.rst @@ -0,0 +1,65 @@ +echo command +============ + +Synopsis +-------- + +:: + + echo [-n] [args ...] + +Description +----------- + +The echo command prints its arguments to the console separated by spaces. + +-n + Do not print a line feed after the last argument. + +args + Arguments to be printed. The arguments are evaluated before being passed to + the command. + +Examples +-------- + +Strings are parsed before the arguments are passed to the echo command: + +:: + + => echo "a" 'b' c + a b c + => + +Observe how variables included in strings are handled: + +:: + + => setenv var X; echo "a)" ${var} 'b)' '${var}' c) ${var} + a) X b) ${var} c) X + => + + +-n suppresses the line feed: + +:: + + => echo -n 1 2 3; echo a b c + 1 2 3a b c + => echo -n 1 2 3 + 1 2 3=> + +A more complex example: + +:: + + => for i in a b c; do for j in 1 2 3; do echo -n "${i}${j}, "; done; echo; done; + a1, a2, a3, + b1, b2, b3, + c1, c2, c3, + => + +Return value +------------ + +The return value $? is always set to 0 (true). diff --git a/doc/usage/exit.rst b/doc/usage/exit.rst new file mode 100644 index 00000000000..769223c4775 --- /dev/null +++ b/doc/usage/exit.rst @@ -0,0 +1,40 @@ +exit command +============ + +Synopsis +-------- + +:: + + exit + +Description +----------- + +The exit command terminates a script started via the run or source command. +If scripts are nested, only the innermost script is left. + +:: + + => setenv inner 'echo entry inner; exit; echo inner done' + => setenv outer 'echo entry outer; run inner; echo outer done' + => run outer + entry outer + entry inner + outer done + => + +When executed outside a script a warning is written. Following commands are not +executed. + +:: + + => echo first; exit; echo last + first + exit not allowed from main input shell. + => + +Return value +------------ + +$? is always set to 0 (true). diff --git a/doc/usage/false.rst b/doc/usage/false.rst new file mode 100644 index 00000000000..a17fe860217 --- /dev/null +++ b/doc/usage/false.rst @@ -0,0 +1,28 @@ +false command +============= + +Synopsis +-------- + +:: + + false + +Description +----------- + +The false command sets the return value $? to 1 (false). + +Example +------- + +:: + + => false; echo $? + 1 + => + +Configuration +------------- + +The false command is only available if CONFIG_HUSH_PARSER=y. diff --git a/doc/usage/for.rst b/doc/usage/for.rst new file mode 100644 index 00000000000..f9e504979c3 --- /dev/null +++ b/doc/usage/for.rst @@ -0,0 +1,65 @@ +for command +=========== + +Synopis +------- + +:: + + for <variable> in <items>; do <commands>; done + +Description +----------- + +The for command is used to loop over a list of values and execute a series of +commands for each of these. + +The counter variable of the loop is a shell variable. Please, keep in mind that +an environment variable takes precedence over a shell variable of the same name. + +variable + name of the counter variable + +items + space separated item list + +commands + commands to execute + +Example +------- + +:: + + => setenv c + => for c in 1 2 3; do echo item ${c}; done + item 1 + item 2 + item 3 + => echo ${c} + 3 + => setenv c x + => for c in 1 2 3; do echo item ${c}; done + item x + item x + item x + => + +The first line ensures that there is no environment variable *c*. Hence in the +first loop the shell variable *c* is printed. + +After defining an environment variable of name *c* it takes precedence over the +shell variable and the environment variable is printed. + +Return value +------------ + +The return value $? after the done statement is the return value of the last +statement executed in the loop. + +:: + + => for i in true false; do ${i}; done; echo $? + 1 + => for i in false true; do ${i}; done; echo $? + 0 diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 6def2507663..f75bd082378 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -17,5 +17,13 @@ Shell commands bootefi bootmenu button + conitrace + echo + exit + false + for + loady mbr pstore + sbi + true diff --git a/doc/usage/loady.rst b/doc/usage/loady.rst new file mode 100644 index 00000000000..2819cc72aef --- /dev/null +++ b/doc/usage/loady.rst @@ -0,0 +1,67 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +loady command +============= + +Synopsis +-------- + +:: + + loady [addr [baud]] + +Description +----------- + +The loady command is used to transfer a file to the device via the serial line +using the YMODEM protocol. + +The number of transferred bytes is saved in environment variable filesize. + +addr + load address, defaults to environment variable loadaddr or if loadaddr is + not set to configuration variable CONFIG_SYS_LOAD_ADDR + +baud + baud rate for the ymodem transmission. After the transmission the baud + rate is reset to the original value. + +Example +------- + +In the example below the terminal emulation program picocom was used to +transfer a file to the device. + +After entering the loady command the key sequence <CTRL-A><CTRL-S> is used to +let picocom prompt for the file name. Picocom invokes the program sz for the +file transfer. + +:: + + => loady 80064000 115200 + ## Ready for binary (ymodem) download to 0x80064000 at 115200 bps... + C + *** file: BOOTRISCV64.EFI + $ sz -b -vv BOOTRISCV64.EFI + Sending: BOOTRISCV64.EFI + Bytes Sent: 398976 BPS:7883 + Sending: + Ymodem sectors/kbytes sent: 0/ 0k + Transfer complete + + *** exit status: 0 *** + /1(CAN) packets, 4 retries + ## Total Size = 0x0006165f = 398943 Bytes + => echo ${filesize} + 6165f + => + +Configuration +------------- + +The command is only available if CONFIG_CMD_LOADB=y. + +Return value +------------ + +The return value $? is always 0 (true). diff --git a/doc/usage/sbi.rst b/doc/usage/sbi.rst new file mode 100644 index 00000000000..96d8861057f --- /dev/null +++ b/doc/usage/sbi.rst @@ -0,0 +1,49 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +sbi command +=========== + +Synopsis +-------- + +:: + + sbi + +Description +----------- + +The sbi command is used to display information about the SBI (Supervisor Binary +Interface) implementation on RISC-V systems. + +The output may look like: + +:: + + => sbi + SBI 0.2 + OpenSBI + Extensions: + sbi_set_timer + sbi_console_putchar + sbi_console_getchar + sbi_clear_ipi + sbi_send_ipi + sbi_remote_fence_i + sbi_remote_sfence_vma + sbi_remote_sfence_vma_asid + sbi_shutdown + SBI Base Functionality + Timer Extension + IPI Extension + RFENCE Extension + Hart State Management Extension + +The first line indicates the version of the RISC-V SBI specification. +The second line indicates the implementation. +The further lines enumerate the implemented extensions. + +Configuration +------------- + +To use the sbi command you must specify CONFIG_CMD_SBI=y. diff --git a/doc/usage/true.rst b/doc/usage/true.rst new file mode 100644 index 00000000000..f9ef71b2d1b --- /dev/null +++ b/doc/usage/true.rst @@ -0,0 +1,28 @@ +true command +============ + +Synopsis +-------- + +:: + + true + +Description +----------- + +The true command sets the return value $? to 0 (true). + +Example +------- + +:: + + => true; echo $? + 0 + => + +Configuration +------------- + +The true command is only available if CONFIG_HUSH_PARSER=y. diff --git a/drivers/mmc/exynos_dw_mmc.c b/drivers/mmc/exynos_dw_mmc.c index 2fc1ef18c74..b4ff1c3fb4b 100644 --- a/drivers/mmc/exynos_dw_mmc.c +++ b/drivers/mmc/exynos_dw_mmc.c @@ -135,8 +135,6 @@ static int exynos_dwmci_core_init(struct dwmci_host *host) return 0; } -static struct dwmci_host dwmci_host[DWMMC_MAX_CH_NUM]; - static int do_dwmci_init(struct dwmci_host *host) { int flag, err; @@ -208,60 +206,6 @@ static int exynos_dwmci_get_config(const void *blob, int node, return 0; } -static int exynos_dwmci_process_node(const void *blob, - int node_list[], int count) -{ - struct dwmci_exynos_priv_data *priv; - struct dwmci_host *host; - int i, node, err; - - for (i = 0; i < count; i++) { - node = node_list[i]; - if (node <= 0) - continue; - host = &dwmci_host[i]; - - priv = malloc(sizeof(struct dwmci_exynos_priv_data)); - if (!priv) { - pr_err("dwmci_exynos_priv_data malloc fail!\n"); - return -ENOMEM; - } - - err = exynos_dwmci_get_config(blob, node, host, priv); - if (err) { - printf("%s: failed to decode dev %d\n", __func__, i); - free(priv); - return err; - } - host->priv = priv; - - do_dwmci_init(host); - } - return 0; -} - -int exynos_dwmmc_init(const void *blob) -{ - int node_list[DWMMC_MAX_CH_NUM]; - int boot_dev_node; - int err = 0, count; - - count = fdtdec_find_aliases_for_id(blob, "mmc", - COMPAT_SAMSUNG_EXYNOS_DWMMC, node_list, - DWMMC_MAX_CH_NUM); - - /* For DWMMC always set boot device as mmc 0 */ - if (count >= 3 && get_boot_mode() == BOOT_MODE_SD) { - boot_dev_node = node_list[2]; - node_list[2] = node_list[0]; - node_list[0] = boot_dev_node; - } - - err = exynos_dwmci_process_node(blob, node_list, count); - - return err; -} - #ifdef CONFIG_DM_MMC static int exynos_dwmmc_probe(struct udevice *dev) { diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 2225b33ff65..6e26467700a 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -144,11 +144,20 @@ struct macb_device { #endif }; +struct macb_usrio_cfg { + unsigned int mii; + unsigned int rmii; + unsigned int rgmii; + unsigned int clken; +}; + struct macb_config { unsigned int dma_burst_length; unsigned int hw_dma_cap; + unsigned int caps; int (*clk_init)(struct udevice *dev, ulong rate); + const struct macb_usrio_cfg *usrio; }; #ifndef CONFIG_DM_ETH @@ -586,6 +595,23 @@ static int macb_sifive_clk_init(struct udevice *dev, ulong rate) return 0; } +static int macb_sama7g5_clk_init(struct udevice *dev, ulong rate) +{ + struct clk clk; + int ret; + + ret = clk_get_by_name(dev, "tx_clk", &clk); + if (ret) + return ret; + + /* + * This is for using GCK. Clock rate is addressed via assigned-clock + * property, so only clock enable is needed here. The switching to + * proper clock rate depending on link speed is managed by IP logic. + */ + return clk_enable(&clk); +} + int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed) { #ifdef CONFIG_CLK @@ -622,7 +648,7 @@ int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed) if (tx_clk.dev) { ret = clk_set_rate(&tx_clk, rate); - if (ret) + if (ret < 0) return ret; } #endif @@ -850,6 +876,7 @@ static int _macb_init(struct macb_device *macb, const char *name) { #ifdef CONFIG_DM_ETH struct macb_device *macb = dev_get_priv(dev); + unsigned int val = 0; #endif unsigned long paddr; int ret; @@ -920,11 +947,20 @@ static int _macb_init(struct macb_device *macb, const char *name) * to select interface between RMII and MII. */ #ifdef CONFIG_DM_ETH - if ((macb->phy_interface == PHY_INTERFACE_MODE_RMII) || - (macb->phy_interface == PHY_INTERFACE_MODE_RGMII)) - gem_writel(macb, USRIO, GEM_BIT(RGMII)); - else - gem_writel(macb, USRIO, 0); + if (macb->phy_interface == PHY_INTERFACE_MODE_RGMII || + macb->phy_interface == PHY_INTERFACE_MODE_RGMII_ID || + macb->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID || + macb->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) + val = macb->config->usrio->rgmii; + else if (macb->phy_interface == PHY_INTERFACE_MODE_RMII) + val = macb->config->usrio->rmii; + else if (macb->phy_interface == PHY_INTERFACE_MODE_MII) + val = macb->config->usrio->mii; + + if (macb->config->caps & MACB_CAPS_USRIO_HAS_CLKEN) + val |= macb->config->usrio->clken; + + gem_writel(macb, USRIO, val); if (macb->phy_interface == PHY_INTERFACE_MODE_SGMII) { unsigned int ncfgr = macb_readl(macb, NCFGR); @@ -934,7 +970,7 @@ static int _macb_init(struct macb_device *macb, const char *name) } #else #if defined(CONFIG_RGMII) || defined(CONFIG_RMII) - gem_writel(macb, USRIO, GEM_BIT(RGMII)); + gem_writel(macb, USRIO, macb->config->usrio->rgmii); #else gem_writel(macb, USRIO, 0); #endif @@ -945,28 +981,30 @@ static int _macb_init(struct macb_device *macb, const char *name) #ifdef CONFIG_AT91FAMILY if (macb->phy_interface == PHY_INTERFACE_MODE_RMII) { macb_writel(macb, USRIO, - MACB_BIT(RMII) | MACB_BIT(CLKEN)); + macb->config->usrio->rmii | + macb->config->usrio->clken); } else { - macb_writel(macb, USRIO, MACB_BIT(CLKEN)); + macb_writel(macb, USRIO, macb->config->usrio->clken); } #else if (macb->phy_interface == PHY_INTERFACE_MODE_RMII) macb_writel(macb, USRIO, 0); else - macb_writel(macb, USRIO, MACB_BIT(MII)); + macb_writel(macb, USRIO, macb->config->usrio->mii); #endif #else #ifdef CONFIG_RMII #ifdef CONFIG_AT91FAMILY - macb_writel(macb, USRIO, MACB_BIT(RMII) | MACB_BIT(CLKEN)); + macb_writel(macb, USRIO, macb->config->usrio->rmii | + macb->config->usrio->clken); #else macb_writel(macb, USRIO, 0); #endif #else #ifdef CONFIG_AT91FAMILY - macb_writel(macb, USRIO, MACB_BIT(CLKEN)); + macb_writel(macb, USRIO, macb->config->usrio->clken); #else - macb_writel(macb, USRIO, MACB_BIT(MII)); + macb_writel(macb, USRIO, macb->config->usrio->mii); #endif #endif /* CONFIG_RMII */ #endif @@ -1307,10 +1345,18 @@ static int macb_enable_clk(struct udevice *dev) } #endif +static const struct macb_usrio_cfg macb_default_usrio = { + .mii = MACB_BIT(MII), + .rmii = MACB_BIT(RMII), + .rgmii = GEM_BIT(RGMII), + .clken = MACB_BIT(CLKEN), +}; + static const struct macb_config default_gem_config = { .dma_burst_length = 16, .hw_dma_cap = HW_DMA_CAP_32B, .clk_init = NULL, + .usrio = &macb_default_usrio, }; static int macb_eth_probe(struct udevice *dev) @@ -1404,28 +1450,56 @@ static int macb_eth_of_to_plat(struct udevice *dev) return macb_late_eth_of_to_plat(dev); } +static const struct macb_usrio_cfg sama7g5_usrio = { + .mii = 0, + .rmii = 1, + .rgmii = 2, + .clken = BIT(2), +}; + static const struct macb_config microchip_config = { .dma_burst_length = 16, .hw_dma_cap = HW_DMA_CAP_64B, .clk_init = NULL, + .usrio = &macb_default_usrio, }; static const struct macb_config sama5d4_config = { .dma_burst_length = 4, .hw_dma_cap = HW_DMA_CAP_32B, .clk_init = NULL, + .usrio = &macb_default_usrio, }; static const struct macb_config sifive_config = { .dma_burst_length = 16, .hw_dma_cap = HW_DMA_CAP_32B, .clk_init = macb_sifive_clk_init, + .usrio = &macb_default_usrio, +}; + +static const struct macb_config sama7g5_gmac_config = { + .dma_burst_length = 16, + .hw_dma_cap = HW_DMA_CAP_32B, + .clk_init = macb_sama7g5_clk_init, + .usrio = &sama7g5_usrio, +}; + +static const struct macb_config sama7g5_emac_config = { + .caps = MACB_CAPS_USRIO_HAS_CLKEN, + .dma_burst_length = 16, + .hw_dma_cap = HW_DMA_CAP_32B, + .usrio = &sama7g5_usrio, }; static const struct udevice_id macb_eth_ids[] = { { .compatible = "cdns,macb" }, { .compatible = "cdns,at91sam9260-macb" }, { .compatible = "cdns,sam9x60-macb" }, + { .compatible = "cdns,sama7g5-gem", + .data = (ulong)&sama7g5_gmac_config }, + { .compatible = "cdns,sama7g5-emac", + .data = (ulong)&sama7g5_emac_config }, { .compatible = "atmel,sama5d2-gem" }, { .compatible = "atmel,sama5d3-gem" }, { .compatible = "atmel,sama5d4-gem", .data = (ulong)&sama5d4_config }, diff --git a/drivers/net/phy/micrel_ksz90x1.c b/drivers/net/phy/micrel_ksz90x1.c index f0032e8ce16..77fad4a8fc9 100644 --- a/drivers/net/phy/micrel_ksz90x1.c +++ b/drivers/net/phy/micrel_ksz90x1.c @@ -396,9 +396,70 @@ static struct phy_driver ksz9031_driver = { /* * KSZ9131 */ + +#define KSZ9131RN_MMD_COMMON_CTRL_REG 2 +#define KSZ9131RN_RXC_DLL_CTRL 76 +#define KSZ9131RN_TXC_DLL_CTRL 77 +#define KSZ9131RN_DLL_CTRL_BYPASS BIT_MASK(12) +#define KSZ9131RN_DLL_ENABLE_DELAY 0 +#define KSZ9131RN_DLL_DISABLE_DELAY BIT(12) + +static int ksz9131_config_rgmii_delay(struct phy_device *phydev) +{ + struct phy_driver *drv = phydev->drv; + u16 rxcdll_val, txcdll_val, val; + int ret; + + switch (phydev->interface) { + case PHY_INTERFACE_MODE_RGMII: + rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY; + txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY; + break; + case PHY_INTERFACE_MODE_RGMII_ID: + rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY; + txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY; + break; + case PHY_INTERFACE_MODE_RGMII_RXID: + rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY; + txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY; + break; + case PHY_INTERFACE_MODE_RGMII_TXID: + rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY; + txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY; + break; + default: + return 0; + } + + val = drv->readext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG, + KSZ9131RN_RXC_DLL_CTRL); + val &= ~KSZ9131RN_DLL_CTRL_BYPASS; + val |= rxcdll_val; + ret = drv->writeext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG, + KSZ9131RN_RXC_DLL_CTRL, val); + if (ret) + return ret; + + val = drv->readext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG, + KSZ9131RN_TXC_DLL_CTRL); + + val &= ~KSZ9131RN_DLL_CTRL_BYPASS; + val |= txcdll_val; + ret = drv->writeext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG, + KSZ9131RN_TXC_DLL_CTRL, val); + + return ret; +} + static int ksz9131_config(struct phy_device *phydev) { - /* TBD: Implement Skew values for dts */ + int ret; + + if (phy_interface_is_rgmii(phydev)) { + ret = ksz9131_config_rgmii_delay(phydev); + if (ret) + return ret; + } /* add an option to disable the gigabit feature of this PHY */ if (env_get("disable_giga")) { @@ -430,7 +491,7 @@ static int ksz9131_config(struct phy_device *phydev) } static struct phy_driver ksz9131_driver = { - .name = "Micrel ksz9031", + .name = "Micrel ksz9131", .uid = PHY_ID_KSZ9131, .mask = MII_KSZ9x31_SILICON_REV_MASK, .features = PHY_GBIT_FEATURES, diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c index 1aba8a91501..3a5143adc38 100644 --- a/drivers/pinctrl/pinctrl-at91-pio4.c +++ b/drivers/pinctrl/pinctrl-at91-pio4.c @@ -34,17 +34,19 @@ static const struct pinconf_param conf_params[] = { { "input-schmitt-disable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0 }, { "input-schmitt-enable", PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1 }, { "input-debounce", PIN_CONFIG_INPUT_DEBOUNCE, 0 }, + { "atmel,drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 }, }; -static u32 atmel_pinctrl_get_pinconf(const void *blob, int node) +static u32 atmel_pinctrl_get_pinconf(struct udevice *config) { const struct pinconf_param *params; u32 param, arg, conf = 0; u32 i; + u32 val; for (i = 0; i < ARRAY_SIZE(conf_params); i++) { params = &conf_params[i]; - if (!fdt_get_property(blob, node, params->property, NULL)) + if (!dev_read_prop(config, params->property, NULL)) continue; param = params->param; @@ -82,6 +84,12 @@ static u32 atmel_pinctrl_get_pinconf(const void *blob, int node) conf |= ATMEL_PIO_IFSCEN_MASK; } break; + case PIN_CONFIG_DRIVE_STRENGTH: + dev_read_u32(config, params->property, &val); + conf &= (~ATMEL_PIO_DRVSTR_MASK); + conf |= (val << ATMEL_PIO_DRVSTR_OFFSET) + & ATMEL_PIO_DRVSTR_MASK; + break; default: printf("%s: Unsupported configuration parameter: %u\n", __func__, param); @@ -115,7 +123,7 @@ static int atmel_pinctrl_set_state(struct udevice *dev, struct udevice *config) u32 i, conf; int count; - conf = atmel_pinctrl_get_pinconf(blob, node); + conf = atmel_pinctrl_get_pinconf(config); count = fdtdec_get_int_array_count(blob, node, "pinmux", cells, ARRAY_SIZE(cells)); diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 157dad60a48..fb6ce094ac1 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -123,16 +123,16 @@ static void get_name(dir_entry *dirent, char *s_name) { char *ptr; - memcpy(s_name, dirent->name, 8); + memcpy(s_name, dirent->nameext.name, 8); s_name[8] = '\0'; ptr = s_name; while (*ptr && *ptr != ' ') ptr++; if (dirent->lcase & CASE_LOWER_BASE) downcase(s_name, (unsigned)(ptr - s_name)); - if (dirent->ext[0] && dirent->ext[0] != ' ') { + if (dirent->nameext.ext[0] && dirent->nameext.ext[0] != ' ') { *ptr++ = '.'; - memcpy(ptr, dirent->ext, 3); + memcpy(ptr, dirent->nameext.ext, 3); if (dirent->lcase & CASE_LOWER_EXT) downcase(ptr, 3); ptr[3] = '\0'; @@ -472,16 +472,15 @@ static int slot2str(dir_slot *slotptr, char *l_name, int *idx) } /* Calculate short name checksum */ -static __u8 mkcksum(const char name[8], const char ext[3]) +static __u8 mkcksum(struct nameext *nameext) { int i; + u8 *pos = (void *)nameext; __u8 ret = 0; - for (i = 0; i < 8; i++) - ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + name[i]; - for (i = 0; i < 3; i++) - ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + ext[i]; + for (i = 0; i < 11; i++) + ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + pos[i]; return ret; } @@ -896,7 +895,7 @@ static dir_entry *next_dent(fat_itr *itr) } /* have we reached the last valid entry? */ - if (itr->dent->name[0] == 0) + if (itr->dent->nameext.name[0] == 0) return NULL; return itr->dent; @@ -905,7 +904,7 @@ static dir_entry *next_dent(fat_itr *itr) static dir_entry *extract_vfat_name(fat_itr *itr) { struct dir_entry *dent = itr->dent; - int seqn = itr->dent->name[0] & ~LAST_LONG_ENTRY_MASK; + int seqn = itr->dent->nameext.name[0] & ~LAST_LONG_ENTRY_MASK; u8 chksum, alias_checksum = ((dir_slot *)dent)->alias_checksum; int n = 0; @@ -932,18 +931,19 @@ static dir_entry *extract_vfat_name(fat_itr *itr) * We are now at the short file name entry. * If it is marked as deleted, just skip it. */ - if (dent->name[0] == DELETED_FLAG || - dent->name[0] == aRING) + if (dent->nameext.name[0] == DELETED_FLAG || + dent->nameext.name[0] == aRING) return NULL; itr->l_name[n] = '\0'; - chksum = mkcksum(dent->name, dent->ext); + chksum = mkcksum(&dent->nameext); /* checksum mismatch could mean deleted file, etc.. skip it: */ if (chksum != alias_checksum) { debug("** chksum=%x, alias_checksum=%x, l_name=%s, s_name=%8s.%3s\n", - chksum, alias_checksum, itr->l_name, dent->name, dent->ext); + chksum, alias_checksum, itr->l_name, dent->nameext.name, + dent->nameext.ext); return NULL; } @@ -984,12 +984,12 @@ static int fat_itr_next(fat_itr *itr) itr->dent_rem = itr->remaining; itr->dent_start = itr->dent; itr->dent_clust = itr->clust; - if (dent->name[0] == DELETED_FLAG) + if (dent->nameext.name[0] == DELETED_FLAG) continue; if (dent->attr & ATTR_VOLUME) { if ((dent->attr & ATTR_VFAT) == ATTR_VFAT && - (dent->name[0] & LAST_LONG_ENTRY_MASK)) { + (dent->nameext.name[0] & LAST_LONG_ENTRY_MASK)) { /* long file name */ dent = extract_vfat_name(itr); /* diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 20a54a24189..0132ef9b42f 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -275,7 +275,7 @@ static int fat_find_empty_dentries(fat_itr *itr, int count) log_debug("Not enough directory entries available\n"); return -ENOSPC; } - switch (itr->dent->name[0]) { + switch (itr->dent->nameext.name[0]) { case 0x00: case DELETED_FLAG: if (!n) { @@ -399,7 +399,7 @@ fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) int idx = 0, ret; /* Get short file name checksum value */ - checksum = mkcksum(shortname, shortname + 8); + checksum = mkcksum((void *)shortname); do { memset(slotptr, 0x00, sizeof(dir_slot)); @@ -418,8 +418,12 @@ fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) slotptr--; counter--; - if (itr->remaining == 0) - flush_dir(itr); + if (!itr->remaining) { + /* Write directory table to device */ + ret = flush_dir(itr); + if (ret) + return ret; + } next_dent(itr); if (!itr->dent) @@ -639,15 +643,23 @@ set_cluster(fsdata *mydata, u32 clustnum, u8 *buffer, u32 size) buffer, size); } -static int -flush_dir(fat_itr *itr) +/** + * flush_dir() - flush directory + * + * @itr: directory iterator + * Return: 0 for success, -EIO on error + */ +static int flush_dir(fat_itr *itr) { fsdata *mydata = itr->fsdata; u32 startsect, sect_offset, nsects; + int ret; - if (!itr->is_root || mydata->fatsize == 32) - return set_cluster(mydata, itr->clust, itr->block, - mydata->clust_size * mydata->sect_size); + if (!itr->is_root || mydata->fatsize == 32) { + ret = set_cluster(mydata, itr->clust, itr->block, + mydata->clust_size * mydata->sect_size); + goto out; + } sect_offset = itr->clust * mydata->clust_size; startsect = mydata->rootdir_sect + sect_offset; @@ -655,8 +667,14 @@ flush_dir(fat_itr *itr) nsects = min_t(u32, mydata->clust_size, mydata->rootdir_size - sect_offset); - return set_sectors(mydata, startsect, itr->block, - nsects * mydata->sect_size); + ret = set_sectors(mydata, startsect, itr->block, + nsects * mydata->sect_size); +out: + if (ret) { + log_err("Error: writing directory entry\n"); + return -EIO; + } + return 0; } /* @@ -1151,7 +1169,7 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr, dentptr->attr = attr; - memcpy(dentptr->name, shortname, SHORT_NAME_SIZE); + memcpy(&dentptr->nameext, shortname, SHORT_NAME_SIZE); } /** @@ -1176,7 +1194,7 @@ static dir_entry *find_directory_entry(fat_itr *itr, char *filename) if (!match) continue; - if (itr->dent->name[0] == '\0') + if (itr->dent->nameext.name[0] == '\0') return NULL; else return itr->dent; @@ -1390,10 +1408,6 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, /* Write directory table to device */ ret = flush_dir(itr); - if (ret) { - printf("Error: writing directory entry\n"); - ret = -EIO; - } exit: free(filename_copy); @@ -1456,14 +1470,10 @@ static int delete_single_dentry(fat_itr *itr) struct dir_entry *dent = itr->dent; memset(dent, 0, sizeof(*dent)); - dent->name[0] = DELETED_FLAG; + dent->nameext.name[0] = DELETED_FLAG; - if (!itr->remaining) { - if (flush_dir(itr)) { - printf("error: writing directory entry\n"); - return -EIO; - } - } + if (!itr->remaining) + return flush_dir(itr); return 0; } @@ -1476,7 +1486,7 @@ static int delete_single_dentry(fat_itr *itr) static int delete_long_name(fat_itr *itr) { struct dir_entry *dent = itr->dent; - int seqn = itr->dent->name[0] & ~LAST_LONG_ENTRY_MASK; + int seqn = itr->dent->nameext.name[0] & ~LAST_LONG_ENTRY_MASK; while (seqn--) { int ret; @@ -1521,7 +1531,7 @@ static int delete_dentry_long(fat_itr *itr) dent = itr->dent_start; /* Delete long name */ if ((dent->attr & ATTR_VFAT) == ATTR_VFAT && - (dent->name[0] & LAST_LONG_ENTRY_MASK)) { + (dent->nameext.name[0] & LAST_LONG_ENTRY_MASK)) { int ret; ret = delete_long_name(itr); @@ -1530,12 +1540,7 @@ static int delete_dentry_long(fat_itr *itr) } /* Delete short name */ delete_single_dentry(itr); - if (flush_dir(itr)) { - printf("error: writing directory entry\n"); - return -EIO; - } - - return 0; + return flush_dir(itr); } int fat_unlink(const char *filename) @@ -1707,12 +1712,10 @@ int fat_mkdir(const char *new_dirname) } memset(dotdent, 0, bytesperclust); - memcpy(dotdent[0].name, ". ", 8); - memcpy(dotdent[0].ext, " ", 3); + memcpy(&dotdent[0].nameext, ". ", 11); dotdent[0].attr = ATTR_DIR | ATTR_ARCH; - memcpy(dotdent[1].name, ".. ", 8); - memcpy(dotdent[1].ext, " ", 3); + memcpy(&dotdent[1].nameext, ".. ", 11); dotdent[1].attr = ATTR_DIR | ATTR_ARCH; if (itr->is_root) @@ -1739,13 +1742,12 @@ int fat_mkdir(const char *new_dirname) ret = flush_dirty_fat_buffer(mydata); if (ret) { printf("Error: flush fat buffer\n"); + ret = -EIO; goto exit; } /* Write directory table to device */ ret = flush_dir(itr); - if (ret) - printf("Error: writing directory entry\n"); exit: free(dirname_copy); diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 19f70393b45..b6f707e97e5 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -198,13 +198,21 @@ struct global_data { */ struct udevice *dm_root_f; /** - * @uclass_root: head of core tree + * @uclass_root_s: + * head of core tree when uclasses are not in read-only memory. + * + * When uclasses are in read-only memory, @uclass_root_s is not used and + * @uclass_root points to the root node generated by dtoc. */ struct list_head uclass_root_s; /** - * @uclass_root: pointer to head of core tree, if uclasses are in - * read-only memory and cannot be adjusted to use @uclass_root as a - * list head. + * @uclass_root: + * pointer to head of core tree, if uclasses are in read-only memory and + * cannot be adjusted to use @uclass_root as a list head. + * + * When not in read-only memory, @uclass_root_s is used to hold the + * uclass root, and @uclass_root points to the address of + * @uclass_root_s. */ struct list_head *uclass_root; # if CONFIG_IS_ENABLED(OF_PLATDATA) diff --git a/include/configs/sama5d27_som1_ek.h b/include/configs/sama5d27_som1_ek.h index 3358149e662..8942d159349 100644 --- a/include/configs/sama5d27_som1_ek.h +++ b/include/configs/sama5d27_som1_ek.h @@ -27,14 +27,11 @@ #define CONFIG_SYS_LOAD_ADDR 0x22000000 /* load address */ -/* NAND flash */ - -/* SPI flash */ - #undef CONFIG_BOOTCOMMAND #ifdef CONFIG_SD_BOOT /* bootstrap + u-boot + env in sd card */ -#define CONFIG_BOOTCOMMAND "fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x21000000 at91-sama5d27_som1_ek.dtb; " \ +#define CONFIG_BOOTCOMMAND "fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x21000000 " \ + CONFIG_DEFAULT_DEVICE_TREE ".dtb; " \ "fatload mmc " CONFIG_ENV_FAT_DEVICE_AND_PART " 0x22000000 zImage; " \ "bootz 0x22000000 - 0x21000000" #endif diff --git a/include/dt-bindings/pinctrl/at91.h b/include/dt-bindings/pinctrl/at91.h index 616f5ce4007..3831f91fb3b 100644 --- a/include/dt-bindings/pinctrl/at91.h +++ b/include/dt-bindings/pinctrl/at91.h @@ -1,9 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ /* * This header provides constants for most at91 pinctrl bindings. * * Copyright (C) 2013 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> - * - * GPLv2 only */ #ifndef __DT_BINDINGS_AT91_PINCTRL_H__ @@ -43,4 +42,8 @@ #define AT91_PERIPH_C 3 #define AT91_PERIPH_D 4 +#define ATMEL_PIO_DRVSTR_LO 1 +#define ATMEL_PIO_DRVSTR_ME 2 +#define ATMEL_PIO_DRVSTR_HI 3 + #endif /* __DT_BINDINGS_AT91_PINCTRL_H__ */ diff --git a/include/fat.h b/include/fat.h index b9f273f381f..bd8e450b33a 100644 --- a/include/fat.h +++ b/include/fat.h @@ -132,8 +132,13 @@ typedef struct volume_info #define CASE_LOWER_BASE 8 /* base (name) is lower case */ #define CASE_LOWER_EXT 16 /* extension is lower case */ +struct nameext { + char name[8]; + char ext[3]; +}; + typedef struct dir_entry { - char name[8],ext[3]; /* Name and extension */ + struct nameext nameext; /* Name and extension */ __u8 attr; /* Attribute bits */ __u8 lcase; /* Case for name and ext (CASE_LOWER_x) */ __u8 ctime_ms; /* Creation time, milliseconds */ diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index b2cb0160c08..ce658a8e733 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -687,8 +687,15 @@ efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl, return EFI_INVALID_PARAMETER; } + /* + * The UEFI specification requires event notification levels to be + * > TPL_APPLICATION and <= TPL_HIGH_LEVEL. + * + * Parameter NotifyTpl should not be checked if it is not used. + */ if ((type & (EVT_NOTIFY_WAIT | EVT_NOTIFY_SIGNAL)) && - (!notify_function || is_valid_tpl(notify_tpl) != EFI_SUCCESS)) + (!notify_function || is_valid_tpl(notify_tpl) != EFI_SUCCESS || + notify_tpl == TPL_APPLICATION)) return EFI_INVALID_PARAMETER; ret = efi_allocate_pool(pool_type, sizeof(struct efi_event), @@ -1990,10 +1997,7 @@ efi_status_t efi_load_image_from_path(bool boot_policy, if (ret != EFI_SUCCESS) efi_free_pages(addr, pages); out: - if (load_file_protocol) - EFI_CALL(efi_close_protocol(device, - &efi_guid_load_file2_protocol, - efi_root, NULL)); + EFI_CALL(efi_close_protocol(device, guid, efi_root, NULL)); if (ret == EFI_SUCCESS) { *buffer = (void *)(uintptr_t)addr; *size = buffer_size; diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index dad1b0fcf7c..0d5a7b63ec8 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -764,7 +764,7 @@ static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num) goto err; /* make a list */ - tmp_files = malloc(count * sizeof(*files)); + tmp_files = malloc(count * sizeof(*tmp_files)); if (!tmp_files) { ret = EFI_OUT_OF_RESOURCES; goto err; diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 26b953461bc..c0804effdef 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -343,7 +343,7 @@ static int efi_fs_exists(struct blk_desc *desc, int part) * @if_typename: interface name for block device * @desc: internal block device * @dev_index: device index for block device - * @offset: offset into disk for simple partitions + * @part_info: partition info * @part: partition * @disk: pointer to receive the created handle * Return: disk object @@ -354,7 +354,7 @@ static efi_status_t efi_disk_add_dev( const char *if_typename, struct blk_desc *desc, int dev_index, - lbaint_t offset, + struct disk_partition *part_info, unsigned int part, struct efi_disk_obj **disk) { @@ -374,7 +374,7 @@ static efi_status_t efi_disk_add_dev( efi_add_handle(&diskobj->header); /* Fill in object data */ - if (part) { + if (part_info) { struct efi_device_path *node = efi_dp_part_node(desc, part); struct efi_handler *handler; void *protocol_interface; @@ -396,8 +396,12 @@ static efi_status_t efi_disk_add_dev( diskobj->dp = efi_dp_append_node(dp_parent, node); efi_free_pool(node); + diskobj->offset = part_info->start; + diskobj->media.last_block = part_info->size - 1; } else { diskobj->dp = efi_dp_from_part(desc, part); + diskobj->offset = 0; + diskobj->media.last_block = desc->lba - 1; } diskobj->part = part; @@ -432,7 +436,6 @@ static efi_status_t efi_disk_add_dev( diskobj->ops = block_io_disk_template; diskobj->ifname = if_typename; diskobj->dev_index = dev_index; - diskobj->offset = offset; diskobj->desc = desc; /* Fill in EFI IO Media info (for read/write callbacks) */ @@ -445,13 +448,21 @@ static efi_status_t efi_disk_add_dev( diskobj->media.media_id = 1; diskobj->media.block_size = desc->blksz; diskobj->media.io_align = desc->blksz; - diskobj->media.last_block = desc->lba - offset; if (part) diskobj->media.logical_partition = 1; diskobj->ops.media = &diskobj->media; if (disk) *disk = diskobj; + EFI_PRINT("BlockIO: part %u, present %d, logical %d, removable %d" + ", offset " LBAF ", last_block %llu\n", + diskobj->part, + diskobj->media.media_present, + diskobj->media.logical_partition, + diskobj->media.removable_media, + diskobj->offset, + diskobj->media.last_block); + /* Store first EFI system partition */ if (part && !efi_system_partition.if_type) { int r; @@ -493,7 +504,6 @@ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, { int disks = 0; char devname[32] = { 0 }; /* dp->str is u16[32] long */ - struct disk_partition info; int part; struct efi_device_path *dp = NULL; efi_status_t ret; @@ -506,12 +516,14 @@ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, /* Add devices for each partition */ for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { + struct disk_partition info; + if (part_get_info(desc, part, &info)) continue; snprintf(devname, sizeof(devname), "%s:%d", pdevname, part); ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid, - info.start, part, NULL); + &info, part, NULL); if (ret != EFI_SUCCESS) { log_err("Adding partition %s failed\n", pdevname); continue; @@ -553,7 +565,7 @@ efi_status_t efi_disk_register(void) /* Add block device for the full device */ log_info("Scanning disk %s...\n", dev->name); ret = efi_disk_add_dev(NULL, NULL, if_typename, - desc, desc->devnum, 0, 0, &disk); + desc, desc->devnum, NULL, 0, &disk); if (ret == EFI_NOT_READY) { log_notice("Disk %s not ready\n", dev->name); continue; @@ -599,7 +611,7 @@ efi_status_t efi_disk_register(void) /* Add block device for the full device */ ret = efi_disk_add_dev(NULL, NULL, if_typename, desc, - i, 0, 0, &disk); + i, NULL, 0, &disk); if (ret == EFI_NOT_READY) { log_notice("Disk %s not ready\n", devname); continue; diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 758bc14273b..5451e9ea901 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -2,6 +2,9 @@ # # Copyright (c) 2013 Google, Inc +ifdef CONFIG_HUSH_PARSER +obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o +endif obj-y += mem.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o obj-$(CONFIG_CMD_PWM) += pwm.o diff --git a/test/cmd/test_echo.c b/test/cmd/test_echo.c new file mode 100644 index 00000000000..4183cf75bb6 --- /dev/null +++ b/test/cmd/test_echo.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for echo command + * + * Copyright 2020, Heinrich Schuchadt <xypron.glpk@gmx.de> + */ + +#include <common.h> +#include <command.h> +#include <display_options.h> +#include <test/lib.h> +#include <test/test.h> +#include <test/ut.h> + +DECLARE_GLOBAL_DATA_PTR; + +struct test_data { + char *cmd; + char *expected; +}; + +static struct test_data echo_data[] = { + {"echo 1 2 3", + "1 2 3"}, + /* Test new line handling */ + {"echo -n 1 2 3; echo a b c", + "1 2 3a b c"}, + /* + * Test handling of environment variables. + * + * j, q, x are among the least frequent letters in English. + * Hence no collision for the variable name jQx is expected. + */ + {"setenv jQx X; echo \"a)\" ${jQx} 'b)' '${jQx}' c) ${jQx}; setenv jQx", + "a) X b) ${jQx} c) X"}, + /* Test handling of shell variables. */ + {"setenv jQx; for jQx in 1 2 3; do echo -n \"${jQx}, \"; done; echo;", + "1, 2, 3, "}, +}; + +static int lib_test_hush_echo(struct unit_test_state *uts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(echo_data); ++i) { + console_record_reset_enable(); + ut_assertok(run_command(echo_data[i].cmd, 0)); + gd->flags &= ~GD_FLG_RECORD; + console_record_readline(uts->actual_str, + sizeof(uts->actual_str)); + ut_asserteq_str(echo_data[i].expected, uts->actual_str); + ut_assertok(ut_check_console_end(uts)); + } + return 0; +} + +LIB_TEST(lib_test_hush_echo, 0); diff --git a/tools/Makefile b/tools/Makefile index 9b1aa51b10a..2d550432ba5 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -155,7 +155,7 @@ HOSTCFLAGS_kwbimage.o += -DCONFIG_KWB_SECURE endif # MXSImage needs LibSSL -ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_ARMADA_39X)$(CONFIG_FIT_SIGNATURE),) +ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_ARMADA_39X)$(CONFIG_FIT_SIGNATURE)$(CONFIG_FIT_CIPHER),) HOSTCFLAGS_kwbimage.o += \ $(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "") HOSTLDLIBS_mkimage += \ diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 66cb9d2a25e..2a61a5d6f04 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1208,7 +1208,7 @@ static int flash_write(int fd_current, int fd_target, int dev_target) if (IS_UBI(dev_target)) { if (ubi_update_start(fd_target, CUR_ENVSIZE) < 0) - return 0; + return -1; return ubi_write(fd_target, environment.image, CUR_ENVSIZE); } diff --git a/tools/image-host.c b/tools/image-host.c index e32cc642579..33a224129a0 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -700,13 +700,84 @@ static const char *fit_config_get_image_list(void *fit, int noffset, return default_list; } +static int fit_config_add_hash(void *fit, const char *conf_name, const char *sig_name, + struct strlist *node_inc, const char *iname, int image_noffset) +{ + char name[200], path[200]; + int noffset; + int hash_count; + int ret; + + ret = fdt_get_path(fit, image_noffset, path, sizeof(path)); + if (ret < 0) + goto err_path; + if (strlist_add(node_inc, path)) + goto err_mem; + + snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, + conf_name); + + /* Add all this image's hashes */ + hash_count = 0; + for (noffset = fdt_first_subnode(fit, image_noffset); + noffset >= 0; + noffset = fdt_next_subnode(fit, noffset)) { + const char *name = fit_get_name(fit, noffset, NULL); + + if (strncmp(name, FIT_HASH_NODENAME, + strlen(FIT_HASH_NODENAME))) + continue; + ret = fdt_get_path(fit, noffset, path, sizeof(path)); + if (ret < 0) + goto err_path; + if (strlist_add(node_inc, path)) + goto err_mem; + hash_count++; + } + + if (!hash_count) { + printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n", + conf_name, sig_name, iname); + return -ENOMSG; + } + + /* Add this image's cipher node if present */ + noffset = fdt_subnode_offset(fit, image_noffset, + FIT_CIPHER_NODENAME); + if (noffset != -FDT_ERR_NOTFOUND) { + if (noffset < 0) { + printf("Failed to get cipher node in configuration '%s/%s' image '%s': %s\n", + conf_name, sig_name, iname, + fdt_strerror(noffset)); + return -EIO; + } + ret = fdt_get_path(fit, noffset, path, sizeof(path)); + if (ret < 0) + goto err_path; + if (strlist_add(node_inc, path)) + goto err_mem; + } + + return 0; + +err_mem: + printf("Out of memory processing configuration '%s/%s'\n", conf_name, + sig_name); + return -ENOMEM; + +err_path: + printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n", + iname, conf_name, sig_name, fdt_strerror(ret)); + return -ENOENT; +} + static int fit_config_get_hash_list(void *fit, int conf_noffset, int sig_offset, struct strlist *node_inc) { int allow_missing; const char *prop, *iname, *end; const char *conf_name, *sig_name; - char name[200], path[200]; + char name[200]; int image_count; int ret, len; @@ -733,72 +804,32 @@ static int fit_config_get_hash_list(void *fit, int conf_noffset, end = prop + len; image_count = 0; for (iname = prop; iname < end; iname += strlen(iname) + 1) { - int noffset; int image_noffset; - int hash_count; + int index, max_index; - image_noffset = fit_conf_get_prop_node(fit, conf_noffset, - iname); - if (image_noffset < 0) { - printf("Failed to find image '%s' in configuration '%s/%s'\n", - iname, conf_name, sig_name); - if (allow_missing) - continue; + max_index = fdt_stringlist_count(fit, conf_noffset, iname); - return -ENOENT; - } - - ret = fdt_get_path(fit, image_noffset, path, sizeof(path)); - if (ret < 0) - goto err_path; - if (strlist_add(node_inc, path)) - goto err_mem; + for (index = 0; index < max_index; index++) { + image_noffset = fit_conf_get_prop_node_index(fit, conf_noffset, + iname, index); - snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, - conf_name); + if (image_noffset < 0) { + printf("Failed to find image '%s' in configuration '%s/%s'\n", + iname, conf_name, sig_name); + if (allow_missing) + continue; - /* Add all this image's hashes */ - hash_count = 0; - for (noffset = fdt_first_subnode(fit, image_noffset); - noffset >= 0; - noffset = fdt_next_subnode(fit, noffset)) { - const char *name = fit_get_name(fit, noffset, NULL); + return -ENOENT; + } - if (strncmp(name, FIT_HASH_NODENAME, - strlen(FIT_HASH_NODENAME))) - continue; - ret = fdt_get_path(fit, noffset, path, sizeof(path)); + ret = fit_config_add_hash(fit, conf_name, + sig_name, node_inc, + iname, image_noffset); if (ret < 0) - goto err_path; - if (strlist_add(node_inc, path)) - goto err_mem; - hash_count++; - } + return ret; - if (!hash_count) { - printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n", - conf_name, sig_name, iname); - return -ENOMSG; + image_count++; } - - /* Add this image's cipher node if present */ - noffset = fdt_subnode_offset(fit, image_noffset, - FIT_CIPHER_NODENAME); - if (noffset != -FDT_ERR_NOTFOUND) { - if (noffset < 0) { - printf("Failed to get cipher node in configuration '%s/%s' image '%s': %s\n", - conf_name, sig_name, iname, - fdt_strerror(noffset)); - return -EIO; - } - ret = fdt_get_path(fit, noffset, path, sizeof(path)); - if (ret < 0) - goto err_path; - if (strlist_add(node_inc, path)) - goto err_mem; - } - - image_count++; } if (!image_count) { @@ -813,11 +844,6 @@ err_mem: printf("Out of memory processing configuration '%s/%s'\n", conf_name, sig_name); return -ENOMEM; - -err_path: - printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n", - iname, conf_name, sig_name, fdt_strerror(ret)); - return -ENOENT; } static int fit_config_get_data(void *fit, int conf_noffset, int noffset, diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c index 270943fc90a..162494907a8 100644 --- a/tools/mkeficapsule.c +++ b/tools/mkeficapsule.c @@ -137,8 +137,8 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, bool overlay) { int ret; - int srcfd = 0; - int destfd = 0; + int srcfd = -1; + int destfd = -1; void *sptr = NULL; void *dptr = NULL; off_t src_size; @@ -150,6 +150,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (srcfd == -1) { fprintf(stderr, "%s: Can't open %s: %s\n", __func__, pkey_file, strerror(errno)); + ret = -1; goto err; } @@ -157,6 +158,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (ret == -1) { fprintf(stderr, "%s: Can't stat %s: %s\n", __func__, pkey_file, strerror(errno)); + ret = -1; goto err; } @@ -164,9 +166,10 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, /* mmap the public key esl file */ sptr = mmap(0, src_size, PROT_READ, MAP_SHARED, srcfd, 0); - if ((sptr == MAP_FAILED) || (errno != 0)) { + if (sptr == MAP_FAILED) { fprintf(stderr, "%s: Failed to mmap %s:%s\n", __func__, pkey_file, strerror(errno)); + ret = -1; goto err; } @@ -175,6 +178,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (destfd == -1) { fprintf(stderr, "%s: Can't open %s: %s\n", __func__, dtb_file, strerror(errno)); + ret = -1; goto err; } @@ -189,21 +193,24 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (ftruncate(destfd, dtb.st_size)) { fprintf(stderr, "%s: Can't expand %s: %s\n", __func__, dtb_file, strerror(errno)); - goto err;; + ret = -1; + goto err; } errno = 0; /* mmap the dtb file */ dptr = mmap(0, dtb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, destfd, 0); - if ((dptr == MAP_FAILED) || (errno != 0)) { + if (dptr == MAP_FAILED) { fprintf(stderr, "%s: Failed to mmap %s:%s\n", __func__, dtb_file, strerror(errno)); + ret = -1; goto err; } if (fdt_check_header(dptr)) { fprintf(stderr, "%s: Invalid FDT header\n", __func__); + ret = -1; goto err; } @@ -211,6 +218,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (ret) { fprintf(stderr, "%s: Cannot expand FDT: %s\n", __func__, fdt_strerror(ret)); + ret = -1; goto err; } @@ -219,10 +227,11 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (ret < 0) { fprintf(stderr, "%s: Unable to add public key to the FDT\n", __func__); + ret = -1; goto err; } - return 0; + ret = 0; err: if (sptr) @@ -231,13 +240,13 @@ err: if (dptr) munmap(dptr, dtb.st_size); - if (srcfd >= 0) + if (srcfd != -1) close(srcfd); - if (destfd >= 0) + if (destfd != -1) close(destfd); - return -1; + return ret; } static int create_fwbin(char *path, char *bin, efi_guid_t *guid, @@ -310,6 +319,9 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid, image.version = 0x00000003; memcpy(&image.update_image_type_id, guid, sizeof(*guid)); image.update_image_index = index; + image.reserved[0] = 0; + image.reserved[1] = 0; + image.reserved[2] = 0; image.update_image_size = bin_stat.st_size; image.update_vendor_code_size = 0; /* none */ image.update_hardware_instance = instance; @@ -421,26 +433,25 @@ int main(int argc, char **argv) /* need a fit image file or raw image file */ if (!file && !pkey_file && !dtb_file) { - printf("%s: %d\n", __func__, __LINE__); print_usage(); - return -1; + exit(EXIT_FAILURE); } if (pkey_file && dtb_file) { ret = add_public_key(pkey_file, dtb_file, overlay); if (ret == -1) { printf("Adding public key to the dtb failed\n"); - return -1; + exit(EXIT_FAILURE); } else { - return 0; + exit(EXIT_SUCCESS); } } if (create_fwbin(argv[optind], file, guid, index, instance) < 0) { printf("Creating firmware capsule failed\n"); - return -1; + exit(EXIT_FAILURE); } - return 0; + exit(EXIT_SUCCESS); } diff --git a/tools/mkimage.c b/tools/mkimage.c index e78608293e7..68d5206cb4f 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -94,18 +94,18 @@ static void usage(const char *msg) " -x ==> set XIP (execute in place)\n", params.cmdname); fprintf(stderr, - " %s [-D dtc_options] [-f fit-image.its|-f auto|-F] [-b <dtb> [-b <dtb>]] [-i <ramdisk.cpio.gz>] fit-image\n" + " %s [-D dtc_options] [-f fit-image.its|-f auto|-F] [-b <dtb> [-b <dtb>]] [-E] [-B size] [-i <ramdisk.cpio.gz>] fit-image\n" " <dtb> file is used with -f auto, it may occur multiple times.\n", params.cmdname); fprintf(stderr, " -D => set all options for device tree compiler\n" " -f => input filename for FIT source\n" - " -i => input filename for ramdisk file\n"); + " -i => input filename for ramdisk file\n" + " -E => place data outside of the FIT structure\n" + " -B => align size in hex for FIT structure and header\n"); #ifdef CONFIG_FIT_SIGNATURE fprintf(stderr, - "Signing / verified boot options: [-E] [-B size] [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n" - " -E => place data outside of the FIT structure\n" - " -B => align size in hex for FIT structure and header\n" + "Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n" " -k => set directory containing private keys\n" " -K => write public keys to this .dtb file\n" " -c => add comment in signature node\n" @@ -142,6 +142,7 @@ static int add_content(int type, const char *fname) return 0; } +#define OPT_STRING "a:A:b:B:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qstT:vVx" static void process_args(int argc, char **argv) { char *ptr; |