diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index adcc0fbcb2c..473ddee3835 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -2,7 +2,7 @@ variables: windows_vm: vs2017-win2016 ubuntu_vm: ubuntu-18.04 macos_vm: macOS-10.15 - ci_runner_image: trini/u-boot-gitlab-ci-runner:bionic-20200713-05Aug2020 + ci_runner_image: trini/u-boot-gitlab-ci-runner:bionic-20200807-02Sep2020 # Add '-u 0' options for Azure pipelines, otherwise we get "permission # denied" error when it tries to "useradd -m -u 1001 vsts_azpcontainer", # since our $(ci_runner_image) user is not root. @@ -253,6 +253,18 @@ jobs: qemu_x86_64: TEST_PY_BD: "qemu-x86_64" TEST_PY_TEST_SPEC: "not sleep" + r2dplus_i82557c: + TEST_PY_BD: "r2dplus" + TEST_PY_ID: "--id i82557c_qemu" + r2dplus_pcnet: + TEST_PY_BD: "r2dplus" + TEST_PY_ID: "--id pcnet_qemu" + r2dplus_rtl8139: + TEST_PY_BD: "r2dplus" + TEST_PY_ID: "--id rtl8139_qemu" + r2dplus_tulip: + TEST_PY_BD: "r2dplus" + TEST_PY_ID: "--id tulip_qemu" xilinx_zynq_virt: TEST_PY_BD: "xilinx_zynq_virt" TEST_PY_ID: "--id qemu" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b0d7679b45e..9ac2b336a11 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ # Grab our configured image. The source for this is found at: # https://gitlab.denx.de/u-boot/gitlab-ci-runner -image: trini/u-boot-gitlab-ci-runner:bionic-20200713-05Aug2020 +image: trini/u-boot-gitlab-ci-runner:bionic-20200807-02Sep2020 # We run some tests in different order, to catch some failures quicker. stages: @@ -359,6 +359,34 @@ qemu-x86_64 test.py: TEST_PY_TEST_SPEC: "not sleep" <<: *buildman_and_testpy_dfn +r2dplus_i82557c test.py: + tags: [ 'all' ] + variables: + TEST_PY_BD: "r2dplus" + TEST_PY_ID: "--id i82557c_qemu" + <<: *buildman_and_testpy_dfn + +r2dplus_pcnet test.py: + tags: [ 'all' ] + variables: + TEST_PY_BD: "r2dplus" + TEST_PY_ID: "--id pcnet_qemu" + <<: *buildman_and_testpy_dfn + +r2dplus_rtl8139 test.py: + tags: [ 'all' ] + variables: + TEST_PY_BD: "r2dplus" + TEST_PY_ID: "--id rtl8139_qemu" + <<: *buildman_and_testpy_dfn + +r2dplus_tulip test.py: + tags: [ 'all' ] + variables: + TEST_PY_BD: "r2dplus" + TEST_PY_ID: "--id tulip_qemu" + <<: *buildman_and_testpy_dfn + xilinx_zynq_virt test.py: tags: [ 'all' ] variables: diff --git a/.travis.yml b/.travis.yml index 7e9e65f04fc..fb8f73157d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -646,6 +646,34 @@ matrix: QEMU_TARGET="x86_64-softmmu" TOOLCHAIN="i386" BUILD_ROM="yes" + - name: "test/py r2dplus_i82557c" + env: + - TEST_PY_BD="r2dplus" + TEST_PY_ID="--id i82557c_qemu" + QEMU_TARGET="sh4-softmmu" + BUILDMAN="sh -x arm" + TOOLCHAIN="sh" + - name: "test/py r2dplus_pcnet" + env: + - TEST_PY_BD="r2dplus" + TEST_PY_ID="--id pcnet_qemu" + QEMU_TARGET="sh4-softmmu" + BUILDMAN="sh -x arm" + TOOLCHAIN="sh" + - name: "test/py r2dplus_rtl8139" + env: + - TEST_PY_BD="r2dplus" + TEST_PY_ID="--id rtl8139_qemu" + QEMU_TARGET="sh4-softmmu" + BUILDMAN="sh -x arm" + TOOLCHAIN="sh" + - name: "test/py r2dplus_tulip" + env: + - TEST_PY_BD="r2dplus" + TEST_PY_ID="--id tulip_qemu" + QEMU_TARGET="sh4-softmmu" + BUILDMAN="sh -x arm" + TOOLCHAIN="sh" - name: "test/py xilinx_zynq_virt" env: - TEST_PY_BD="xilinx_zynq_virt" diff --git a/MAINTAINERS b/MAINTAINERS index bebe87b4d1f..7e46470c709 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -506,9 +506,7 @@ F: arch/arm/mach-u8500/ F: drivers/timer/nomadik-mtu-timer.c ARM UNIPHIER -M: Masahiro Yamada -S: Maintained -T: git https://gitlab.denx.de/u-boot/custodians/u-boot-uniphier.git +S: Orphan (Since 2020-09) F: arch/arm/mach-uniphier/ F: configs/uniphier_*_defconfig N: uniphier @@ -621,7 +619,7 @@ F: drivers/mtd/jedec_flash.c CLOCK M: Lukasz Majewski S: Maintained -T: git git://git.denx.de/u-boot-dfu.git +T: git https://gitlab.denx.de/u-boot/custodians/u-boot-clk.git F: drivers/clk/ F: drivers/clk/imx/ @@ -985,6 +983,8 @@ F: include/spmi/ SQUASHFS M: Joao Marcos Costa +R: Thomas Petazzoni +R: Miquel Raynal S: Maintained F: fs/squashfs/ F: include/sqfs.h diff --git a/Makefile b/Makefile index 5dd4c6bd402..6665cd69600 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ VERSION = 2020 PATCHLEVEL = 10 SUBLEVEL = -EXTRAVERSION = -rc3 +EXTRAVERSION = -rc4 NAME = # *DOCUMENTATION* @@ -2025,7 +2025,7 @@ CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h tools/version.h \ # Directories & files removed with 'make mrproper' MRPROPER_DIRS += include/config include/generated spl tpl \ - .tmp_objdiff + .tmp_objdiff doc/output MRPROPER_FILES += .config .config.old include/autoconf.mk* include/config.h \ ctags etags tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \ drivers/video/fonts/*.S diff --git a/arch/arm/dts/armada-3720-db.dts b/arch/arm/dts/armada-3720-db.dts index 1b219c423bd..1b1b66b94de 100644 --- a/arch/arm/dts/armada-3720-db.dts +++ b/arch/arm/dts/armada-3720-db.dts @@ -159,6 +159,6 @@ &pcie0 { pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; - reset-gpio = <&gpiosb 3 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "okay"; }; diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts index 84e2c2adbae..4534f5ff295 100644 --- a/arch/arm/dts/armada-3720-espressobin.dts +++ b/arch/arm/dts/armada-3720-espressobin.dts @@ -67,18 +67,29 @@ device_type = "memory"; reg = <0x00000000 0x00000000 0x00000000 0x20000000>; }; + + vcc_sd_reg0: regulator@0 { + compatible = "regulator-gpio"; + regulator-name = "vcc_sd0"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <3300000>; + regulator-type = "voltage"; + states = <1800000 0x1 + 3300000 0x0>; + gpios = <&gpionb 4 GPIO_ACTIVE_HIGH>; + }; }; &comphy { max-lanes = <3>; phy0 { - phy-type = ; - phy-speed = ; + phy-type = ; + phy-speed = ; }; phy1 { - phy-type = ; - phy-speed = ; + phy-type = ; + phy-speed = ; }; phy2 { @@ -110,6 +121,15 @@ status = "okay"; }; +&sdhci0 { + pinctrl-names = "default"; + pinctrl-0 = <&sdio_pins>; + bus-width = <4>; + cd-gpios = <&gpionb 3 GPIO_ACTIVE_LOW>; + vqmmc-supply = <&vcc_sd_reg0>; + status = "okay"; +}; + &spi0 { status = "okay"; pinctrl-names = "default"; @@ -145,6 +165,6 @@ &pcie0 { pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; - reset-gpio = <&gpiosb 3 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "okay"; }; diff --git a/arch/arm/dts/armada-3720-turris-mox.dts b/arch/arm/dts/armada-3720-turris-mox.dts index 0f0a6ce65d8..974270cc8c6 100644 --- a/arch/arm/dts/armada-3720-turris-mox.dts +++ b/arch/arm/dts/armada-3720-turris-mox.dts @@ -172,6 +172,6 @@ &pcie0 { pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; - reset-gpio = <&gpiosb 3 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "disabled"; }; diff --git a/arch/arm/dts/k3-am65-mcu.dtsi b/arch/arm/dts/k3-am65-mcu.dtsi index 9717cae0a8b..0b07e188b59 100644 --- a/arch/arm/dts/k3-am65-mcu.dtsi +++ b/arch/arm/dts/k3-am65-mcu.dtsi @@ -135,7 +135,7 @@ <0x0 0x2a500000 0x0 0x40000>; reg-names = "rt", "fifos", "proxy_gcfg", "proxy_target"; ti,num-rings = <286>; - ti,sci-rm-range-gp-rings = <0x2>; /* GP ring range */ + ti,sci-rm-range-gp-rings = <0x1>; /* GP ring range */ ti,dma-ring-reset-quirk; ti,sci = <&dmsc>; ti,sci-dev-id = <195>; @@ -153,11 +153,11 @@ ti,sci-dev-id = <194>; ti,ringacc = <&mcu_ringacc>; - ti,sci-rm-range-tchan = <0x1>, /* TX_HCHAN */ - <0x2>; /* TX_CHAN */ - ti,sci-rm-range-rchan = <0x3>, /* RX_HCHAN */ - <0x4>; /* RX_CHAN */ - ti,sci-rm-range-rflow = <0x5>; /* GP RFLOW */ + ti,sci-rm-range-tchan = <0xf>, /* TX_HCHAN */ + <0xd>; /* TX_CHAN */ + ti,sci-rm-range-rchan = <0xb>, /* RX_HCHAN */ + <0xa>; /* RX_CHAN */ + ti,sci-rm-range-rflow = <0x0>; /* GP RFLOW */ }; }; diff --git a/arch/arm/dts/rv1108-u-boot.dtsi b/arch/arm/dts/rv1108-u-boot.dtsi index 41ac054b81e..6a2098b8d41 100644 --- a/arch/arm/dts/rv1108-u-boot.dtsi +++ b/arch/arm/dts/rv1108-u-boot.dtsi @@ -4,3 +4,7 @@ */ #include "rockchip-u-boot.dtsi" + +&grf { + u-boot,dm-pre-reloc; +}; diff --git a/arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi b/arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi index cb92fc9c141..1ae57e18542 100644 --- a/arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi +++ b/arch/arm/dts/stm32mp15xx-dhcor-avenger96-u-boot.dtsi @@ -75,6 +75,8 @@ }; pins2 { u-boot,dm-pre-reloc; + /delete-property/ bias-disable; + bias-pull-up; }; }; diff --git a/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi b/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi index 7529068c517..c73318488d0 100644 --- a/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi +++ b/arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi @@ -132,11 +132,11 @@ u-boot,dm-pre-reloc; }; - /* VCO = 600.0 MHz => P = 100, Q = 50, R = 100 */ + /* VCO = 600.0 MHz => P = 99, Q = 74, R = 99 */ pll4: st,pll@3 { compatible = "st,stm32mp1-pll"; reg = <3>; - cfg = < 1 49 5 11 5 PQR(1,1,1) >; + cfg = < 3 98 5 7 5 PQR(1,1,1) >; u-boot,dm-pre-reloc; }; }; diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c index 76a5f7aca61..aa2686bb921 100644 --- a/arch/arm/mach-imx/spl.c +++ b/arch/arm/mach-imx/spl.c @@ -187,6 +187,12 @@ int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) return 0; } + +#define SDPV_BCD_DEVICE 0x500 +int g_dnl_get_board_bcd_device_number(int gcnum) +{ + return SDPV_BCD_DEVICE; +} #endif #if defined(CONFIG_SPL_MMC_SUPPORT) diff --git a/arch/arm/mach-mediatek/Kconfig b/arch/arm/mach-mediatek/Kconfig index 0042e57017f..7f40ba93190 100644 --- a/arch/arm/mach-mediatek/Kconfig +++ b/arch/arm/mach-mediatek/Kconfig @@ -47,10 +47,10 @@ config TARGET_MT8512 select ARM64 select MT8512 help - The MediaTek MT8512 is a ARM64-based SoC with a quad-core Cortex-A53. + The MediaTek MT8512 is a ARM64-based SoC with a dual-core Cortex-A53. including UART, SPI, USB2.0 and OTG, SD and MMC cards, NAND, PWM, - Ethernet, IR TX/RX, I2C, I2S, S/PDIF, and built-in Wi-Fi / Bluetooth combo - chip and several DDR3 and DDR4 options. + IR RX, I2C, I2S, S/PDIF, and built-in Wi-Fi / Bluetooth digital + and several LPDDR3 and LPDDR4 options. config TARGET_MT8516 bool "MediaTek MT8516 SoC" diff --git a/arch/arm/mach-meson/board-common.c b/arch/arm/mach-meson/board-common.c index 0f21ec8e537..7ea0ed47947 100644 --- a/arch/arm/mach-meson/board-common.c +++ b/arch/arm/mach-meson/board-common.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -153,8 +154,11 @@ int board_late_init(void) #if CONFIG_IS_ENABLED(FASTBOOT) static unsigned int reboot_reason = REBOOT_REASON_NORMAL; -int fastboot_set_reboot_flag() +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { + if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER) + return -ENOTSUPP; + reboot_reason = REBOOT_REASON_BOOTLOADER; printf("Using reboot reason: 0x%x\n", reboot_reason); diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c index 430c0cbf41e..ba4da72b391 100644 --- a/arch/arm/mach-rockchip/board.c +++ b/arch/arm/mach-rockchip/board.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -152,8 +153,11 @@ int board_usb_init(int index, enum usb_init_type init) #endif /* CONFIG_USB_GADGET */ #if CONFIG_IS_ENABLED(FASTBOOT) -int fastboot_set_reboot_flag(void) +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { + if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER) + return -ENOTSUPP; + printf("Setting reboot to fastboot flag ...\n"); /* Set boot mode to fastboot */ writel(BOOT_FASTBOOT, CONFIG_ROCKCHIP_BOOT_MODE_REG); diff --git a/arch/arm/mach-rockchip/make_fit_atf.py b/arch/arm/mach-rockchip/make_fit_atf.py index d15c32b3032..f3224d25552 100755 --- a/arch/arm/mach-rockchip/make_fit_atf.py +++ b/arch/arm/mach-rockchip/make_fit_atf.py @@ -189,8 +189,9 @@ def unpack_elf(filename): p_type, p_flags, p_offset = struct.unpack_from(' 0: + p_data = elf[p_offset:p_offset + p_filesz] + segments.append((index, e_entry, p_paddr, p_data)) return segments def main(): diff --git a/arch/arm/mach-socfpga/include/mach/misc.h b/arch/arm/mach-socfpga/include/mach/misc.h index a85c5aeef95..649d2f6ce24 100644 --- a/arch/arm/mach-socfpga/include/mach/misc.h +++ b/arch/arm/mach-socfpga/include/mach/misc.h @@ -39,6 +39,11 @@ void socfpga_init_security_policies(void); void socfpga_sdram_remap_zero(void); #endif +#if defined(CONFIG_TARGET_SOCFPGA_STRATIX10) || \ + defined(CONFIG_TARGET_SOCFPGA_AGILEX) +int is_fpga_config_ready(void); +#endif + void do_bridge_reset(int enable, unsigned int mask); void socfpga_pl310_clear(void); void socfpga_get_managers_addr(void); diff --git a/arch/arm/mach-socfpga/include/mach/system_manager_soc64.h b/arch/arm/mach-socfpga/include/mach/system_manager_soc64.h index c90f63a754c..5e3f54a6a8c 100644 --- a/arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +++ b/arch/arm/mach-socfpga/include/mach/system_manager_soc64.h @@ -88,8 +88,12 @@ void sysmgr_pinmux_table_delay(const u32 **table, unsigned int *table_len); #define SYSMGR_ECC_OCRAM_EN BIT(0) #define SYSMGR_ECC_OCRAM_SERR BIT(3) #define SYSMGR_ECC_OCRAM_DERR BIT(4) -#define SYSMGR_FPGAINTF_USEFPGA 0x1 +#define SYSMGR_FPGACONFIG_FPGA_COMPLETE BIT(0) +#define SYSMGR_FPGACONFIG_EARLY_USERMODE BIT(1) +#define SYSMGR_FPGACONFIG_READY_MASK (SYSMGR_FPGACONFIG_FPGA_COMPLETE | \ + SYSMGR_FPGACONFIG_EARLY_USERMODE) +#define SYSMGR_FPGAINTF_USEFPGA 0x1 #define SYSMGR_FPGAINTF_NAND BIT(4) #define SYSMGR_FPGAINTF_SDMMC BIT(8) #define SYSMGR_FPGAINTF_SPIM0 BIT(16) diff --git a/arch/arm/mach-socfpga/misc_s10.c b/arch/arm/mach-socfpga/misc_s10.c index 670bfa1a31f..52868fb3448 100644 --- a/arch/arm/mach-socfpga/misc_s10.c +++ b/arch/arm/mach-socfpga/misc_s10.c @@ -151,17 +151,19 @@ int arch_early_init_r(void) return 0; } +/* Return 1 if FPGA is ready otherwise return 0 */ +int is_fpga_config_ready(void) +{ + return (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGA_CONFIG) & + SYSMGR_FPGACONFIG_READY_MASK) == SYSMGR_FPGACONFIG_READY_MASK; +} + void do_bridge_reset(int enable, unsigned int mask) { /* Check FPGA status before bridge enable */ - if (enable) { - int ret = mbox_get_fpga_config_status(MBOX_RECONFIG_STATUS); - - if (ret && ret != MBOX_CFGSTAT_STATE_CONFIG) - ret = mbox_get_fpga_config_status(MBOX_CONFIG_STATUS); - - if (ret) - return; + if (!is_fpga_config_ready()) { + puts("FPGA not ready. Bridge reset aborted!\n"); + return; } socfpga_bridges_reset(enable); diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c index b7fcee2b367..f19e5c3f33a 100644 --- a/arch/arm/mach-stm32mp/cpu.c +++ b/arch/arm/mach-stm32mp/cpu.c @@ -580,8 +580,8 @@ __weak int setup_mac_address(void) return -EINVAL; } pr_debug("OTP MAC address = %pM\n", enetaddr); - ret = !eth_env_set_enetaddr("ethaddr", enetaddr); - if (!ret) + ret = eth_env_set_enetaddr("ethaddr", enetaddr); + if (ret) pr_err("Failed to set mac address %pM from OTP: %d\n", enetaddr, ret); #endif diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h index 2eb14815bcf..b711fcc44d1 100644 --- a/arch/riscv/include/asm/global_data.h +++ b/arch/riscv/include/asm/global_data.h @@ -39,4 +39,13 @@ struct arch_global_data { #define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("gp") +static inline void set_gd(volatile gd_t *gd_ptr) +{ +#ifdef CONFIG_64BIT + asm volatile("ld gp, %0\n" : : "m"(gd_ptr)); +#else + asm volatile("lw gp, %0\n" : : "m"(gd_ptr)); +#endif +} + #endif /* __ASM_GBL_DATA_H */ diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index a34b108fffa..76276c60274 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -203,6 +203,9 @@ config SPL_X86_32BIT_INIT help This is enabled when 32-bit init is in SPL +config USE_EARLY_BOARD_INIT + bool + config RESET_SEG_START hex depends on X86_RESET_VECTOR diff --git a/arch/x86/cpu/start.S b/arch/x86/cpu/start.S index 4ad515ce085..3b6ed37bc07 100644 --- a/arch/x86/cpu/start.S +++ b/arch/x86/cpu/start.S @@ -88,6 +88,7 @@ _start: /* Clear the interrupt vectors */ lidt blank_idt_ptr +#ifdef CONFIG_USE_EARLY_BOARD_INIT /* * Critical early platform init - generally not used, we prefer init * to happen later when we have a console, in case something goes @@ -96,6 +97,8 @@ _start: jmp early_board_init .globl early_board_init_ret early_board_init_ret: +#endif + post_code(POST_START) /* Initialise Cache-As-RAM */ diff --git a/arch/x86/include/asm/acpi_nhlt.h b/arch/x86/include/asm/acpi_nhlt.h index 47203213818..2c44196317b 100644 --- a/arch/x86/include/asm/acpi_nhlt.h +++ b/arch/x86/include/asm/acpi_nhlt.h @@ -137,14 +137,6 @@ int nhlt_endpoint_add_formats(struct nhlt_endpoint *endpoint, */ void nhlt_next_instance(struct nhlt *nhlt, int link_type); -/* - * Serialize NHLT object to ACPI table. Take in the beginning address of where - * the table will reside and return the address of the next ACPI table. On - * error 0 will be returned. The NHLT object is no longer valid after this - * function is called. - */ -uintptr_t nhlt_serialise(struct nhlt *nhlt, uintptr_t acpi_addr); - /* * Serialize NHLT object to ACPI table. Take in the beginning address of where * the table will reside oem_id and oem_table_id and return the address of the diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c index 9bea1986d4d..7b9c3223edb 100644 --- a/board/Marvell/mvebu_armada-37xx/board.c +++ b/board/Marvell/mvebu_armada-37xx/board.c @@ -44,6 +44,7 @@ DECLARE_GLOBAL_DATA_PTR; /* Switch Port Registers */ #define MVEBU_SW_LINK_CTRL_REG (1) #define MVEBU_SW_PORT_CTRL_REG (4) +#define MVEBU_SW_PORT_BASE_VLAN (6) /* Global 2 Registers */ #define MVEBU_G2_SMI_PHY_CMD_REG (24) @@ -207,8 +208,16 @@ int board_network_enable(struct mii_dev *bus) * FIXME: remove this code once Topaz driver gets available * A3720 Community Board Only * Configure Topaz switch (88E6341) + * Restrict output to ports 1,2,3 only from port 0 (CPU) * Set port 0,1,2,3 to forwarding Mode (through Switch Port registers) */ + mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(1), + MVEBU_SW_PORT_BASE_VLAN, BIT(0)); + mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(2), + MVEBU_SW_PORT_BASE_VLAN, BIT(0)); + mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(3), + MVEBU_SW_PORT_BASE_VLAN, BIT(0)); + mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(0), MVEBU_SW_PORT_CTRL_REG, 0x7f); mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(1), @@ -234,3 +243,103 @@ int board_network_enable(struct mii_dev *bus) return 0; } + +#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_ENV_IS_IN_SPI_FLASH) +int ft_board_setup(void *blob, struct bd_info *bd) +{ + int ret; + int spi_off; + int parts_off; + int part_off; + + /* Fill SPI MTD partitions for Linux kernel on Espressobin */ + if (!of_machine_is_compatible("marvell,armada-3720-espressobin")) + return 0; + + spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor"); + if (spi_off < 0) + return 0; + + /* Do not touch partitions if they are already defined */ + if (fdt_subnode_offset(blob, spi_off, "partitions") >= 0) + return 0; + + parts_off = fdt_add_subnode(blob, spi_off, "partitions"); + if (parts_off < 0) { + printf("Can't add partitions node: %s\n", fdt_strerror(parts_off)); + return 0; + } + + ret = fdt_setprop_string(blob, parts_off, "compatible", "fixed-partitions"); + if (ret < 0) { + printf("Can't set compatible property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_setprop_u32(blob, parts_off, "#address-cells", 1); + if (ret < 0) { + printf("Can't set #address-cells property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_setprop_u32(blob, parts_off, "#size-cells", 1); + if (ret < 0) { + printf("Can't set #size-cells property: %s\n", fdt_strerror(ret)); + return 0; + } + + /* Add u-boot-env partition */ + + part_off = fdt_add_subnode(blob, parts_off, "partition@u-boot-env"); + if (part_off < 0) { + printf("Can't add partition@u-boot-env node: %s\n", fdt_strerror(part_off)); + return 0; + } + + ret = fdt_setprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET); + if (ret < 0) { + printf("Can't set partition@u-boot-env reg property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_appendprop_u32(blob, part_off, "reg", CONFIG_ENV_SIZE); + if (ret < 0) { + printf("Can't set partition@u-boot-env reg property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_setprop_string(blob, part_off, "label", "u-boot-env"); + if (ret < 0) { + printf("Can't set partition@u-boot-env label property: %s\n", fdt_strerror(ret)); + return 0; + } + + /* Add firmware partition */ + + part_off = fdt_add_subnode(blob, parts_off, "partition@firmware"); + if (part_off < 0) { + printf("Can't add partition@firmware node: %s\n", fdt_strerror(part_off)); + return 0; + } + + ret = fdt_setprop_u32(blob, part_off, "reg", 0); + if (ret < 0) { + printf("Can't set partition@firmware reg property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_appendprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET); + if (ret < 0) { + printf("Can't set partition@firmware reg property: %s\n", fdt_strerror(ret)); + return 0; + } + + ret = fdt_setprop_string(blob, part_off, "label", "firmware"); + if (ret < 0) { + printf("Can't set partition@firmware label property: %s\n", fdt_strerror(ret)); + return 0; + } + + return 0; +} +#endif diff --git a/board/advantech/som-db5800-som-6867/Makefile b/board/advantech/som-db5800-som-6867/Makefile index 0524766bb71..7975547f410 100644 --- a/board/advantech/som-db5800-som-6867/Makefile +++ b/board/advantech/som-db5800-som-6867/Makefile @@ -2,5 +2,5 @@ # # Copyright (C) 2015, Google, Inc -obj-y += som-db5800-som-6867.o start.o +obj-y += som-db5800-som-6867.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o diff --git a/board/advantech/som-db5800-som-6867/start.S b/board/advantech/som-db5800-som-6867/start.S deleted file mode 100644 index 65d1f7e9615..00000000000 --- a/board/advantech/som-db5800-som-6867/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2015, Google, Inc - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/amazon/kc1/kc1.c b/board/amazon/kc1/kc1.c index 7d62a1d5a86..973bc5a9272 100644 --- a/board/amazon/kc1/kc1.c +++ b/board/amazon/kc1/kc1.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -163,8 +164,11 @@ void get_board_serial(struct tag_serialnr *serialnr) omap_die_id_get_board_serial(serialnr); } -int fastboot_set_reboot_flag(void) +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { + if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER) + return -ENOTSUPP; + return omap_reboot_mode_store("b"); } diff --git a/board/congatec/conga-qeval20-qa3-e3845/Makefile b/board/congatec/conga-qeval20-qa3-e3845/Makefile index 2f04828a27f..451a4fcd6c4 100644 --- a/board/congatec/conga-qeval20-qa3-e3845/Makefile +++ b/board/congatec/conga-qeval20-qa3-e3845/Makefile @@ -2,5 +2,5 @@ # # Copyright (C) 2015, Google, Inc -obj-y += conga-qeval20-qa3.o start.o +obj-y += conga-qeval20-qa3.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o diff --git a/board/congatec/conga-qeval20-qa3-e3845/start.S b/board/congatec/conga-qeval20-qa3-e3845/start.S deleted file mode 100644 index 65d1f7e9615..00000000000 --- a/board/congatec/conga-qeval20-qa3-e3845/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2015, Google, Inc - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/coreboot/coreboot/Makefile b/board/coreboot/coreboot/Makefile index 8db7cc62f30..d292b7032c2 100644 --- a/board/coreboot/coreboot/Makefile +++ b/board/coreboot/coreboot/Makefile @@ -10,4 +10,4 @@ # (C) Copyright 2002 # Daniel Engström, Omicron Ceti AB, daniel@omicron.se. -obj-y += start.o coreboot.o +obj-y += coreboot.o diff --git a/board/coreboot/coreboot/start.S b/board/coreboot/coreboot/start.S deleted file mode 100644 index aa702622d48..00000000000 --- a/board/coreboot/coreboot/start.S +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2011 The Chromium OS Authors. - * (C) Copyright 2008 - * Graeme Russ, graeme.russ@gmail.com. - */ - -/* board early intialization */ -.globl early_board_init -early_board_init: - /* No 32-bit board specific initialisation */ - jmp early_board_init_ret diff --git a/board/dfi/dfi-bt700/Makefile b/board/dfi/dfi-bt700/Makefile index 99cf357b701..50d88f29545 100644 --- a/board/dfi/dfi-bt700/Makefile +++ b/board/dfi/dfi-bt700/Makefile @@ -2,5 +2,5 @@ # # Copyright (C) 2015, Google, Inc -obj-y += dfi-bt700.o start.o +obj-y += dfi-bt700.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o diff --git a/board/dfi/dfi-bt700/start.S b/board/dfi/dfi-bt700/start.S deleted file mode 100644 index 65d1f7e9615..00000000000 --- a/board/dfi/dfi-bt700/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2015, Google, Inc - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/efi/efi-x86_payload/Makefile b/board/efi/efi-x86_payload/Makefile index 00ef69534d0..a4ebc85aa5b 100644 --- a/board/efi/efi-x86_payload/Makefile +++ b/board/efi/efi-x86_payload/Makefile @@ -2,4 +2,4 @@ # # Copyright (C) 2018, Bin Meng -obj-y += start.o payload.o +obj-y += payload.o diff --git a/board/efi/efi-x86_payload/start.S b/board/efi/efi-x86_payload/start.S deleted file mode 100644 index f7eaa7cb12a..00000000000 --- a/board/efi/efi-x86_payload/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2018, Bin Meng - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/elgin/elgin_rv1108/elgin_rv1108.c b/board/elgin/elgin_rv1108/elgin_rv1108.c index 5d8f62244b0..245e5abcaeb 100644 --- a/board/elgin/elgin_rv1108/elgin_rv1108.c +++ b/board/elgin/elgin_rv1108/elgin_rv1108.c @@ -15,7 +15,7 @@ DECLARE_GLOBAL_DATA_PTR; -int mach_cpu_init(void) +int board_early_init_f(void) { struct rv1108_grf *grf; enum { diff --git a/board/emulation/qemu-x86/Makefile b/board/emulation/qemu-x86/Makefile index 782e298b74c..ff4aaa51c54 100644 --- a/board/emulation/qemu-x86/Makefile +++ b/board/emulation/qemu-x86/Makefile @@ -2,4 +2,4 @@ # # Copyright (C) 2015, Bin Meng -obj-y += start.o +obj-y += qemu-x86.o diff --git a/board/emulation/qemu-x86/qemu-x86.c b/board/emulation/qemu-x86/qemu-x86.c new file mode 100644 index 00000000000..e69de29bb2d diff --git a/board/emulation/qemu-x86/start.S b/board/emulation/qemu-x86/start.S deleted file mode 100644 index e4bde561b20..00000000000 --- a/board/emulation/qemu-x86/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2015, Bin Meng - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/google/chromebook_coral/Kconfig b/board/google/chromebook_coral/Kconfig index 940bee89b0b..27671958e14 100644 --- a/board/google/chromebook_coral/Kconfig +++ b/board/google/chromebook_coral/Kconfig @@ -18,6 +18,7 @@ config SYS_TEXT_BASE config BOARD_SPECIFIC_OPTIONS # dummy def_bool y select X86_RESET_VECTOR + select USE_EARLY_BOARD_INIT select INTEL_APOLLOLAKE select BOARD_ROMSIZE_KB_16384 diff --git a/board/google/chromebook_link/Kconfig b/board/google/chromebook_link/Kconfig index 944716d002c..dd29ddf694b 100644 --- a/board/google/chromebook_link/Kconfig +++ b/board/google/chromebook_link/Kconfig @@ -19,6 +19,7 @@ config SYS_TEXT_BASE config BOARD_SPECIFIC_OPTIONS # dummy def_bool y select X86_RESET_VECTOR + select USE_EARLY_BOARD_INIT select NORTHBRIDGE_INTEL_IVYBRIDGE select HAVE_INTEL_ME select BOARD_ROMSIZE_KB_8192 diff --git a/board/google/chromebook_samus/Kconfig b/board/google/chromebook_samus/Kconfig index 90c23cba1be..9f66d799887 100644 --- a/board/google/chromebook_samus/Kconfig +++ b/board/google/chromebook_samus/Kconfig @@ -19,6 +19,7 @@ config SYS_TEXT_BASE config BOARD_SPECIFIC_OPTIONS # dummy def_bool y select X86_RESET_VECTOR + select USE_EARLY_BOARD_INIT select INTEL_BROADWELL select HAVE_INTEL_ME select BOARD_ROMSIZE_KB_8192 diff --git a/board/intel/bayleybay/Makefile b/board/intel/bayleybay/Makefile index e0553f14624..d19447184a6 100644 --- a/board/intel/bayleybay/Makefile +++ b/board/intel/bayleybay/Makefile @@ -2,5 +2,5 @@ # # Copyright (C) 2015, Bin Meng -obj-y += bayleybay.o start.o +obj-y += bayleybay.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o diff --git a/board/intel/bayleybay/start.S b/board/intel/bayleybay/start.S deleted file mode 100644 index e4bde561b20..00000000000 --- a/board/intel/bayleybay/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2015, Bin Meng - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/intel/cherryhill/Makefile b/board/intel/cherryhill/Makefile index b09581a9195..ff6e14836a1 100644 --- a/board/intel/cherryhill/Makefile +++ b/board/intel/cherryhill/Makefile @@ -2,4 +2,4 @@ # # Copyright (C) 2017, Bin Meng -obj-y += cherryhill.o start.o +obj-y += cherryhill.o diff --git a/board/intel/cherryhill/start.S b/board/intel/cherryhill/start.S deleted file mode 100644 index 2e3e7f84094..00000000000 --- a/board/intel/cherryhill/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2017, Bin Meng - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/intel/cougarcanyon2/Makefile b/board/intel/cougarcanyon2/Makefile index 75cc508f4ec..13b19ae6538 100644 --- a/board/intel/cougarcanyon2/Makefile +++ b/board/intel/cougarcanyon2/Makefile @@ -2,4 +2,4 @@ # # Copyright (C) 2016, Bin Meng -obj-y += cougarcanyon2.o start.o +obj-y += cougarcanyon2.o diff --git a/board/intel/cougarcanyon2/start.S b/board/intel/cougarcanyon2/start.S deleted file mode 100644 index 8521800921e..00000000000 --- a/board/intel/cougarcanyon2/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2016, Bin Meng - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/intel/crownbay/Makefile b/board/intel/crownbay/Makefile index b52c69aeaa1..6abd3eeb554 100644 --- a/board/intel/crownbay/Makefile +++ b/board/intel/crownbay/Makefile @@ -2,4 +2,4 @@ # # Copyright (C) 2014, Bin Meng -obj-y += crownbay.o start.o +obj-y += crownbay.o diff --git a/board/intel/crownbay/start.S b/board/intel/crownbay/start.S deleted file mode 100644 index 7faa7d05fae..00000000000 --- a/board/intel/crownbay/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2014, Bin Meng - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/intel/edison/Makefile b/board/intel/edison/Makefile index eed8d65eb66..1eaf7ca7f8e 100644 --- a/board/intel/edison/Makefile +++ b/board/intel/edison/Makefile @@ -4,5 +4,5 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-y += start.o edison.o +obj-y += edison.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o diff --git a/board/intel/edison/start.S b/board/intel/edison/start.S deleted file mode 100644 index aa702622d48..00000000000 --- a/board/intel/edison/start.S +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2011 The Chromium OS Authors. - * (C) Copyright 2008 - * Graeme Russ, graeme.russ@gmail.com. - */ - -/* board early intialization */ -.globl early_board_init -early_board_init: - /* No 32-bit board specific initialisation */ - jmp early_board_init_ret diff --git a/board/intel/galileo/Makefile b/board/intel/galileo/Makefile index e8f58bff9ac..4130bb02365 100644 --- a/board/intel/galileo/Makefile +++ b/board/intel/galileo/Makefile @@ -2,5 +2,5 @@ # # Copyright (C) 2015, Bin Meng -obj-y += galileo.o start.o +obj-y += galileo.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o diff --git a/board/intel/galileo/start.S b/board/intel/galileo/start.S deleted file mode 100644 index e4bde561b20..00000000000 --- a/board/intel/galileo/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2015, Bin Meng - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/intel/minnowmax/Makefile b/board/intel/minnowmax/Makefile index 989344df1c9..d339b5ad0a5 100644 --- a/board/intel/minnowmax/Makefile +++ b/board/intel/minnowmax/Makefile @@ -2,5 +2,5 @@ # # Copyright (C) 2015, Google, Inc -obj-y += minnowmax.o start.o +obj-y += minnowmax.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o diff --git a/board/intel/minnowmax/start.S b/board/intel/minnowmax/start.S deleted file mode 100644 index 65d1f7e9615..00000000000 --- a/board/intel/minnowmax/start.S +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2015, Google, Inc - */ - -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/intel/slimbootloader/Makefile b/board/intel/slimbootloader/Makefile index fd8fa98a8d3..50330cc6e5d 100644 --- a/board/intel/slimbootloader/Makefile +++ b/board/intel/slimbootloader/Makefile @@ -2,4 +2,4 @@ # # Copyright (C) 2019 Intel Corporation -obj-y += start.o slimbootloader.o +obj-y += slimbootloader.o diff --git a/board/intel/slimbootloader/start.S b/board/intel/slimbootloader/start.S deleted file mode 100644 index 5c3f3df09eb..00000000000 --- a/board/intel/slimbootloader/start.S +++ /dev/null @@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (C) 2019 Intel Corporation - */ - -/* board early initialization */ -.globl early_board_init -early_board_init: - jmp early_board_init_ret diff --git a/board/lg/sniper/sniper.c b/board/lg/sniper/sniper.c index b08a267c52c..dff159025b1 100644 --- a/board/lg/sniper/sniper.c +++ b/board/lg/sniper/sniper.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -175,8 +176,11 @@ void reset_misc(void) omap_reboot_mode_store(reboot_mode); } -int fastboot_set_reboot_flag(void) +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { + if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER) + return -ENOTSUPP; + return omap_reboot_mode_store("b"); } diff --git a/board/rockchip/evb_rv1108/evb_rv1108.c b/board/rockchip/evb_rv1108/evb_rv1108.c index c57913828d7..fc31c493116 100644 --- a/board/rockchip/evb_rv1108/evb_rv1108.c +++ b/board/rockchip/evb_rv1108/evb_rv1108.c @@ -14,7 +14,7 @@ DECLARE_GLOBAL_DATA_PTR; -int mach_cpu_init(void) +int board_early_init_f(void) { struct rv1108_grf *grf; enum { diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c index 69dce70a601..78098755106 100644 --- a/board/ti/am57xx/board.c +++ b/board/ti/am57xx/board.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -1172,8 +1173,11 @@ int board_fit_config_name_match(const char *name) #endif #if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE) -int fastboot_set_reboot_flag(void) +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { + if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER) + return -ENOTSUPP; + printf("Setting reboot to fastboot flag ...\n"); env_set("dofastboot", "1"); env_save(); diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index e09ecda4d7e..8b3b4bc8253 100644 --- a/board/ti/common/board_detect.c +++ b/board/ti/common/board_detect.c @@ -113,18 +113,15 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr, /* Corrupted data??? */ if (hdr_read != header) { - rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4); /* * read the eeprom header using i2c again, but use only a * 1 byte address (some legacy boards need this..) */ - if (rc) { - rc = i2c_set_chip_offset_len(dev, 1); - if (rc) - return rc; + rc = i2c_set_chip_offset_len(dev, 1); + if (rc) + return rc; - rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4); - } + rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4); if (rc) return rc; } @@ -153,16 +150,13 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr, /* Corrupted data??? */ if (hdr_read != header) { - rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read, 4); /* * read the eeprom header using i2c again, but use only a * 1 byte address (some legacy boards need this..) */ byte = 1; - if (rc) { - rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read, - 4); - } + rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read, + 4); if (rc) return rc; } diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c index 5ae179f69b9..ca1976e16a5 100644 --- a/board/ti/dra7xx/evm.c +++ b/board/ti/dra7xx/evm.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -1050,8 +1051,11 @@ int board_fit_config_name_match(const char *name) #endif #if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE) -int fastboot_set_reboot_flag(void) +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { + if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER) + return -ENOTSUPP; + printf("Setting reboot to fastboot flag ...\n"); env_set("dofastboot", "1"); env_save(); diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 06563d28ca9..40d5ef2b3a5 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -433,7 +433,9 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) { efi_handle_t mem_handle = NULL, handle; struct efi_device_path *file_path = NULL; + struct efi_device_path *msg_path; efi_status_t ret; + u16 *load_options; if (!bootefi_device_path || !bootefi_image_path) { /* @@ -456,17 +458,21 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) file_path); if (ret != EFI_SUCCESS) goto out; + msg_path = file_path; } else { file_path = efi_dp_append(bootefi_device_path, bootefi_image_path); + msg_path = bootefi_image_path; } + log_info("Booting %pD\n", msg_path); + ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer, source_size, &handle)); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS) { + log_err("Loading image failed\n"); goto out; - - u16 *load_options; + } /* Transfer environment variable as load options */ ret = efi_env_set_load_options(handle, "bootargs", &load_options); diff --git a/cmd/efi.c b/cmd/efi.c index b3a3bf82821..1558cb17eb0 100644 --- a/cmd/efi.c +++ b/cmd/efi.c @@ -71,7 +71,19 @@ static int h_cmp_entry(const void *v1, const void *v2) return diff < 0 ? -1 : diff > 0 ? 1 : 0; } -void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs) +/** + * efi_build_mem_table() - make a sorted copy of the memory table + * + * @map: Pointer to EFI memory map table + * @size: Size of table in bytes + * @skip_bs: True to skip boot-time memory and merge it with conventional + * memory. This will significantly reduce the number of table + * entries. + * Return: pointer to the new table. It should be freed with free() by the + * caller. + */ +static void *efi_build_mem_table(struct efi_entry_memmap *map, int size, + bool skip_bs) { struct efi_mem_desc *desc, *end, *base, *dest, *prev; int count; @@ -92,7 +104,13 @@ void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs) end = (struct efi_mem_desc *)((ulong)base + count * map->desc_size); for (desc = base; desc < end; desc = efi_get_next_mem_desc(map, desc)) { bool merge = true; - int type = desc->type; + u32 type = desc->type; + + if (type >= EFI_MAX_MEMORY_TYPE) { + printf("Memory map contains invalid entry type %u\n", + type); + continue; + } if (skip_bs && is_boot_services(desc->type)) type = EFI_CONVENTIONAL_MEMORY; @@ -119,7 +137,7 @@ void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs) } /* Mark the end */ - dest->type = EFI_TABLE_END; + dest->type = EFI_MAX_MEMORY_TYPE; return base; } @@ -138,7 +156,7 @@ static void efi_print_mem_table(struct efi_entry_memmap *map, /* Keep track of all the different attributes we have seen */ attr_seen_count = 0; addr = 0; - for (upto = 0; desc->type != EFI_TABLE_END; + for (upto = 0; desc->type != EFI_MAX_MEMORY_TYPE; upto++, desc = efi_get_next_mem_desc(map, desc)) { const char *name; u64 size; diff --git a/cmd/nvedit.c b/cmd/nvedit.c index d188c6aa6b7..9f145dd2846 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -1171,6 +1171,11 @@ static int do_env_import(struct cmd_tbl *cmdtp, int flag, uint32_t crc; env_t *ep = (env_t *)ptr; + if (size <= offsetof(env_t, data)) { + printf("## Error: Invalid size 0x%zX\n", size); + return 1; + } + size -= offsetof(env_t, data); memcpy(&crc, &ep->crc, sizeof(crc)); diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c index d565635c6c4..cf2f55994e0 100644 --- a/cmd/usb_mass_storage.c +++ b/cmd/usb_mass_storage.c @@ -170,7 +170,7 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag, goto cleanup_ums_init; } - rc = fsg_init(ums, ums_count); + rc = fsg_init(ums, ums_count, controller_index); if (rc) { pr_err("fsg_init failed\n"); rc = CMD_RET_FAILURE; diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c index e118bba5a2a..99efecb9d8e 100644 --- a/cmd/x86/mtrr.c +++ b/cmd/x86/mtrr.c @@ -121,7 +121,8 @@ static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int argc, if (argc < 1 || !cmd) { cmd = 'l'; reg = 0; - } else { + } + if (cmd != 'l') { if (argc < 2) return CMD_RET_USAGE; reg = simple_strtoul(argv[1], NULL, 16); diff --git a/common/Kconfig b/common/Kconfig index c58f08ba91b..b1934b3a9c5 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -378,7 +378,7 @@ config USE_BOOTARGS config BOOTARGS string "Boot arguments" - depends on USE_BOOTARGS + depends on USE_BOOTARGS && !USE_DEFAULT_ENV_FILE help This can be used to pass arguments to the bootm command. The value of CONFIG_BOOTARGS goes into the environment value "bootargs". Note that @@ -395,7 +395,7 @@ config USE_BOOTCOMMAND config BOOTCOMMAND string "bootcmd value" - depends on USE_BOOTCOMMAND + depends on USE_BOOTCOMMAND && !USE_DEFAULT_ENV_FILE default "run distro_bootcmd" if DISTRO_DEFAULTS help This is the string of commands that will be used as bootcmd and if @@ -416,7 +416,7 @@ config USE_PREBOOT config PREBOOT string "preboot default value" - depends on USE_PREBOOT + depends on USE_PREBOOT && !USE_DEFAULT_ENV_FILE default "" help This is the default of "preboot" environment variable. diff --git a/common/bootm.c b/common/bootm.c index 247b600d9c6..b3377490b3e 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -390,6 +390,8 @@ static int bootm_load_os(bootm_headers_t *images, int boot_progress) bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); return err; } + /* We need the decompressed image size in the next steps */ + images->os.image_len = load_end - load; flush_cache(flush_start, ALIGN(load_end, ARCH_DMA_MINALIGN) - flush_start); diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 365104fe028..a8bfd388b10 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -349,9 +349,12 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image, /* * Use the address following the image as target address for the - * device tree. + * device tree. Load address is aligned to 8 bytes to match the required + * alignment specified for linux arm [1] and arm 64 [2] booting + * [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arm/booting.rst#n126 + * [2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arm64/booting.rst#n45 */ - image_info.load_addr = spl_image->load_addr + spl_image->size; + image_info.load_addr = ALIGN(spl_image->load_addr + spl_image->size, 8); /* Figure out which device tree the board wants to use */ node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, index++); diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c index e7f7b684116..ae9c09883a4 100644 --- a/common/spl/spl_sdp.c +++ b/common/spl/spl_sdp.c @@ -19,6 +19,8 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image, usb_gadget_initialize(controller_index); + board_usb_init(0, USB_INIT_DEVICE); + g_dnl_clear_detach(); ret = g_dnl_register("usb_dnl_sdp"); if (ret) { diff --git a/common/update.c b/common/update.c index c8dd346a095..36b6b7523d5 100644 --- a/common/update.c +++ b/common/update.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -280,7 +281,7 @@ int update_tftp(ulong addr, char *interface, char *devstring) } got_update_file: - fit = (void *)addr; + fit = map_sysmem(addr, 0); if (!fit_check_format((void *)fit)) { printf("Bad FIT format of the update file, aborting " @@ -309,8 +310,7 @@ got_update_file: printf("\n"); if (update_fit_getparams(fit, noffset, &update_addr, &update_fladdr, &update_size)) { - printf("Error: can't get update parameteres, " - "aborting\n"); + printf("Error: can't get update parameters, aborting\n"); ret = 1; goto next_node; } diff --git a/configs/axs101_defconfig b/configs/axs101_defconfig index 633bc119298..9dbc594169c 100644 --- a/configs/axs101_defconfig +++ b/configs/axs101_defconfig @@ -31,7 +31,6 @@ CONFIG_ENV_IS_IN_FAT=y CONFIG_ENV_FAT_DEVICE_AND_PART="0:1" CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y -CONFIG_DM=y CONFIG_HSDK_CREG_GPIO=y CONFIG_MMC=y CONFIG_DM_MMC=y diff --git a/configs/axs103_defconfig b/configs/axs103_defconfig index 24996ac1cbb..399ec9c090a 100644 --- a/configs/axs103_defconfig +++ b/configs/axs103_defconfig @@ -31,7 +31,6 @@ CONFIG_ENV_IS_IN_FAT=y CONFIG_ENV_FAT_DEVICE_AND_PART="0:1" CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y -CONFIG_DM=y CONFIG_HSDK_CREG_GPIO=y CONFIG_MMC=y CONFIG_DM_MMC=y diff --git a/configs/elgin-rv1108_defconfig b/configs/elgin-rv1108_defconfig index 54d1c29072f..5d98f1913fb 100644 --- a/configs/elgin-rv1108_defconfig +++ b/configs/elgin-rv1108_defconfig @@ -15,6 +15,7 @@ CONFIG_DEFAULT_FDT_FILE="rv1108-elgin-r1.dtb" CONFIG_BOARD_LATE_INIT=y # CONFIG_DISPLAY_CPUINFO is not set CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_BOARD_EARLY_INIT_F=y CONFIG_CMD_GPIO=y CONFIG_RANDOM_UUID=y CONFIG_CMD_MMC=y diff --git a/configs/emsdp_defconfig b/configs/emsdp_defconfig index 6dc60f709ba..2b05828e978 100644 --- a/configs/emsdp_defconfig +++ b/configs/emsdp_defconfig @@ -22,7 +22,6 @@ CONFIG_ENV_IS_IN_FAT=y CONFIG_ENV_FAT_DEVICE_AND_PART="0:1" CONFIG_SYS_RELOC_GD_ENV_ADDR=y # CONFIG_NET is not set -CONFIG_DM=y CONFIG_MMC=y CONFIG_DM_MMC=y CONFIG_MMC_DW=y diff --git a/configs/evb-rv1108_defconfig b/configs/evb-rv1108_defconfig index ba6396af3ab..c9cbf046860 100644 --- a/configs/evb-rv1108_defconfig +++ b/configs/evb-rv1108_defconfig @@ -11,6 +11,7 @@ CONFIG_DEBUG_UART=y CONFIG_DEFAULT_FDT_FILE="rv1108-evb.dtb" # CONFIG_DISPLAY_CPUINFO is not set CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_BOARD_EARLY_INIT_F=y CONFIG_RANDOM_UUID=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set diff --git a/configs/hsdk_4xd_defconfig b/configs/hsdk_4xd_defconfig index c968468593a..e5d77677b32 100644 --- a/configs/hsdk_4xd_defconfig +++ b/configs/hsdk_4xd_defconfig @@ -35,7 +35,6 @@ CONFIG_ENV_IS_IN_FAT=y CONFIG_ENV_FAT_DEVICE_AND_PART="0:1" CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y -CONFIG_DM=y CONFIG_CLK_HSDK=y CONFIG_HSDK_CREG_GPIO=y CONFIG_MMC=y diff --git a/configs/hsdk_defconfig b/configs/hsdk_defconfig index 63ac6b3100e..224a29539d2 100644 --- a/configs/hsdk_defconfig +++ b/configs/hsdk_defconfig @@ -34,7 +34,6 @@ CONFIG_ENV_IS_IN_FAT=y CONFIG_ENV_FAT_DEVICE_AND_PART="0:1" CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y -CONFIG_DM=y CONFIG_CLK_HSDK=y CONFIG_HSDK_CREG_GPIO=y CONFIG_MMC=y diff --git a/configs/iot_devkit_defconfig b/configs/iot_devkit_defconfig index 972bb9ab787..5530440839c 100644 --- a/configs/iot_devkit_defconfig +++ b/configs/iot_devkit_defconfig @@ -26,7 +26,6 @@ CONFIG_ENV_IS_IN_FAT=y CONFIG_ENV_FAT_DEVICE_AND_PART="0:1" CONFIG_SYS_RELOC_GD_ENV_ADDR=y # CONFIG_NET is not set -CONFIG_DM=y CONFIG_MMC=y CONFIG_DM_MMC=y CONFIG_MMC_DW=y diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index 5136f02806c..7aabbba59f0 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -6,7 +6,7 @@ CONFIG_SYS_MALLOC_F_LEN=0x2000 CONFIG_NR_DRAM_BANKS=1 CONFIG_TARGET_MVEBU_ARMADA_37XX=y CONFIG_ENV_SIZE=0x10000 -CONFIG_ENV_OFFSET=0x180000 +CONFIG_ENV_OFFSET=0x3F0000 CONFIG_ENV_SECT_SIZE=0x10000 CONFIG_DM_GPIO=y CONFIG_DEBUG_UART_BASE=0xd0012000 @@ -16,6 +16,7 @@ CONFIG_DEBUG_UART=y CONFIG_AHCI=y CONFIG_DISTRO_DEFAULTS=y # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set +CONFIG_OF_BOARD_SETUP=y CONFIG_USE_PREBOOT=y CONFIG_SYS_CONSOLE_INFO_QUIET=y # CONFIG_DISPLAY_CPUINFO is not set @@ -51,20 +52,23 @@ CONFIG_MMC_SDHCI_SDMA=y CONFIG_MMC_SDHCI_XENON=y CONFIG_MTD=y CONFIG_SF_DEFAULT_MODE=0 +CONFIG_SPI_FLASH_GIGADEVICE=y +CONFIG_SPI_FLASH_ISSI=y CONFIG_SPI_FLASH_MACRONIX=y CONFIG_SPI_FLASH_SPANSION=y CONFIG_SPI_FLASH_STMICRO=y CONFIG_SPI_FLASH_WINBOND=y -CONFIG_PHYLIB=y CONFIG_PHY_MARVELL=y CONFIG_PHY_GIGE=y CONFIG_E1000=y +CONFIG_MVNETA=y CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_PCI_AARDVARK=y CONFIG_MVEBU_COMPHY_SUPPORT=y CONFIG_PINCTRL=y CONFIG_PINCTRL_ARMADA_37XX=y +CONFIG_DM_REGULATOR_GPIO=y CONFIG_DEBUG_UART_SHIFT=2 CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_MVEBU_A3700_UART=y diff --git a/configs/nsim_700_defconfig b/configs/nsim_700_defconfig index b2494c69f05..e8faf72051d 100644 --- a/configs/nsim_700_defconfig +++ b/configs/nsim_700_defconfig @@ -16,7 +16,6 @@ CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y # CONFIG_NET is not set -CONFIG_DM=y CONFIG_DM_SERIAL=y CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYS_NS16550=y diff --git a/configs/nsim_700be_defconfig b/configs/nsim_700be_defconfig index 914e118f8c5..358ea77f7cf 100644 --- a/configs/nsim_700be_defconfig +++ b/configs/nsim_700be_defconfig @@ -17,7 +17,6 @@ CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y # CONFIG_NET is not set -CONFIG_DM=y CONFIG_DM_SERIAL=y CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYS_NS16550=y diff --git a/configs/nsim_hs38_defconfig b/configs/nsim_hs38_defconfig index 1309eca8156..3a66b3b2537 100644 --- a/configs/nsim_hs38_defconfig +++ b/configs/nsim_hs38_defconfig @@ -19,7 +19,6 @@ CONFIG_CMD_DHCP=y CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y -CONFIG_DM=y CONFIG_BLK=y CONFIG_HAVE_BLOCK_DEVICE=y CONFIG_DM_ETH=y diff --git a/configs/nsim_hs38be_defconfig b/configs/nsim_hs38be_defconfig index 90642e3f9af..97ede6e09d7 100644 --- a/configs/nsim_hs38be_defconfig +++ b/configs/nsim_hs38be_defconfig @@ -18,7 +18,6 @@ CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y # CONFIG_NET is not set -CONFIG_DM=y CONFIG_DM_SERIAL=y CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYS_NS16550=y diff --git a/configs/odroid-c4_defconfig b/configs/odroid-c4_defconfig index bf79d7424a9..ffaaaab2b4a 100644 --- a/configs/odroid-c4_defconfig +++ b/configs/odroid-c4_defconfig @@ -49,6 +49,7 @@ CONFIG_USB_XHCI_DWC3=y CONFIG_USB_DWC3=y # CONFIG_USB_DWC3_GADGET is not set CONFIG_USB_DWC3_MESON_G12A=y +CONFIG_USB_KEYBOARD=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_VENDOR_NUM=0x1b8e CONFIG_USB_GADGET_PRODUCT_NUM=0xfada @@ -56,6 +57,9 @@ CONFIG_USB_GADGET_DWC2_OTG=y CONFIG_USB_GADGET_DWC2_OTG_PHY_BUS_WIDTH_8=y CONFIG_USB_GADGET_DOWNLOAD=y CONFIG_DM_VIDEO=y +# CONFIG_VIDEO_BPP8 is not set +# CONFIG_VIDEO_BPP16 is not set +CONFIG_SYS_WHITE_ON_BLACK=y CONFIG_VIDEO_MESON=y CONFIG_VIDEO_DT_SIMPLEFB=y CONFIG_SPLASH_SCREEN=y diff --git a/configs/odroid-n2_defconfig b/configs/odroid-n2_defconfig index 358d1fc6307..e8b8da90841 100644 --- a/configs/odroid-n2_defconfig +++ b/configs/odroid-n2_defconfig @@ -34,6 +34,8 @@ CONFIG_ETH_DESIGNWARE=y CONFIG_MESON_G12A_USB_PHY=y CONFIG_PINCTRL=y CONFIG_PINCTRL_MESON_G12A=y +CONFIG_POWER_DOMAIN=y +CONFIG_MESON_EE_POWER_DOMAIN=y CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_FIXED=y CONFIG_DM_RESET=y @@ -47,10 +49,17 @@ CONFIG_USB_XHCI_DWC3=y CONFIG_USB_DWC3=y # CONFIG_USB_DWC3_GADGET is not set CONFIG_USB_DWC3_MESON_G12A=y +CONFIG_USB_KEYBOARD=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_VENDOR_NUM=0x1b8e CONFIG_USB_GADGET_PRODUCT_NUM=0xfada CONFIG_USB_GADGET_DWC2_OTG=y CONFIG_USB_GADGET_DWC2_OTG_PHY_BUS_WIDTH_8=y CONFIG_USB_GADGET_DOWNLOAD=y +CONFIG_DM_VIDEO=y +# CONFIG_VIDEO_BPP8 is not set +# CONFIG_VIDEO_BPP16 is not set +CONFIG_SYS_WHITE_ON_BLACK=y +CONFIG_VIDEO_MESON=y +CONFIG_VIDEO_DT_SIMPLEFB=y CONFIG_OF_LIBFDT_OVERLAY=y diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig index 377f8473afd..31ea2d342fc 100644 --- a/configs/qemu_arm64_defconfig +++ b/configs/qemu_arm64_defconfig @@ -10,25 +10,34 @@ CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y CONFIG_FIT_BEST_MATCH=y CONFIG_LEGACY_IMAGE_FORMAT=y +CONFIG_USE_PREBOOT=y # CONFIG_DISPLAY_CPUINFO is not set # CONFIG_DISPLAY_BOARDINFO is not set CONFIG_PCI_INIT_R=y CONFIG_CMD_BOOTEFI_SELFTEST=y CONFIG_CMD_NVEDIT_EFI=y +CONFIG_CMD_DFU=y +CONFIG_CMD_MTD=y CONFIG_CMD_PCI=y CONFIG_CMD_USB=y +CONFIG_CMD_MTDPARTS=y CONFIG_OF_BOARD=y CONFIG_ENV_IS_IN_FLASH=y CONFIG_ENV_ADDR=0x4000000 CONFIG_SCSI_AHCI=y CONFIG_AHCI_PCI=y CONFIG_BLK=y +CONFIG_DFU_TFTP=y +CONFIG_DFU_RAM=y +CONFIG_DFU_MTD=y # CONFIG_MMC is not set +CONFIG_MTD=y CONFIG_DM_MTD=y CONFIG_MTD_NOR_FLASH=y CONFIG_FLASH_CFI_DRIVER=y CONFIG_CFI_FLASH=y CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y +CONFIG_FLASH_CFI_MTD=y CONFIG_SYS_FLASH_CFI=y CONFIG_DM_ETH=y CONFIG_E1000=y diff --git a/configs/qemu_arm_defconfig b/configs/qemu_arm_defconfig index 8a97f1bcb3c..1ffa727e638 100644 --- a/configs/qemu_arm_defconfig +++ b/configs/qemu_arm_defconfig @@ -13,25 +13,34 @@ CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y CONFIG_FIT_BEST_MATCH=y CONFIG_LEGACY_IMAGE_FORMAT=y +CONFIG_USE_PREBOOT=y # CONFIG_DISPLAY_CPUINFO is not set # CONFIG_DISPLAY_BOARDINFO is not set CONFIG_PCI_INIT_R=y CONFIG_CMD_BOOTEFI_SELFTEST=y CONFIG_CMD_NVEDIT_EFI=y +CONFIG_CMD_DFU=y +CONFIG_CMD_MTD=y CONFIG_CMD_PCI=y CONFIG_CMD_USB=y +CONFIG_CMD_MTDPARTS=y CONFIG_OF_BOARD=y CONFIG_ENV_IS_IN_FLASH=y CONFIG_ENV_ADDR=0x4000000 CONFIG_SCSI_AHCI=y CONFIG_AHCI_PCI=y CONFIG_BLK=y +CONFIG_DFU_TFTP=y +CONFIG_DFU_RAM=y +CONFIG_DFU_MTD=y # CONFIG_MMC is not set +CONFIG_MTD=y CONFIG_DM_MTD=y CONFIG_MTD_NOR_FLASH=y CONFIG_FLASH_CFI_DRIVER=y CONFIG_CFI_FLASH=y CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y +CONFIG_FLASH_CFI_MTD=y CONFIG_SYS_FLASH_CFI=y CONFIG_DM_ETH=y CONFIG_E1000=y diff --git a/configs/rpi_4_32b_defconfig b/configs/rpi_4_32b_defconfig index db7b781976f..4a88448e9d6 100644 --- a/configs/rpi_4_32b_defconfig +++ b/configs/rpi_4_32b_defconfig @@ -42,6 +42,7 @@ CONFIG_DM_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PCI=y +CONFIG_USB_KEYBOARD=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="FSL" CONFIG_USB_GADGET_VENDOR_NUM=0x0525 diff --git a/configs/tb100_defconfig b/configs/tb100_defconfig index 5fd7f030090..47e2f571bff 100644 --- a/configs/tb100_defconfig +++ b/configs/tb100_defconfig @@ -14,7 +14,6 @@ CONFIG_CMD_PING=y CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y -CONFIG_DM=y CONFIG_PHY_GIGE=y CONFIG_ETH_DESIGNWARE=y CONFIG_DM_SERIAL=y diff --git a/doc/README.marvell b/doc/README.marvell index 336461745c2..5416bc3035b 100644 --- a/doc/README.marvell +++ b/doc/README.marvell @@ -13,7 +13,8 @@ Build Procedure 2. Set the cross compiler: - # export CROSS_COMPILE=/path/to/toolchain/aarch64-marvell-linux-gnu- + # sudo apt-get install gcc-aarch64-linux-gnu + # export CROSS_COMPILE=aarch64-linux-gnu- 3. Clean-up old residuals: @@ -30,7 +31,7 @@ Build Procedure 5. Configure the device-tree and build the U-Boot image: - Compile u-boot and set the required device-tree using: + For the Armada-70x0/80x0 DB board compile u-boot and set the required device-tree using: # make DEVICE_TREE= @@ -42,12 +43,45 @@ Build Procedure In order to prevent this, the required device-tree MUST be set during compilation. All device-tree files are located in ./arch/arm/dts/ folder. + For other DB boards (MacchiatoBin, EspressoBin and 3700 DB board) compile u-boot with + just default device-tree from defconfig using: + + # make + NOTE: The u-boot.bin should not be used as a stand-alone image. The ARM Trusted Firmware (ATF) build process uses this image to generate the - flash image. + flash image. See TF-A Build Instructions for Marvell Platforms for more details at: + https://trustedfirmware-a.readthedocs.io/en/latest/plat/marvell/armada/build.html Configuration update --------------------- To update the U-Boot configuration, please refer to doc/README.kconfig + +Permanent ethernet MAC address +------------------------------- + Prior flashing new U-Boot version (as part of ATF image) it is suggested to backup + permanent ethernet MAC address as it is stored only in U-Boot env storage (SPI or eMMC). + Some boards like EspressoBin have MAC address printed on sticker. To print current MAC + address run: + + # echo $ethaddr + + MAC addresses 00:51:82:11:22:00, 00:51:82:11:22:01, 00:51:82:11:22:02, 00:51:82:11:22:03 + and F0:AD:4E:03:64:7F are default hardcoded values found in Marvell's and Armbian U-Boot + forks and therefore *not* unique. Usage of static hardcoded MAC addresses should be avoided. + When original address is lost (e.g. erased by Armbian boot scripts for EspressoBin) it is + suggested to generate new random one. + + After flashing new U-Boot version it is suggested to reset U-Boot env variables to default + and then set correct permanent ethernet MAC address. + + # env default -a + # setenv ethaddr XX:XX:XX:XX:XX:XX + # saveenv + + Where XX:XX:XX:XX:XX:XX is permanent ethernet MAC address. + + Recent Linux kernel versions use correct permanent ethernet MAC address from U-Boot env as + U-Boot will inject it into kernel's device-tree. diff --git a/doc/android/fastboot.rst b/doc/android/fastboot.rst index de3f6c37d7d..2877c3cbaaa 100644 --- a/doc/android/fastboot.rst +++ b/doc/android/fastboot.rst @@ -85,6 +85,25 @@ for example:: fastboot_partition_alias_boot=LNX +Raw partition descriptors +^^^^^^^^^^^^^^^^^^^^^^^^^ + +In cases where no partition table is present, a raw partition descriptor can be +defined, specifying the offset, size, and optionally the MMC hardware partition +number for a given partition name. + +This is useful when using fastboot to flash files (e.g. SPL or U-Boot) to a +specific offset in the eMMC boot partition, without having to update the entire +boot partition. + +To define a raw partition descriptor, add an environment variable similar to:: + + fastboot_raw_partition_= [mmcpart ] + +for example:: + + fastboot_raw_partition_boot=0x100 0x1f00 mmcpart 1 + Variable overrides ^^^^^^^^^^^^^^^^^^ diff --git a/doc/board/emulation/qemu-arm.rst b/doc/board/emulation/qemu-arm.rst index ca751d4af4a..8d7fda10f15 100644 --- a/doc/board/emulation/qemu-arm.rst +++ b/doc/board/emulation/qemu-arm.rst @@ -80,3 +80,13 @@ can be enabled with the following command line parameters: -drive if=none,file=disk.img,id=mydisk -device nvme,drive=mydisk,serial=foo These have been tested in QEMU 2.9.0 but should work in at least 2.5.0 as well. + +Debug UART +---------- + +The debug UART on the ARM virt board uses these settings:: + + CONFIG_DEBUG_UART=y + CONFIG_DEBUG_UART_PL010=y + CONFIG_DEBUG_UART_BASE=0x9000000 + CONFIG_DEBUG_UART_CLOCK=0 diff --git a/doc/build/gcc.rst b/doc/build/gcc.rst new file mode 100644 index 00000000000..fcb0b1ffb3b --- /dev/null +++ b/doc/build/gcc.rst @@ -0,0 +1,119 @@ +Building with GCC +================= + +Dependencies +------------ + +For building U-Boot you need a GCC compiler for your host platform. If you +are not building on the target platform you further need a GCC cross compiler. + +Debian based +~~~~~~~~~~~~ + +On Debian based systems the cross compiler packages are named +gcc--linux-gnu. + +You could install GCC and the GCC cross compiler for the ARMv8 architecture with + +.. code-block:: bash + + sudo apt-get gcc gcc-aarch64-linux-gnu + +Depending on the build targets further packages maybe needed + +.. code-block:: bash + + sudo apt-get install bc bison build-essential coccinelle \ + device-tree-compiler dfu-util efitools flex gdisk liblz4-tool \ + libguestfs-tools libncurses-dev libpython3-dev libsdl2-dev libssl-dev \ + lzma-alone openssl python3 python3-coverage python3-pyelftools \ + python3-pytest python3-sphinxcontrib.apidoc python3-sphinx-rtd-theme swig + +Prerequisites +------------- + +For some boards you have to build prerequisite files before you can build +U-Boot, e.g. for the some boards you will need to build the ARM Trusted Firmware +beforehand. Please, refer to the board specific documentation +:doc:`../board/index`. + +Configuration +------------- + +Directory configs/ contains the template configuration files for the maintained +boards following the naming scheme:: + + _defconfig + +These files have been stripped of default settings. So you cannot use them +directly. Instead their name serves as a make target to generate the actual +configuration file .config. For instance the configuration template for the +Odroid C2 board is called odroid-c2_defconfig. The corresponding .config file +is generated by + +.. code-block:: bash + + make odroid-c2_defconfig + +You can adjust the configuration using + +.. code-block:: bash + + make menuconfig + +Building +-------- + +When cross compiling you will have to specify the prefix of the cross-compiler. +You can either specify the value of the CROSS_COMPILE variable on the make +command line or export it beforehand. + +.. code-block:: bash + + CROSS_COMPILE= make + +Assuming cross compiling on Debian for ARMv8 this would be + +.. code-block:: bash + + CROSS_COMPILE=aarch64-linux-gnu- make + +Build parameters +~~~~~~~~~~~~~~~~ + +A list of available parameters for the make command can be obtained via + +.. code-block:: bash + + make help + +You can speed up compilation by parallelization using the -j parameter, e.g. + +.. code-block:: bash + + CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc) + +Further important build parameters are + +* O= - generate all output files in directory , including .config +* V=1 - verbose build + +Other build targets +~~~~~~~~~~~~~~~~~~~ + +A list of all make targets can be obtained via + +.. code-block:: bash + + make help + +Important ones are + +* clean - remove most generated files but keep the configuration +* mrproper - remove all generated files + config + various backup files + +Installation +------------ + +The process for installing U-Boot on the target device is device specific. +Please, refer to the board specific documentation :doc:`../board/index`. diff --git a/doc/build/index.rst b/doc/build/index.rst index e0072afb5e8..5f90f95acab 100644 --- a/doc/build/index.rst +++ b/doc/build/index.rst @@ -6,5 +6,7 @@ Build U-Boot .. toctree:: :maxdepth: 2 + source + gcc clang tools diff --git a/doc/build/source.rst b/doc/build/source.rst new file mode 100644 index 00000000000..75720e20275 --- /dev/null +++ b/doc/build/source.rst @@ -0,0 +1,30 @@ +Obtaining the source +===================== + +The source of the U-Boot project is maintained in a Git repository. + +You can download the source via + +.. code-block:: bash + + git clone https://gitlab.denx.de/u-boot/u-boot.git + +A mirror of the source is maintained on Github + +.. code-block:: bash + + git clone https://github.com/u-boot/u-boot + +The released versions are available as tags which use the naming scheme:: + + v. + +Release candidates are named:: + + v.-rc + +To checkout the October 2020 release you would use: + +.. code-block:: bash + + git checkout v2020.10 diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig index 5d45d7d7c2d..0eec00ba734 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -71,6 +71,7 @@ config DFU_SF_PART config DFU_MTD bool "MTD back end for DFU" depends on DM_MTD + depends on CMD_MTDPARTS help This option enables using DFU to read and write to on any MTD device. diff --git a/drivers/dfu/dfu_ram.c b/drivers/dfu/dfu_ram.c index cc98668e7a4..ab0ce9e6fa9 100644 --- a/drivers/dfu/dfu_ram.c +++ b/drivers/dfu/dfu_ram.c @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -27,9 +28,9 @@ static int dfu_transfer_medium_ram(enum dfu_op op, struct dfu_entity *dfu, } if (op == DFU_OP_WRITE) - memcpy(dfu->data.ram.start + offset, buf, *len); + memcpy(map_sysmem(dfu->data.ram.start + offset, 0), buf, *len); else - memcpy(buf, dfu->data.ram.start + offset, *len); + memcpy(buf, map_sysmem(dfu->data.ram.start + offset, 0), *len); return 0; } @@ -73,7 +74,7 @@ int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) } dfu->layout = DFU_RAM_ADDR; - dfu->data.ram.start = (void *)simple_strtoul(argv[1], NULL, 16); + dfu->data.ram.start = simple_strtoul(argv[1], NULL, 16); dfu->data.ram.size = simple_strtoul(argv[2], NULL, 16); dfu->write_medium = dfu_write_medium_ram; diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index d4436dfc917..4352ba67a71 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -165,6 +165,18 @@ config FASTBOOT_CMD_OEM_FORMAT relies on the env variable partitions to contain the list of partitions as required by the gpt command. +config FASTBOOT_USE_BCB_SET_REBOOT_FLAG + bool "Use BCB by fastboot to set boot reason" + depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \ + !TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM + default y + help + Fastboot could implement setting of reboot reason in a generic fashion + via BCB commands. BCB commands are able to write reboot reason into + command field of boot control block. In general case it is sufficient + implementation if your platform supports BCB commands and doesn't + require any specific reboot reason handling. + endif # FASTBOOT endmenu diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile index 048af5aa823..2b2c390fe4d 100644 --- a/drivers/fastboot/Makefile +++ b/drivers/fastboot/Makefile @@ -5,3 +5,4 @@ obj-y += fb_getvar.o obj-y += fb_command.o obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o +obj-$(CONFIG_FASTBOOT_USE_BCB_SET_REBOOT_FLAG) += fb_bcb_impl.o diff --git a/drivers/fastboot/fb_bcb_impl.c b/drivers/fastboot/fb_bcb_impl.c new file mode 100644 index 00000000000..89ec3601b6f --- /dev/null +++ b/drivers/fastboot/fb_bcb_impl.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 GlobalLogic. + * Roman Kovalivskyi + */ + +#include +#include + +/** + * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader + * + * Set flag which indicates that we should reboot into the bootloader + * following the reboot that fastboot executes after this function. + * + * This function should be overridden in your board file with one + * which sets whatever flag your board specific Android bootloader flow + * requires in order to re-enter the bootloader. + */ +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) +{ + char cmd[64]; + + if (reason >= FASTBOOT_REBOOT_REASONS_COUNT) + return -EINVAL; + + snprintf(cmd, sizeof(cmd), "bcb load %d misc", + CONFIG_FASTBOOT_FLASH_MMC_DEV); + + if (run_command(cmd, 0)) + return -ENODEV; + + snprintf(cmd, sizeof(cmd), "bcb set command %s", + fastboot_boot_cmds[reason]); + + if (run_command(cmd, 0)) + return -ENOEXEC; + + if (run_command("bcb store", 0)) + return -EIO; + + return 0; +} diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index 49f6a61c374..d3c578672dc 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -37,6 +37,8 @@ static void flash(char *, char *); static void erase(char *, char *); #endif static void reboot_bootloader(char *, char *); +static void reboot_fastbootd(char *, char *); +static void reboot_recovery(char *, char *); #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) static void oem_format(char *, char *); #endif @@ -79,6 +81,14 @@ static const struct { .command = "reboot-bootloader", .dispatch = reboot_bootloader }, + [FASTBOOT_COMMAND_REBOOT_FASTBOOTD] = { + .command = "reboot-fastboot", + .dispatch = reboot_fastbootd + }, + [FASTBOOT_COMMAND_REBOOT_RECOVERY] = { + .command = "reboot-recovery", + .dispatch = reboot_recovery + }, [FASTBOOT_COMMAND_SET_ACTIVE] = { .command = "set_active", .dispatch = okay @@ -307,12 +317,40 @@ static void erase(char *cmd_parameter, char *response) */ static void reboot_bootloader(char *cmd_parameter, char *response) { - if (fastboot_set_reboot_flag()) + if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_BOOTLOADER)) fastboot_fail("Cannot set reboot flag", response); else fastboot_okay(NULL, response); } +/** + * reboot_fastbootd() - Sets reboot fastboot flag. + * + * @cmd_parameter: Pointer to command parameter + * @response: Pointer to fastboot response buffer + */ +static void reboot_fastbootd(char *cmd_parameter, char *response) +{ + if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_FASTBOOTD)) + fastboot_fail("Cannot set fastboot flag", response); + else + fastboot_okay(NULL, response); +} + +/** + * reboot_recovery() - Sets reboot recovery flag. + * + * @cmd_parameter: Pointer to command parameter + * @response: Pointer to fastboot response buffer + */ +static void reboot_recovery(char *cmd_parameter, char *response) +{ + if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_REASON_RECOVERY)) + fastboot_fail("Cannot set recovery flag", response); + else + fastboot_okay(NULL, response); +} + #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) /** * oem_format() - Execute the OEM format command diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c index c3735a44af7..736ce1cd024 100644 --- a/drivers/fastboot/fb_common.c +++ b/drivers/fastboot/fb_common.c @@ -88,7 +88,7 @@ void fastboot_okay(const char *reason, char *response) * which sets whatever flag your board specific Android bootloader flow * requires in order to re-enter the bootloader. */ -int __weak fastboot_set_reboot_flag(void) +int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { return -ENOSYS; } diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c index 52da34b1e37..d43f2cfee66 100644 --- a/drivers/fastboot/fb_getvar.c +++ b/drivers/fastboot/fb_getvar.c @@ -95,7 +95,7 @@ static const struct { * * @param[in] part_name Info for which partition name to look for * @param[in,out] response Pointer to fastboot response buffer - * @param[out] size If not NULL, will contain partition size (in blocks) + * @param[out] size If not NULL, will contain partition size * @return Partition number or negative value on error */ static int getvar_get_part_info(const char *part_name, char *response, @@ -109,7 +109,7 @@ static int getvar_get_part_info(const char *part_name, char *response, r = fastboot_mmc_get_part_info(part_name, &dev_desc, &part_info, response); if (r >= 0 && size) - *size = part_info.size; + *size = part_info.size * part_info.blksz; # elif CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND) struct part_info *part_info; diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index b2f8932e1c7..ae8e8e512f2 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -50,6 +50,48 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc, return ret; } +static int raw_part_get_info_by_name(struct blk_desc *dev_desc, + const char *name, struct disk_partition *info, int *mmcpart) +{ + /* strlen("fastboot_raw_partition_") + PART_NAME_LEN + 1 */ + char env_desc_name[23 + PART_NAME_LEN + 1]; + char *raw_part_desc; + const char *argv[2]; + const char **parg = argv; + + /* check for raw partition descriptor */ + strcpy(env_desc_name, "fastboot_raw_partition_"); + strncat(env_desc_name, name, PART_NAME_LEN); + raw_part_desc = strdup(env_get(env_desc_name)); + if (raw_part_desc == NULL) + return -ENODEV; + + /* + * parse partition descriptor + * + * [mmcpart ] + */ + for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { + *parg = strsep(&raw_part_desc, " "); + if (*parg == NULL) { + pr_err("Invalid number of arguments.\n"); + return -ENODEV; + } + } + + info->start = simple_strtoul(argv[0], NULL, 0); + info->size = simple_strtoul(argv[1], NULL, 0); + info->blksz = dev_desc->blksz; + strncpy((char *)info->name, name, PART_NAME_LEN); + + if (raw_part_desc) { + if (strcmp(strsep(&raw_part_desc, " "), "mmcpart") == 0) + *mmcpart = simple_strtoul(raw_part_desc, NULL, 0); + } + + return 0; +} + /** * fb_mmc_blk_write() - Write/erase MMC in chunks of FASTBOOT_MAX_BLK_WRITE * @@ -376,7 +418,8 @@ int fastboot_mmc_get_part_info(const char *part_name, struct blk_desc **dev_desc, struct disk_partition *part_info, char *response) { - int r; + int r = 0; + int mmcpart; *dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); if (!*dev_desc) { @@ -388,10 +431,12 @@ int fastboot_mmc_get_part_info(const char *part_name, return -ENOENT; } - r = part_get_info_by_name_or_alias(*dev_desc, part_name, part_info); - if (r < 0) { - fastboot_fail("partition not found", response); - return r; + if (raw_part_get_info_by_name(*dev_desc, part_name, part_info, &mmcpart) < 0) { + r = part_get_info_by_name_or_alias(*dev_desc, part_name, part_info); + if (r < 0) { + fastboot_fail("partition not found", response); + return r; + } } return r; @@ -410,6 +455,7 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, { struct blk_desc *dev_desc; struct disk_partition info; + int mmcpart = 0; dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { @@ -482,7 +528,13 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, } #endif - if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) { + if (raw_part_get_info_by_name(dev_desc, cmd, &info, &mmcpart) == 0) { + if (blk_dselect_hwpart(dev_desc, mmcpart)) { + pr_err("Failed to select hwpart\n"); + fastboot_fail("Failed to select hwpart", response); + return; + } + } else if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) { pr_err("cannot find partition: '%s'\n", cmd); fastboot_fail("cannot find partition", response); return; @@ -524,11 +576,11 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer, */ void fastboot_mmc_erase(const char *cmd, char *response) { - int ret; struct blk_desc *dev_desc; struct disk_partition info; lbaint_t blks, blks_start, blks_size, grp_size; struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV); + int mmcpart = 0; if (mmc == NULL) { pr_err("invalid mmc device\n"); @@ -562,8 +614,13 @@ void fastboot_mmc_erase(const char *cmd, char *response) } #endif - ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info); - if (ret < 0) { + if (raw_part_get_info_by_name(dev_desc, cmd, &info, &mmcpart) == 0) { + if (blk_dselect_hwpart(dev_desc, mmcpart)) { + pr_err("Failed to select hwpart\n"); + fastboot_fail("Failed to select hwpart", response); + return; + } + } else if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) { pr_err("cannot find partition: '%s'\n", cmd); fastboot_fail("cannot find partition", response); return; diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 15f5b0b14cc..e311f55ef82 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -60,14 +60,12 @@ struct ti_sci_rm_type_map { * @max_msgs: Maximum number of messages that can be pending * simultaneously in the system * @max_msg_size: Maximum size of data per message that can be handled. - * @rm_type_map: RM resource type mapping structure. */ struct ti_sci_desc { u8 default_host_id; int max_rx_timeout_ms; int max_msgs; int max_msg_size; - struct ti_sci_rm_type_map *rm_type_map; }; /** @@ -1605,33 +1603,6 @@ static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle) return ret; } -static int ti_sci_get_resource_type(struct ti_sci_info *info, u16 dev_id, - u16 *type) -{ - struct ti_sci_rm_type_map *rm_type_map = info->desc->rm_type_map; - bool found = false; - int i; - - /* If map is not provided then assume dev_id is used as type */ - if (!rm_type_map) { - *type = dev_id; - return 0; - } - - for (i = 0; rm_type_map[i].dev_id; i++) { - if (rm_type_map[i].dev_id == dev_id) { - *type = rm_type_map[i].type; - found = true; - break; - } - } - - if (!found) - return -EINVAL; - - return 0; -} - /** * ti_sci_get_resource_range - Helper to get a range of resources assigned * to a host. Resource is uniquely identified by @@ -1654,7 +1625,6 @@ static int ti_sci_get_resource_range(const struct ti_sci_handle *handle, struct ti_sci_msg_req_get_resource_range req; struct ti_sci_xfer *xfer; struct ti_sci_info *info; - u16 type; int ret = 0; if (IS_ERR(handle)) @@ -1673,14 +1643,8 @@ static int ti_sci_get_resource_range(const struct ti_sci_handle *handle, return ret; } - ret = ti_sci_get_resource_type(info, dev_id, &type); - if (ret) { - dev_err(dev, "rm type lookup failed for %u\n", dev_id); - goto fail; - } - req.secondary_host = s_host; - req.type = type & MSG_RM_RESOURCE_TYPE_MASK; + req.type = dev_id & MSG_RM_RESOURCE_TYPE_MASK; req.subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK; ret = ti_sci_do_xfer(info, xfer); @@ -3096,7 +3060,6 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle, struct udevice *dev, u32 dev_id, char *of_prop) { u32 resource_subtype; - u16 resource_type; struct ti_sci_resource *res; bool valid_set = false; int sets, i, ret; @@ -3120,13 +3083,6 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle, if (!res->desc) return ERR_PTR(-ENOMEM); - ret = ti_sci_get_resource_type(handle_to_ti_sci_info(handle), dev_id, - &resource_type); - if (ret) { - dev_err(dev, "No valid resource type for %u\n", dev_id); - return ERR_PTR(-EINVAL); - } - ret = dev_read_u32_array(dev, of_prop, temp, res->sets); if (ret) return ERR_PTR(-EINVAL); @@ -3139,7 +3095,7 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle, &res->desc[i].num); if (ret) { dev_dbg(dev, "type %d subtype %d not allocated for host %d\n", - resource_type, resource_subtype, + dev_id, resource_subtype, handle_to_ti_sci_info(handle)->host_id); res->desc[i].start = 0; res->desc[i].num = 0; @@ -3148,7 +3104,7 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle, valid_set = true; dev_dbg(dev, "res type = %d, subtype = %d, start = %d, num = %d\n", - resource_type, resource_subtype, res->desc[i].start, + dev_id, resource_subtype, res->desc[i].start, res->desc[i].num); res->desc[i].res_map = @@ -3172,17 +3128,6 @@ static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = { /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */ .max_msgs = 20, .max_msg_size = 64, - .rm_type_map = NULL, -}; - -static struct ti_sci_rm_type_map ti_sci_am654_rm_type_map[] = { - {.dev_id = 56, .type = 0x00b}, /* GIC_IRQ */ - {.dev_id = 179, .type = 0x000}, /* MAIN_NAV_UDMASS_IA0 */ - {.dev_id = 187, .type = 0x009}, /* MAIN_NAV_RA */ - {.dev_id = 188, .type = 0x006}, /* MAIN_NAV_UDMAP */ - {.dev_id = 194, .type = 0x007}, /* MCU_NAV_UDMAP */ - {.dev_id = 195, .type = 0x00a}, /* MCU_NAV_RA */ - {.dev_id = 0, .type = 0x000}, /* end of table */ }; /* Description for AM654 */ @@ -3193,7 +3138,6 @@ static const struct ti_sci_desc ti_sci_pmmc_am654_desc = { /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */ .max_msgs = 20, .max_msg_size = 60, - .rm_type_map = ti_sci_am654_rm_type_map, }; static const struct udevice_id ti_sci_ids[] = { diff --git a/drivers/mmc/msm_sdhci.c b/drivers/mmc/msm_sdhci.c index 56c3e35c9e9..2a1f412278e 100644 --- a/drivers/mmc/msm_sdhci.c +++ b/drivers/mmc/msm_sdhci.c @@ -142,6 +142,10 @@ static int msm_sdc_probe(struct udevice *dev) writel(caps, host->ioaddr + SDHCI_VENDOR_SPEC_CAPABILITIES0); } + ret = mmc_of_parse(dev, &plat->cfg); + if (ret) + return ret; + host->mmc = &plat->mmc; host->mmc->dev = dev; ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0); diff --git a/drivers/mmc/xenon_sdhci.c b/drivers/mmc/xenon_sdhci.c index 356dd9846d6..6ce9d00d0ae 100644 --- a/drivers/mmc/xenon_sdhci.c +++ b/drivers/mmc/xenon_sdhci.c @@ -22,6 +22,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -42,6 +43,14 @@ DECLARE_GLOBAL_DATA_PTR; #define SDHC_SYS_EXT_OP_CTRL 0x010C #define MASK_CMD_CONFLICT_ERROR BIT(8) +#define SDHC_SLOT_EMMC_CTRL 0x0130 +#define ENABLE_DATA_STROBE_SHIFT 24 +#define SET_EMMC_RSTN_SHIFT 16 +#define EMMC_VCCQ_MASK 0x3 +#define EMMC_VCCQ_1_8V 0x1 +#define EMMC_VCCQ_1_2V 0x2 +#define EMMC_VCCQ_3_3V 0x3 + #define SDHC_SLOT_RETUNING_REQ_CTRL 0x0144 /* retuning compatible */ #define RETUNING_COMPATIBLE 0x1 @@ -108,6 +117,8 @@ DECLARE_GLOBAL_DATA_PTR; #define MMC_TIMING_MMC_HS400 10 #define XENON_MMC_MAX_CLK 400000000 +#define XENON_MMC_3V3_UV 3300000 +#define XENON_MMC_1V8_UV 1800000 enum soc_pad_ctrl_type { SOC_PAD_SD, @@ -128,6 +139,8 @@ struct xenon_sdhci_priv { void *pad_ctrl_reg; int pad_type; + + struct udevice *vqmmc; }; static int xenon_mmc_phy_init(struct sdhci_host *host) @@ -208,6 +221,51 @@ static void armada_3700_soc_pad_voltage_set(struct sdhci_host *host) writel(ARMADA_3700_SOC_PAD_3_3V, priv->pad_ctrl_reg); } +static int xenon_mmc_start_signal_voltage_switch(struct sdhci_host *host) +{ + struct xenon_sdhci_priv *priv = host->mmc->priv; + u8 voltage; + u32 ctrl; + int ret = 0; + + /* If there is no vqmmc regulator, return */ + if (!priv->vqmmc) + return 0; + + if (priv->pad_type == SOC_PAD_FIXED_1_8V) { + /* Switch to 1.8v */ + ret = regulator_set_value(priv->vqmmc, + XENON_MMC_1V8_UV); + } else if (priv->pad_type == SOC_PAD_SD) { + /* Get voltage info */ + voltage = sdhci_readb(host, SDHCI_POWER_CONTROL); + voltage &= ~SDHCI_POWER_ON; + + if (voltage == SDHCI_POWER_330) { + /* Switch to 3.3v */ + ret = regulator_set_value(priv->vqmmc, + XENON_MMC_3V3_UV); + } else { + /* Switch to 1.8v */ + ret = regulator_set_value(priv->vqmmc, + XENON_MMC_1V8_UV); + } + } + + /* Set VCCQ, eMMC mode: 1.8V; SD/SDIO mode: 3.3V */ + ctrl = sdhci_readl(host, SDHC_SLOT_EMMC_CTRL); + if (IS_SD(host->mmc)) + ctrl |= EMMC_VCCQ_3_3V; + else + ctrl |= EMMC_VCCQ_1_8V; + sdhci_writel(host, ctrl, SDHC_SLOT_EMMC_CTRL); + + if (ret) + printf("Signal voltage switch fail\n"); + + return ret; +} + static void xenon_mmc_phy_set(struct sdhci_host *host) { struct xenon_sdhci_priv *priv = host->mmc->priv; @@ -334,6 +392,13 @@ static int xenon_sdhci_set_ios_post(struct sdhci_host *host) uint speed = host->mmc->tran_speed; int pwr_18v = 0; + /* + * Signal Voltage Switching is only applicable for Host Controllers + * v3.00 and above. + */ + if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) + xenon_mmc_start_signal_voltage_switch(host); + if ((sdhci_readb(host, SDHCI_POWER_CONTROL) & ~SDHCI_POWER_ON) == SDHCI_POWER_180) pwr_18v = 1; @@ -394,6 +459,18 @@ static int xenon_sdhci_probe(struct udevice *dev) /* Set default timing */ priv->timing = MMC_TIMING_LEGACY; + /* Get the vqmmc regulator if there is */ + device_get_supply_regulator(dev, "vqmmc-supply", &priv->vqmmc); + /* Set the initial voltage value to 3.3V if there is regulator */ + if (priv->vqmmc) { + ret = regulator_set_value(priv->vqmmc, + XENON_MMC_3V3_UV); + if (ret) { + printf("Failed to set VQMMC regulator to 3.3V\n"); + return ret; + } + } + /* Disable auto clock gating during init */ xenon_mmc_set_acg(host, false); @@ -408,25 +485,15 @@ static int xenon_sdhci_probe(struct udevice *dev) armada_3700_soc_pad_voltage_set(host); host->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_DDR_52MHz; - switch (fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), "bus-width", - 1)) { - case 8: - host->host_caps |= MMC_MODE_8BIT; - break; - case 4: - host->host_caps |= MMC_MODE_4BIT; - break; - case 1: - break; - default: - printf("Invalid \"bus-width\" value\n"); - return -EINVAL; - } + + ret = mmc_of_parse(dev, &plat->cfg); + if (ret) + return ret; host->ops = &xenon_sdhci_ops; host->max_clk = XENON_MMC_MAX_CLK; - ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0); + ret = sdhci_setup_cfg(&plat->cfg, host, XENON_MMC_MAX_CLK, 0); if (ret) return ret; diff --git a/drivers/mtd/nand/raw/nand_util.c b/drivers/mtd/nand/raw/nand_util.c index 5b74ef0dfdb..00c3c6c4122 100644 --- a/drivers/mtd/nand/raw/nand_util.c +++ b/drivers/mtd/nand/raw/nand_util.c @@ -635,14 +635,14 @@ int nand_write_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length, } while (left_to_write > 0) { + loff_t block_start = offset & ~(loff_t)(mtd->erasesize - 1); size_t block_offset = offset & (mtd->erasesize - 1); size_t write_size, truncated_write_size; WATCHDOG_RESET(); - if (nand_block_isbad(mtd, offset & ~(mtd->erasesize - 1))) { - printf("Skip bad block 0x%08llx\n", - offset & ~(mtd->erasesize - 1)); + if (nand_block_isbad(mtd, block_start)) { + printf("Skip bad block 0x%08llx\n", block_start); offset += mtd->erasesize - block_offset; continue; } diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c index 11b6148ab63..ace13313621 100644 --- a/drivers/net/bcmgenet.c +++ b/drivers/net/bcmgenet.c @@ -378,8 +378,6 @@ static void rx_descs_init(struct bcmgenet_eth_priv *priv) u32 len_stat, i; void *desc_base = priv->rx_desc_base; - priv->c_index = 0; - len_stat = (RX_BUF_LENGTH << DMA_BUFLENGTH_SHIFT) | DMA_OWN; for (i = 0; i < RX_DESCS; i++) { @@ -403,8 +401,11 @@ static void rx_ring_init(struct bcmgenet_eth_priv *priv) writel(RX_DESCS * DMA_DESC_SIZE / 4 - 1, priv->mac_reg + RDMA_RING_REG_BASE + DMA_END_ADDR); - writel(0x0, priv->mac_reg + RDMA_PROD_INDEX); - writel(0x0, priv->mac_reg + RDMA_CONS_INDEX); + /* cannot init RDMA_PROD_INDEX to 0, so align RDMA_CONS_INDEX on it instead */ + priv->c_index = readl(priv->mac_reg + RDMA_PROD_INDEX); + writel(priv->c_index, priv->mac_reg + RDMA_CONS_INDEX); + priv->rx_index = priv->c_index; + priv->rx_index &= 0xFF; writel((RX_DESCS << DMA_RING_SIZE_SHIFT) | RX_BUF_LENGTH, priv->mac_reg + RDMA_RING_REG_BASE + DMA_RING_BUF_SIZE); writel(DMA_FC_THRESH_VALUE, priv->mac_reg + RDMA_XON_XOFF_THRESH); @@ -421,8 +422,10 @@ static void tx_ring_init(struct bcmgenet_eth_priv *priv) writel(0x0, priv->mac_reg + TDMA_WRITE_PTR); writel(TX_DESCS * DMA_DESC_SIZE / 4 - 1, priv->mac_reg + TDMA_RING_REG_BASE + DMA_END_ADDR); - writel(0x0, priv->mac_reg + TDMA_PROD_INDEX); - writel(0x0, priv->mac_reg + TDMA_CONS_INDEX); + /* cannot init TDMA_CONS_INDEX to 0, so align TDMA_PROD_INDEX on it instead */ + priv->tx_index = readl(priv->mac_reg + TDMA_CONS_INDEX); + writel(priv->tx_index, priv->mac_reg + TDMA_PROD_INDEX); + priv->tx_index &= 0xFF; writel(0x1, priv->mac_reg + TDMA_RING_REG_BASE + DMA_MBUF_DONE_THRESH); writel(0x0, priv->mac_reg + TDMA_FLOW_PERIOD); writel((TX_DESCS << DMA_RING_SIZE_SHIFT) | RX_BUF_LENGTH, @@ -454,7 +457,8 @@ static int bcmgenet_adjust_link(struct bcmgenet_eth_priv *priv) clrsetbits_32(priv->mac_reg + EXT_RGMII_OOB_CTRL, OOB_DISABLE, RGMII_LINK | RGMII_MODE_EN); - if (phy_dev->interface == PHY_INTERFACE_MODE_RGMII) + if (phy_dev->interface == PHY_INTERFACE_MODE_RGMII || + phy_dev->interface == PHY_INTERFACE_MODE_RGMII_RXID) setbits_32(priv->mac_reg + EXT_RGMII_OOB_CTRL, ID_MODE_DIS); writel(speed << CMD_SPEED_SHIFT, (priv->mac_reg + UMAC_CMD)); @@ -469,8 +473,6 @@ static int bcmgenet_gmac_eth_start(struct udevice *dev) priv->tx_desc_base = priv->mac_reg + GENET_TX_OFF; priv->rx_desc_base = priv->mac_reg + GENET_RX_OFF; - priv->tx_index = 0x0; - priv->rx_index = 0x0; bcmgenet_umac_reset(priv); diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index c19d09bc417..dd1cc652290 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -30,6 +30,7 @@ config PCI_AARDVARK bool "Enable Aardvark PCIe driver" default n depends on DM_PCI + depends on DM_GPIO depends on ARMADA_3700 help Say Y here if you want to enable PCIe controller support on diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 711b930d0f9..b2c417701f2 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -148,6 +148,7 @@ struct pcie_advk { void *base; int first_busno; struct udevice *dev; + struct gpio_desc reset_gpio; }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) @@ -613,10 +614,7 @@ static int pcie_advk_probe(struct udevice *dev) { struct pcie_advk *pcie = dev_get_priv(dev); -#if CONFIG_IS_ENABLED(DM_GPIO) - struct gpio_desc reset_gpio; - - gpio_request_by_name(dev, "reset-gpio", 0, &reset_gpio, + gpio_request_by_name(dev, "reset-gpios", 0, &pcie->reset_gpio, GPIOD_IS_OUT); /* * Issue reset to add-in card through the dedicated GPIO. @@ -631,15 +629,14 @@ static int pcie_advk_probe(struct udevice *dev) * possible before PCIe PHY initialization. Moreover, the PCIe * clock should be gated as well. */ - if (dm_gpio_is_valid(&reset_gpio)) { + if (dm_gpio_is_valid(&pcie->reset_gpio)) { dev_dbg(pcie->dev, "Toggle PCIE Reset GPIO ...\n"); - dm_gpio_set_value(&reset_gpio, 0); + dm_gpio_set_value(&pcie->reset_gpio, 1); mdelay(200); - dm_gpio_set_value(&reset_gpio, 1); + dm_gpio_set_value(&pcie->reset_gpio, 0); + } else { + dev_warn(pcie->dev, "PCIE Reset on GPIO support is missing\n"); } -#else - dev_dbg(pcie->dev, "PCIE Reset on GPIO support is missing\n"); -#endif /* DM_GPIO */ pcie->first_busno = dev->seq; pcie->dev = pci_get_controller(dev); @@ -647,6 +644,16 @@ static int pcie_advk_probe(struct udevice *dev) return pcie_advk_setup_hw(pcie); } +static int pcie_advk_remove(struct udevice *dev) +{ + struct pcie_advk *pcie = dev_get_priv(dev); + + if (dm_gpio_is_valid(&pcie->reset_gpio)) + dm_gpio_set_value(&pcie->reset_gpio, 1); + + return 0; +} + /** * pcie_advk_ofdata_to_platdata() - Translate from DT to device state * @@ -687,5 +694,7 @@ U_BOOT_DRIVER(pcie_advk) = { .ops = &pcie_advk_ops, .ofdata_to_platdata = pcie_advk_ofdata_to_platdata, .probe = pcie_advk_probe, + .remove = pcie_advk_remove, + .flags = DM_FLAG_OS_PREPARE, .priv_auto_alloc_size = sizeof(struct pcie_advk), }; diff --git a/drivers/pci/pcie_mediatek.c b/drivers/pci/pcie_mediatek.c index ad34f7c597e..55b6a40f254 100644 --- a/drivers/pci/pcie_mediatek.c +++ b/drivers/pci/pcie_mediatek.c @@ -443,29 +443,36 @@ static void mtk_pcie_enable_port(struct mtk_pcie_port *port) err = clk_enable(&port->sys_ck); if (err) - goto exit; + goto err_sys_clk; err = reset_assert(&port->reset); if (err) - goto exit; + goto err_reset; err = reset_deassert(&port->reset); if (err) - goto exit; + goto err_reset; err = generic_phy_init(&port->phy); if (err) - goto exit; + goto err_phy_init; err = generic_phy_power_on(&port->phy); if (err) - goto exit; + goto err_phy_on; if (!mtk_pcie_startup_port(port)) return; pr_err("Port%d link down\n", port->slot); -exit: + + generic_phy_power_off(&port->phy); +err_phy_on: + generic_phy_exit(&port->phy); +err_phy_init: +err_reset: + clk_disable(&port->sys_ck); +err_sys_clk: mtk_pcie_port_free(port); } diff --git a/drivers/phy/marvell/comphy_a3700.c b/drivers/phy/marvell/comphy_a3700.c index dc188c44e0d..4606de6f48e 100644 --- a/drivers/phy/marvell/comphy_a3700.c +++ b/drivers/phy/marvell/comphy_a3700.c @@ -273,16 +273,23 @@ static void reg_set_indirect(u32 reg, u16 data, u16 mask) * * return: 1 if PLL locked (OK), 0 otherwise (FAIL) */ -static int comphy_sata_power_up(void) +static int comphy_sata_power_up(u32 invert) { int ret; + u32 data = 0; debug_enter(); /* - * 0. Swap SATA TX lines + * 0. Check the Polarity invert bits */ - reg_set_indirect(vphy_sync_pattern_reg, bs_txd_inv, bs_txd_inv); + if (invert & PHY_POLARITY_TXD_INVERT) + data |= bs_txd_inv; + + if (invert & PHY_POLARITY_RXD_INVERT) + data |= bs_rxd_inv; + + reg_set_indirect(vphy_sync_pattern_reg, data, bs_txd_inv | bs_rxd_inv); /* * 1. Select 40-bit data width width @@ -924,22 +931,6 @@ void comphy_dedicated_phys_init(void) } } - node = fdt_node_offset_by_compatible(blob, -1, - "marvell,armada-3700-ahci"); - if (node > 0) { - if (fdtdec_get_is_enabled(blob, node)) { - ret = comphy_sata_power_up(); - if (!ret) - printf("Failed to initialize SATA PHY\n"); - else - debug("SATA PHY init succeed\n"); - } else { - debug("SATA node is disabled\n"); - } - } else { - debug("No SATA node in DT\n"); - } - node = fdt_node_offset_by_compatible(blob, -1, "marvell,armada-8k-sdhci"); if (node <= 0) { @@ -1007,6 +998,10 @@ int comphy_a3700_init(struct chip_serdes_phy_config *chip_cfg, comphy_map->invert); break; + case PHY_TYPE_SATA0: + ret = comphy_sata_power_up(comphy_map->invert); + break; + default: debug("Unknown SerDes type, skip initialize SerDes %d\n", lane); diff --git a/drivers/pinctrl/intel/Kconfig b/drivers/pinctrl/intel/Kconfig index 1acc5dabb01..316a8fe27fd 100644 --- a/drivers/pinctrl/intel/Kconfig +++ b/drivers/pinctrl/intel/Kconfig @@ -22,7 +22,7 @@ config INTEL_PINCTRL_MULTI_ACPI_DEVICES Enable this if the pinctrl devices are modelled as multiple, separate ACPI devices in the ACPI tables. If enabled, the ACPI devices match the U-Boot pinctrl devices and the pin 'offset' is - relatove to a particular pinctrl device. If disabled, there is a + relative to a particular pinctrl device. If disabled, there is a single ACPI pinctrl device which includes all U-Boot pinctrl devices and the pin 'offset' is in effect a global pin number. diff --git a/drivers/serial/serial_sh.c b/drivers/serial/serial_sh.c index 13b179f03de..e27d256574f 100644 --- a/drivers/serial/serial_sh.c +++ b/drivers/serial/serial_sh.c @@ -116,7 +116,10 @@ static int serial_getc_check(struct uart_port *port) handle_error(port); if (sci_in(port, SCLSR) & SCxSR_ORER(port)) handle_error(port); - return status & (SCIF_DR | SCxSR_RDxF(port)); + status &= (SCIF_DR | SCxSR_RDxF(port)); + if (status) + return status; + return scif_rxfill(port); } static int sh_serial_getc_generic(struct uart_port *port) diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c index 1845d957f97..215bcbbef80 100644 --- a/drivers/usb/eth/r8152.c +++ b/drivers/usb/eth/r8152.c @@ -68,6 +68,8 @@ static const struct r8152_version r8152_versions[] = { { 0x5c20, RTL_VER_05, 1 }, { 0x5c30, RTL_VER_06, 1 }, { 0x4800, RTL_VER_07, 0 }, + { 0x6000, RTL_VER_08, 1 }, + { 0x6010, RTL_VER_09, 1 }, }; static @@ -331,6 +333,12 @@ void sram_write(struct r8152 *tp, u16 addr, u16 data) ocp_reg_write(tp, OCP_SRAM_DATA, data); } +static u16 sram_read(struct r8152 *tp, u16 addr) +{ + ocp_reg_write(tp, OCP_SRAM_ADDR, addr); + return ocp_reg_read(tp, OCP_SRAM_DATA); +} + int r8152_wait_for_bit(struct r8152 *tp, bool ocp_reg, u16 type, u16 index, const u32 mask, bool set, unsigned int timeout) { @@ -467,12 +475,56 @@ static void r8153_set_rx_early_timeout(struct r8152 *tp) { u32 ocp_data = tp->coalesce / 8; - ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, ocp_data); + switch (tp->version) { + case RTL_VER_03: + case RTL_VER_04: + case RTL_VER_05: + case RTL_VER_06: + ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, + ocp_data); + break; + + case RTL_VER_08: + case RTL_VER_09: + /* The RTL8153B uses USB_RX_EXTRA_AGGR_TMR for rx timeout + * primarily. For USB_RX_EARLY_TIMEOUT, we fix it to 1264ns. + */ + ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT, + RX_AUXILIARY_TIMER / 8); + ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR, + ocp_data); + break; + + default: + debug("** %s Invalid Device\n", __func__); + break; + } } static void r8153_set_rx_early_size(struct r8152 *tp) { - u32 ocp_data = (RTL8152_AGG_BUF_SZ - RTL8153_RMS) / 4; + u32 ocp_data = (RTL8152_AGG_BUF_SZ - RTL8153_RMS - + sizeof(struct rx_desc)); + + switch (tp->version) { + case RTL_VER_03: + case RTL_VER_04: + case RTL_VER_05: + case RTL_VER_06: + ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, + ocp_data / 4); + break; + + case RTL_VER_08: + case RTL_VER_09: + ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, + ocp_data / 8); + break; + + default: + debug("** %s Invalid Device\n", __func__); + break; + } ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE, ocp_data); } @@ -540,6 +592,19 @@ static void r8153_u1u2en(struct r8152 *tp, bool enable) usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2); } +static void r8153b_u1u2en(struct r8152 *tp, bool enable) +{ + u16 ocp_data; + + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_LPM_CONFIG); + if (enable) + ocp_data |= LPM_U1U2_EN; + else + ocp_data &= ~LPM_U1U2_EN; + + ocp_write_word(tp, MCU_TYPE_USB, USB_LPM_CONFIG, ocp_data); +} + static void r8153_u2p3en(struct r8152 *tp, bool enable) { u32 ocp_data; @@ -568,6 +633,17 @@ static void r8153_power_cut_en(struct r8152 *tp, bool enable) ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data); } +static void rtl_reset_bmu(struct r8152 *tp) +{ + u8 ocp_data; + + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_BMU_RESET); + ocp_data &= ~(BMU_RESET_EP_IN | BMU_RESET_EP_OUT); + ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); + ocp_data |= BMU_RESET_EP_IN | BMU_RESET_EP_OUT; + ocp_write_byte(tp, MCU_TYPE_USB, USB_BMU_RESET, ocp_data); +} + static int r8152_read_mac(struct r8152 *tp, unsigned char *macaddr) { int ret; @@ -773,6 +849,71 @@ static void r8153_hw_phy_cfg(struct r8152 *tp) sram_write(tp, SRAM_10M_AMP2, 0x0208); } +static u32 r8152_efuse_read(struct r8152 *tp, u8 addr) +{ + u32 ocp_data; + + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD, EFUSE_READ_CMD | addr); + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD); + ocp_data = (ocp_data & EFUSE_DATA_BIT16) << 9; /* data of bit16 */ + ocp_data |= ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_DATA); + + return ocp_data; +} + +static void r8153b_hw_phy_cfg(struct r8152 *tp) +{ + u32 ocp_data; + u16 data; + + data = r8152_mdio_read(tp, MII_BMCR); + if (data & BMCR_PDOWN) { + data &= ~BMCR_PDOWN; + r8152_mdio_write(tp, MII_BMCR, data); + } + + /* U1/U2/L1 idle timer. 500 us */ + ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500); + + r8153b_firmware(tp); + + data = sram_read(tp, SRAM_GREEN_CFG); + data |= R_TUNE_EN; + sram_write(tp, SRAM_GREEN_CFG, data); + data = ocp_reg_read(tp, OCP_NCTL_CFG); + data |= PGA_RETURN_EN; + ocp_reg_write(tp, OCP_NCTL_CFG, data); + + /* ADC Bias Calibration: + * read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake + * bit (bit3) to rebuild the real 16-bit data. Write the data to the + * ADC ioffset. + */ + ocp_data = r8152_efuse_read(tp, 0x7d); + ocp_data = ((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7); + if (ocp_data != 0xffff) + ocp_reg_write(tp, OCP_ADC_IOFFSET, ocp_data); + + /* ups mode tx-link-pulse timing adjustment: + * rg_saw_cnt = OCP reg 0xC426 Bit[13:0] + * swr_cnt_1ms_ini = 16000000 / rg_saw_cnt + */ + ocp_data = ocp_reg_read(tp, 0xc426); + ocp_data &= 0x3fff; + if (ocp_data) { + u32 swr_cnt_1ms_ini; + + swr_cnt_1ms_ini = (16000000 / ocp_data) & SAW_CNT_1MS_MASK; + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG); + ocp_data = (ocp_data & ~SAW_CNT_1MS_MASK) | swr_cnt_1ms_ini; + ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CFG, ocp_data); + } + + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); + ocp_data |= PFM_PWM_SWITCH; + ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); +} + static void r8153_first_init(struct r8152 *tp) { u32 ocp_data; @@ -786,6 +927,7 @@ static void r8153_first_init(struct r8152 *tp) r8153_hw_phy_cfg(tp); rtl8152_nic_reset(tp); + rtl_reset_bmu(tp); ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL); ocp_data &= ~NOW_IS_OOB; @@ -832,6 +974,7 @@ static void r8153_enter_oob(struct r8152 *tp) ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); rtl_disable(tp); + rtl_reset_bmu(tp); rtl8152_reinit_ll(tp); @@ -873,6 +1016,7 @@ static void rtl8153_disable(struct r8152 *tp) { r8153_disable_aldps(tp); rtl_disable(tp); + rtl_reset_bmu(tp); } static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex) @@ -933,7 +1077,7 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex) return -EINVAL; } - bmcr = BMCR_ANENABLE | BMCR_ANRESTART; + bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET; } if (tp->supports_gmii) @@ -977,6 +1121,16 @@ static void rtl8153_down(struct r8152 *tp) r8153_enter_oob(tp); } +static void rtl8153b_up(struct r8152 *tp) +{ + r8153_first_init(tp); +} + +static void rtl8153b_down(struct r8152 *tp) +{ + r8153_enter_oob(tp); +} + static void r8152b_get_version(struct r8152 *tp) { u32 ocp_data; @@ -1140,6 +1294,60 @@ static void r8153_init(struct r8152 *tp) rtl_tally_reset(tp); } +static void r8153b_init(struct r8152 *tp) +{ + u32 ocp_data; + int i; + + r8153_disable_aldps(tp); + r8153b_u1u2en(tp, false); + + r8152_wait_for_bit(tp, 0, MCU_TYPE_PLA, PLA_BOOT_CTRL, + AUTOLOAD_DONE, 1, R8152_WAIT_TIMEOUT); + + for (i = 0; i < R8152_WAIT_TIMEOUT; i++) { + ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK; + if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN) + break; + + mdelay(1); + } + + r8153_u2p3en(tp, false); + + /* MSC timer = 0xfff * 8ms = 32760 ms */ + ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff); + + r8153_power_cut_en(tp, false); + + /* MAC clock speed down */ + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2); + ocp_data |= MAC_CLK_SPDWN_EN; + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data); + + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3); + ocp_data &= ~PLA_MCU_SPDWN_EN; + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); + + if (tp->version == RTL_VER_09) { + /* Disable Test IO for 32QFN */ + if (ocp_read_byte(tp, MCU_TYPE_PLA, 0xdc00) & BIT(5)) { + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR); + ocp_data |= TEST_IO_OFF; + ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data); + } + } + + /* rx aggregation */ + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL); + ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN); + ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data); + + rtl_tally_reset(tp); + r8153b_hw_phy_cfg(tp); + r8152b_enable_fc(tp); +} + static void rtl8152_unload(struct r8152 *tp) { if (tp->version != RTL_VER_01) @@ -1180,6 +1388,15 @@ static int rtl_ops_init(struct r8152 *tp) ops->unload = rtl8153_unload; break; + case RTL_VER_08: + case RTL_VER_09: + ops->init = r8153b_init; + ops->enable = rtl8153_enable; + ops->disable = rtl8153_disable; + ops->up = rtl8153b_up; + ops->down = rtl8153b_down; + break; + default: ret = -ENODEV; printf("r8152 Unknown Device\n"); diff --git a/drivers/usb/eth/r8152.h b/drivers/usb/eth/r8152.h index 10e0da8eb10..fa57e42502a 100644 --- a/drivers/usb/eth/r8152.h +++ b/drivers/usb/eth/r8152.h @@ -26,6 +26,8 @@ #define PLA_TEREDO_TIMER 0xd2cc #define PLA_REALWOW_TIMER 0xd2e8 #define PLA_EXTRA_STATUS 0xd398 +#define PLA_EFUSE_DATA 0xdd00 +#define PLA_EFUSE_CMD 0xdd02 #define PLA_LEDSEL 0xdd90 #define PLA_LED_FEATURE 0xdd92 #define PLA_PHYAR 0xde00 @@ -76,8 +78,10 @@ #define USB_CSR_DUMMY2 0xb466 #define USB_DEV_STAT 0xb808 #define USB_CONNECT_TIMER 0xcbf8 +#define USB_MSC_TIMER 0xcbfc #define USB_BURST_SIZE 0xcfc0 #define USB_FW_FIX_EN1 0xcfcc +#define USB_LPM_CONFIG 0xcfd8 #define USB_USB_CTRL 0xd406 #define USB_PHY_CTRL 0xd408 #define USB_TX_AGG 0xd40a @@ -85,25 +89,23 @@ #define USB_USB_TIMER 0xd428 #define USB_RX_EARLY_TIMEOUT 0xd42c #define USB_RX_EARLY_SIZE 0xd42e -#define USB_PM_CTRL_STATUS 0xd432 +#define USB_PM_CTRL_STATUS 0xd432 /* RTL8153A */ +#define USB_RX_EXTRA_AGGR_TMR 0xd432 /* RTL8153B */ #define USB_TX_DMA 0xd434 #define USB_TOLERANCE 0xd490 #define USB_LPM_CTRL 0xd41a +#define USB_BMU_RESET 0xd4b0 +#define USB_U1U2_TIMER 0xd4da #define USB_UPS_CTRL 0xd800 -#define USB_MISC_0 0xd81a #define USB_POWER_CUT 0xd80a +#define USB_MISC_0 0xd81a #define USB_AFE_CTRL2 0xd824 +#define USB_UPS_CFG 0xd842 #define USB_WDT11_CTRL 0xe43c -#define USB_BP_BA 0xfc26 -#define USB_BP_0 0xfc28 -#define USB_BP_1 0xfc2a -#define USB_BP_2 0xfc2c -#define USB_BP_3 0xfc2e -#define USB_BP_4 0xfc30 -#define USB_BP_5 0xfc32 -#define USB_BP_6 0xfc34 -#define USB_BP_7 0xfc36 -#define USB_BP_EN 0xfc38 +#define USB_BP_BA PLA_BP_BA +#define USB_BP(n) (0xfc28 + 2 * (n)) +#define USB_BP_EN PLA_BP_EN /* RTL8153A */ +#define USB_BP2_EN 0xfc48 /* OCP Registers */ #define OCP_ALDPS_CONFIG 0x2010 @@ -114,6 +116,7 @@ #define OCP_EEE_AR 0xa41a #define OCP_EEE_DATA 0xa41c #define OCP_PHY_STATUS 0xa420 +#define OCP_NCTL_CFG 0xa42c #define OCP_POWER_CFG 0xa430 #define OCP_EEE_CFG 0xa432 #define OCP_SRAM_ADDR 0xa436 @@ -123,9 +126,11 @@ #define OCP_EEE_ADV 0xa5d0 #define OCP_EEE_LPABLE 0xa5d2 #define OCP_PHY_STATE 0xa708 /* nway state for 8153 */ +#define OCP_ADC_IOFFSET 0xbcfc #define OCP_ADC_CFG 0xbc06 /* SRAM Register */ +#define SRAM_GREEN_CFG 0x8011 #define SRAM_LPF_CFG 0x8012 #define SRAM_10M_AMP1 0x8080 #define SRAM_10M_AMP2 0x8082 @@ -207,6 +212,7 @@ /* PLA_PHY_PWR */ #define PLA_PHY_PWR_LLR (LINK_LIST_READY << 24) #define PLA_PHY_PWR_TXEMP (TXFIFO_EMPTY << 24) +#define TEST_IO_OFF BIT(4) /* PLA_MISC_1 */ #define RXDY_GATED_EN 0x0008 @@ -230,6 +236,10 @@ /* PLA_BDC_CR */ #define ALDPS_PROXY_MODE 0x0001 +/* PLA_EFUSE_CMD */ +#define EFUSE_READ_CMD BIT(15) +#define EFUSE_DATA_BIT16 BIT(7) + /* PLA_CONFIG34 */ #define LINK_ON_WAKE_EN 0x0010 #define LINK_OFF_WAKE_EN 0x0008 @@ -255,8 +265,10 @@ /* PLA_MAC_PWR_CTRL2 */ #define EEE_SPDWN_RATIO 0x8007 +#define MAC_CLK_SPDWN_EN BIT(15) /* PLA_MAC_PWR_CTRL3 */ +#define PLA_MCU_SPDWN_EN BIT(14) #define PKT_AVAIL_SPDWN_EN 0x0100 #define SUSPEND_SPDWN_EN 0x0004 #define U1U2_SPDWN_EN 0x0002 @@ -312,6 +324,9 @@ /* USB_FW_FIX_EN1 */ #define FW_IP_RESET_EN BIT(9) +/* USB_LPM_CONFIG */ +#define LPM_U1U2_EN BIT(0) + /* USB_TX_AGG */ #define TX_AGG_MAX_THRESHOLD 0x03 @@ -320,10 +335,17 @@ #define RX_THR_HIGH 0x7a120180 #define RX_THR_SLOW 0xffff0180 +/* USB_RX_EARLY_TIMEOUT */ +#define RX_AUXILIARY_TIMER 1264 + /* USB_TX_DMA */ #define TEST_MODE_DISABLE 0x00000001 #define TX_SIZE_ADJUST1 0x00000100 +/* USB_BMU_RESET */ +#define BMU_RESET_EP_IN 0x01 +#define BMU_RESET_EP_OUT 0x02 + /* USB_UPS_CTRL */ #define POWER_CUT 0x0100 @@ -366,6 +388,9 @@ #define SEN_VAL_NORMAL 0xa000 #define SEL_RXIDLE 0x0100 +/* USB_UPS_CFG */ +#define SAW_CNT_1MS_MASK 0x0fff + /* OCP_ALDPS_CONFIG */ #define ENPWRSAVE 0x8000 #define ENPDNPS 0x0200 @@ -377,6 +402,9 @@ #define PHY_STAT_LAN_ON 3 #define PHY_STAT_PWRDN 5 +/* OCP_NCTL_CFG */ +#define PGA_RETURN_EN BIT(1) + /* OCP_POWER_CFG */ #define EEE_CLKDIV_EN 0x8000 #define EN_ALDPS 0x0004 @@ -429,6 +457,10 @@ #define ADC_EN 0x0080 #define EN_EMI_L 0x0040 +/* SRAM_GREEN_CFG */ +#define GREEN_ETH_EN BIT(15) +#define R_TUNE_EN BIT(11) + /* SRAM_LPF_CFG */ #define LPF_AUTO_TUNE 0x8000 @@ -573,6 +605,8 @@ enum rtl_version { RTL_VER_05, RTL_VER_06, RTL_VER_07, + RTL_VER_08, + RTL_VER_09, RTL_VER_MAX }; @@ -640,4 +674,5 @@ int r8152_wait_for_bit(struct r8152 *tp, bool ocp_reg, u16 type, u16 index, void r8152b_firmware(struct r8152 *tp); void r8153_firmware(struct r8152 *tp); +void r8153b_firmware(struct r8152 *tp); #endif diff --git a/drivers/usb/eth/r8152_fw.c b/drivers/usb/eth/r8152_fw.c index f953b0384b8..a41abed3069 100644 --- a/drivers/usb/eth/r8152_fw.c +++ b/drivers/usb/eth/r8152_fw.c @@ -729,28 +729,161 @@ static u16 r8153_pla_patch_d_bp[] = { 0xfc2e, 0x0000, 0xfc30, 0x0000, 0xfc32, 0x0000, 0xfc34, 0x0000, 0xfc36, 0x0000, 0xfc38, 0x0007 }; -static void rtl_clear_bp(struct r8152 *tp) +static u8 usb_patch2_b[] = { + 0x10, 0xe0, 0x26, 0xe0, 0x3a, 0xe0, 0x58, 0xe0, + 0x6c, 0xe0, 0x85, 0xe0, 0xa5, 0xe0, 0xbe, 0xe0, + 0xd8, 0xe0, 0xdb, 0xe0, 0xf3, 0xe0, 0xf5, 0xe0, + 0xf7, 0xe0, 0xf9, 0xe0, 0xfb, 0xe0, 0xfd, 0xe0, + 0x16, 0xc0, 0x00, 0x75, 0xd1, 0x49, 0x0d, 0xf0, + 0x0f, 0xc0, 0x0f, 0xc5, 0x00, 0x1e, 0x08, 0x9e, + 0x0c, 0x9d, 0x0c, 0xc6, 0x0a, 0x9e, 0x8f, 0x1c, + 0x0e, 0x8c, 0x0e, 0x74, 0xcf, 0x49, 0xfe, 0xf1, + 0x02, 0xc0, 0x00, 0xb8, 0x96, 0x31, 0x00, 0xdc, + 0x24, 0xe4, 0x80, 0x02, 0x34, 0xd3, 0xff, 0xc3, + 0x60, 0x72, 0xa1, 0x49, 0x0d, 0xf0, 0xf8, 0xc3, + 0xf8, 0xc2, 0x00, 0x1c, 0x68, 0x9c, 0xf6, 0xc4, + 0x6a, 0x9c, 0x6c, 0x9a, 0x8f, 0x1c, 0x6e, 0x8c, + 0x6e, 0x74, 0xcf, 0x49, 0xfe, 0xf1, 0x04, 0xc0, + 0x02, 0xc2, 0x00, 0xba, 0xa8, 0x28, 0xf8, 0xc7, + 0xea, 0xc0, 0x00, 0x75, 0xd1, 0x49, 0x15, 0xf0, + 0x19, 0xc7, 0x17, 0xc2, 0xec, 0x9a, 0x00, 0x19, + 0xee, 0x89, 0xee, 0x71, 0x9f, 0x49, 0xfe, 0xf1, + 0xea, 0x71, 0x9f, 0x49, 0x0a, 0xf0, 0xd9, 0xc2, + 0xec, 0x9a, 0x00, 0x19, 0xe8, 0x99, 0x81, 0x19, + 0xee, 0x89, 0xee, 0x71, 0x9f, 0x49, 0xfe, 0xf1, + 0x06, 0xc3, 0x02, 0xc2, 0x00, 0xba, 0xf0, 0x1d, + 0x4c, 0xe8, 0x00, 0xdc, 0x00, 0xd4, 0xcb, 0xc0, + 0x00, 0x75, 0xd1, 0x49, 0x0d, 0xf0, 0xc4, 0xc0, + 0xc4, 0xc5, 0x00, 0x1e, 0x08, 0x9e, 0xc2, 0xc6, + 0x0a, 0x9e, 0x0c, 0x9d, 0x8f, 0x1c, 0x0e, 0x8c, + 0x0e, 0x74, 0xcf, 0x49, 0xfe, 0xf1, 0x04, 0xc0, + 0x02, 0xc1, 0x00, 0xb9, 0xc4, 0x16, 0x20, 0xd4, + 0xb6, 0xc0, 0x00, 0x75, 0xd1, 0x48, 0x00, 0x9d, + 0xe5, 0xc7, 0xaf, 0xc2, 0xec, 0x9a, 0x00, 0x19, + 0xe8, 0x9a, 0x81, 0x19, 0xee, 0x89, 0xee, 0x71, + 0x9f, 0x49, 0xfe, 0xf1, 0x2c, 0xc1, 0xec, 0x99, + 0x81, 0x19, 0xee, 0x89, 0xee, 0x71, 0x9f, 0x49, + 0xfe, 0xf1, 0x04, 0xc3, 0x02, 0xc2, 0x00, 0xba, + 0x96, 0x1c, 0xc0, 0xd4, 0xc0, 0x88, 0x1e, 0xc6, + 0xc0, 0x70, 0x8f, 0x49, 0x0e, 0xf0, 0x8f, 0x48, + 0x93, 0xc6, 0xca, 0x98, 0x11, 0x18, 0xc8, 0x98, + 0x16, 0xc0, 0xcc, 0x98, 0x8f, 0x18, 0xce, 0x88, + 0xce, 0x70, 0x8f, 0x49, 0xfe, 0xf1, 0x0b, 0xe0, + 0x43, 0xc6, 0x00, 0x18, 0xc8, 0x98, 0x0b, 0xc0, + 0xcc, 0x98, 0x81, 0x18, 0xce, 0x88, 0xce, 0x70, + 0x8f, 0x49, 0xfe, 0xf1, 0x02, 0xc0, 0x00, 0xb8, + 0xf2, 0x19, 0x40, 0xd3, 0x20, 0xe4, 0x33, 0xc2, + 0x40, 0x71, 0x91, 0x48, 0x40, 0x99, 0x30, 0xc2, + 0x00, 0x19, 0x48, 0x99, 0xf8, 0xc1, 0x4c, 0x99, + 0x81, 0x19, 0x4e, 0x89, 0x4e, 0x71, 0x9f, 0x49, + 0xfe, 0xf1, 0x0b, 0xc1, 0x4c, 0x99, 0x81, 0x19, + 0x4e, 0x89, 0x4e, 0x71, 0x9f, 0x49, 0xfe, 0xf1, + 0x02, 0x71, 0x02, 0xc2, 0x00, 0xba, 0x0e, 0x34, + 0x24, 0xe4, 0x19, 0xc2, 0x40, 0x71, 0x91, 0x48, + 0x40, 0x99, 0x16, 0xc2, 0x00, 0x19, 0x48, 0x99, + 0xde, 0xc1, 0x4c, 0x99, 0x81, 0x19, 0x4e, 0x89, + 0x4e, 0x71, 0x9f, 0x49, 0xfe, 0xf1, 0xf1, 0xc1, + 0x4c, 0x99, 0x81, 0x19, 0x4e, 0x89, 0x4e, 0x71, + 0x9f, 0x49, 0xfe, 0xf1, 0x02, 0x71, 0x02, 0xc2, + 0x00, 0xba, 0x60, 0x33, 0x34, 0xd3, 0x00, 0xdc, + 0x1e, 0x89, 0x02, 0xc0, 0x00, 0xb8, 0xfa, 0x12, + 0x18, 0xc0, 0x00, 0x65, 0xd1, 0x49, 0x0e, 0xf0, + 0x11, 0xc0, 0x11, 0xc5, 0x00, 0x1e, 0x08, 0x9e, + 0x0c, 0x9d, 0x0e, 0xc6, 0x0a, 0x9e, 0x8f, 0x1c, + 0x0e, 0x8c, 0x0e, 0x74, 0xcf, 0x49, 0xfe, 0xf1, + 0x04, 0xc0, 0x02, 0xc2, 0x00, 0xba, 0xa0, 0x41, + 0x06, 0xd4, 0x00, 0xdc, 0x24, 0xe4, 0x80, 0x02, + 0x34, 0xd3, 0x02, 0xc0, 0x00, 0xb8, 0x00, 0x00, + 0x02, 0xc0, 0x00, 0xb8, 0x00, 0x00, 0x02, 0xc0, + 0x00, 0xb8, 0x00, 0x00, 0x02, 0xc0, 0x00, 0xb8, + 0x00, 0x00, 0x02, 0xc0, 0x00, 0xb8, 0x00, 0x00, + 0x02, 0xc0, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00 }; + +static u16 r8153b_usb_patch_b_bp[] = { + 0xfc26, 0xa000, 0xfc28, 0x2a20, 0xfc2a, 0x28a6, 0xfc2c, 0x1dee, + 0xfc2e, 0x16c2, 0xfc30, 0x1c94, 0xfc32, 0x19f0, 0xfc34, 0x340c, + 0xfc36, 0x335e, 0xfc38, 0x12f8, 0xfc3a, 0x419e, 0xfc3c, 0x0000, + 0xfc3e, 0x0000, 0xfc40, 0x0000, 0xfc42, 0x0000, 0xfc44, 0x0000, + 0xfc46, 0x0000, 0xfc48, 0x03ff }; + +static u8 pla_patch2_b[] = { + 0x05, 0xe0, 0x1b, 0xe0, 0x2c, 0xe0, 0x60, 0xe0, + 0x73, 0xe0, 0x15, 0xc6, 0xc2, 0x64, 0xd2, 0x49, + 0x06, 0xf1, 0xc4, 0x48, 0xc5, 0x48, 0xc6, 0x48, + 0xc7, 0x48, 0x05, 0xe0, 0x44, 0x48, 0x45, 0x48, + 0x46, 0x48, 0x47, 0x48, 0xc2, 0x8c, 0xc0, 0x64, + 0x46, 0x48, 0xc0, 0x8c, 0x05, 0xc5, 0x02, 0xc4, + 0x00, 0xbc, 0x18, 0x02, 0x06, 0xdc, 0xb0, 0xc0, + 0x10, 0xc5, 0xa0, 0x77, 0xa0, 0x74, 0x46, 0x48, + 0x47, 0x48, 0xa0, 0x9c, 0x0b, 0xc5, 0xa0, 0x74, + 0x44, 0x48, 0x43, 0x48, 0xa0, 0x9c, 0x05, 0xc5, + 0xa0, 0x9f, 0x02, 0xc5, 0x00, 0xbd, 0x3c, 0x03, + 0x1c, 0xe8, 0x20, 0xe8, 0xd4, 0x49, 0x04, 0xf1, + 0xd5, 0x49, 0x20, 0xf1, 0x28, 0xe0, 0x2a, 0xc7, + 0xe0, 0x75, 0xda, 0x49, 0x14, 0xf0, 0x27, 0xc7, + 0xe0, 0x75, 0xdc, 0x49, 0x10, 0xf1, 0x24, 0xc7, + 0xe0, 0x75, 0x25, 0xc7, 0xe0, 0x74, 0x2c, 0x40, + 0x0a, 0xfa, 0x1f, 0xc7, 0xe4, 0x75, 0xd0, 0x49, + 0x09, 0xf1, 0x1c, 0xc5, 0xe6, 0x9d, 0x11, 0x1d, + 0xe4, 0x8d, 0x04, 0xe0, 0x16, 0xc7, 0x00, 0x1d, + 0xe4, 0x8d, 0xe0, 0x8e, 0x11, 0x1d, 0xe0, 0x8d, + 0x07, 0xe0, 0x0c, 0xc7, 0xe0, 0x75, 0xda, 0x48, + 0xe0, 0x9d, 0x0b, 0xc7, 0xe4, 0x8e, 0x02, 0xc4, + 0x00, 0xbc, 0x28, 0x03, 0x02, 0xc4, 0x00, 0xbc, + 0x14, 0x03, 0x12, 0xe8, 0x4e, 0xe8, 0x1c, 0xe6, + 0x20, 0xe4, 0x80, 0x02, 0xa4, 0xc0, 0x12, 0xc2, + 0x40, 0x73, 0xb0, 0x49, 0x08, 0xf0, 0xb8, 0x49, + 0x06, 0xf0, 0xb8, 0x48, 0x40, 0x9b, 0x0b, 0xc2, + 0x40, 0x76, 0x05, 0xe0, 0x02, 0x61, 0x02, 0xc3, + 0x00, 0xbb, 0x0a, 0x0a, 0x02, 0xc3, 0x00, 0xbb, + 0x1a, 0x0a, 0x98, 0xd3, 0x1e, 0xfc, 0xfe, 0xc0, + 0x02, 0x62, 0xa0, 0x48, 0x02, 0x8a, 0x00, 0x72, + 0xa0, 0x49, 0x11, 0xf0, 0x13, 0xc1, 0x20, 0x62, + 0x2e, 0x21, 0x2f, 0x25, 0x00, 0x71, 0x9f, 0x24, + 0x0a, 0x40, 0x09, 0xf0, 0x00, 0x71, 0x18, 0x48, + 0xa0, 0x49, 0x03, 0xf1, 0x9f, 0x48, 0x02, 0xe0, + 0x1f, 0x48, 0x00, 0x99, 0x02, 0xc2, 0x00, 0xba, + 0xda, 0x0e, 0x08, 0xe9 }; + +static u16 r8153b_pla_patch_b_bp[] = { + 0xfc26, 0x8000, 0xfc28, 0x0216, 0xfc2a, 0x0332, 0xfc2c, 0x030c, + 0xfc2e, 0x0a08, 0xfc30, 0x0ec0, 0xfc32, 0x0000, 0xfc34, 0x0000, + 0xfc36, 0x0000, 0xfc38, 0x001e }; + +static void rtl_clear_bp(struct r8152 *tp, u16 type) { - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0); - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0); - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0); - ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0); - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0); - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0); - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0); - ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0); + u8 zeros[16] = {0}; + + switch (tp->version) { + case RTL_VER_01: + case RTL_VER_02: + case RTL_VER_07: + break; + case RTL_VER_03: + case RTL_VER_04: + case RTL_VER_05: + case RTL_VER_06: + ocp_write_byte(tp, type, PLA_BP_EN, 0); + break; + case RTL_VER_08: + case RTL_VER_09: + default: + if (type == MCU_TYPE_USB) { + ocp_write_byte(tp, MCU_TYPE_USB, USB_BP2_EN, 0); + + generic_ocp_write(tp, USB_BP(8), 0xff, sizeof(zeros), + zeros, type); + } else { + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0); + } + break; + } + + generic_ocp_write(tp, USB_BP(0), 0xff, sizeof(zeros), zeros, type); mdelay(6); - ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0); -} - -static void r8153_clear_bp(struct r8152 *tp) -{ - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0); - ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0); - rtl_clear_bp(tp); + ocp_write_word(tp, type, PLA_BP_BA, 0); } static void r8152b_set_dq_desc(struct r8152 *tp) @@ -826,7 +959,7 @@ void r8152b_firmware(struct r8152 *tp) int i; r8152b_set_dq_desc(tp); - rtl_clear_bp(tp); + rtl_clear_bp(tp, MCU_TYPE_PLA); generic_ocp_write(tp, 0xf800, 0x3f, sizeof(r8152b_pla_patch_a), @@ -847,7 +980,7 @@ void r8152b_firmware(struct r8152 *tp) ocp_write_word(tp, MCU_TYPE_PLA, 0xb098, 0x0200); ocp_write_word(tp, MCU_TYPE_PLA, 0xb092, 0x7030); } else if (tp->version == RTL_VER_02) { - rtl_clear_bp(tp); + rtl_clear_bp(tp, MCU_TYPE_PLA); generic_ocp_write(tp, 0xf800, 0xff, sizeof(r8152b_pla_patch_a2), @@ -866,8 +999,6 @@ void r8153_firmware(struct r8152 *tp) int i; if (tp->version == RTL_VER_03) { - r8153_clear_bp(tp); - r8153_pre_ram_code(tp, 0x7000); for (i = 0; i < ARRAY_SIZE(r8153_ram_code_a); i += 2) @@ -887,7 +1018,8 @@ void r8153_firmware(struct r8152 *tp) r8153_post_ram_code(tp); r8153_wdt1_end(tp); - r8153_clear_bp(tp); + + rtl_clear_bp(tp, MCU_TYPE_USB); ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, @@ -904,6 +1036,8 @@ void r8153_firmware(struct r8152 *tp) ocp_write_word(tp, MCU_TYPE_PLA, 0xd38e, 0x0082); } + rtl_clear_bp(tp, MCU_TYPE_PLA); + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, sizeof(r8153_pla_patch_b), @@ -932,7 +1066,8 @@ void r8153_firmware(struct r8152 *tp) r8153_post_ram_code(tp); r8153_wdt1_end(tp); - r8153_clear_bp(tp); + + rtl_clear_bp(tp, MCU_TYPE_USB); ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, @@ -951,6 +1086,8 @@ void r8153_firmware(struct r8152 *tp) ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x00ef); } + rtl_clear_bp(tp, MCU_TYPE_PLA); + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, sizeof(r8153_pla_patch_c), @@ -985,7 +1122,7 @@ void r8153_firmware(struct r8152 *tp) r8153_post_ram_code(tp); - r8153_clear_bp(tp); + rtl_clear_bp(tp, MCU_TYPE_USB); ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, sizeof(usb_patch_d), @@ -996,6 +1133,8 @@ void r8153_firmware(struct r8152 *tp) r8153_usb_patch_d_bp[i], r8153_usb_patch_d_bp[i+1]); + rtl_clear_bp(tp, MCU_TYPE_PLA); + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000); generic_ocp_write(tp, 0xf800, 0xff, sizeof(pla_patch_d), pla_patch_d, MCU_TYPE_PLA); @@ -1014,3 +1153,42 @@ void r8153_firmware(struct r8152 *tp) ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data); } } + +void r8153b_firmware(struct r8152 *tp) +{ + u32 ocp_data; + int i; + + if (tp->version != RTL_VER_09) + return; + + rtl_clear_bp(tp, MCU_TYPE_USB); + + ocp_write_word(tp, MCU_TYPE_USB, USB_BP_EN, 0x0000); + generic_ocp_write(tp, 0xe600, 0xff, sizeof(usb_patch2_b), + usb_patch2_b, MCU_TYPE_USB); + + for (i = 0; i < ARRAY_SIZE(r8153b_usb_patch_b_bp); i += 2) + ocp_write_word(tp, MCU_TYPE_USB, + r8153b_usb_patch_b_bp[i], + r8153b_usb_patch_b_bp[i + 1]); + + rtl_clear_bp(tp, MCU_TYPE_PLA); + + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_EN, 0x0000); + generic_ocp_write(tp, 0xf800, 0xff, sizeof(pla_patch2_b), + pla_patch2_b, MCU_TYPE_PLA); + + for (i = 0; i < ARRAY_SIZE(r8153b_pla_patch_b_bp); i += 2) + ocp_write_word(tp, MCU_TYPE_PLA, + r8153b_pla_patch_b_bp[i], + r8153b_pla_patch_b_bp[i + 1]); + + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_USB2PHY); + ocp_data |= USB2PHY_L1 | USB2PHY_SUSPEND; + ocp_write_byte(tp, MCU_TYPE_USB, USB_USB2PHY, ocp_data); + + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1); + ocp_data |= FW_IP_RESET_EN; + ocp_write_word(tp, MCU_TYPE_USB, USB_FW_FIX_EN1, ocp_data); +} diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 46aa3fe9543..7c0df5c264d 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -105,6 +105,12 @@ config CI_UDC Say Y here to enable device controller functionality of the ChipIdea driver. +config USB_GADGET_MAX3420 + bool "MAX3420 USB Over SPI" + depends on DM_SPI + help + MAX3420, from MAXIM, implements USB-over-SPI Full-Speed device controller. + config USB_GADGET_VBUS_DRAW int "Maximum VBUS Power usage (2-500 mA)" range 2 500 diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 70f3bf43e7e..f560068b419 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_USB_GADGET_BCM_UDC_OTG_PHY) += bcm_udc_otg_phy.o obj-$(CONFIG_USB_GADGET_DWC2_OTG) += dwc2_udc_otg.o obj-$(CONFIG_USB_GADGET_DWC2_OTG_PHY) += dwc2_udc_otg_phy.o obj-$(CONFIG_USB_GADGET_FOTG210) += fotg210.o +obj-$(CONFIG_USB_GADGET_MAX3420) += max3420_udc.o obj-$(CONFIG_CI_UDC) += ci_udc.o ifndef CONFIG_SPL_BUILD obj-$(CONFIG_USB_GADGET_DOWNLOAD) += g_dnl.o diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index cdbdbcc5cac..cdb8f6fb3d0 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -1053,6 +1053,13 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) free(controller.items_mem); free(controller.epts); +#if CONFIG_IS_ENABLED(DM_USB) + usb_remove_ehci_gadget(&controller.ctrl); +#else + usb_lowlevel_stop(0); + controller.ctrl = NULL; +#endif + return 0; } diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 384c0f6f6e2..d1d087e12b2 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -441,8 +441,6 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req) req->length = rx_bytes_expected(ep); } - fastboot_tx_write_str(response); - if (!strncmp("OKAY", response, 4)) { switch (cmd) { case FASTBOOT_COMMAND_BOOT: @@ -455,11 +453,15 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req) case FASTBOOT_COMMAND_REBOOT: case FASTBOOT_COMMAND_REBOOT_BOOTLOADER: + case FASTBOOT_COMMAND_REBOOT_FASTBOOTD: + case FASTBOOT_COMMAND_REBOOT_RECOVERY: fastboot_func->in_req->complete = compl_do_reset; break; } } + fastboot_tx_write_str(response); + *cmdbuf = '\0'; req->actual = 0; usb_ep_queue(ep, req, 0); diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 439a31c2556..45f0504b6e8 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -435,6 +435,7 @@ static void set_bulk_out_req_length(struct fsg_common *common, static struct ums *ums; static int ums_count; static struct fsg_common *the_fsg_common; +static unsigned int controller_index; static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep) { @@ -679,7 +680,7 @@ static int sleep_thread(struct fsg_common *common) k = 0; } - usb_gadget_handle_interrupts(0); + usb_gadget_handle_interrupts(controller_index); } common->thread_wakeup_needed = 0; return rc; @@ -2764,10 +2765,11 @@ int fsg_add(struct usb_configuration *c) return fsg_bind_config(c->cdev, c, fsg_common); } -int fsg_init(struct ums *ums_devs, int count) +int fsg_init(struct ums *ums_devs, int count, unsigned int controller_idx) { ums = ums_devs; ums_count = count; + controller_index = controller_idx; return 0; } diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index f2fe89d2a6c..e48aa2f90df 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -71,6 +71,10 @@ struct hid_report { #define SDP_COMMAND_LEN 16 +#define SDP_HID_PACKET_SIZE_EP1 1024 + +#define SDP_EXIT 1 + struct sdp_command { u16 cmd; u32 addr; @@ -82,8 +86,10 @@ struct sdp_command { enum sdp_state { SDP_STATE_IDLE, + SDP_STATE_RX_CMD, SDP_STATE_RX_DCD_DATA, SDP_STATE_RX_FILE_DATA, + SDP_STATE_RX_FILE_DATA_BUSY, SDP_STATE_TX_SEC_CONF, SDP_STATE_TX_SEC_CONF_BUSY, SDP_STATE_TX_REGISTER, @@ -114,8 +120,12 @@ struct f_sdp { /* EP1 IN */ struct usb_ep *in_ep; struct usb_request *in_req; + /* EP1 OUT */ + struct usb_ep *out_ep; + struct usb_request *out_req; bool configuration_done; + bool ep_int_enable; }; static struct f_sdp *sdp_func; @@ -129,7 +139,7 @@ static struct usb_interface_descriptor sdp_intf_runtime = { .bLength = sizeof(sdp_intf_runtime), .bDescriptorType = USB_DT_INTERFACE, .bAlternateSetting = 0, - .bNumEndpoints = 1, + .bNumEndpoints = 2, .bInterfaceClass = USB_CLASS_HID, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, @@ -159,10 +169,49 @@ static struct usb_endpoint_descriptor in_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress = 1 | USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = 64, + .bInterval = 1, +}; + +static struct usb_endpoint_descriptor in_hs_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress = 1 | USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = 512, + .bInterval = 3, +}; + +static struct usb_endpoint_descriptor out_hs_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress = 1 | USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = SDP_HID_PACKET_SIZE_EP1, + .bInterval = 3, +}; + static struct usb_descriptor_header *sdp_runtime_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc, (struct usb_descriptor_header *)&in_desc, + (struct usb_descriptor_header *)&out_desc, + NULL, +}; + +static struct usb_descriptor_header *sdp_runtime_hs_descs[] = { + (struct usb_descriptor_header *)&sdp_intf_runtime, + (struct usb_descriptor_header *)&sdp_hid_desc, + (struct usb_descriptor_header *)&in_hs_desc, + (struct usb_descriptor_header *)&out_hs_desc, NULL, }; @@ -328,7 +377,7 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req) int status = req->status; u8 *data = req->buf; u8 report = data[0]; - int datalen = req->length - 1; + int datalen = req->actual - 1; if (status != 0) { pr_err("Status: %d\n", status); @@ -351,13 +400,15 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req) sdp->dnl_bytes_remaining -= datalen; } - if (sdp->state == SDP_STATE_RX_FILE_DATA) { + if (sdp->state == SDP_STATE_RX_FILE_DATA_BUSY) { memcpy(sdp_ptr(sdp->dnl_address), req->buf + 1, datalen); sdp->dnl_address += datalen; } - if (sdp->dnl_bytes_remaining) + if (sdp->dnl_bytes_remaining) { + sdp->state = SDP_STATE_RX_FILE_DATA; return; + } #ifndef CONFIG_SPL_BUILD env_set_hex("filesize", sdp->dnl_bytes); @@ -365,7 +416,7 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req) printf("done\n"); switch (sdp->state) { - case SDP_STATE_RX_FILE_DATA: + case SDP_STATE_RX_FILE_DATA_BUSY: sdp->state = SDP_STATE_TX_SEC_CONF; break; case SDP_STATE_RX_DCD_DATA: @@ -446,10 +497,12 @@ static int sdp_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) case 1: value = SDP_COMMAND_LEN + 1; req->complete = sdp_rx_command_complete; + sdp_func->ep_int_enable = false; break; case 2: value = len; req->complete = sdp_rx_data_complete; + sdp_func->state = SDP_STATE_RX_FILE_DATA_BUSY; break; } } @@ -480,16 +533,29 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f) return id; sdp_intf_runtime.bInterfaceNumber = id; - struct usb_ep *ep; + struct usb_ep *ep_in, *ep_out; /* allocate instance-specific endpoints */ - ep = usb_ep_autoconfig(gadget, &in_desc); - if (!ep) { + ep_in = usb_ep_autoconfig(gadget, &in_desc); + if (!ep_in) { rv = -ENODEV; goto error; } - sdp->in_ep = ep; /* Store IN EP for enabling @ setup */ + ep_out = usb_ep_autoconfig(gadget, &out_desc); + if (!ep_out) { + rv = -ENODEV; + goto error; + } + + if (gadget_is_dualspeed(gadget)) { + /* Assume endpoint addresses are the same for both speeds */ + in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress; + out_hs_desc.bEndpointAddress = out_desc.bEndpointAddress; + } + + sdp->in_ep = ep_in; /* Store IN EP for enabling @ setup */ + sdp->out_ep = ep_out; cdev->req->context = sdp; @@ -522,18 +588,29 @@ static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) } -static struct usb_request *sdp_start_ep(struct usb_ep *ep) +static struct usb_request *sdp_start_ep(struct usb_ep *ep, bool in) { struct usb_request *req; - req = alloc_ep_req(ep, 64); + if (in) + req = alloc_ep_req(ep, 65); + else + req = alloc_ep_req(ep, 2048); +/* + * OUT endpoint request length should be an integral multiple of + * maxpacket size 1024, else we break on certain controllers like + * DWC3 that expect bulk OUT requests to be divisible by maxpacket size. + */ debug("%s: ep:%p req:%p\n", __func__, ep, req); if (!req) return NULL; memset(req->buf, 0, req->length); - req->complete = sdp_tx_complete; + if (in) + req->complete = sdp_tx_complete; + else + req->complete = sdp_rx_command_complete; return req; } @@ -541,20 +618,32 @@ static int sdp_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { struct f_sdp *sdp = func_to_sdp(f); struct usb_composite_dev *cdev = f->config->cdev; + struct usb_gadget *gadget = cdev->gadget; int result; debug("%s: intf: %d alt: %d\n", __func__, intf, alt); - result = usb_ep_enable(sdp->in_ep, &in_desc); + if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH) { + result = usb_ep_enable(sdp->in_ep, &in_hs_desc); + result |= usb_ep_enable(sdp->out_ep, &out_hs_desc); + } else { + result = usb_ep_enable(sdp->in_ep, &in_desc); + result |= usb_ep_enable(sdp->out_ep, &out_desc); + } if (result) return result; - sdp->in_req = sdp_start_ep(sdp->in_ep); + + sdp->in_req = sdp_start_ep(sdp->in_ep, true); sdp->in_req->context = sdp; + sdp->out_req = sdp_start_ep(sdp->out_ep, false); + sdp->out_req->context = sdp; sdp->in_ep->driver_data = cdev; /* claim */ + sdp->out_ep->driver_data = cdev; /* claim */ sdp->altsetting = alt; sdp->state = SDP_STATE_IDLE; + sdp->ep_int_enable = true; return 0; } @@ -571,11 +660,18 @@ static void sdp_disable(struct usb_function *f) struct f_sdp *sdp = func_to_sdp(f); usb_ep_disable(sdp->in_ep); + usb_ep_disable(sdp->out_ep); if (sdp->in_req) { - free(sdp->in_req); + free(sdp->in_req->buf); + usb_ep_free_request(sdp->in_ep, sdp->in_req); sdp->in_req = NULL; } + if (sdp->out_req) { + free(sdp->out_req->buf); + usb_ep_free_request(sdp->out_ep, sdp->out_req); + sdp->out_req = NULL; + } } static int sdp_bind_config(struct usb_configuration *c) @@ -591,7 +687,7 @@ static int sdp_bind_config(struct usb_configuration *c) memset(sdp_func, 0, sizeof(*sdp_func)); sdp_func->usb_function.name = "sdp"; - sdp_func->usb_function.hs_descriptors = sdp_runtime_descs; + sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs; sdp_func->usb_function.descriptors = sdp_runtime_descs; sdp_func->usb_function.bind = sdp_bind; sdp_func->usb_function.unbind = sdp_unbind; @@ -641,19 +737,43 @@ static u32 sdp_jump_imxheader(void *address) } #ifdef CONFIG_SPL_BUILD -#ifdef CONFIG_SPL_LOAD_FIT -static ulong sdp_fit_read(struct spl_load_info *load, ulong sector, - ulong count, void *buf) +static ulong sdp_load_read(struct spl_load_info *load, ulong sector, + ulong count, void *buf) { debug("%s: sector %lx, count %lx, buf %lx\n", __func__, sector, count, (ulong)buf); memcpy(buf, (void *)(load->dev + sector), count); return count; } -#endif + +static ulong search_fit_header(ulong p, int size) +{ + int i; + + for (i = 0; i < size; i += 4) { + if (genimg_get_format((const void *)(p + i)) == IMAGE_FORMAT_FIT) + return p + i; + } + + return 0; +} + +static ulong search_container_header(ulong p, int size) +{ + int i; + u8 *hdr; + + for (i = 0; i < size; i += 4) { + hdr = (u8 *)(p + i); + if (*(hdr + 3) == 0x87 && *hdr == 0) + if (*(hdr + 1) != 0 || *(hdr + 2) != 0) + return p + i; + } + return 0; +} #endif -static void sdp_handle_in_ep(struct spl_image_info *spl_image) +static int sdp_handle_in_ep(struct spl_image_info *spl_image) { u8 *data = sdp_func->in_req->buf; u32 status; @@ -705,6 +825,15 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) /* If imx header fails, try some U-Boot specific headers */ if (status) { #ifdef CONFIG_SPL_BUILD + if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) + sdp_func->jmp_address = (u32)search_container_header((ulong)sdp_func->jmp_address, sdp_func->dnl_bytes); + else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) + sdp_func->jmp_address = (u32)search_fit_header((ulong)sdp_func->jmp_address, sdp_func->dnl_bytes); + if (sdp_func->jmp_address == 0) + panic("Error in search header, failed to jump\n"); + + printf("Found header at 0x%08x\n", sdp_func->jmp_address); + image_header_t *header = sdp_ptr(sdp_func->jmp_address); #ifdef CONFIG_SPL_LOAD_FIT @@ -714,13 +843,23 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) debug("Found FIT\n"); load.dev = header; load.bl_len = 1; - load.read = sdp_fit_read; + load.read = sdp_load_read; spl_load_simple_fit(spl_image, &load, 0, header); - return; + return SDP_EXIT; } #endif + if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) { + struct spl_load_info load; + + load.dev = header; + load.bl_len = 1; + load.read = sdp_load_read; + spl_load_imx_container(spl_image, &load, 0); + return SDP_EXIT; + } + /* In SPL, allow jumps to U-Boot images */ struct spl_image_info spl_image = {}; spl_parse_image_header(&spl_image, header); @@ -743,6 +882,29 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) default: break; }; + + return 0; +} + +static void sdp_handle_out_ep(void) +{ + int rc; + + if (sdp_func->state == SDP_STATE_IDLE) { + sdp_func->out_req->complete = sdp_rx_command_complete; + rc = usb_ep_queue(sdp_func->out_ep, sdp_func->out_req, 0); + if (rc) + printf("error in submission: %s\n", + sdp_func->out_ep->name); + sdp_func->state = SDP_STATE_RX_CMD; + } else if (sdp_func->state == SDP_STATE_RX_FILE_DATA) { + sdp_func->out_req->complete = sdp_rx_data_complete; + rc = usb_ep_queue(sdp_func->out_ep, sdp_func->out_req, 0); + if (rc) + printf("error in submission: %s\n", + sdp_func->out_ep->name); + sdp_func->state = SDP_STATE_RX_FILE_DATA_BUSY; + } } #ifndef CONFIG_SPL_BUILD @@ -751,6 +913,7 @@ int sdp_handle(int controller_index) int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) #endif { + int flag = 0; printf("SDP: handle requests...\n"); while (1) { if (ctrlc()) { @@ -758,19 +921,19 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) return -EINVAL; } -#ifdef CONFIG_SPL_BUILD - if (spl_image->flags & SPL_FIT_FOUND) + if (flag == SDP_EXIT) return 0; -#endif WATCHDOG_RESET(); usb_gadget_handle_interrupts(controller_index); #ifdef CONFIG_SPL_BUILD - sdp_handle_in_ep(spl_image); + flag = sdp_handle_in_ep(spl_image); #else - sdp_handle_in_ep(NULL); + flag = sdp_handle_in_ep(NULL); #endif + if (sdp_func->ep_int_enable) + sdp_handle_out_ep(); } } diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index 91b0285244e..587204cfb7a 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h @@ -155,6 +155,12 @@ #define gadget_is_cdns3(g) 0 #endif +#ifdef CONFIG_USB_GADGET_MAX3420 +#define gadget_is_max3420(g) (!strcmp("max3420-udc", (g)->name)) +#else +#define gadget_is_max3420(g) 0 +#endif + /** * usb_gadget_controller_number - support bcdDevice id convention * @gadget: the controller being driven @@ -216,5 +222,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) return 0x23; else if (gadget_is_cdns3(gadget)) return 0x24; + else if (gadget_is_max3420(gadget)) + return 0x25; return -ENOENT; } diff --git a/drivers/usb/gadget/max3420_udc.c b/drivers/usb/gadget/max3420_udc.c new file mode 100644 index 00000000000..b38b9dc68f7 --- /dev/null +++ b/drivers/usb/gadget/max3420_udc.c @@ -0,0 +1,875 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX3420_MAX_EPS 4 +#define EP_MAX_PACKET 64 /* Same for all Endpoints */ +#define EPNAME_SIZE 16 /* Buffer size for endpoint name */ + +#define MAX3420_SPI_DIR_RD 0 /* read register from MAX3420 */ +#define MAX3420_SPI_DIR_WR 1 /* write register to MAX3420 */ + +/* SPI commands: */ +#define MAX3420_SPI_ACK_MASK BIT(0) +#define MAX3420_SPI_DIR_MASK BIT(1) +#define MAX3420_SPI_REG_MASK GENMASK(7, 3) + +#define MAX3420_REG_EP0FIFO 0 +#define MAX3420_REG_EP1FIFO 1 +#define MAX3420_REG_EP2FIFO 2 +#define MAX3420_REG_EP3FIFO 3 +#define MAX3420_REG_SUDFIFO 4 +#define MAX3420_REG_EP0BC 5 +#define MAX3420_REG_EP1BC 6 +#define MAX3420_REG_EP2BC 7 +#define MAX3420_REG_EP3BC 8 + +#define MAX3420_REG_EPSTALLS 9 + #define bACKSTAT BIT(6) + #define bSTLSTAT BIT(5) + #define bSTLEP3IN BIT(4) + #define bSTLEP2IN BIT(3) + #define bSTLEP1OUT BIT(2) + #define bSTLEP0OUT BIT(1) + #define bSTLEP0IN BIT(0) + +#define MAX3420_REG_CLRTOGS 10 + #define bEP3DISAB BIT(7) + #define bEP2DISAB BIT(6) + #define bEP1DISAB BIT(5) + #define bCTGEP3IN BIT(4) + #define bCTGEP2IN BIT(3) + #define bCTGEP1OUT BIT(2) + +#define MAX3420_REG_EPIRQ 11 +#define MAX3420_REG_EPIEN 12 + #define bSUDAVIRQ BIT(5) + #define bIN3BAVIRQ BIT(4) + #define bIN2BAVIRQ BIT(3) + #define bOUT1DAVIRQ BIT(2) + #define bOUT0DAVIRQ BIT(1) + #define bIN0BAVIRQ BIT(0) + +#define MAX3420_REG_USBIRQ 13 +#define MAX3420_REG_USBIEN 14 + #define bOSCOKIRQ BIT(0) + #define bRWUDNIRQ BIT(1) + #define bBUSACTIRQ BIT(2) + #define bURESIRQ BIT(3) + #define bSUSPIRQ BIT(4) + #define bNOVBUSIRQ BIT(5) + #define bVBUSIRQ BIT(6) + #define bURESDNIRQ BIT(7) + +#define MAX3420_REG_USBCTL 15 + #define bHOSCSTEN BIT(7) + #define bVBGATE BIT(6) + #define bCHIPRES BIT(5) + #define bPWRDOWN BIT(4) + #define bCONNECT BIT(3) + #define bSIGRWU BIT(2) + +#define MAX3420_REG_CPUCTL 16 + #define bIE BIT(0) + +#define MAX3420_REG_PINCTL 17 + #define bEP3INAK BIT(7) + #define bEP2INAK BIT(6) + #define bEP0INAK BIT(5) + #define bFDUPSPI BIT(4) + #define bINTLEVEL BIT(3) + #define bPOSINT BIT(2) + #define bGPXB BIT(1) + #define bGPXA BIT(0) + +#define MAX3420_REG_REVISION 18 + +#define MAX3420_REG_FNADDR 19 + #define FNADDR_MASK 0x7f + +#define MAX3420_REG_IOPINS 20 +#define MAX3420_REG_IOPINS2 21 +#define MAX3420_REG_GPINIRQ 22 +#define MAX3420_REG_GPINIEN 23 +#define MAX3420_REG_GPINPOL 24 +#define MAX3420_REG_HIRQ 25 +#define MAX3420_REG_HIEN 26 +#define MAX3420_REG_MODE 27 +#define MAX3420_REG_PERADDR 28 +#define MAX3420_REG_HCTL 29 +#define MAX3420_REG_HXFR 30 +#define MAX3420_REG_HRSL 31 + +struct max3420_req { + struct usb_request usb_req; + struct list_head queue; + struct max3420_ep *ep; +}; + +struct max3420_ep { + struct max3420_udc *udc; + struct list_head queue; + char name[EPNAME_SIZE]; + unsigned int maxpacket; + struct usb_ep ep_usb; + int halted; + int id; +}; + +struct max3420_udc { + struct max3420_ep ep[MAX3420_MAX_EPS]; + struct usb_gadget_driver *driver; + bool softconnect; + struct usb_ctrlrequest setup; + struct max3420_req ep0req; + struct usb_gadget gadget; + struct spi_slave *slave; + struct udevice *dev; + u8 ep0buf[64]; + int remote_wkp; + bool suspended; +}; + +#define to_max3420_req(r) container_of((r), struct max3420_req, usb_req) +#define to_max3420_ep(e) container_of((e), struct max3420_ep, ep_usb) +#define to_udc(g) container_of((g), struct max3420_udc, gadget) + +static void spi_ack_ctrl(struct max3420_udc *udc) +{ + struct spi_slave *slave = udc->slave; + u8 txdata[1]; + + txdata[0] = FIELD_PREP(MAX3420_SPI_ACK_MASK, 1); + spi_xfer(slave, sizeof(txdata), txdata, NULL, SPI_XFER_ONCE); +} + +static u8 spi_rd8_ack(struct max3420_udc *udc, u8 reg, int ackstat) +{ + struct spi_slave *slave = udc->slave; + u8 txdata[2], rxdata[2]; + + txdata[0] = FIELD_PREP(MAX3420_SPI_REG_MASK, reg) | + FIELD_PREP(MAX3420_SPI_DIR_MASK, MAX3420_SPI_DIR_RD) | + FIELD_PREP(MAX3420_SPI_ACK_MASK, ackstat ? 1 : 0); + + rxdata[0] = 0; + rxdata[1] = 0; + spi_xfer(slave, sizeof(txdata), txdata, rxdata, SPI_XFER_ONCE); + + return rxdata[1]; +} + +static u8 spi_rd8(struct max3420_udc *udc, u8 reg) +{ + return spi_rd8_ack(udc, reg, 0); +} + +static void spi_wr8_ack(struct max3420_udc *udc, u8 reg, u8 val, int ackstat) +{ + struct spi_slave *slave = udc->slave; + u8 txdata[2]; + + txdata[0] = FIELD_PREP(MAX3420_SPI_REG_MASK, reg) | + FIELD_PREP(MAX3420_SPI_DIR_MASK, MAX3420_SPI_DIR_WR) | + FIELD_PREP(MAX3420_SPI_ACK_MASK, ackstat ? 1 : 0); + txdata[1] = val; + + spi_xfer(slave, sizeof(txdata), txdata, NULL, SPI_XFER_ONCE); +} + +static void spi_wr8(struct max3420_udc *udc, u8 reg, u8 val) +{ + spi_wr8_ack(udc, reg, val, 0); +} + +static void spi_rd_buf(struct max3420_udc *udc, u8 reg, void *buf, u8 len) +{ + struct spi_slave *slave = udc->slave; + u8 txdata[1]; + + txdata[0] = FIELD_PREP(MAX3420_SPI_REG_MASK, reg) | + FIELD_PREP(MAX3420_SPI_DIR_MASK, MAX3420_SPI_DIR_RD); + + spi_xfer(slave, sizeof(txdata), txdata, NULL, SPI_XFER_BEGIN); + spi_xfer(slave, len * 8, NULL, buf, SPI_XFER_END); +} + +static void spi_wr_buf(struct max3420_udc *udc, u8 reg, void *buf, u8 len) +{ + struct spi_slave *slave = udc->slave; + u8 txdata[1]; + + txdata[0] = FIELD_PREP(MAX3420_SPI_REG_MASK, reg) | + FIELD_PREP(MAX3420_SPI_DIR_MASK, MAX3420_SPI_DIR_WR); + + spi_xfer(slave, sizeof(txdata), txdata, NULL, SPI_XFER_BEGIN); + spi_xfer(slave, len * 8, buf, NULL, SPI_XFER_END); +} + +/* 0 if not-connected */ +int g_dnl_board_usb_cable_connected(void) +{ + return 1; +} + +static void spi_max3420_enable(struct max3420_ep *ep, int enable) +{ + struct max3420_udc *udc = ep->udc; + u8 epdis, epien; + + if (ep->id == 0) + return; + + epien = spi_rd8(udc, MAX3420_REG_EPIEN); + epdis = spi_rd8(udc, MAX3420_REG_CLRTOGS); + + if (enable) { + epdis &= ~BIT(ep->id + 4); + epien |= BIT(ep->id + 1); + } else { + epdis |= BIT(ep->id + 4); + epien &= ~BIT(ep->id + 1); + } + + spi_wr8(udc, MAX3420_REG_CLRTOGS, epdis); + spi_wr8(udc, MAX3420_REG_EPIEN, epien); +} + +static int +max3420_ep_enable(struct usb_ep *_ep, + const struct usb_endpoint_descriptor *desc) +{ + struct max3420_ep *ep = to_max3420_ep(_ep); + + _ep->desc = desc; + _ep->maxpacket = usb_endpoint_maxp(desc) & 0x7ff; + + spi_max3420_enable(ep, 1); + + return 0; +} + +static void max3420_req_done(struct max3420_req *req, int status) +{ + struct max3420_ep *ep = req->ep; + + if (req->usb_req.status == -EINPROGRESS) + req->usb_req.status = status; + else + status = req->usb_req.status; + + if (status && status != -ESHUTDOWN) + dev_err(ep->udc->dev, "%s done %p, status %d\n", + ep->ep_usb.name, req, status); + + if (req->usb_req.complete) + req->usb_req.complete(&ep->ep_usb, &req->usb_req); +} + +static void max3420_ep_nuke(struct max3420_ep *ep, int status) +{ + struct max3420_req *req, *r; + + list_for_each_entry_safe(req, r, &ep->queue, queue) { + list_del_init(&req->queue); + max3420_req_done(req, status); + } +} + +static int max3420_ep_disable(struct usb_ep *_ep) +{ + struct max3420_ep *ep = to_max3420_ep(_ep); + + _ep->desc = NULL; + max3420_ep_nuke(ep, -ESHUTDOWN); + spi_max3420_enable(ep, 0); + + return 0; +} + +static struct usb_request * +max3420_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) +{ + struct max3420_ep *ep = to_max3420_ep(_ep); + struct max3420_req *req = kzalloc(sizeof(*req), gfp_flags); + + if (!req) + return NULL; + + req->ep = ep; + INIT_LIST_HEAD(&req->queue); + + return &req->usb_req; +} + +static void +max3420_ep_free_request(struct usb_ep *_ep, struct usb_request *_req) +{ + kfree(to_max3420_req(_req)); +} + +static int +max3420_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) +{ + struct max3420_req *req = to_max3420_req(_req); + struct max3420_ep *ep = to_max3420_ep(_ep); + + _req->status = -EINPROGRESS; + _req->actual = 0; + list_add_tail(&req->queue, &ep->queue); + + return 0; +} + +static int max3420_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) +{ + struct max3420_req *req = to_max3420_req(_req); + + list_del_init(&req->queue); + max3420_req_done(req, -ECONNRESET); + + return 0; +} + +static int max3420_ep_set_halt(struct usb_ep *_ep, int halt) +{ + struct max3420_ep *ep = to_max3420_ep(_ep); + struct max3420_udc *udc = ep->udc; + u8 epstalls; + + if (ep->id == 0) /* can't stall EP0 */ + return 0; + + epstalls = spi_rd8(udc, MAX3420_REG_EPSTALLS); + if (halt) { + ep->halted = 1; + epstalls |= BIT(ep->id + 1); + } else { + u8 clrtogs; + + ep->halted = 0; + epstalls &= ~BIT(ep->id + 1); + clrtogs = spi_rd8(udc, MAX3420_REG_CLRTOGS); + clrtogs |= BIT(ep->id + 1); + spi_wr8(udc, MAX3420_REG_CLRTOGS, clrtogs); + } + spi_wr8(udc, MAX3420_REG_EPSTALLS, epstalls | bACKSTAT); + + return 0; +} + +static const struct usb_ep_ops max3420_ep_ops = { + .enable = max3420_ep_enable, + .disable = max3420_ep_disable, + .alloc_request = max3420_ep_alloc_request, + .free_request = max3420_ep_free_request, + .queue = max3420_ep_queue, + .dequeue = max3420_ep_dequeue, + .set_halt = max3420_ep_set_halt, +}; + +static void __max3420_stop(struct max3420_udc *udc) +{ + u8 val; + + /* Disable IRQ to CPU */ + spi_wr8(udc, MAX3420_REG_CPUCTL, 0); + + val = spi_rd8(udc, MAX3420_REG_USBCTL); + val |= bPWRDOWN; + val |= bHOSCSTEN; + spi_wr8(udc, MAX3420_REG_USBCTL, val); +} + +static void __max3420_start(struct max3420_udc *udc) +{ + u8 val; + + /* configure SPI */ + spi_wr8(udc, MAX3420_REG_PINCTL, bFDUPSPI); + + /* Chip Reset */ + spi_wr8(udc, MAX3420_REG_USBCTL, bCHIPRES); + mdelay(5); + spi_wr8(udc, MAX3420_REG_USBCTL, 0); + + /* Poll for OSC to stabilize */ + while (1) { + val = spi_rd8(udc, MAX3420_REG_USBIRQ); + if (val & bOSCOKIRQ) + break; + cond_resched(); + } + + /* Enable PULL-UP only when Vbus detected */ + val = spi_rd8(udc, MAX3420_REG_USBCTL); + val |= bVBGATE | bCONNECT; + spi_wr8(udc, MAX3420_REG_USBCTL, val); + + val = bURESDNIRQ | bURESIRQ; + spi_wr8(udc, MAX3420_REG_USBIEN, val); + + /* Enable only EP0 interrupts */ + val = bIN0BAVIRQ | bOUT0DAVIRQ | bSUDAVIRQ; + spi_wr8(udc, MAX3420_REG_EPIEN, val); + + /* Enable IRQ to CPU */ + spi_wr8(udc, MAX3420_REG_CPUCTL, bIE); +} + +static int max3420_udc_start(struct usb_gadget *gadget, + struct usb_gadget_driver *driver) +{ + struct max3420_udc *udc = to_udc(gadget); + + udc->driver = driver; + udc->remote_wkp = 0; + udc->softconnect = true; + + __max3420_start(udc); + + return 0; +} + +static int max3420_udc_stop(struct usb_gadget *gadget) +{ + struct max3420_udc *udc = to_udc(gadget); + + udc->driver = NULL; + udc->softconnect = false; + + __max3420_stop(udc); + + return 0; +} + +static int max3420_wakeup(struct usb_gadget *gadget) +{ + struct max3420_udc *udc = to_udc(gadget); + u8 usbctl; + + /* Only if wakeup allowed by host */ + if (!udc->remote_wkp || !udc->suspended) + return 0; + + /* Set Remote-Wakeup Signal*/ + usbctl = spi_rd8(udc, MAX3420_REG_USBCTL); + usbctl |= bSIGRWU; + spi_wr8(udc, MAX3420_REG_USBCTL, usbctl); + + mdelay(5); + + /* Clear Remote-WkUp Signal*/ + usbctl = spi_rd8(udc, MAX3420_REG_USBCTL); + usbctl &= ~bSIGRWU; + spi_wr8(udc, MAX3420_REG_USBCTL, usbctl); + + udc->suspended = false; + + return 0; +} + +static const struct usb_gadget_ops max3420_udc_ops = { + .udc_start = max3420_udc_start, + .udc_stop = max3420_udc_stop, + .wakeup = max3420_wakeup, +}; + +static struct usb_endpoint_descriptor ep0_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_CONTROL, + .wMaxPacketSize = cpu_to_le16(EP_MAX_PACKET), +}; + +static void max3420_getstatus(struct max3420_udc *udc) +{ + struct max3420_ep *ep; + u16 status = 0; + + switch (udc->setup.bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + /* Get device status */ + status = 0 << USB_DEVICE_SELF_POWERED; + status |= (udc->remote_wkp << USB_DEVICE_REMOTE_WAKEUP); + break; + case USB_RECIP_INTERFACE: + if (udc->driver->setup(&udc->gadget, &udc->setup) < 0) + goto stall; + break; + case USB_RECIP_ENDPOINT: + ep = &udc->ep[udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK]; + if (ep->halted) + status = 1 << USB_ENDPOINT_HALT; + break; + default: + goto stall; + } + + status = cpu_to_le16(status); + spi_wr_buf(udc, MAX3420_REG_EP0FIFO, &status, 2); + spi_wr8_ack(udc, MAX3420_REG_EP0BC, 2, 1); + return; +stall: + dev_err(udc->dev, "Can't respond to getstatus request\n"); + spi_wr8(udc, MAX3420_REG_EPSTALLS, bSTLEP0IN | bSTLEP0OUT | bSTLSTAT); +} + +static void max3420_set_clear_feature(struct max3420_udc *udc) +{ + int set = udc->setup.bRequest == USB_REQ_SET_FEATURE; + struct max3420_ep *ep; + int id; + + switch (udc->setup.bRequestType) { + case USB_RECIP_DEVICE: + if (udc->setup.wValue != USB_DEVICE_REMOTE_WAKEUP) + break; + + if (udc->setup.bRequest == USB_REQ_SET_FEATURE) + udc->remote_wkp = 1; + else + udc->remote_wkp = 0; + + return spi_ack_ctrl(udc); + + case USB_RECIP_ENDPOINT: + if (udc->setup.wValue != USB_ENDPOINT_HALT) + break; + + id = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; + ep = &udc->ep[id]; + + max3420_ep_set_halt(&ep->ep_usb, set); + return; + default: + break; + } + + dev_err(udc->dev, "Can't respond to SET/CLEAR FEATURE\n"); + spi_wr8(udc, MAX3420_REG_EPSTALLS, bSTLEP0IN | bSTLEP0OUT | bSTLSTAT); +} + +static void max3420_handle_setup(struct max3420_udc *udc) +{ + struct usb_ctrlrequest setup; + u8 addr; + + spi_rd_buf(udc, MAX3420_REG_SUDFIFO, (void *)&setup, 8); + + udc->setup = setup; + udc->setup.wValue = cpu_to_le16(setup.wValue); + udc->setup.wIndex = cpu_to_le16(setup.wIndex); + udc->setup.wLength = cpu_to_le16(setup.wLength); + + switch (udc->setup.bRequest) { + case USB_REQ_GET_STATUS: + /* Data+Status phase form udc */ + if ((udc->setup.bRequestType & + (USB_DIR_IN | USB_TYPE_MASK)) != + (USB_DIR_IN | USB_TYPE_STANDARD)) { + break; + } + return max3420_getstatus(udc); + case USB_REQ_SET_ADDRESS: + /* Status phase from udc */ + if (udc->setup.bRequestType != (USB_DIR_OUT | + USB_TYPE_STANDARD | USB_RECIP_DEVICE)) + break; + addr = spi_rd8_ack(udc, MAX3420_REG_FNADDR, 1); + dev_dbg(udc->dev, "Assigned Address=%d/%d\n", + udc->setup.wValue, addr); + return; + case USB_REQ_CLEAR_FEATURE: + case USB_REQ_SET_FEATURE: + /* Requests with no data phase, status phase from udc */ + if ((udc->setup.bRequestType & USB_TYPE_MASK) + != USB_TYPE_STANDARD) + break; + return max3420_set_clear_feature(udc); + default: + break; + } + + if (udc->driver->setup(&udc->gadget, &setup) < 0) { + /* Stall EP0 */ + spi_wr8(udc, MAX3420_REG_EPSTALLS, + bSTLEP0IN | bSTLEP0OUT | bSTLSTAT); + } +} + +static int do_data(struct max3420_udc *udc, int ep_id, int in) +{ + struct max3420_ep *ep = &udc->ep[ep_id]; + struct max3420_req *req; + int done, length, psz; + void *buf; + + if (list_empty(&ep->queue)) + return 0; + + req = list_first_entry(&ep->queue, struct max3420_req, queue); + buf = req->usb_req.buf + req->usb_req.actual; + + psz = ep->ep_usb.maxpacket; + length = req->usb_req.length - req->usb_req.actual; + length = min(length, psz); + + if (length == 0) { + done = 1; + goto xfer_done; + } + + done = 0; + if (in) { + spi_wr_buf(udc, MAX3420_REG_EP0FIFO + ep_id, buf, length); + spi_wr8(udc, MAX3420_REG_EP0BC + ep_id, length); + if (length < psz) + done = 1; + } else { + psz = spi_rd8(udc, MAX3420_REG_EP0BC + ep_id); + length = min(length, psz); + spi_rd_buf(udc, MAX3420_REG_EP0FIFO + ep_id, buf, length); + if (length < ep->ep_usb.maxpacket) + done = 1; + } + + req->usb_req.actual += length; + + if (req->usb_req.actual == req->usb_req.length) + done = 1; + +xfer_done: + if (done) { + list_del_init(&req->queue); + + if (ep_id == 0) + spi_ack_ctrl(udc); + + max3420_req_done(req, 0); + } + + return 1; +} + +static int max3420_handle_irqs(struct max3420_udc *udc) +{ + u8 epien, epirq, usbirq, usbien, reg[4]; + int ret = 0; + + spi_rd_buf(udc, MAX3420_REG_EPIRQ, reg, 4); + epirq = reg[0]; + epien = reg[1]; + usbirq = reg[2]; + usbien = reg[3]; + + usbirq &= usbien; + epirq &= epien; + + if (epirq & bSUDAVIRQ) { + spi_wr8(udc, MAX3420_REG_EPIRQ, bSUDAVIRQ); + max3420_handle_setup(udc); + return 1; + } + + if (usbirq & bVBUSIRQ) { + spi_wr8(udc, MAX3420_REG_USBIRQ, bVBUSIRQ); + dev_dbg(udc->dev, "Cable plugged in\n"); + g_dnl_clear_detach(); + return 1; + } + + if (usbirq & bNOVBUSIRQ) { + spi_wr8(udc, MAX3420_REG_USBIRQ, bNOVBUSIRQ); + dev_dbg(udc->dev, "Cable pulled out\n"); + g_dnl_trigger_detach(); + return 1; + } + + if (usbirq & bURESIRQ) { + spi_wr8(udc, MAX3420_REG_USBIRQ, bURESIRQ); + return 1; + } + + if (usbirq & bURESDNIRQ) { + spi_wr8(udc, MAX3420_REG_USBIRQ, bURESDNIRQ); + spi_wr8(udc, MAX3420_REG_USBIEN, bURESDNIRQ | bURESIRQ); + spi_wr8(udc, MAX3420_REG_EPIEN, bSUDAVIRQ + | bIN0BAVIRQ | bOUT0DAVIRQ); + return 1; + } + + if (usbirq & bSUSPIRQ) { + spi_wr8(udc, MAX3420_REG_USBIRQ, bSUSPIRQ); + dev_dbg(udc->dev, "USB Suspend - Enter\n"); + udc->suspended = true; + return 1; + } + + if (usbirq & bBUSACTIRQ) { + spi_wr8(udc, MAX3420_REG_USBIRQ, bBUSACTIRQ); + dev_dbg(udc->dev, "USB Suspend - Exit\n"); + udc->suspended = false; + return 1; + } + + if (usbirq & bRWUDNIRQ) { + spi_wr8(udc, MAX3420_REG_USBIRQ, bRWUDNIRQ); + dev_dbg(udc->dev, "Asked Host to wakeup\n"); + return 1; + } + + if (usbirq & bOSCOKIRQ) { + spi_wr8(udc, MAX3420_REG_USBIRQ, bOSCOKIRQ); + dev_dbg(udc->dev, "Osc stabilized, start work\n"); + return 1; + } + + if (epirq & bOUT0DAVIRQ && do_data(udc, 0, 0)) { + spi_wr8_ack(udc, MAX3420_REG_EPIRQ, bOUT0DAVIRQ, 1); + ret = 1; + } + + if (epirq & bIN0BAVIRQ && do_data(udc, 0, 1)) + ret = 1; + + if (epirq & bOUT1DAVIRQ && do_data(udc, 1, 0)) { + spi_wr8_ack(udc, MAX3420_REG_EPIRQ, bOUT1DAVIRQ, 1); + ret = 1; + } + + if (epirq & bIN2BAVIRQ && do_data(udc, 2, 1)) + ret = 1; + + if (epirq & bIN3BAVIRQ && do_data(udc, 3, 1)) + ret = 1; + + return ret; +} + +static int max3420_irq(struct max3420_udc *udc) +{ + do_data(udc, 0, 1); /* get done with the EP0 ZLP */ + + return max3420_handle_irqs(udc); +} + +static void max3420_setup_eps(struct max3420_udc *udc) +{ + int i; + + INIT_LIST_HEAD(&udc->gadget.ep_list); + INIT_LIST_HEAD(&udc->ep[0].ep_usb.ep_list); + + for (i = 0; i < MAX3420_MAX_EPS; i++) { + struct max3420_ep *ep = &udc->ep[i]; + + INIT_LIST_HEAD(&ep->queue); + + ep->id = i; + ep->udc = udc; + ep->ep_usb.ops = &max3420_ep_ops; + ep->ep_usb.name = ep->name; + ep->ep_usb.maxpacket = EP_MAX_PACKET; + + if (i == 0) { + ep->ep_usb.desc = &ep0_desc; + snprintf(ep->name, EPNAME_SIZE, "ep0"); + continue; + } + + list_add_tail(&ep->ep_usb.ep_list, &udc->gadget.ep_list); + + if (i == 1) + snprintf(ep->name, EPNAME_SIZE, "ep1out-bulk"); + else + snprintf(ep->name, EPNAME_SIZE, "ep%din-bulk", i); + }; +} + +static void max3420_setup_spi(struct max3420_udc *udc) +{ + u8 reg[8]; + + spi_claim_bus(udc->slave); + spi_rd_buf(udc, MAX3420_REG_EPIRQ, reg, 8); + /* configure SPI */ + spi_wr8(udc, MAX3420_REG_PINCTL, bFDUPSPI); +} + +int dm_usb_gadget_handle_interrupts(struct udevice *dev) +{ + struct max3420_udc *udc = dev_get_priv(dev); + + return max3420_irq(udc); +} + +static int max3420_udc_probe(struct udevice *dev) +{ + struct max3420_udc *udc = dev_get_priv(dev); + struct dm_spi_slave_platdata *slave_pdata; + struct udevice *bus = dev->parent; + int busnum = bus->seq; + unsigned int cs; + uint speed, mode; + struct udevice *spid; + + slave_pdata = dev_get_parent_platdata(dev); + cs = slave_pdata->cs; + speed = slave_pdata->max_hz; + mode = slave_pdata->mode; + spi_get_bus_and_cs(busnum, cs, speed, mode, "spi_generic_drv", + NULL, &spid, &udc->slave); + + udc->dev = dev; + udc->gadget.ep0 = &udc->ep[0].ep_usb; + udc->gadget.max_speed = USB_SPEED_FULL; + udc->gadget.speed = USB_SPEED_FULL; + udc->gadget.is_dualspeed = 0; + udc->gadget.ops = &max3420_udc_ops; + udc->gadget.name = "max3420-udc"; + + max3420_setup_eps(udc); + max3420_setup_spi(udc); + + usb_add_gadget_udc((struct device *)dev, &udc->gadget); + + return 0; +} + +static int max3420_udc_remove(struct udevice *dev) +{ + struct max3420_udc *udc = dev_get_priv(dev); + + usb_del_gadget_udc(&udc->gadget); + + spi_release_bus(udc->slave); + + return 0; +} + +static const struct udevice_id max3420_ids[] = { + { .compatible = "maxim,max3421-udc" }, + { } +}; + +U_BOOT_DRIVER(max3420_generic_udc) = { + .name = "max3420-udc", + .id = UCLASS_USB_GADGET_GENERIC, + .of_match = max3420_ids, + .probe = max3420_udc_probe, + .remove = max3420_udc_remove, + .priv_auto_alloc_size = sizeof(struct max3420_udc), +}; diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index e5dda79b94c..8773824e057 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -411,6 +411,24 @@ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp) return 0; } +int usb_remove_ehci_gadget(struct ehci_ctrl **ctlrp) +{ + struct udevice *dev; + int ret; + + /* Find the old device and remove it */ + ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev); + if (ret) + return ret; + ret = device_remove(dev, DM_REMOVE_NORMAL); + if (ret) + return ret; + + *ctlrp = NULL; + + return 0; +} + /* returns 0 if no match, 1 if match */ static int usb_match_device(const struct usb_device_descriptor *desc, const struct usb_device_id *id) diff --git a/fs/fs.c b/fs/fs.c index 17e4bc33f76..29ad4d1a695 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -3,6 +3,8 @@ * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ +#define LOG_CATEGORY LOGC_CORE + #include #include #include @@ -34,7 +36,7 @@ static int fs_type = FS_TYPE_ANY; static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) { - printf("** Unrecognized filesystem type **\n"); + log_err("** Unrecognized filesystem type **\n"); return -1; } @@ -508,7 +510,7 @@ static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset, if (lmb_alloc_addr(&lmb, addr, read_len) == addr) return 0; - printf("** Reading file would overwrite reserved memory **\n"); + log_err("** Reading file would overwrite reserved memory **\n"); return -ENOSPC; } #endif @@ -538,7 +540,7 @@ static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, /* If we requested a specific number of bytes, check we got it */ if (ret == 0 && len && *actread != len) - debug("** %s shorter than offset + len **\n", filename); + log_debug("** %s shorter than offset + len **\n", filename); fs_close(); return ret; @@ -562,7 +564,7 @@ int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, unmap_sysmem(buf); if (ret < 0 && len != *actwrite) { - printf("** Unable to write file %s **\n", filename); + log_err("** Unable to write file %s **\n", filename); ret = -1; } fs_close(); @@ -656,7 +658,7 @@ int fs_ln(const char *fname, const char *target) ret = info->ln(fname, target); if (ret < 0) { - printf("** Unable to create link %s -> %s **\n", fname, target); + log_err("** Unable to create link %s -> %s **\n", fname, target); ret = -1; } fs_close(); @@ -737,7 +739,7 @@ int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], ret = _fs_read(filename, addr, pos, bytes, 1, &len_read); time = get_timer(time); if (ret < 0) { - printf("Failed to load '%s'\n", filename); + log_err("Failed to load '%s'\n", filename); return 1; } @@ -902,7 +904,7 @@ int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], ret = fs_mkdir(argv[3]); if (ret) { - printf("** Unable to create a directory \"%s\" **\n", argv[3]); + log_err("** Unable to create a directory \"%s\" **\n", argv[3]); return 1; } diff --git a/fs/fs_internal.c b/fs/fs_internal.c index 8b19811a639..bfc35c996c8 100644 --- a/fs/fs_internal.c +++ b/fs/fs_internal.c @@ -5,6 +5,8 @@ * Derived from code in ext4/dev.c, which was based on reiserfs/dev.c */ +#define LOG_CATEGORY LOGC_CORE + #include #include #include @@ -19,7 +21,7 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, int log2blksz; ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (blk ? blk->blksz : 0)); if (blk == NULL) { - printf("** Invalid Block Device Descriptor (NULL)\n"); + log_err("** Invalid Block Device Descriptor (NULL)\n"); return 0; } log2blksz = blk->log2blksz; @@ -27,8 +29,8 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, /* Check partition boundaries */ if ((sector + ((byte_offset + byte_len - 1) >> log2blksz)) >= partition->size) { - printf("%s read outside partition " LBAFU "\n", __func__, - sector); + log_err("%s read outside partition " LBAFU "\n", __func__, + sector); return 0; } @@ -36,14 +38,14 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, sector += byte_offset >> log2blksz; byte_offset &= blk->blksz - 1; - debug(" <" LBAFU ", %d, %d>\n", sector, byte_offset, byte_len); + log_debug(" <" LBAFU ", %d, %d>\n", sector, byte_offset, byte_len); if (byte_offset != 0) { int readlen; /* read first part which isn't aligned with start of sector */ if (blk_dread(blk, partition->start + sector, 1, (void *)sec_buf) != 1) { - printf(" ** %s read error **\n", __func__); + log_err(" ** %s read error **\n", __func__); return 0; } readlen = min((int)blk->blksz - byte_offset, @@ -73,7 +75,7 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, if (blk_dread(blk, partition->start + sector, block_len >> log2blksz, (void *)buf) != block_len >> log2blksz) { - printf(" ** %s read error - block\n", __func__); + log_err(" ** %s read error - block\n", __func__); return 0; } block_len = byte_len & ~(blk->blksz - 1); @@ -85,7 +87,7 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, /* read rest of data which are not in whole sector */ if (blk_dread(blk, partition->start + sector, 1, (void *)sec_buf) != 1) { - printf("* %s read error - last part\n", __func__); + log_err("* %s read error - last part\n", __func__); return 0; } memcpy(buf, sec_buf, byte_len); diff --git a/include/configs/mvebu_armada-37xx.h b/include/configs/mvebu_armada-37xx.h index ca662b0ce73..905ce09b7a2 100644 --- a/include/configs/mvebu_armada-37xx.h +++ b/include/configs/mvebu_armada-37xx.h @@ -37,7 +37,7 @@ /* * Other required minimal configurations */ -#define CONFIG_SYS_LOAD_ADDR 0x00800000 /* default load adr- 8M */ +#define CONFIG_SYS_LOAD_ADDR 0x06000000 /* default load adr */ #define CONFIG_SYS_RESET_ADDRESS 0xffff0000 /* Rst Vector Adr */ #define CONFIG_SYS_MAXARGS 32 /* max number of command args */ @@ -90,12 +90,15 @@ #include +/* fdt_addr and kernel_addr are needed for existing distribution boot scripts */ #define CONFIG_EXTRA_ENV_SETTINGS \ - "scriptaddr=0x4d00000\0" \ - "pxefile_addr_r=0x4e00000\0" \ - "fdt_addr_r=0x4f00000\0" \ - "kernel_addr_r=0x5000000\0" \ - "ramdisk_addr_r=0x8000000\0" \ + "scriptaddr=0x6d00000\0" \ + "pxefile_addr_r=0x6e00000\0" \ + "fdt_addr=0x6f00000\0" \ + "fdt_addr_r=0x6f00000\0" \ + "kernel_addr=0x7000000\0" \ + "kernel_addr_r=0x7000000\0" \ + "ramdisk_addr_r=0xa000000\0" \ BOOTENV #endif /* _CONFIG_MVEBU_ARMADA_37XX_H */ diff --git a/include/dfu.h b/include/dfu.h index 6fa45059360..84abdc79acd 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -79,7 +79,7 @@ struct nand_internal_data { }; struct ram_internal_data { - void *start; + unsigned long start; unsigned int size; }; diff --git a/include/efi.h b/include/efi.h index f986aad8777..5695273ce9a 100644 --- a/include/efi.h +++ b/include/efi.h @@ -180,7 +180,6 @@ enum efi_mem_type { EFI_PERSISTENT_MEMORY_TYPE, EFI_MAX_MEMORY_TYPE, - EFI_TABLE_END, /* For efi_build_mem_table() */ }; /* Attribute values */ @@ -481,17 +480,4 @@ void efi_putc(struct efi_priv *priv, const char ch); */ int efi_info_get(enum efi_entry_t type, void **datap, int *sizep); -/** - * efi_build_mem_table() - make a sorted copy of the memory table - * - * @map: Pointer to EFI memory map table - * @size: Size of table in bytes - * @skip_bs: True to skip boot-time memory and merge it with conventional - * memory. This will significantly reduce the number of table - * entries. - * @return pointer to the new table. It should be freed with free() by the - * caller - */ -void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs); - #endif /* _LINUX_EFI_H */ diff --git a/include/fastboot.h b/include/fastboot.h index 1933b1d98e3..8e9ee80907d 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -32,6 +32,8 @@ enum { FASTBOOT_COMMAND_CONTINUE, FASTBOOT_COMMAND_REBOOT, FASTBOOT_COMMAND_REBOOT_BOOTLOADER, + FASTBOOT_COMMAND_REBOOT_FASTBOOTD, + FASTBOOT_COMMAND_REBOOT_RECOVERY, FASTBOOT_COMMAND_SET_ACTIVE, #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT) FASTBOOT_COMMAND_OEM_FORMAT, @@ -40,6 +42,25 @@ enum { FASTBOOT_COMMAND_COUNT }; +/** + * Reboot reasons + */ +enum fastboot_reboot_reason { + FASTBOOT_REBOOT_REASON_BOOTLOADER, + FASTBOOT_REBOOT_REASON_FASTBOOTD, + FASTBOOT_REBOOT_REASON_RECOVERY, + FASTBOOT_REBOOT_REASONS_COUNT +}; + +/** + * BCB boot commands + */ +static const char * const fastboot_boot_cmds[] = { + [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader", + [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot", + [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery" +}; + /** * fastboot_response() - Writes a response of the form "$tag$reason". * @@ -77,7 +98,7 @@ void fastboot_okay(const char *reason, char *response); * which sets whatever flag your board specific Android bootloader flow * requires in order to re-enter the bootloader. */ -int fastboot_set_reboot_flag(void); +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason); /** * fastboot_set_progress_callback() - set progress callback diff --git a/include/phy.h b/include/phy.h index 1dbbf651113..cbdb10d6fce 100644 --- a/include/phy.h +++ b/include/phy.h @@ -205,7 +205,7 @@ static inline int phy_write(struct phy_device *phydev, int devad, int regnum, { struct mii_dev *bus = phydev->bus; - if (!bus || !bus->read) { + if (!bus || !bus->write) { debug("%s: No bus configured\n", __func__); return -1; } diff --git a/include/usb.h b/include/usb.h index fa9e09607e2..5a7af882fb6 100644 --- a/include/usb.h +++ b/include/usb.h @@ -921,6 +921,15 @@ struct ehci_ctrl; */ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp); +/** + * usb_remove_ehci_gadget() - Remove a gadget USB device + * + * TODO(sjg@chromium.org): Tidy this up when USB gadgets can use driver model + * + * This provides a way to tell a controller to remove a USB device + */ +int usb_remove_ehci_gadget(struct ehci_ctrl **ctlrp); + /** * usb_stor_reset() - Prepare to scan USB storage devices * diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h index c7b770fa3e8..08ccc97cf22 100644 --- a/include/usb_mass_storage.h +++ b/include/usb_mass_storage.h @@ -25,7 +25,7 @@ struct ums { struct blk_desc block_dev; }; -int fsg_init(struct ums *ums_devs, int count); +int fsg_init(struct ums *ums_devs, int count, unsigned int controller_idx); void fsg_cleanup(void); int fsg_main_thread(void *); int fsg_add(struct usb_configuration *c); diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index d49145fc76b..bf78176217c 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -42,9 +42,9 @@ LIST_HEAD(efi_register_notify_events); /* Handle of the currently executing image */ static efi_handle_t current_image; -#ifdef CONFIG_ARM +#if defined(CONFIG_ARM) || defined(CONFIG_RISCV) /* - * The "gd" pointer lives in a register on ARM and AArch64 that we declare + * The "gd" pointer lives in a register on ARM and RISC-V that we declare * fixed when compiling U-Boot. However, the payload does not know about that * restriction so we need to manually swap its and our view of that register on * EFI callback entry/exit. @@ -86,7 +86,7 @@ static efi_status_t EFIAPI efi_disconnect_controller( int __efi_entry_check(void) { int ret = entry_count++ == 0; -#ifdef CONFIG_ARM +#if defined(CONFIG_ARM) || defined(CONFIG_RISCV) assert(efi_gd); app_gd = gd; set_gd(efi_gd); @@ -98,7 +98,7 @@ int __efi_entry_check(void) int __efi_exit_check(void) { int ret = --entry_count == 0; -#ifdef CONFIG_ARM +#if defined(CONFIG_ARM) || defined(CONFIG_RISCV) set_gd(app_gd); #endif return ret; @@ -107,7 +107,7 @@ int __efi_exit_check(void) /** * efi_save_gd() - save global data register * - * On the ARM architecture gd is mapped to a fixed register (r9 or x18). + * On the ARM and RISC-V architectures gd is mapped to a fixed register. * As this register may be overwritten by an EFI payload we save it here * and restore it on every callback entered. * @@ -115,7 +115,7 @@ int __efi_exit_check(void) */ void efi_save_gd(void) { -#ifdef CONFIG_ARM +#if defined(CONFIG_ARM) || defined(CONFIG_RISCV) efi_gd = gd; #endif } @@ -123,13 +123,13 @@ void efi_save_gd(void) /** * efi_restore_gd() - restore global data register * - * On the ARM architecture gd is mapped to a fixed register (r9 or x18). + * On the ARM and RISC-V architectures gd is mapped to a fixed register. * Restore it after returning from the UEFI world to the value saved via * efi_save_gd(). */ void efi_restore_gd(void) { -#ifdef CONFIG_ARM +#if defined(CONFIG_ARM) || defined(CONFIG_RISCV) /* Only restore if we're already in EFI context */ if (!efi_gd) return; @@ -1883,10 +1883,6 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy, if (ret != EFI_SUCCESS) goto error; } else { - if (!source_size) { - ret = EFI_LOAD_ERROR; - goto error; - } dest_buffer = source_buffer; } /* split file_path which contains both the device and file parts */ @@ -2924,7 +2920,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, * us to the current line. This implies that the second half * of the EFI_CALL macro has not been executed. */ -#ifdef CONFIG_ARM +#if defined(CONFIG_ARM) || defined(CONFIG_RISCV) /* * efi_exit() called efi_restore_gd(). We have to undo this * otherwise __efi_entry_check() will put the wrong value into diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index eea42cc2043..94f76ef6b8b 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -7,9 +7,12 @@ * Copyright (c) 2016 Alexander Graf */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include +#include #include #include #include @@ -153,14 +156,14 @@ static efi_status_t efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel, case IMAGE_REL_BASED_RISCV_LOW12S: /* We know that we're 4k aligned */ if (delta & 0xfff) { - printf("Unsupported reloc offset\n"); + log_err("Unsupported reloc offset\n"); return EFI_LOAD_ERROR; } break; #endif default: - printf("Unknown Relocation off %x type %x\n", - offset, type); + log_err("Unknown Relocation off %x type %x\n", + offset, type); return EFI_LOAD_ERROR; } relocs++; @@ -202,7 +205,7 @@ static void efi_set_code_and_data_type( loaded_image_info->image_data_type = EFI_RUNTIME_SERVICES_DATA; break; default: - printf("%s: invalid image type: %u\n", __func__, image_type); + log_err("invalid image type: %u\n", image_type); /* Let's assume it is an application */ loaded_image_info->image_code_type = EFI_LOADER_CODE; loaded_image_info->image_data_type = EFI_LOADER_DATA; @@ -499,7 +502,7 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) size_t new_efi_size, auth_size; bool ret = false; - debug("%s: Enter, %d\n", __func__, ret); + EFI_PRINT("%s: Enter, %d\n", __func__, ret); if (!efi_secure_boot_enabled()) return true; @@ -645,14 +648,14 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) break; } - debug("Signature was not verified by \"db\"\n"); + EFI_PRINT("Signature was not verified by \"db\"\n"); if (efi_signature_lookup_digest(regs, db)) { ret = true; break; } - debug("Image's digest was not found in \"db\" or \"dbx\"\n"); + EFI_PRINT("Image's digest was not found in \"db\" or \"dbx\"\n"); } err: @@ -662,7 +665,7 @@ err: free(regs); free(new_efi); - debug("%s: Exit, %d\n", __func__, ret); + EFI_PRINT("%s: Exit, %d\n", __func__, ret); return ret; } #else @@ -704,14 +707,14 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, /* Sanity check for a file header */ if (efi_size < sizeof(*dos)) { - printf("%s: Truncated DOS Header\n", __func__); + log_err("Truncated DOS Header\n"); ret = EFI_LOAD_ERROR; goto err; } dos = efi; if (dos->e_magic != IMAGE_DOS_SIGNATURE) { - printf("%s: Invalid DOS Signature\n", __func__); + log_err("Invalid DOS Signature\n"); ret = EFI_LOAD_ERROR; goto err; } @@ -722,14 +725,14 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, * of the 64bit header which is longer than the 32bit header. */ if (efi_size < dos->e_lfanew + sizeof(IMAGE_NT_HEADERS64)) { - printf("%s: Invalid offset for Extended Header\n", __func__); + log_err("Invalid offset for Extended Header\n"); ret = EFI_LOAD_ERROR; goto err; } nt = (void *) ((char *)efi + dos->e_lfanew); if (nt->Signature != IMAGE_NT_SIGNATURE) { - printf("%s: Invalid NT Signature\n", __func__); + log_err("Invalid NT Signature\n"); ret = EFI_LOAD_ERROR; goto err; } @@ -741,8 +744,8 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, } if (!supported) { - printf("%s: Machine type 0x%04x is not supported\n", - __func__, nt->FileHeader.Machine); + log_err("Machine type 0x%04x is not supported\n", + nt->FileHeader.Machine); ret = EFI_LOAD_ERROR; goto err; } @@ -753,17 +756,18 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, if (efi_size < ((void *)sections + sizeof(sections[0]) * num_sections - efi)) { - printf("%s: Invalid number of sections: %d\n", - __func__, num_sections); + log_err("Invalid number of sections: %d\n", num_sections); ret = EFI_LOAD_ERROR; goto err; } /* Authenticate an image */ - if (efi_image_authenticate(efi, efi_size)) + if (efi_image_authenticate(efi, efi_size)) { handle->auth_status = EFI_IMAGE_AUTH_PASSED; - else + } else { handle->auth_status = EFI_IMAGE_AUTH_FAILED; + log_err("Image not authenticated\n"); + } /* Calculate upper virtual address boundary */ for (i = num_sections - 1; i >= 0; i--) { @@ -782,8 +786,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, efi_reloc = efi_alloc(virt_size, loaded_image_info->image_code_type); if (!efi_reloc) { - printf("%s: Could not allocate %lu bytes\n", - __func__, virt_size); + log_err("Out of memory\n"); ret = EFI_OUT_OF_RESOURCES; goto err; } @@ -799,8 +802,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, efi_reloc = efi_alloc(virt_size, loaded_image_info->image_code_type); if (!efi_reloc) { - printf("%s: Could not allocate %lu bytes\n", - __func__, virt_size); + log_err("Out of memory\n"); ret = EFI_OUT_OF_RESOURCES; goto err; } @@ -809,8 +811,8 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress; virt_size = ALIGN(virt_size, opt->SectionAlignment); } else { - printf("%s: Invalid optional header magic %x\n", __func__, - nt->OptionalHeader.Magic); + log_err("Invalid optional header magic %x\n", + nt->OptionalHeader.Magic); ret = EFI_LOAD_ERROR; goto err; } diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c index 8f4a5a5e470..1d2b44580f2 100644 --- a/lib/efi_loader/efi_var_mem.c +++ b/lib/efi_loader/efi_var_mem.c @@ -211,7 +211,7 @@ static void efi_var_mem_bs_del(void) * @event: callback event * @context: callback context */ -static void EFIAPI __efi_runtime +static void EFIAPI efi_var_mem_notify_exit_boot_services(struct efi_event *event, void *context) { EFI_ENTRY("%p, %p", event, context); diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index 85fe8e1216a..06d66cfdd11 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -62,10 +62,6 @@ ifeq ($(CONFIG_BLK)$(CONFIG_DOS_PARTITION),yy) obj-y += efi_selftest_block_device.o endif -# TODO: As of v2019.10 the relocation code for the EFI application cannot -# be built on ARMv7-M. -ifeq ($(CONFIG_CPU_V7M),) - obj-y += \ efi_selftest_exception.o \ efi_selftest_loadimage.o \ @@ -99,5 +95,3 @@ $(obj)/efi_selftest_exception.o: $(obj)/efi_miniapp_file_image_exception.h $(obj)/efi_selftest_startimage_exit.o: $(obj)/efi_miniapp_file_image_exit.h $(obj)/efi_selftest_startimage_return.o: $(obj)/efi_miniapp_file_image_return.h - -endif diff --git a/lib/efi_selftest/efi_selftest.c b/lib/efi_selftest/efi_selftest.c index 6eec8ae2a7c..165fa265f23 100644 --- a/lib/efi_selftest/efi_selftest.c +++ b/lib/efi_selftest/efi_selftest.c @@ -311,11 +311,13 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, efi_st_printf("Preparing for reset. Press any key...\n"); efi_st_get_key(); - if (IS_ENABLED(CONFIG_EFI_HAVE_RUNTIME_RESET)) + if (IS_ENABLED(CONFIG_EFI_HAVE_RUNTIME_RESET)) { runtime->reset_system(EFI_RESET_WARM, EFI_NOT_READY, sizeof(reset_message), reset_message); - else + } else { + efi_restore_gd(); do_reset(NULL, 0, 0, NULL); + } efi_st_printf("\n"); efi_st_error("Reset failed\n"); diff --git a/lib/fdtdec.c b/lib/fdtdec.c index d3b22ec3238..5f41f58a63c 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1101,7 +1101,7 @@ int fdtdec_setup_memory_banksize(void) if (ret < 0) { reg = 0; mem = get_next_memory_node(mem); - if (ofnode_valid(mem)) + if (!ofnode_valid(mem)) break; ret = ofnode_read_resource(mem, reg++, &res); @@ -1146,7 +1146,7 @@ int fdtdec_setup_mem_size_base_lowest(void) if (ret < 0) { reg = 0; mem = get_next_memory_node(mem); - if (ofnode_valid(mem)) + if (!ofnode_valid(mem)) break; ret = ofnode_read_resource(mem, reg++, &res); diff --git a/lib/rsa/rsa-keyprop.c b/lib/rsa/rsa-keyprop.c index 1e83eedc82c..98855f67b89 100644 --- a/lib/rsa/rsa-keyprop.c +++ b/lib/rsa/rsa-keyprop.c @@ -12,9 +12,9 @@ #include #include #include -#include #include #include +#include /** * br_dec16be() - Convert 16-bit big-endian integer to native @@ -23,7 +23,7 @@ */ static unsigned br_dec16be(const void *src) { - return be16_to_cpup(src); + return get_unaligned_be16(src); } /** @@ -33,7 +33,7 @@ static unsigned br_dec16be(const void *src) */ static uint32_t br_dec32be(const void *src) { - return be32_to_cpup(src); + return get_unaligned_be32(src); } /** diff --git a/net/fastboot.c b/net/fastboot.c index 0c57fb9947d..7e7a601b9fe 100644 --- a/net/fastboot.c +++ b/net/fastboot.c @@ -227,6 +227,8 @@ static void fastboot_send(struct fastboot_header header, char *fastboot_data, case FASTBOOT_COMMAND_REBOOT: case FASTBOOT_COMMAND_REBOOT_BOOTLOADER: + case FASTBOOT_COMMAND_REBOOT_FASTBOOTD: + case FASTBOOT_COMMAND_REBOOT_RECOVERY: do_reset(NULL, 0, 0, NULL); break; } diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py index 2ae8f25381e..940279651da 100644 --- a/test/py/tests/test_env.py +++ b/test/py/tests/test_env.py @@ -151,7 +151,7 @@ def validate_empty(state_test_env, var): Nothing. """ - response = state_test_env.u_boot_console.run_command('echo $%s' % var) + response = state_test_env.u_boot_console.run_command('echo ${%s}' % var) assert response == '' def validate_set(state_test_env, var, value):