diff options
85 files changed, 1339 insertions, 316 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 17ac45587b..bebe87b4d1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1097,6 +1097,22 @@ T: git https://gitlab.denx.de/u-boot/custodians/u-boot-x86.git F: arch/x86/ F: cmd/x86/ +XEN +M: Anastasiia Lukianenko <anastasiia_lukianenko@epam.com> +M: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com> +S: Maintained +F: arch/arm/cpu/armv8/xen/ +F: arch/arm/include/asm/xen.h +F: arch/arm/include/asm/xen/ +F: cmd/pvblock.c +F: drivers/serial/serial_xen.c +F: drivers/xen/ +F: include/pvblock.h +F: include/xen/ +F: include/xen.h +F: lib/sscanf.c +F: test/lib/sscanf.c + XTENSA M: Max Filippov <jcmvbkbc@gmail.com> S: Maintained diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 870620713b..80702c23d3 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1198,6 +1198,15 @@ config TARGET_VEXPRESS64_JUNO select USB select DM_USB +config TARGET_TOTAL_COMPUTE + bool "Support Total Compute Platform" + select ARM64 + select PL01X_SERIAL + select DM + select DM_SERIAL + select DM_MMC + select DM_GPIO + config TARGET_LS2080A_EMU bool "Support ls2080a_emu" select ARCH_LS2080A @@ -1926,6 +1935,8 @@ source "arch/arm/mach-imx/Kconfig" source "arch/arm/mach-nexell/Kconfig" +source "board/armltd/total_compute/Kconfig" + source "board/bosch/shc/Kconfig" source "board/bosch/guardian/Kconfig" source "board/CarMediaLab/flea3/Kconfig" diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index b2b5360f6d..f8f529435b 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -962,7 +962,7 @@ dtb-$(CONFIG_SOC_K3_J721E) += k3-j721e-common-proc-board.dtb \ dtb-$(CONFIG_ARCH_MEDIATEK) += \ mt7622-rfb.dtb \ mt7623a-unielec-u7623-02-emmc.dtb \ - mt7622-bpi-r64.dtb \ + mt7622-bananapi-bpi-r64.dtb \ mt7623n-bananapi-bpi-r2.dtb \ mt7629-rfb.dtb \ mt8512-bm1-emmc.dtb \ @@ -981,6 +981,8 @@ dtb-$(CONFIG_TARGET_VEXPRESS_CA5X2) += vexpress-v2p-ca5s.dtb dtb-$(CONFIG_TARGET_VEXPRESS_CA9X4) += vexpress-v2p-ca9.dtb dtb-$(CONFIG_TARGET_VEXPRESS_CA15_TC2) += vexpress-v2p-ca15_a7.dtb +dtb-$(CONFIG_TARGET_TOTAL_COMPUTE) += total_compute.dtb + dtb-$(CONFIG_TARGET_DURIAN) += phytium-durian.dtb dtb-$(CONFIG_TARGET_PRESIDIO_ASIC) += ca-presidio-engboard.dtb diff --git a/arch/arm/dts/mt7622-bpi-r64.dts b/arch/arm/dts/mt7622-bananapi-bpi-r64.dts index 51287cea3a..4f2f04851d 100644 --- a/arch/arm/dts/mt7622-bpi-r64.dts +++ b/arch/arm/dts/mt7622-bananapi-bpi-r64.dts @@ -244,3 +244,11 @@ output-low; }; }; + +&ssusb { + status = "okay"; +}; + +&u3phy { + status = "okay"; +}; diff --git a/arch/arm/dts/mt7622-rfb.dts b/arch/arm/dts/mt7622-rfb.dts index 317fc78abd..ef7d0f0270 100644 --- a/arch/arm/dts/mt7622-rfb.dts +++ b/arch/arm/dts/mt7622-rfb.dts @@ -222,3 +222,11 @@ full-duplex; }; }; + +&ssusb { + status = "okay"; +}; + +&u3phy { + status = "okay"; +}; diff --git a/arch/arm/dts/mt7622.dtsi b/arch/arm/dts/mt7622.dtsi index c43ad65702..d888545809 100644 --- a/arch/arm/dts/mt7622.dtsi +++ b/arch/arm/dts/mt7622.dtsi @@ -192,6 +192,14 @@ status = "disabled"; }; + ssusbsys: ssusbsys@1a000000 { + compatible = "mediatek,mt7622-ssusbsys", + "syscon"; + reg = <0x1a000000 0x1000>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + pciesys: pciesys@1a100800 { compatible = "mediatek,mt7622-pciesys", "syscon"; reg = <0x1a100800 0x1000>; @@ -302,6 +310,54 @@ }; }; + ssusb: usb@1a0c0000 { + compatible = "mediatek,mt7622-xhci", + "mediatek,mtk-xhci"; + reg = <0x1a0c0000 0x01000>, + <0x1a0c4700 0x0100>; + reg-names = "mac", "ippc"; + interrupts = <GIC_SPI 232 IRQ_TYPE_LEVEL_LOW>; + power-domains = <&scpsys MT7629_POWER_DOMAIN_HIF1>; + clocks = <&ssusbsys CLK_SSUSB_SYS_EN>, + <&ssusbsys CLK_SSUSB_REF_EN>, + <&ssusbsys CLK_SSUSB_MCU_EN>, + <&ssusbsys CLK_SSUSB_DMA_EN>; + clock-names = "sys_ck", "ref_ck", "mcu_ck", "dma_ck"; + phys = <&u2port0 PHY_TYPE_USB2>, + <&u3port0 PHY_TYPE_USB3>, + <&u2port1 PHY_TYPE_USB2>; + status = "disabled"; + }; + + u3phy: usb-phy@1a0c4000 { + compatible = "mediatek,mt7622-u3phy", + "mediatek,generic-tphy-v1"; + reg = <0x1a0c4000 0x700>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + status = "disabled"; + + u2port0: usb-phy@1a0c4800 { + reg = <0x1a0c4800 0x0100>; + #phy-cells = <1>; + clocks = <&ssusbsys CLK_SSUSB_U2_PHY_EN>; + clock-names = "ref"; + }; + + u3port0: usb-phy@1a0c4900 { + reg = <0x1a0c4900 0x0700>; + #phy-cells = <1>; + }; + + u2port1: usb-phy@1a0c5000 { + reg = <0x1a0c5000 0x0100>; + #phy-cells = <1>; + clocks = <&ssusbsys CLK_SSUSB_U2_PHY_1P_EN>; + clock-names = "ref"; + }; + }; + ethsys: syscon@1b000000 { compatible = "mediatek,mt7622-ethsys", "syscon"; reg = <0x1b000000 0x1000>; diff --git a/arch/arm/dts/mt7623.dtsi b/arch/arm/dts/mt7623.dtsi index 0452889ef8..b5a802552b 100644 --- a/arch/arm/dts/mt7623.dtsi +++ b/arch/arm/dts/mt7623.dtsi @@ -352,6 +352,52 @@ }; }; + usb1: usb@1a1c0000 { + compatible = "mediatek,mt7623-xhci", "mediatek,mtk-xhci"; + reg = <0x1a1c0000 0x1000>, <0x1a1c4700 0x0100>; + reg-names = "mac", "ippc"; + power-domains = <&scpsys MT7623_POWER_DOMAIN_HIF>; + clocks = <&hifsys CLK_HIFSYS_USB0PHY>, <&topckgen CLK_TOP_ETHIF_SEL>; + clock-names = "sys_ck", "ref_ck"; + phys = <&u2port0 PHY_TYPE_USB2>, <&u3port0 PHY_TYPE_USB3>; + status = "disabled"; + }; + + u3phy1: usb-phy@1a1c4000 { + compatible = "mediatek,mt7623-tphy", "mediatek,generic-tphy-v1"; + + reg = <0x1a1c4000 0x0700>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + status = "disabled"; + + u2port0: usb-phy@1a1c4800 { + reg = <0x1a1c4800 0x0100>; + #phy-cells = <1>; + clocks = <&topckgen CLK_TOP_USB_PHY48M>; + clock-names = "ref"; + }; + + u3port0: usb-phy@1a1c4900 { + reg = <0x1a1c4900 0x0700>; + #phy-cells = <1>; + clocks = <&clk26m>; + clock-names = "ref"; + }; + }; + + usb2: usb@1a240000 { + compatible = "mediatek,mt7623-xhci", "mediatek,mtk-xhci"; + reg = <0x1a240000 0x1000>, <0x1a244700 0x0100>; + reg-names = "mac", "ippc"; + power-domains = <&scpsys MT7623_POWER_DOMAIN_HIF>; + clocks = <&hifsys CLK_HIFSYS_USB1PHY>, <&topckgen CLK_TOP_ETHIF_SEL>; + clock-names = "sys_ck", "ref_ck"; + phys = <&u2port1 PHY_TYPE_USB2>, <&u3port1 PHY_TYPE_USB3>; + status = "disabled"; + }; + u3phy2: usb-phy@1a244000 { compatible = "mediatek,generic-tphy-v1"; reg = <0x1a244000 0x0700>; diff --git a/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts b/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts index bcedcf20f1..ef07369627 100644 --- a/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts +++ b/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts @@ -248,3 +248,19 @@ pinctrl-0 = <&uart2_pins_a>; status = "okay"; }; + +&usb1 { + status = "okay"; +}; + +&u3phy1 { + status = "okay"; +}; + +&usb2 { + status = "okay"; +}; + +&u3phy2 { + status = "okay"; +}; diff --git a/arch/arm/dts/rk3399-evb-u-boot.dtsi b/arch/arm/dts/rk3399-evb-u-boot.dtsi index 1be54feacc..8056dc843e 100644 --- a/arch/arm/dts/rk3399-evb-u-boot.dtsi +++ b/arch/arm/dts/rk3399-evb-u-boot.dtsi @@ -37,3 +37,16 @@ dr_mode = "host"; status = "okay"; }; + +&sdmmc { + u-boot,dm-pre-reloc; + bus-width = <4>; + cap-mmc-highspeed; + cap-sd-highspeed; + cd-gpios = <&gpio0 7 GPIO_ACTIVE_LOW>; + disable-wp; + max-frequency = <150000000>; + pinctrl-names = "default"; + pinctrl-0 = <&sdmmc_clk &sdmmc_cmd &sdmmc_bus4>; + status = "okay"; +}; diff --git a/arch/arm/dts/total_compute.dts b/arch/arm/dts/total_compute.dts new file mode 100644 index 0000000000..4399269a44 --- /dev/null +++ b/arch/arm/dts/total_compute.dts @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2020 Arm Limited + */ + +/dts-v1/; + +/ { + model = "total_compute"; + compatible = "arm,total_compute"; + #address-cells = <2>; + #size-cells = <2>; + + sysreg: sysreg@1c010000 { + compatible = "arm,vexpress-sysreg"; + reg = <0x0 0x001c010000 0x0 0x1000>; + gpio-controller; + #gpio-cells = <2>; + }; + + fixed_3v3: v2m-3v3 { + compatible = "regulator-fixed"; + regulator-name = "3V3"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + regulator-always-on; + }; + + mmci@1c050000 { + compatible = "arm,pl180", "arm,primecell"; + reg = <0x0 0x001c050000 0x0 0x1000>; + cd-gpios = <&sysreg 0 0>; + arm,primecell-periphid = <0x00880180>; + wp-gpios = <&sysreg 1 0>; + bus-width = <8>; + max-frequency = <12000000>; + vmmc-supply = <&fixed_3v3>; + clocks = <&clock24mhz>, <&clock24mhz>; + clock-names = "mclk", "apb_pclk"; + }; + + clock24mhz: clock24mhz { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <24000000>; + clock-output-names = "bp:clock24mhz"; + }; +}; diff --git a/arch/arm/include/asm/gpio.h b/arch/arm/include/asm/gpio.h index 7dc87afb83..6ecb876eda 100644 --- a/arch/arm/include/asm/gpio.h +++ b/arch/arm/include/asm/gpio.h @@ -3,7 +3,7 @@ !defined(CONFIG_ARCH_BCM6858) && !defined(CONFIG_ARCH_BCM63158) && \ !defined(CONFIG_ARCH_ROCKCHIP) && !defined(CONFIG_ARCH_ASPEED) && \ !defined(CONFIG_ARCH_U8500) && !defined(CONFIG_CORTINA_PLATFORM) && \ - !defined(CONFIG_TARGET_BCMNS3) + !defined(CONFIG_TARGET_BCMNS3) && !defined(CONFIG_TARGET_TOTAL_COMPUTE) #include <asm/arch/gpio.h> #endif #include <asm-generic/gpio.h> diff --git a/arch/arm/mach-rockchip/rk3188/rk3188.c b/arch/arm/mach-rockchip/rk3188/rk3188.c index 1b2f4a4757..222953ab94 100644 --- a/arch/arm/mach-rockchip/rk3188/rk3188.c +++ b/arch/arm/mach-rockchip/rk3188/rk3188.c @@ -6,6 +6,7 @@ #include <dm.h> #include <hang.h> #include <init.h> +#include <led.h> #include <log.h> #include <syscon.h> #include <asm/io.h> @@ -105,6 +106,7 @@ int rk_board_late_init(void) } #ifdef CONFIG_SPL_BUILD +DECLARE_GLOBAL_DATA_PTR; static int setup_led(void) { #ifdef CONFIG_SPL_LED @@ -120,7 +122,7 @@ static int setup_led(void) debug("%s: get=%d\n", __func__, ret); return ret; } - ret = led_set_on(dev, 1); + ret = led_set_state(dev, LEDST_ON); if (ret) return ret; #endif diff --git a/arch/riscv/cpu/fu540/cache.c b/arch/riscv/cpu/fu540/cache.c index 54de14238c..78f5ad9d60 100644 --- a/arch/riscv/cpu/fu540/cache.c +++ b/arch/riscv/cpu/fu540/cache.c @@ -35,7 +35,8 @@ int cache_enable_ways(void) if (node < 0) return node; - base = fdtdec_get_addr(blob, node, "reg"); + base = fdtdec_get_addr_size_auto_parent(blob, 0, node, "reg", 0, + NULL, false); if (base == FDT_ADDR_T_NONE) return FDT_ADDR_T_NONE; diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 08e1ac0c0e..53ca316180 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -115,6 +115,8 @@ void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, unsigned long asid); #endif void sbi_set_timer(uint64_t stime_value); +long sbi_get_spec_version(void); +int sbi_get_impl_id(void); int sbi_probe_extension(int ext); #endif diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c index 8fbc23839d..77845a73ca 100644 --- a/arch/riscv/lib/sbi.c +++ b/arch/riscv/lib/sbi.c @@ -54,6 +54,42 @@ void sbi_set_timer(uint64_t stime_value) } /** + * sbi_get_spec_version() - get current SBI specification version + * + * Return: version id + */ +long sbi_get_spec_version(void) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_SPEC_VERSION, + 0, 0, 0, 0, 0, 0); + if (!ret.error) + if (ret.value) + return ret.value; + + return -ENOTSUPP; +} + +/** + * sbi_get_impl_id() - get SBI implementation ID + * + * Return: implementation ID + */ +int sbi_get_impl_id(void) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_ID, + 0, 0, 0, 0, 0, 0); + if (!ret.error) + if (ret.value) + return ret.value; + + return -ENOTSUPP; +} + +/** * sbi_probe_extension() - Check if an SBI extension ID is supported or not. * @extid: The extension ID to be probed. * diff --git a/arch/riscv/lib/spl.c b/arch/riscv/lib/spl.c index e24ec5a46c..5e19d0f36a 100644 --- a/arch/riscv/lib/spl.c +++ b/arch/riscv/lib/spl.c @@ -39,7 +39,7 @@ void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) { typedef void __noreturn (*image_entry_riscv_t)(ulong hart, void *dtb); void *fdt_blob; - int ret; + __maybe_unused int ret; #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL) fdt_blob = spl_image->fdt_addr; diff --git a/board/armltd/total_compute/Kconfig b/board/armltd/total_compute/Kconfig new file mode 100644 index 0000000000..62e6e6f4ac --- /dev/null +++ b/board/armltd/total_compute/Kconfig @@ -0,0 +1,12 @@ +if TARGET_TOTAL_COMPUTE + +config SYS_BOARD + default "total_compute" + +config SYS_VENDOR + default "armltd" + +config SYS_CONFIG_NAME + default "total_compute" + +endif diff --git a/board/armltd/total_compute/MAINTAINERS b/board/armltd/total_compute/MAINTAINERS new file mode 100644 index 0000000000..3dc1cd188a --- /dev/null +++ b/board/armltd/total_compute/MAINTAINERS @@ -0,0 +1,7 @@ +TOTAL_COMPUTE BOARD +M: Usama Arif <usama.arif@arm.com> +S: Maintained +F: board/armltd/total_compute/ +F: include/configs/total_compute.h +F: configs/total_compute_defconfig +F: arch/arm/dts/total_compute.dts diff --git a/board/armltd/total_compute/Makefile b/board/armltd/total_compute/Makefile new file mode 100644 index 0000000000..8b10458431 --- /dev/null +++ b/board/armltd/total_compute/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2020 Arm Limited +# Usama Arif <usama.arif@arm.com> + +obj-y := total_compute.o diff --git a/board/armltd/total_compute/total_compute.c b/board/armltd/total_compute/total_compute.c new file mode 100644 index 0000000000..0be6435fe3 --- /dev/null +++ b/board/armltd/total_compute/total_compute.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2020 Arm Limited + * Usama Arif <usama.arif@arm.com> + */ + +#include <common.h> +#include <dm.h> +#include <dm/platform_data/serial_pl01x.h> +#include <asm/armv8/mmu.h> + +static const struct pl01x_serial_platdata serial_platdata = { + .base = UART0_BASE, + .type = TYPE_PL011, + .clock = CONFIG_PL011_CLOCK, +}; + +U_BOOT_DEVICE(total_compute_serials) = { + .name = "serial_pl01x", + .platdata = &serial_platdata, +}; + +static struct mm_region total_compute_mem_map[] = { + { + .virt = 0x0UL, + .phys = 0x0UL, + .size = 0x80000000UL, + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | + PTE_BLOCK_NON_SHARE | + PTE_BLOCK_PXN | PTE_BLOCK_UXN + }, { + .virt = 0x80000000UL, + .phys = 0x80000000UL, + .size = 0xff80000000UL, + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | + PTE_BLOCK_INNER_SHARE + }, { + /* List terminator */ + 0, + } +}; + +struct mm_region *mem_map = total_compute_mem_map; + +int board_init(void) +{ + return 0; +} + +int dram_init(void) +{ + gd->ram_size = PHYS_SDRAM_1_SIZE; + return 0; +} + +int dram_init_banksize(void) +{ + gd->bd->bi_dram[0].start = PHYS_SDRAM_1; + gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; + + return 0; +} + +/* Nothing to be done here as handled by PSCI interface */ +void reset_cpu(ulong addr) +{ +} diff --git a/board/firefly/firefly-rk3288/firefly-rk3288.c b/board/firefly/firefly-rk3288/firefly-rk3288.c index 1965985a0f..bd8a32cf7b 100644 --- a/board/firefly/firefly-rk3288/firefly-rk3288.c +++ b/board/firefly/firefly-rk3288/firefly-rk3288.c @@ -5,9 +5,11 @@ #include <common.h> #include <hang.h> +#include <led.h> #include <log.h> #ifdef CONFIG_SPL_BUILD +DECLARE_GLOBAL_DATA_PTR; static int setup_led(void) { #ifdef CONFIG_SPL_LED @@ -23,7 +25,7 @@ static int setup_led(void) debug("%s: get=%d\n", __func__, ret); return ret; } - ret = led_set_on(dev, 1); + ret = led_set_state(dev, LEDST_ON); if (ret) return ret; #endif diff --git a/board/sipeed/maix/MAINTAINERS b/board/sipeed/maix/MAINTAINERS index e7bb9ec433..0778af7a55 100644 --- a/board/sipeed/maix/MAINTAINERS +++ b/board/sipeed/maix/MAINTAINERS @@ -4,7 +4,7 @@ S: Maintained F: arch/riscv/dts/k210.dtsi F: arch/riscv/dts/k210-maix-bit.dts F: board/sipeed/maix/ -F: configs/sipeed_maix_bitm_defconfig +F: configs/sipeed_maix*_defconfig F: doc/board/sipeed/ F: include/configs/sipeed-maix.h F: include/dt-bindings/*/k210-sysctl.h diff --git a/board/xen/xenguest_arm64/MAINTAINERS b/board/xen/xenguest_arm64/MAINTAINERS index 787e9e0d0e..264920e240 100644 --- a/board/xen/xenguest_arm64/MAINTAINERS +++ b/board/xen/xenguest_arm64/MAINTAINERS @@ -1,5 +1,6 @@ XEN GUEST FOR ARM64 -M: Andrii Anisov <andrii_anisov@epam.com> +M: Anastasiia Lukianenko <anastasiia_lukianenko@epam.com> +M: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com> S: Maintained F: board/xen/xenguest_arm64/ F: doc/board/xen/ diff --git a/board/xen/xenguest_arm64/xenguest_arm64.c b/board/xen/xenguest_arm64/xenguest_arm64.c index cce54369bb..4660f3fff2 100644 --- a/board/xen/xenguest_arm64/xenguest_arm64.c +++ b/board/xen/xenguest_arm64/xenguest_arm64.c @@ -184,11 +184,6 @@ int ft_board_setup(void *blob, struct bd_info *bd) return 0; } -int board_early_init_f(void) -{ - return 0; -} - int print_cpuinfo(void) { printf("Xen virtual CPU\n"); diff --git a/cmd/Kconfig b/cmd/Kconfig index 9ad511aa17..30c26b5d2b 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -270,6 +270,12 @@ config SPL_CMD_TLV_EEPROM help Read system EEPROM data block in ONIE Tlvinfo format from SPL. +config CMD_SBI + bool "sbi" + depends on RISCV_SMODE && SBI_V02 + help + Display information about the SBI implementation. + endmenu menu "Boot commands" diff --git a/cmd/bootefi.c b/cmd/bootefi.c index fbfed54e85..06563d28ca 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -304,7 +304,11 @@ efi_status_t efi_install_fdt(void *fdt) /** * do_bootefi_exec() - execute EFI binary * + * The image indicated by @handle is started. When it returns the allocated + * memory for the @load_options is freed. + * * @handle: handle of loaded image + * @load_options: load options * Return: status code * * Load the EFI binary into a newly assigned memory unwinding the relocation diff --git a/cmd/clone.c b/cmd/clone.c index 97747f8f08..32473a032c 100644 --- a/cmd/clone.c +++ b/cmd/clone.c @@ -38,7 +38,7 @@ static int do_clone(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv srcbz = srcdesc->blksz; destbz = destdesc->blksz; - if ((srcbz * (buffersize / srcbz) != buffersize) && + if ((srcbz * (buffersize / srcbz) != buffersize) || (destbz * (buffersize / destbz) != buffersize)) { printf("failed: cannot match device block sizes\n"); return 1; @@ -55,10 +55,12 @@ static int do_clone(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv switch (unit[0]) { case 'g': case 'G': - requested *= 1024; + requested *= 1024 * 1024 * 1024; + break; case 'm': case 'M': - requested *= 1024; + requested *= 1024 * 1024; + break; case 'k': case 'K': requested *= 1024; diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index 8e31f43e1f..094c0e8098 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -473,7 +473,7 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc, argc--; argv++; addr = simple_strtoul(argv[0], &ep, 16); - if (*ep != ',') + if (*ep != ':') return CMD_RET_USAGE; /* 0 should be allowed for delete */ diff --git a/cmd/riscv/Makefile b/cmd/riscv/Makefile index 24df023ece..1e6ac364e3 100644 --- a/cmd/riscv/Makefile +++ b/cmd/riscv/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0+ obj-$(CONFIG_CMD_EXCEPTION) += exception.o +obj-$(CONFIG_CMD_SBI) += sbi.o diff --git a/cmd/riscv/sbi.c b/cmd/riscv/sbi.c new file mode 100644 index 0000000000..e66fc8e41d --- /dev/null +++ b/cmd/riscv/sbi.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * The 'sbi' command displays information about the SBI implementation. + * + * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de> + */ + +#include <common.h> +#include <command.h> +#include <asm/sbi.h> + +struct sbi_ext { + const u32 id; + const char *name; +}; + +static struct sbi_ext extensions[] = { + { 0x00000000, "sbi_set_timer" }, + { 0x00000001, "sbi_console_putchar" }, + { 0x00000002, "sbi_console_getchar" }, + { 0x00000003, "sbi_clear_ipi" }, + { 0x00000004, "sbi_send_ipi" }, + { 0x00000005, "sbi_remote_fence_i" }, + { 0x00000006, "sbi_remote_sfence_vma" }, + { 0x00000007, "sbi_remote_sfence_vma_asid" }, + { 0x00000008, "sbi_shutdown" }, + { 0x00000010, "SBI Base Functionality" }, + { 0x54494D45, "Timer Extension" }, + { 0x00735049, "IPI Extension" }, + { 0x52464E43, "RFENCE Extension" }, + { 0x0048534D, "Hart State Management Extension" }, +}; + +static int do_sbi(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int i; + long ret; + + ret = sbi_get_spec_version(); + if (ret >= 0) + printf("SBI %ld.%ld\n", ret >> 24, ret & 0xffffff); + ret = sbi_get_impl_id(); + if (ret >= 0) { + switch (ret) { + case 0: + printf("Berkeley Boot Loader (BBL)\n"); + break; + case 1: + printf("OpenSBI\n"); + break; + case 2: + printf("Xvisor\n"); + break; + case 3: + printf("KVM\n"); + break; + default: + printf("Unknown implementation\n"); + break; + } + } + printf("Extensions:\n"); + for (i = 0; i < ARRAY_SIZE(extensions); ++i) { + ret = sbi_probe_extension(extensions[i].id); + if (ret > 0) + printf(" %s\n", extensions[i].name); + } + return 0; +} + +#ifdef CONFIG_SYS_LONGHELP +static char sbi_help_text[] = + "- display SBI spec version, implementation, and available extensions"; + +#endif + +U_BOOT_CMD_COMPLETE( + sbi, 1, 0, do_sbi, + "display SBI information", + sbi_help_text, NULL +); diff --git a/common/Kconfig b/common/Kconfig index 8f61aa7602..c58f08ba91 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -1003,7 +1003,7 @@ config HASH config AVB_VERIFY bool "Build Android Verified Boot operations" - depends on LIBAVB && FASTBOOT + depends on LIBAVB depends on PARTITION_UUIDS help This option enables compilation of bootloader-dependent operations, @@ -1012,6 +1012,24 @@ config AVB_VERIFY * Helpers to access MMC, similar to drivers/fastboot/fb_mmc.c. * Helpers to alloc/init/free avb ops. +if AVB_VERIFY + +config AVB_BUF_ADDR + hex "Define AVB buffer address" + default FASTBOOT_BUF_ADDR + help + AVB requires a buffer for memory transactions. This variable defines the + buffer address. + +config AVB_BUF_SIZE + hex "Define AVB buffer SIZE" + default FASTBOOT_BUF_SIZE + help + AVB requires a buffer for memory transactions. This variable defines the + buffer size. + +endif # AVB_VERIFY + config SPL_HASH bool # "Support hashing API (SHA1, SHA256, etc.)" help diff --git a/common/avb_verify.c b/common/avb_verify.c index a2b739626b..db10d0f21f 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -7,7 +7,6 @@ #include <avb_verify.h> #include <blk.h> #include <cpu_func.h> -#include <fastboot.h> #include <image.h> #include <malloc.h> #include <part.h> diff --git a/configs/evb-rk3399_defconfig b/configs/evb-rk3399_defconfig index 509c86b81b..909c68822c 100644 --- a/configs/evb-rk3399_defconfig +++ b/configs/evb-rk3399_defconfig @@ -30,6 +30,7 @@ CONFIG_ROCKCHIP_GPIO=y CONFIG_SYS_I2C_ROCKCHIP=y CONFIG_MISC=y CONFIG_MMC_DW=y +CONFIG_MMC_DW_ROCKCHIP=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_ROCKCHIP=y CONFIG_SF_DEFAULT_SPEED=20000000 diff --git a/configs/octeontx2_95xx_defconfig b/configs/octeontx2_95xx_defconfig index 6aeb12c3f9..047cb45a21 100644 --- a/configs/octeontx2_95xx_defconfig +++ b/configs/octeontx2_95xx_defconfig @@ -37,6 +37,7 @@ CONFIG_CMD_DM=y CONFIG_CMD_GPIO=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y +CONFIG_CMD_BKOPS_ENABLE=y CONFIG_CMD_PART=y CONFIG_CMD_PCI=y CONFIG_CMD_SF_TEST=y @@ -84,7 +85,6 @@ CONFIG_SPI_FLASH_MACRONIX=y CONFIG_SPI_FLASH_SPANSION=y CONFIG_SPI_FLASH_STMICRO=y CONFIG_DM_ETH=y -CONFIG_NET_OCTEONTX2=y CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y diff --git a/configs/octeontx2_96xx_defconfig b/configs/octeontx2_96xx_defconfig index 05cc1332d6..b48733b71f 100644 --- a/configs/octeontx2_96xx_defconfig +++ b/configs/octeontx2_96xx_defconfig @@ -37,6 +37,7 @@ CONFIG_CMD_DM=y CONFIG_CMD_GPIO=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y +CONFIG_CMD_BKOPS_ENABLE=y CONFIG_CMD_PART=y CONFIG_CMD_PCI=y CONFIG_CMD_SF_TEST=y @@ -97,7 +98,6 @@ CONFIG_DM_ETH=y CONFIG_E1000=y CONFIG_E1000_SPI=y CONFIG_CMD_E1000=y -CONFIG_NET_OCTEONTX2=y CONFIG_NVME=y CONFIG_PCI=y CONFIG_DM_PCI=y diff --git a/configs/octeontx_81xx_defconfig b/configs/octeontx_81xx_defconfig index 00df57432a..ca3286b901 100644 --- a/configs/octeontx_81xx_defconfig +++ b/configs/octeontx_81xx_defconfig @@ -38,6 +38,7 @@ CONFIG_CMD_DM=y CONFIG_CMD_GPIO=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y +CONFIG_CMD_BKOPS_ENABLE=y CONFIG_CMD_PART=y CONFIG_CMD_PCI=y CONFIG_CMD_SF_TEST=y diff --git a/configs/octeontx_83xx_defconfig b/configs/octeontx_83xx_defconfig index e8cacb859f..e7dd3f6b73 100644 --- a/configs/octeontx_83xx_defconfig +++ b/configs/octeontx_83xx_defconfig @@ -36,6 +36,7 @@ CONFIG_CMD_DM=y CONFIG_CMD_GPIO=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y +CONFIG_CMD_BKOPS_ENABLE=y CONFIG_CMD_PART=y CONFIG_CMD_PCI=y CONFIG_CMD_SF_TEST=y @@ -95,8 +96,6 @@ CONFIG_DM_ETH=y CONFIG_E1000=y CONFIG_E1000_SPI=y CONFIG_CMD_E1000=y -CONFIG_NET_OCTEONTX=y -CONFIG_OCTEONTX_SMI=y CONFIG_NVME=y CONFIG_PCI=y CONFIG_DM_PCI=y diff --git a/configs/sipeed_maix_smode_defconfig b/configs/sipeed_maix_smode_defconfig new file mode 100644 index 0000000000..2516bb7258 --- /dev/null +++ b/configs/sipeed_maix_smode_defconfig @@ -0,0 +1,10 @@ +CONFIG_RISCV=y +CONFIG_SYS_TEXT_BASE=0x80020000 +CONFIG_TARGET_SIPEED_MAIX=y +CONFIG_ARCH_RV64I=y +CONFIG_RISCV_SMODE=y +CONFIG_STACK_SIZE=0x100000 +# CONFIG_NET is not set +# CONFIG_INPUT is not set +# CONFIG_DM_ETH is not set +# CONFIG_EFI_UNICODE_CAPITALIZATION is not set diff --git a/configs/total_compute_defconfig b/configs/total_compute_defconfig new file mode 100644 index 0000000000..e36d701ff4 --- /dev/null +++ b/configs/total_compute_defconfig @@ -0,0 +1,53 @@ +CONFIG_ARM=y +CONFIG_TARGET_TOTAL_COMPUTE=y +CONFIG_SYS_TEXT_BASE=0xe0000000 +CONFIG_SYS_MALLOC_F_LEN=0x2000 +CONFIG_ENV_SIZE=0x2a00000 +CONFIG_NR_DRAM_BANKS=2 +CONFIG_DEFAULT_DEVICE_TREE="total_compute" +CONFIG_DISTRO_DEFAULTS=y +CONFIG_ANDROID_BOOT_IMAGE=y +CONFIG_FIT=y +CONFIG_FIT_SIGNATURE=y +CONFIG_LEGACY_IMAGE_FORMAT=y +CONFIG_BOOTDELAY=5 +CONFIG_USE_BOOTARGS=y +CONFIG_BOOTARGS="console=ttyAMA0 debug user_debug=31 earlycon=pl011,0x7ff80000 loglevel=9 androidboot.hardware=total_compute video=640x480-32@60 androidboot.boot_devices=1c050000.mmci ip=dhcp androidboot.selinux=permissive" +# CONFIG_USE_BOOTCOMMAND is not set +# CONFIG_DISPLAY_CPUINFO is not set +# CONFIG_DISPLAY_BOARDINFO is not set +CONFIG_AVB_VERIFY=y +CONFIG_AVB_BUF_ADDR=0x90000000 +CONFIG_AVB_BUF_SIZE=0x10000000 +CONFIG_SYS_PROMPT="TOTAL_COMPUTE# " +# CONFIG_CMD_CONSOLE is not set +# CONFIG_CMD_XIMG is not set +# CONFIG_CMD_EDITENV is not set +CONFIG_CMD_MEMTEST=y +CONFIG_SYS_MEMTEST_START=0x80000000 +CONFIG_SYS_MEMTEST_END=0xff000000 +CONFIG_CMD_ARMFLASH=y +CONFIG_CMD_GPT=y +# CONFIG_RANDOM_UUID is not set +# CONFIG_CMD_LOADS is not set +CONFIG_CMD_MMC=y +# CONFIG_CMD_ITEST is not set +# CONFIG_CMD_SETEXPR is not set +CONFIG_CMD_CACHE=y +# CONFIG_CMD_MISC is not set +CONFIG_CMD_AVB=y +CONFIG_CMD_UBI=y +# CONFIG_ISO_PARTITION is not set +CONFIG_OF_CONTROL=y +# CONFIG_NET is not set +CONFIG_CLK=y +# CONFIG_MMC_WRITE is not set +CONFIG_ARM_PL180_MMCI=y +CONFIG_MTD=y +CONFIG_MTD_NOR_FLASH=y +CONFIG_FLASH_CFI_DRIVER=y +CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y +CONFIG_SYS_FLASH_PROTECTION=y +CONFIG_SYS_FLASH_CFI=y +CONFIG_LIBAVB=y +CONFIG_OF_LIBFDT_OVERLAY=y diff --git a/configs/xenguest_arm64_defconfig b/configs/xenguest_arm64_defconfig index 46473c251d..042ea79729 100644 --- a/configs/xenguest_arm64_defconfig +++ b/configs/xenguest_arm64_defconfig @@ -1,60 +1,39 @@ CONFIG_ARM=y CONFIG_POSITION_INDEPENDENT=y +CONFIG_TARGET_XENGUEST_ARM64=y CONFIG_SYS_TEXT_BASE=0x40080000 CONFIG_SYS_MALLOC_F_LEN=0x2000 CONFIG_IDENT_STRING=" xenguest" -CONFIG_TARGET_XENGUEST_ARM64=y CONFIG_BOOTDELAY=10 - CONFIG_SYS_PROMPT="xenguest# " - -CONFIG_CMD_NET=n -CONFIG_CMD_BDI=n -CONFIG_CMD_BOOTD=n -CONFIG_CMD_BOOTEFI=n -CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n -CONFIG_CMD_ELF=n +# CONFIG_CMD_BDI is not set +# CONFIG_CMD_BOOTD is not set +# CONFIG_CMD_ELF is not set +# CONFIG_CMD_GO is not set +# CONFIG_CMD_IMI is not set +# CONFIG_CMD_XIMG is not set +# CONFIG_CMD_EXPORTENV is not set +# CONFIG_CMD_IMPORTENV is not set +# CONFIG_CMD_EDITENV is not set +# CONFIG_CMD_SAVEENV is not set +# CONFIG_CMD_ENV_EXISTS is not set +# CONFIG_CMD_CRC32 is not set +# CONFIG_CMD_LZMADEC is not set +# CONFIG_CMD_UNZIP is not set +# CONFIG_CMD_LOADB is not set +# CONFIG_CMD_LOADS is not set +CONFIG_CMD_PVBLOCK=y +# CONFIG_CMD_ECHO is not set +# CONFIG_CMD_ITEST is not set +# CONFIG_CMD_SOURCE is not set +# CONFIG_CMD_SETEXPR is not set +# CONFIG_CMD_NET is not set +# CONFIG_CMD_MISC is not set CONFIG_CMD_EXT4=y CONFIG_CMD_FAT=y -CONFIG_CMD_GO=n -CONFIG_CMD_RUN=n -CONFIG_CMD_IMI=n -CONFIG_CMD_IMLS=n -CONFIG_CMD_XIMG=n -CONFIG_CMD_EXPORTENV=n -CONFIG_CMD_IMPORTENV=n -CONFIG_CMD_EDITENV=n -CONFIG_CMD_ENV_EXISTS=n -CONFIG_CMD_MEMORY=y -CONFIG_CMD_CRC32=n -CONFIG_CMD_DM=n -CONFIG_CMD_LOADB=n -CONFIG_CMD_LOADS=n -CONFIG_CMD_FLASH=n -CONFIG_CMD_GPT=n -CONFIG_CMD_FPGA=n -CONFIG_CMD_ECHO=n -CONFIG_CMD_ITEST=n -CONFIG_CMD_SOURCE=n -CONFIG_CMD_SETEXPR=n -CONFIG_CMD_MISC=n -CONFIG_CMD_UNZIP=n -CONFIG_CMD_LZMADEC=n -CONFIG_CMD_SAVEENV=n -CONFIG_CMD_UMS=n - -CONFIG_CMD_PVBLOCK=y - -#CONFIG_USB=n -# CONFIG_ISO_PARTITION is not set - -#CONFIG_EFI_PARTITION=y -# CONFIG_EFI_LOADER is not set - +CONFIG_OF_BOARD=y CONFIG_DM=y # CONFIG_MMC is not set -CONFIG_DM_SERIAL=y # CONFIG_REQUIRE_SERIAL_CONSOLE is not set - -CONFIG_OF_BOARD=y -CONFIG_OF_LIBFDT=y +CONFIG_DM_SERIAL=y +# CONFIG_EFI_LOADER is not set diff --git a/doc/board/sipeed/maix.rst b/doc/board/sipeed/maix.rst index b1894f3a6f..efcde9aebf 100644 --- a/doc/board/sipeed/maix.rst +++ b/doc/board/sipeed/maix.rst @@ -75,6 +75,49 @@ console shall be opened immediately. Boot output should look like the following: Err: serial@38000000 => +OpenSBI +^^^^^^^ + +OpenSBI is an open source supervisor execution environment implementing the +RISC-V Supervisor Binary Interface Specification [1]. One of its features is +to intercept run-time exceptions, e.g. for unaligned access or illegal +instructions, and to emulate the failing instructions. + +The OpenSBI source can be downloaded via: + +.. code-block:: bash + + git clone https://github.com/riscv/opensbi + +As OpenSBI will be loaded at 0x80000000 we have to adjust the U-Boot text base. +Furthermore we have to enable building U-Boot for S-mode:: + + CONFIG_SYS_TEXT_BASE=0x80020000 + CONFIG_RISCV_SMODE=y + +Both settings are contained in sipeed_maix_smode_defconfig so we can build +U-Boot with: + +.. code-block:: bash + + make sipeed_maix_smode_defconfig + make + +To build OpenSBI with U-Boot as a payload: + +.. code-block:: bash + + cd opensbi + make \ + PLATFORM=kendryte/k210 \ + FW_PAYLOAD=y \ + FW_PAYLOAD_OFFSET=0x20000 \ + FW_PAYLOAD_PATH=<path to U-Boot>/u-boot-dtb.bin + +The value of FW_PAYLOAD_OFFSET must match CONFIG_SYS_TEXT_BASE - 0x80000000. + +The file to flash is build/platform/kendryte/k210/firmware/fw_payload.bin. + Loading Images ^^^^^^^^^^^^^^ @@ -363,3 +406,9 @@ Address Size Description interrupts) 0x8801f000 0x1000 credits ========== ========= =========== + +Links +----- + +[1] https://github.com/riscv/riscv-sbi-doc + RISC-V Supervisor Binary Interface Specification diff --git a/doc/uefi/uefi.rst b/doc/uefi/uefi.rst index a72e729cc8..07eb3f01b4 100644 --- a/doc/uefi/uefi.rst +++ b/doc/uefi/uefi.rst @@ -59,6 +59,10 @@ Below you find the output of an example session starting GRUB:: 120832 bytes read in 7 ms (16.5 MiB/s) => bootefi ${kernel_addr_r} ${fdt_addr_r} +The bootefi command uses the device, the file name, and the file size +(environment variable 'filesize') of the most recently loaded file when setting +up the binary for execution. So the UEFI binary should be loaded last. + The environment variable 'bootargs' is passed as load options in the UEFI system table. The Linux kernel EFI stub uses the load options as command line arguments. @@ -169,11 +173,11 @@ Sign an image with one of the keys in "db" on your host Now in U-Boot install the keys on your board:: fatload mmc 0:1 <tmpaddr> PK.auth - setenv -e -nv -bs -rt -at -i <tmpaddr>,$filesize PK + setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize PK fatload mmc 0:1 <tmpaddr> KEK.auth - setenv -e -nv -bs -rt -at -i <tmpaddr>,$filesize KEK + setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize KEK fatload mmc 0:1 <tmpaddr> db.auth - setenv -e -nv -bs -rt -at -i <tmpaddr>,$filesize db + setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize db Set up boot parameters on your board:: @@ -217,13 +221,13 @@ which has to be enabled via CONFIG_SUPPORT_EMMC_RPMB=y. Executing the boot manager ~~~~~~~~~~~~~~~~~~~~~~~~~~ -The UEFI specification foresees to define boot entries and boot sequence via UEFI -variables. Booting according to these variables is possible via:: +The UEFI specification foresees to define boot entries and boot sequence via +UEFI variables. Booting according to these variables is possible via:: bootefi bootmgr [fdt address] -As of U-Boot v2018.03 UEFI variables are not persisted and cannot be set at -runtime. +As of U-Boot v2020.10 UEFI variables cannot be set at runtime. The U-Boot +command 'efidebug' can be used to set the variables. Executing the built in hello world application ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/drivers/ata/mtk_ahci.c b/drivers/ata/mtk_ahci.c index 8e09c5f9e6..4ad260a5bb 100644 --- a/drivers/ata/mtk_ahci.c +++ b/drivers/ata/mtk_ahci.c @@ -2,12 +2,10 @@ /* * MTK SATA platform driver * - * (C) Copyright 2020 - * Mediatek + * Copyright (C) 2020 MediaTek Inc. * - * Author: Frank Wunderlich <frank-w@public-files.de> - * based on https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/ata/ahci_mtk.c * Author: Ryder Lee <ryder.lee@mediatek.com> + * Author: Frank Wunderlich <frank-w@public-files.de> */ #include <common.h> diff --git a/drivers/clk/mediatek/clk-mt7622.c b/drivers/clk/mediatek/clk-mt7622.c index d53ed69189..0246149107 100644 --- a/drivers/clk/mediatek/clk-mt7622.c +++ b/drivers/clk/mediatek/clk-mt7622.c @@ -521,6 +521,20 @@ static const struct mtk_gate_regs sgmii_cg_regs = { .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \ } +static const struct mtk_gate_regs ssusb_cg_regs = { + .set_ofs = 0x30, + .clr_ofs = 0x30, + .sta_ofs = 0x30, +}; + +#define GATE_SSUSB(_id, _parent, _shift) { \ + .id = _id, \ + .parent = _parent, \ + .regs = &ssusb_cg_regs, \ + .shift = _shift, \ + .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \ +} + static const struct mtk_gate sgmii_cgs[] = { GATE_SGMII(CLK_SGMII_TX250M_EN, CLK_TOP_SSUSB_TX250M, 2), GATE_SGMII(CLK_SGMII_RX250M_EN, CLK_TOP_SSUSB_EQ_RX250M, 3), @@ -528,6 +542,15 @@ static const struct mtk_gate sgmii_cgs[] = { GATE_SGMII(CLK_SGMII_CDR_FB, CLK_TOP_SSUSB_CDR_FB, 5), }; +static const struct mtk_gate ssusb_cgs[] = { + GATE_SSUSB(CLK_SSUSB_U2_PHY_1P_EN, CLK_TOP_TO_U2_PHY_1P, 0), + GATE_SSUSB(CLK_SSUSB_U2_PHY_EN, CLK_TOP_TO_U2_PHY, 1), + GATE_SSUSB(CLK_SSUSB_REF_EN, CLK_TOP_TO_USB3_REF, 5), + GATE_SSUSB(CLK_SSUSB_SYS_EN, CLK_TOP_TO_USB3_SYS, 6), + GATE_SSUSB(CLK_SSUSB_MCU_EN, CLK_TOP_AXI_SEL, 7), + GATE_SSUSB(CLK_SSUSB_DMA_EN, CLK_TOP_HIF_SEL, 8), +}; + static const struct mtk_clk_tree mt7622_clk_tree = { .xtal_rate = 25 * MHZ, .xtal2_rate = 25 * MHZ, @@ -599,7 +622,6 @@ static int mt7622_pciesys_bind(struct udevice *dev) int ret = 0; if (IS_ENABLED(CONFIG_RESET_MEDIATEK)) { -// PCIESYS uses in linux also 0x34 = ETHSYS reset controller ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1); if (ret) debug("Warning: failed to bind reset controller\n"); @@ -631,6 +653,11 @@ static int mt7622_sgmiisys_probe(struct udevice *dev) return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, sgmii_cgs); } +static int mt7622_ssusbsys_probe(struct udevice *dev) +{ + return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, ssusb_cgs); +} + static const struct udevice_id mt7622_apmixed_compat[] = { { .compatible = "mediatek,mt7622-apmixedsys" }, { } @@ -671,6 +698,11 @@ static const struct udevice_id mt7622_mcucfg_compat[] = { { } }; +static const struct udevice_id mt7622_ssusbsys_compat[] = { + { .compatible = "mediatek,mt7622-ssusbsys" }, + { } +}; + U_BOOT_DRIVER(mtk_mcucfg) = { .name = "mt7622-mcucfg", .id = UCLASS_SYSCON, @@ -747,3 +779,12 @@ U_BOOT_DRIVER(mtk_clk_sgmiisys) = { .priv_auto_alloc_size = sizeof(struct mtk_cg_priv), .ops = &mtk_clk_gate_ops, }; + +U_BOOT_DRIVER(mtk_clk_ssusbsys) = { + .name = "mt7622-clock-ssusbsys", + .id = UCLASS_CLK, + .of_match = mt7622_ssusbsys_compat, + .probe = mt7622_ssusbsys_probe, + .priv_auto_alloc_size = sizeof(struct mtk_cg_priv), + .ops = &mtk_clk_gate_ops, +}; diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index 7d2e49fd3e..68953cc4f4 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -19,6 +19,7 @@ #include <linux/errno.h> #include <linux/printk.h> #include <linux/psci.h> +#include <asm/system.h> #define DRIVER_NAME "psci" @@ -73,6 +74,11 @@ static int psci_probe(struct udevice *dev) { const char *method; +#if defined(CONFIG_ARM64) + if (current_el() == 3) + return -EINVAL; +#endif + method = ofnode_read_string(dev_ofnode(dev), "method"); if (!method) { pr_warn("missing \"method\" property\n"); diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index e851ec462e..f7b2786448 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -46,4 +46,4 @@ obj-$(CONFIG_SYS_I2C_VERSATILE) += i2c-versatile.o obj-$(CONFIG_SYS_I2C_XILINX_XIIC) += xilinx_xiic.o obj-$(CONFIG_TEGRA186_BPMP_I2C) += tegra186_bpmp_i2c.o -obj-$(CONFIG_I2C_MUX) += muxes/ +obj-$(CONFIG_$(SPL_)I2C_MUX) += muxes/ diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile index 68ed9b547d..b690821199 100644 --- a/drivers/i2c/muxes/Makefile +++ b/drivers/i2c/muxes/Makefile @@ -2,6 +2,6 @@ # # Copyright (c) 2015 Google, Inc obj-$(CONFIG_I2C_ARB_GPIO_CHALLENGE) += i2c-arb-gpio-challenge.o -obj-$(CONFIG_$(SPL_)I2C_MUX) += i2c-mux-uclass.o +obj-$(CONFIG_I2C_MUX) += i2c-mux-uclass.o obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o diff --git a/drivers/i2c/octeon_i2c.c b/drivers/i2c/octeon_i2c.c index c11d6ff93d..23dcb1563e 100644 --- a/drivers/i2c/octeon_i2c.c +++ b/drivers/i2c/octeon_i2c.c @@ -3,11 +3,10 @@ * Copyright (C) 2018 Marvell International Ltd. */ -#include <common.h> #include <clk.h> #include <dm.h> #include <i2c.h> -#include <pci_ids.h> +#include <time.h> #include <asm/io.h> #include <linux/bitfield.h> #include <linux/compat.h> @@ -749,6 +748,27 @@ static int octeon_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) return 0; } +static const struct octeon_i2c_data i2c_octeon_data = { + .probe = PROBE_DT, + .reg_offs = 0x0000, + .thp = 3, + .clk_method = CLK_METHOD_OCTEON, +}; + +static const struct octeon_i2c_data i2c_octeontx_data = { + .probe = PROBE_PCI, + .reg_offs = 0x1000, + .thp = 24, + .clk_method = CLK_METHOD_OCTEON, +}; + +static const struct octeon_i2c_data i2c_octeontx2_data = { + .probe = PROBE_PCI, + .reg_offs = 0x1000, + .thp = 3, + .clk_method = CLK_METHOD_OCTEONTX2, +}; + /** * Driver probe function * @@ -761,6 +781,10 @@ static int octeon_i2c_probe(struct udevice *dev) u32 i2c_slave_addr; int ret; + /* Octeon TX2 needs a different data struct */ + if (device_is_compatible(dev, "cavium,thunderx-i2c")) + dev->driver_data = (long)&i2c_octeontx2_data; + twsi->data = (const struct octeon_i2c_data *)dev_get_driver_data(dev); if (twsi->data->probe == PROBE_PCI) { @@ -798,34 +822,11 @@ static const struct dm_i2c_ops octeon_i2c_ops = { .set_bus_speed = octeon_i2c_set_bus_speed, }; -static const struct octeon_i2c_data i2c_octeon_data = { - .probe = PROBE_DT, - .reg_offs = 0x0000, - .thp = 3, - .clk_method = CLK_METHOD_OCTEON, -}; - -static const struct octeon_i2c_data i2c_octeontx_data = { - .probe = PROBE_PCI, - .reg_offs = 0x8000, - .thp = 3, - .clk_method = CLK_METHOD_OCTEON, -}; - -static const struct octeon_i2c_data i2c_octeontx2_data = { - .probe = PROBE_PCI, - .reg_offs = 0x8000, - .thp = 24, - .clk_method = CLK_METHOD_OCTEONTX2, -}; - static const struct udevice_id octeon_i2c_ids[] = { { .compatible = "cavium,octeon-7890-twsi", .data = (ulong)&i2c_octeon_data }, { .compatible = "cavium,thunder-8890-twsi", .data = (ulong)&i2c_octeontx_data }, - { .compatible = "cavium,thunder2-99xx-twsi", - .data = (ulong)&i2c_octeontx2_data }, { } }; @@ -837,11 +838,3 @@ U_BOOT_DRIVER(octeon_pci_twsi) = { .priv_auto_alloc_size = sizeof(struct octeon_twsi), .ops = &octeon_i2c_ops, }; - -static struct pci_device_id octeon_twsi_supported[] = { - { PCI_VDEVICE(CAVIUM, PCI_DEVICE_ID_CAVIUM_TWSI), - .driver_data = (ulong)&i2c_octeontx2_data }, - { }, -}; - -U_BOOT_PCI_DEVICE(octeon_pci_twsi, octeon_twsi_supported); diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c index 326227a30d..3d7b9cd2b1 100644 --- a/drivers/phy/phy-mtk-tphy.c +++ b/drivers/phy/phy-mtk-tphy.c @@ -698,11 +698,10 @@ static int mtk_tphy_probe(struct udevice *dev) tphy->dev = dev; tphy->version = dev_get_driver_data(dev); - /* v1 has shared banks */ + /* v1 has shared banks for usb/pcie mode, */ + /* but not for sata mode */ if (tphy->version == MTK_TPHY_V1) { tphy->sif_base = dev_read_addr_ptr(dev); - if (!tphy->sif_base) - return -ENOENT; } dev_for_each_subnode(subnode, dev) { diff --git a/drivers/ram/sifive/fu540_ddr.c b/drivers/ram/sifive/fu540_ddr.c index 2eef1e7565..5ff88692a8 100644 --- a/drivers/ram/sifive/fu540_ddr.c +++ b/drivers/ram/sifive/fu540_ddr.c @@ -316,12 +316,12 @@ static int fu540_ddr_setup(struct udevice *dev) priv->info.size = get_ram_size((long *)priv->info.base, ddr_size); - debug("%s : %lx\n", __func__, priv->info.size); + debug("%s : %lx\n", __func__, (uintptr_t)priv->info.size); /* check memory access for all memory */ if (priv->info.size != ddr_size) { printf("DDR invalid size : 0x%lx, expected 0x%lx\n", - priv->info.size, (uintptr_t)ddr_size); + (uintptr_t)priv->info.size, (uintptr_t)ddr_size); return -EINVAL; } diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c index 992118c607..1799f5c5eb 100644 --- a/drivers/virtio/virtio_blk.c +++ b/drivers/virtio/virtio_blk.c @@ -115,6 +115,7 @@ static int virtio_blk_probe(struct udevice *dev) return ret; desc->blksz = 512; + desc->log2blksz = 9; virtio_cread(dev, struct virtio_blk_config, capacity, &cap); desc->lba = cap; diff --git a/drivers/xen/gnttab.c b/drivers/xen/gnttab.c index becf7a79fb..9bf1091ab3 100644 --- a/drivers/xen/gnttab.c +++ b/drivers/xen/gnttab.c @@ -100,7 +100,8 @@ int gnttab_end_access(grant_ref_t ref) nflags = gnttab_table[ref].flags; do { - if ((flags = nflags) & (GTF_reading | GTF_writing)) { + flags = nflags; + if ((flags) & (GTF_reading | GTF_writing)) { printf("WARNING: g.e. still in use! (%x)\n", flags); return 0; } diff --git a/drivers/xen/pvblock.c b/drivers/xen/pvblock.c index 76e82fbf41..1b3325bbe2 100644 --- a/drivers/xen/pvblock.c +++ b/drivers/xen/pvblock.c @@ -294,8 +294,8 @@ static void shutdown_blkfront(struct blkfront_dev *dev) snprintf(path, sizeof(path), "%s/state", dev->backend); snprintf(nodename, sizeof(nodename), "%s/state", dev->nodename); - if ((err = xenbus_switch_state(XBT_NIL, nodename, - XenbusStateClosing)) != NULL) { + err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosing); + if (err) { printf("%s: error changing state to %d: %s\n", __func__, XenbusStateClosing, err); goto close; @@ -306,8 +306,8 @@ static void shutdown_blkfront(struct blkfront_dev *dev) err = xenbus_wait_for_state_change(path, &state); free(err); - if ((err = xenbus_switch_state(XBT_NIL, nodename, - XenbusStateClosed)) != NULL) { + err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed); + if (err) { printf("%s: error changing state to %d: %s\n", __func__, XenbusStateClosed, err); goto close; @@ -319,8 +319,8 @@ static void shutdown_blkfront(struct blkfront_dev *dev) free(err); } - if ((err = xenbus_switch_state(XBT_NIL, nodename, - XenbusStateInitialising)) != NULL) { + err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateInitialising); + if (err) { printf("%s: error changing state to %d: %s\n", __func__, XenbusStateInitialising, err); goto close; diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 340e5ebdb9..f67f7c4a40 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -23,12 +23,6 @@ #include "sqfs_filesystem.h" #include "sqfs_utils.h" -struct squashfs_ctxt { - struct disk_partition cur_part_info; - struct blk_desc *cur_dev; - struct squashfs_super_block *sblk; -}; - static struct squashfs_ctxt ctxt; static int sqfs_disk_read(__u32 block, __u32 nr_blocks, void *buf) @@ -110,9 +104,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index, struct squashfs_super_block *sblk = ctxt.sblk; unsigned long dest_len; int block, offset, ret; - u16 header, comp_type; - - comp_type = get_unaligned_le16(&sblk->compression); + u16 header; if (inode_fragment_index >= get_unaligned_le32(&sblk->fragments)) return -EINVAL; @@ -162,6 +154,11 @@ static int sqfs_frag_lookup(u32 inode_fragment_index, header = get_unaligned_le16(metadata_buffer + table_offset); metadata = metadata_buffer + table_offset + SQFS_HEADER_SIZE; + if (!metadata) { + ret = -ENOMEM; + goto free_buffer; + } + entries = malloc(SQFS_METADATA_BLOCK_SIZE); if (!entries) { ret = -ENOMEM; @@ -171,7 +168,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index, if (SQFS_COMPRESSED_METADATA(header)) { src_len = SQFS_METADATA_SIZE(header); dest_len = SQFS_METADATA_BLOCK_SIZE; - ret = sqfs_decompress(comp_type, entries, &dest_len, metadata, + ret = sqfs_decompress(&ctxt, entries, &dest_len, metadata, src_len); if (ret) { ret = -EINVAL; @@ -280,8 +277,8 @@ static int sqfs_join(char **strings, char *dest, int start, int end, */ static int sqfs_tokenize(char **tokens, int count, const char *str) { + int i, j, ret = 0; char *aux, *strc; - int i, j; strc = strdup(str); if (!strc) @@ -290,8 +287,8 @@ static int sqfs_tokenize(char **tokens, int count, const char *str) if (!strcmp(strc, "/")) { tokens[0] = strdup(strc); if (!tokens[0]) { - free(strc); - return -ENOMEM; + ret = -ENOMEM; + goto free_strc; } } else { for (j = 0; j < count; j++) { @@ -300,15 +297,16 @@ static int sqfs_tokenize(char **tokens, int count, const char *str) if (!tokens[j]) { for (i = 0; i < j; i++) free(tokens[i]); - free(strc); - return -ENOMEM; + ret = -ENOMEM; + goto free_strc; } } } +free_strc: free(strc); - return 0; + return ret; } /* @@ -436,9 +434,9 @@ static int sqfs_search_dir(struct squashfs_dir_stream *dirs, char **token_list, { struct squashfs_super_block *sblk = ctxt.sblk; char *path, *target, **sym_tokens, *res, *rem; + struct squashfs_ldir_inode *ldir = NULL; int j, ret, new_inode_number, offset; struct squashfs_symlink_inode *sym; - struct squashfs_ldir_inode *ldir; struct squashfs_dir_inode *dir; struct fs_dir_stream *dirsp; struct fs_dirent *dent; @@ -635,13 +633,12 @@ static int sqfs_read_inode_table(unsigned char **inode_table) { struct squashfs_super_block *sblk = ctxt.sblk; u64 start, n_blks, table_offset, table_size; - int j, ret = 0, metablks_count, comp_type; + int j, ret = 0, metablks_count; unsigned char *src_table, *itb; u32 src_len, dest_offset = 0; - unsigned long dest_len; + unsigned long dest_len = 0; bool compressed; - comp_type = get_unaligned_le16(&sblk->compression); table_size = get_unaligned_le64(&sblk->directory_table_start) - get_unaligned_le64(&sblk->inode_table_start); start = get_unaligned_le64(&sblk->inode_table_start) / @@ -686,7 +683,7 @@ static int sqfs_read_inode_table(unsigned char **inode_table) sqfs_read_metablock(itb, table_offset, &compressed, &src_len); if (compressed) { dest_len = SQFS_METADATA_BLOCK_SIZE; - ret = sqfs_decompress(comp_type, *inode_table + + ret = sqfs_decompress(&ctxt, *inode_table + dest_offset, &dest_len, src_table, src_len); if (ret) { @@ -694,6 +691,7 @@ static int sqfs_read_inode_table(unsigned char **inode_table) goto free_itb; } + dest_offset += dest_len; } else { memcpy(*inode_table + (j * SQFS_METADATA_BLOCK_SIZE), src_table, src_len); @@ -703,7 +701,7 @@ static int sqfs_read_inode_table(unsigned char **inode_table) * Offsets to the decompression destination, to the metadata * buffer 'itb' and to the decompression source, respectively. */ - dest_offset += dest_len; + table_offset += src_len + SQFS_HEADER_SIZE; src_table += src_len + SQFS_HEADER_SIZE; } @@ -717,15 +715,13 @@ free_itb: static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list) { u64 start, n_blks, table_offset, table_size; - int j, ret = 0, metablks_count = -1, comp_type; struct squashfs_super_block *sblk = ctxt.sblk; + int j, ret = 0, metablks_count = -1; unsigned char *src_table, *dtb; u32 src_len, dest_offset = 0; - unsigned long dest_len; + unsigned long dest_len = 0; bool compressed; - comp_type = get_unaligned_le16(&sblk->compression); - /* DIRECTORY TABLE */ table_size = get_unaligned_le64(&sblk->fragment_table_start) - get_unaligned_le64(&sblk->directory_table_start); @@ -779,7 +775,7 @@ static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list) sqfs_read_metablock(dtb, table_offset, &compressed, &src_len); if (compressed) { dest_len = SQFS_METADATA_BLOCK_SIZE; - ret = sqfs_decompress(comp_type, *dir_table + + ret = sqfs_decompress(&ctxt, *dir_table + (j * SQFS_METADATA_BLOCK_SIZE), &dest_len, src_table, src_len); if (ret) { @@ -792,6 +788,8 @@ static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list) dest_offset += dest_len; break; } + + dest_offset += dest_len; } else { memcpy(*dir_table + (j * SQFS_METADATA_BLOCK_SIZE), src_table, src_len); @@ -801,7 +799,6 @@ static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list) * Offsets to the decompression destination, to the metadata * buffer 'dtb' and to the decompression source, respectively. */ - dest_offset += dest_len; table_offset += src_len + SQFS_HEADER_SIZE; src_table += src_len + SQFS_HEADER_SIZE; } @@ -1023,6 +1020,14 @@ int sqfs_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition ctxt.sblk = sblk; + ret = sqfs_decompressor_init(&ctxt); + + if (ret) { + ctxt.cur_dev = NULL; + free(ctxt.sblk); + return -EINVAL; + } + return 0; } @@ -1141,6 +1146,9 @@ static int sqfs_get_regfile_info(struct squashfs_reg_inode *reg, finfo->start = get_unaligned_le32(®->start_block); finfo->frag = SQFS_IS_FRAGMENTED(get_unaligned_le32(®->fragment)); + if (finfo->size < 1 || finfo->offset < 0 || finfo->start < 0) + return -EINVAL; + if (finfo->frag) { datablk_count = finfo->size / le32_to_cpu(blksz); ret = sqfs_frag_lookup(get_unaligned_le32(®->fragment), @@ -1148,6 +1156,8 @@ static int sqfs_get_regfile_info(struct squashfs_reg_inode *reg, if (ret < 0) return -EINVAL; finfo->comp = true; + if (fentry->size < 1 || fentry->start < 0) + return -EINVAL; } else { datablk_count = DIV_ROUND_UP(finfo->size, le32_to_cpu(blksz)); } @@ -1171,6 +1181,9 @@ static int sqfs_get_lregfile_info(struct squashfs_lreg_inode *lreg, finfo->start = get_unaligned_le64(&lreg->start_block); finfo->frag = SQFS_IS_FRAGMENTED(get_unaligned_le32(&lreg->fragment)); + if (finfo->size < 1 || finfo->offset < 0 || finfo->start < 0) + return -EINVAL; + if (finfo->frag) { datablk_count = finfo->size / le32_to_cpu(blksz); ret = sqfs_frag_lookup(get_unaligned_le32(&lreg->fragment), @@ -1178,6 +1191,8 @@ static int sqfs_get_lregfile_info(struct squashfs_lreg_inode *lreg, if (ret < 0) return -EINVAL; finfo->comp = true; + if (fentry->size < 1 || fentry->start < 0) + return -EINVAL; } else { datablk_count = DIV_ROUND_UP(finfo->size, le32_to_cpu(blksz)); } @@ -1195,7 +1210,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, char *dir, *fragment_block, *datablock = NULL, *data_buffer = NULL; char *fragment, *file, *resolved, *data; u64 start, n_blks, table_size, data_offset, table_offset; - int ret, j, i_number, comp_type, datablk_count = 0; + int ret, j, i_number, datablk_count = 0; struct squashfs_super_block *sblk = ctxt.sblk; struct squashfs_fragment_block_entry frag_entry; struct squashfs_file_info finfo = {0}; @@ -1211,8 +1226,6 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, *actread = 0; - comp_type = get_unaligned_le16(&sblk->compression); - /* * sqfs_opendir will uncompress inode and directory tables, and will * return a pointer to the directory that contains the requested file. @@ -1344,7 +1357,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, /* Load the data */ if (SQFS_COMPRESSED_BLOCK(finfo.blk_sizes[j])) { dest_len = get_unaligned_le32(&sblk->block_size); - ret = sqfs_decompress(comp_type, datablock, &dest_len, + ret = sqfs_decompress(&ctxt, datablock, &dest_len, data, table_size); if (ret) goto free_buffer; @@ -1394,7 +1407,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, goto free_fragment; } - ret = sqfs_decompress(comp_type, fragment_block, &dest_len, + ret = sqfs_decompress(&ctxt, fragment_block, &dest_len, (void *)fragment + table_offset, frag_entry.size); if (ret) { @@ -1525,6 +1538,7 @@ void sqfs_close(void) { free(ctxt.sblk); ctxt.cur_dev = NULL; + sqfs_decompressor_cleanup(&ctxt); } void sqfs_closedir(struct fs_dir_stream *dirs) diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c index 09ca6cf6d0..d69ddb24a4 100644 --- a/fs/squashfs/sqfs_decompressor.c +++ b/fs/squashfs/sqfs_decompressor.c @@ -9,14 +9,71 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> + +#if IS_ENABLED(CONFIG_LZO) +#include <linux/lzo.h> +#endif + #if IS_ENABLED(CONFIG_ZLIB) #include <u-boot/zlib.h> #endif +#if IS_ENABLED(CONFIG_ZSTD) +#include <linux/zstd.h> +#endif + #include "sqfs_decompressor.h" -#include "sqfs_filesystem.h" #include "sqfs_utils.h" +int sqfs_decompressor_init(struct squashfs_ctxt *ctxt) +{ + u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression); + + switch (comp_type) { +#if IS_ENABLED(CONFIG_LZO) + case SQFS_COMP_LZO: + break; +#endif +#if IS_ENABLED(CONFIG_ZLIB) + case SQFS_COMP_ZLIB: + break; +#endif +#if IS_ENABLED(CONFIG_ZSTD) + case SQFS_COMP_ZSTD: + ctxt->zstd_workspace = malloc(ZSTD_DCtxWorkspaceBound()); + if (!ctxt->zstd_workspace) + return -ENOMEM; + break; +#endif + default: + printf("Error: unknown compression type.\n"); + return -EINVAL; + } + + return 0; +} + +void sqfs_decompressor_cleanup(struct squashfs_ctxt *ctxt) +{ + u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression); + + switch (comp_type) { +#if IS_ENABLED(CONFIG_LZO) + case SQFS_COMP_LZO: + break; +#endif +#if IS_ENABLED(CONFIG_ZLIB) + case SQFS_COMP_ZLIB: + break; +#endif +#if IS_ENABLED(CONFIG_ZSTD) + case SQFS_COMP_ZSTD: + free(ctxt->zstd_workspace); + break; +#endif + } +} + #if IS_ENABLED(CONFIG_ZLIB) static void zlib_decompression_status(int ret) { @@ -34,15 +91,44 @@ static void zlib_decompression_status(int ret) } #endif -int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len, - void *source, u32 lenp) +#if IS_ENABLED(CONFIG_ZSTD) +static int sqfs_zstd_decompress(struct squashfs_ctxt *ctxt, void *dest, + unsigned long dest_len, void *source, u32 src_len) +{ + ZSTD_DCtx *ctx; + size_t wsize; + int ret; + + wsize = ZSTD_DCtxWorkspaceBound(); + ctx = ZSTD_initDCtx(ctxt->zstd_workspace, wsize); + ret = ZSTD_decompressDCtx(ctx, dest, dest_len, source, src_len); + + return ZSTD_isError(ret); +} +#endif /* CONFIG_ZSTD */ + +int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest, + unsigned long *dest_len, void *source, u32 src_len) { + u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression); int ret = 0; switch (comp_type) { +#if IS_ENABLED(CONFIG_LZO) + case SQFS_COMP_LZO: { + size_t lzo_dest_len = *dest_len; + ret = lzo1x_decompress_safe(source, src_len, dest, &lzo_dest_len); + if (ret) { + printf("LZO decompression failed. Error code: %d\n", ret); + return -EINVAL; + } + + break; + } +#endif #if IS_ENABLED(CONFIG_ZLIB) case SQFS_COMP_ZLIB: - ret = uncompress(dest, dest_len, source, lenp); + ret = uncompress(dest, dest_len, source, src_len); if (ret) { zlib_decompression_status(ret); return -EINVAL; @@ -50,6 +136,16 @@ int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len, break; #endif +#if IS_ENABLED(CONFIG_ZSTD) + case SQFS_COMP_ZSTD: + ret = sqfs_zstd_decompress(ctxt, dest, *dest_len, source, src_len); + if (ret) { + printf("ZSTD Error code: %d\n", ZSTD_getErrorCode(ret)); + return -EINVAL; + } + + break; +#endif default: printf("Error: unknown compression type.\n"); return -EINVAL; diff --git a/fs/squashfs/sqfs_decompressor.h b/fs/squashfs/sqfs_decompressor.h index 378965dda8..892cfb6974 100644 --- a/fs/squashfs/sqfs_decompressor.h +++ b/fs/squashfs/sqfs_decompressor.h @@ -9,6 +9,7 @@ #define SQFS_DECOMPRESSOR_H #include <stdint.h> +#include "sqfs_filesystem.h" #define SQFS_COMP_ZLIB 1 #define SQFS_COMP_LZMA 2 @@ -52,7 +53,9 @@ union squashfs_compression_opts { struct squashfs_lzo_opts *lzo; }; -int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len, - void *source, u32 lenp); +int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest, + unsigned long *dest_len, void *source, u32 src_len); +int sqfs_decompressor_init(struct squashfs_ctxt *ctxt); +void sqfs_decompressor_cleanup(struct squashfs_ctxt *ctxt); #endif /* SQFS_DECOMPRESSOR_H */ diff --git a/fs/squashfs/sqfs_dir.c b/fs/squashfs/sqfs_dir.c index 5f7660aeae..00d2891e7d 100644 --- a/fs/squashfs/sqfs_dir.c +++ b/fs/squashfs/sqfs_dir.c @@ -53,6 +53,9 @@ int sqfs_dir_offset(void *dir_i, u32 *m_list, int m_count) return -EINVAL; } + if (offset < 0) + return -EINVAL; + for (j = 0; j < m_count; j++) { if (m_list[j] == start_block) return (++j * SQFS_METADATA_BLOCK_SIZE) + offset; diff --git a/fs/squashfs/sqfs_filesystem.h b/fs/squashfs/sqfs_filesystem.h index d63e3a41ad..856cd15e34 100644 --- a/fs/squashfs/sqfs_filesystem.h +++ b/fs/squashfs/sqfs_filesystem.h @@ -9,8 +9,9 @@ #define SQFS_FILESYSTEM_H #include <asm/unaligned.h> -#include <stdint.h> #include <fs.h> +#include <part.h> +#include <stdint.h> #define SQFS_UNCOMPRESSED_DATA 0x0002 #define SQFS_MAGIC_NUMBER 0x73717368 @@ -72,6 +73,15 @@ struct squashfs_super_block { __le64 export_table_start; }; +struct squashfs_ctxt { + struct disk_partition cur_part_info; + struct blk_desc *cur_dev; + struct squashfs_super_block *sblk; +#if IS_ENABLED(CONFIG_ZSTD) + void *zstd_workspace; +#endif +}; + struct squashfs_directory_index { u32 index; u32 start; diff --git a/fs/squashfs/sqfs_inode.c b/fs/squashfs/sqfs_inode.c index b037a9b2ac..1387779a85 100644 --- a/fs/squashfs/sqfs_inode.c +++ b/fs/squashfs/sqfs_inode.c @@ -138,11 +138,14 @@ void *sqfs_find_inode(void *inode_table, int inode_number, __le32 inode_count, int sqfs_read_metablock(unsigned char *file_mapping, int offset, bool *compressed, u32 *data_size) { - unsigned char *data; + const unsigned char *data; u16 header; data = file_mapping + offset; header = get_unaligned((u16 *)data); + if (!header || !data) + return -EINVAL; + *compressed = SQFS_COMPRESSED_METADATA(header); *data_size = SQFS_METADATA_SIZE(header); diff --git a/include/avb_verify.h b/include/avb_verify.h index a8d7090f79..1e787ba666 100644 --- a/include/avb_verify.h +++ b/include/avb_verify.h @@ -72,12 +72,12 @@ static inline uint64_t calc_offset(struct mmc_part *part, int64_t offset) static inline size_t get_sector_buf_size(void) { - return (size_t)CONFIG_FASTBOOT_BUF_SIZE; + return (size_t)CONFIG_AVB_BUF_SIZE; } static inline void *get_sector_buf(void) { - return map_sysmem(CONFIG_FASTBOOT_BUF_ADDR, CONFIG_FASTBOOT_BUF_SIZE); + return map_sysmem(CONFIG_AVB_BUF_ADDR, CONFIG_AVB_BUF_SIZE); } static inline bool is_buf_unaligned(void *buffer) diff --git a/include/configs/octeontx2_common.h b/include/configs/octeontx2_common.h index 87dcf5fb37..7c585ad9e2 100644 --- a/include/configs/octeontx2_common.h +++ b/include/configs/octeontx2_common.h @@ -66,7 +66,6 @@ /** EMMC specific defines */ #define CONFIG_SUPPORT_EMMC_BOOT #define CONFIG_SUPPORT_EMMC_RPMB -#define CONFIG_CMD_BKOPS_ENABLE #endif #endif /* __OCTEONTX2_COMMON_H__ */ diff --git a/include/configs/octeontx_common.h b/include/configs/octeontx_common.h index b66aa8b54e..810b2bdbd5 100644 --- a/include/configs/octeontx_common.h +++ b/include/configs/octeontx_common.h @@ -77,7 +77,6 @@ #if defined(CONFIG_MMC_OCTEONTX) #define CONFIG_SUPPORT_EMMC_BOOT #define CONFIG_SUPPORT_EMMC_RPMB -#define CONFIG_CMD_BKOPS_ENABLE #endif #if defined(CONFIG_NAND_OCTEONTX) diff --git a/include/configs/total_compute.h b/include/configs/total_compute.h new file mode 100644 index 0000000000..cc93f1930a --- /dev/null +++ b/include/configs/total_compute.h @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Configuration for Total Compute platform. Parts were derived from other ARM + * configurations. + * (C) Copyright 2020 Arm Limited + * Usama Arif <usama.arif@arm.com> + */ + +#ifndef __TOTAL_COMPUTE_H +#define __TOTAL_COMPUTE_H + +#define CONFIG_REMAKE_ELF + +/* Link Definitions */ +#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x7fff0) + +#define CONFIG_SYS_BOOTM_LEN (64 << 20) + +#define UART0_BASE 0x7ff80000 + +/* Size of malloc() pool */ +#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + (8 << 20)) + +/* PL011 Serial Configuration */ +#define CONFIG_PL011_CLOCK 7372800 + +/* Miscellaneous configurable options */ +#define CONFIG_SYS_LOAD_ADDR 0x90000000 + +/* Physical Memory Map */ +#define PHYS_SDRAM_1 0x80000000 +/* Top 48MB reserved for secure world use */ +#define DRAM_SEC_SIZE 0x03000000 +#define PHYS_SDRAM_1_SIZE 0x80000000 - DRAM_SEC_SIZE +#define CONFIG_SYS_SDRAM_BASE PHYS_SDRAM_1 + +#define CONFIG_ARM_PL180_MMCI_BASE 0x001c050000 +#define CONFIG_SYS_MMC_MAX_BLK_COUNT 127 +#define CONFIG_ARM_PL180_MMCI_CLOCK_FREQ 12000000 + +#define CONFIG_EXTRA_ENV_SETTINGS \ + "bootm_size=0x20000000\0" \ + "load_addr=0xa0000000\0" \ + "kernel_addr_r=0x80080000\0" \ + "initrd_addr_r=0x88000000\0" \ + "fdt_addr_r=0x83000000\0" +/* + * If vbmeta partition is present, boot Android with verification using AVB. + * Else if system partition is present (no vbmeta partition), boot Android + * without verification (for development purposes). + * Else boot FIT image. + */ +#define CONFIG_BOOTCOMMAND \ + "if part number mmc 0 vbmeta is_avb; then" \ + " echo MMC with vbmeta partition detected.;" \ + " echo starting Android Verified boot.;" \ + " avb init 0; " \ + " if avb verify; then " \ + " set bootargs $bootargs $avb_bootargs; " \ + " part start mmc 0 boot boot_start; " \ + " part size mmc 0 boot boot_size; " \ + " mmc read ${load_addr} ${boot_start} ${boot_size}; " \ + " bootm ${load_addr} ${load_addr} ${fdt_addr_r}; " \ + " else; " \ + " echo AVB verification failed.; " \ + " exit; " \ + " fi; " \ + "elif part number mmc 0 system is_non_avb_android; then " \ + " booti ${kernel_addr_r} ${initrd_addr_r} ${fdt_addr_r};" \ + "else;" \ + " echo Booting FIT image.;" \ + " bootm ${load_addr} ${load_addr} ${fdt_addr_r}; " \ + "fi;" + +/* Monitor Command Prompt */ +#define CONFIG_SYS_CBSIZE 512 /* Console I/O Buffer Size */ +#define CONFIG_SYS_MAXARGS 64 /* max command args */ + +#define CONFIG_SYS_FLASH_BASE 0x0C000000 +/* 256 x 256KiB sectors */ +#define CONFIG_SYS_MAX_FLASH_SECT 256 + +#define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_32BIT +#define CONFIG_SYS_MAX_FLASH_BANKS 1 + +#define CONFIG_SYS_FLASH_EMPTY_INFO /* flinfo indicates empty blocks */ +#define FLASH_MAX_SECTOR_SIZE 0x00040000 + +#endif /* __TOTAL_COMPUTE_H */ diff --git a/include/configs/xenguest_arm64.h b/include/configs/xenguest_arm64.h index db3059a82c..c44381e966 100644 --- a/include/configs/xenguest_arm64.h +++ b/include/configs/xenguest_arm64.h @@ -9,8 +9,6 @@ #include <linux/types.h> #endif -#define CONFIG_BOARD_EARLY_INIT_F - #define CONFIG_EXTRA_ENV_SETTINGS #undef CONFIG_NR_DRAM_BANKS @@ -38,11 +36,6 @@ #define CONFIG_OF_SYSTEM_SETUP -#define CONFIG_CMDLINE_TAG 1 -#define CONFIG_INITRD_TAG 1 - -#define CONFIG_CMD_RUN - #undef CONFIG_EXTRA_ENV_SETTINGS #define CONFIG_EXTRA_ENV_SETTINGS \ "loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \ diff --git a/include/efi_loader.h b/include/efi_loader.h index 50a17a33ca..0baa1d2324 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -631,6 +631,8 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, const char *path, struct efi_device_path **device, struct efi_device_path **file); +ssize_t efi_dp_check_length(const struct efi_device_path *dp, + const size_t maxlen); #define EFI_DP_TYPE(_dp, _type, _subtype) \ (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \ diff --git a/include/efi_variable.h b/include/efi_variable.h index 60491cb640..4704a3c16e 100644 --- a/include/efi_variable.h +++ b/include/efi_variable.h @@ -274,7 +274,6 @@ efi_get_next_variable_name_mem(efi_uintn_t *variable_name_size, u16 *variable_na * @data: buffer to which the variable value is copied * @timep: authentication time (seconds since start of epoch) * Return: status code - */ efi_status_t __efi_runtime efi_get_variable_mem(u16 *variable_name, const efi_guid_t *vendor, u32 *attributes, diff --git a/include/kendryte/pll.h b/include/kendryte/pll.h index c8e3200799..55a40b9c97 100644 --- a/include/kendryte/pll.h +++ b/include/kendryte/pll.h @@ -7,6 +7,7 @@ #include <clk.h> #include <test/export.h> +#include <asm/io.h> #define K210_PLL_CLKR GENMASK(3, 0) #define K210_PLL_CLKF GENMASK(9, 4) @@ -43,9 +44,13 @@ struct k210_pll_config { #ifdef CONFIG_UNIT_TEST TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in, struct k210_pll_config *best); + +#ifndef nop #define nop() #endif +#endif + extern const struct clk_ops k210_pll_ops; struct clk *k210_register_pll_struct(const char *name, const char *parent_name, diff --git a/include/linux/kernel.h b/include/linux/kernel.h index b88c210065..3e71d61074 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -19,6 +19,9 @@ #ifndef SIZE_MAX #define SIZE_MAX (~(size_t)0) #endif +#ifndef SSIZE_MAX +#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) +#endif #define U8_MAX ((u8)~0U) #define S8_MAX ((s8)(U8_MAX>>1)) diff --git a/include/xen/gnttab.h b/include/xen/gnttab.h index db1d5361fe..db615004aa 100644 --- a/include/xen/gnttab.h +++ b/include/xen/gnttab.h @@ -1,5 +1,4 @@ -/* - * SPDX-License-Identifier: GPL-2.0 +/* SPDX-License-Identifier: GPL-2.0 * * (C) 2006, Steven Smith <sos22@cam.ac.uk> * (C) 2006, Grzegorz Milos <gm281@cam.ac.uk> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 1e06e60963..61dc72a23d 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -105,10 +105,8 @@ efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data, if (*size < len) return EFI_INVALID_PARAMETER; lo->file_path = (struct efi_device_path *)data; - /* - * TODO: validate device path. There should be an end node within - * the indicated file_path_length. - */ + if (efi_dp_check_length(lo->file_path, len) < 0) + return EFI_INVALID_PARAMETER; data += len; *size -= len; diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 7ae14f3423..8a5c13c424 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1127,3 +1127,36 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, return EFI_SUCCESS; } + +/** + * efi_dp_check_length() - check length of a device path + * + * @dp: pointer to device path + * @maxlen: maximum length of the device path + * Return: + * * length of the device path if it is less or equal @maxlen + * * -1 if the device path is longer then @maxlen + * * -1 if a device path node has a length of less than 4 + * * -EINVAL if maxlen exceeds SSIZE_MAX + */ +ssize_t efi_dp_check_length(const struct efi_device_path *dp, + const size_t maxlen) +{ + ssize_t ret = 0; + u16 len; + + if (maxlen > SSIZE_MAX) + return -EINVAL; + for (;;) { + len = dp->length; + if (len < 4) + return -1; + ret += len; + if (ret > maxlen) + return -1; + if (dp->type == DEVICE_PATH_TYPE_END && + dp->sub_type == DEVICE_PATH_SUB_TYPE_END) + return ret; + dp = (const struct efi_device_path *)((const u8 *)dp + len); + } +} diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 78fd8014d9..dea2b4e5ee 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -365,7 +365,9 @@ out: * efi_reset_system() - reset system * * This function implements the ResetSystem() runtime service after - * SetVirtualAddressMap() is called. It only executes an endless loop. + * SetVirtualAddressMap() is called. As this placeholder cannot reset the + * system it simply return to the caller. + * * Boards may override the helpers below to implement reset functionality. * * See the Unified Extensible Firmware Interface (UEFI) specification for @@ -381,8 +383,7 @@ void __weak __efi_runtime EFIAPI efi_reset_system( efi_status_t reset_status, unsigned long data_size, void *reset_data) { - /* Nothing we can do */ - while (1) { } + return; } /** diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index 45ce6859b8..85fe8e1216 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -31,6 +31,7 @@ efi_selftest_mem.o \ efi_selftest_memory.o \ efi_selftest_open_protocol.o \ efi_selftest_register_notify.o \ +efi_selftest_reset.o \ efi_selftest_set_virtual_address_map.o \ efi_selftest_textinput.o \ efi_selftest_textinputex.o \ diff --git a/lib/efi_selftest/efi_selftest.c b/lib/efi_selftest/efi_selftest.c index 5b01610eca..6eec8ae2a7 100644 --- a/lib/efi_selftest/efi_selftest.c +++ b/lib/efi_selftest/efi_selftest.c @@ -5,6 +5,7 @@ * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de> */ +#include <command.h> #include <efi_selftest.h> #include <vsprintf.h> @@ -309,8 +310,13 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, /* Reset system */ efi_st_printf("Preparing for reset. Press any key...\n"); efi_st_get_key(); - runtime->reset_system(EFI_RESET_WARM, EFI_NOT_READY, - sizeof(reset_message), reset_message); + + if (IS_ENABLED(CONFIG_EFI_HAVE_RUNTIME_RESET)) + runtime->reset_system(EFI_RESET_WARM, EFI_NOT_READY, + sizeof(reset_message), reset_message); + else + do_reset(NULL, 0, 0, NULL); + efi_st_printf("\n"); efi_st_error("Reset failed\n"); diff --git a/lib/efi_selftest/efi_selftest_reset.c b/lib/efi_selftest/efi_selftest_reset.c new file mode 100644 index 0000000000..8b6ac24cb1 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_reset.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * efi_selftest_reset + * + * Copyright (c) 2020 Heinrich Schuchardt <xypron.glpk@gmx.de> + * + * This test checks the following service at boot time or runtime: + * ResetSystem() + */ + +#include <efi_selftest.h> + +static struct efi_runtime_services *runtime; + +/* + * Setup unit test. + * + * @handle: handle of the loaded image + * @systable: system table + * @return: EFI_ST_SUCCESS for success + */ +static int setup(const efi_handle_t handle, + const struct efi_system_table *systable) +{ + runtime = systable->runtime; + return EFI_ST_SUCCESS; +} + +/* + * Execute unit test. + * + * @return: EFI_ST_SUCCESS for success + */ +static int execute(void) +{ + u16 reset_data[] = L"Reset by selftest"; + + runtime->reset_system(EFI_RESET_COLD, EFI_SUCCESS, + sizeof(reset_data), reset_data); + efi_st_error("Reset failed.\n"); + return EFI_ST_FAILURE; +} + +EFI_UNIT_TEST(reset) = { + .name = "reset system", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, + .on_request = true, +}; + +EFI_UNIT_TEST(resetrt) = { + .name = "reset system runtime", + .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, + .on_request = true, +}; diff --git a/lib/sscanf.c b/lib/sscanf.c index d1e2dc272c..4c35c035fe 100644 --- a/lib/sscanf.c +++ b/lib/sscanf.c @@ -555,7 +555,8 @@ literal: if (flags & SUPPRESS) { size_t sum = 0; - if ((n = inr) < width) { + n = inr; + if (n < width) { sum += n; width -= n; inp += n; diff --git a/test/lib/Makefile b/test/lib/Makefile index b6a0a208c5..ada62fe46b 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -3,6 +3,7 @@ # (C) Copyright 2018 # Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc obj-y += cmd_ut_lib.o +obj-$(CONFIG_EFI_LOADER) += efi_device_path.o obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o obj-y += hexdump.o obj-y += lmb.o diff --git a/test/lib/efi_device_path.c b/test/lib/efi_device_path.c new file mode 100644 index 0000000000..24e2f23c5a --- /dev/null +++ b/test/lib/efi_device_path.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device path functions + * + * Copyright (c) 2020 Heinrich Schuchardt <xypron.glpk@gmx.de> + */ + +#include <common.h> +#include <efi_loader.h> +#include <test/lib.h> +#include <test/test.h> +#include <test/ut.h> + +static int lib_test_efi_dp_check_length(struct unit_test_state *uts) +{ + /* end of device path */ + u8 d1[] __aligned(2) = { + 0x7f, 0xff, 0x04, 0x00 }; + /* device path node with length less then 4 */ + u8 d2[] __aligned(2) = { + 0x01, 0x02, 0x02, 0x00, 0x04, 0x00, 0x7f, 0xff, 0x04, 0x00 }; + /* well formed device path */ + u8 d3[] __aligned(2) = { + 0x03, 0x02, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x7f, 0xff, 0x04, 0x00 }; + + struct efi_device_path *p1 = (struct efi_device_path *)d1; + struct efi_device_path *p2 = (struct efi_device_path *)d2; + struct efi_device_path *p3 = (struct efi_device_path *)d3; + + ut_asserteq((ssize_t)-EINVAL, efi_dp_check_length(p1, SIZE_MAX)); + ut_asserteq((ssize_t)sizeof(d1), efi_dp_check_length(p1, sizeof(d1))); + ut_asserteq((ssize_t)sizeof(d1), + efi_dp_check_length(p1, sizeof(d1) + 4)); + ut_asserteq((ssize_t)-1, efi_dp_check_length(p1, sizeof(d1) - 1)); + + ut_asserteq((ssize_t)-1, efi_dp_check_length(p2, sizeof(d2))); + + ut_asserteq((ssize_t)-1, efi_dp_check_length(p3, sizeof(d3) - 1)); + ut_asserteq((ssize_t)sizeof(d3), efi_dp_check_length(p3, sizeof(d3))); + ut_asserteq((ssize_t)sizeof(d3), efi_dp_check_length(p3, SSIZE_MAX)); + ut_asserteq((ssize_t)-EINVAL, + efi_dp_check_length(p3, (size_t)SSIZE_MAX + 1)); + ut_asserteq((ssize_t)sizeof(d3), + efi_dp_check_length(p3, sizeof(d3) + 4)); + + return 0; +} + +LIB_TEST(lib_test_efi_dp_check_length, 0); diff --git a/test/py/tests/test_efi_secboot/test_authvar.py b/test/py/tests/test_efi_secboot/test_authvar.py index d0c6b9035b..f99b8270a6 100644 --- a/test/py/tests/test_efi_secboot/test_authvar.py +++ b/test/py/tests/test_efi_secboot/test_authvar.py @@ -38,14 +38,14 @@ class TestEfiAuthVar(object): # Test Case 1b, PK without AUTHENTICATED_WRITE_ACCESS output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' in ''.join(output) with u_boot_console.log.section('Test Case 1c'): # Test Case 1c, install PK output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'printenv -e -n PK']) assert 'PK:' in ''.join(output) @@ -60,24 +60,24 @@ class TestEfiAuthVar(object): # Test Case 1d, db/dbx without KEK output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' in ''.join(output) with u_boot_console.log.section('Test Case 1e'): # Test Case 1e, install KEK output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -i 4000000,$filesize KEK']) + 'setenv -e -nv -bs -rt -i 4000000:$filesize KEK']) assert 'Failed to set EFI variable' in ''.join(output) output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'printenv -e -n KEK']) assert 'KEK:' in ''.join(output) @@ -89,12 +89,12 @@ class TestEfiAuthVar(object): # Test Case 1f, install db output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) @@ -107,12 +107,12 @@ class TestEfiAuthVar(object): # Test Case 1g, install dbx output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx.auth', - 'setenv -e -nv -bs -rt -i 4000000,$filesize dbx']) + 'setenv -e -nv -bs -rt -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' in ''.join(output) output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f dbx']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'dbx:' in ''.join(output) @@ -132,32 +132,32 @@ class TestEfiAuthVar(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db1.auth', - 'setenv -e -nv -bs -rt -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) with u_boot_console.log.section('Test Case 2b'): # Test Case 2b, update without correct signature output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.esl', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) with u_boot_console.log.section('Test Case 2c'): # Test Case 2c, update with correct signature output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db1.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) @@ -173,32 +173,32 @@ class TestEfiAuthVar(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db1.auth', - 'setenv -e -nv -bs -rt -a -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) with u_boot_console.log.section('Test Case 3b'): # Test Case 3b, update without correct signature output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.esl', - 'setenv -e -nv -bs -rt -at -a -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) with u_boot_console.log.section('Test Case 3c'): # Test Case 3c, update with correct signature output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db1.auth', - 'setenv -e -nv -bs -rt -at -a -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db', 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) @@ -214,11 +214,11 @@ class TestEfiAuthVar(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) @@ -248,18 +248,18 @@ class TestEfiAuthVar(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -n PK']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'PK:' in ''.join(output) output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 PK_null.esl', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'printenv -e -n PK']) assert 'Failed to set EFI variable' in ''.join(output) assert 'PK:' in ''.join(output) @@ -268,7 +268,7 @@ class TestEfiAuthVar(object): # Test Case 5b, Uninstall PK with correct signature output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 PK_null.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'printenv -e -n PK']) assert 'Failed to set EFI variable' not in ''.join(output) assert '\"PK\" not defined' in ''.join(output) diff --git a/test/py/tests/test_efi_secboot/test_signed.py b/test/py/tests/test_efi_secboot/test_signed.py index 1443ba7b62..863685e215 100644 --- a/test/py/tests/test_efi_secboot/test_signed.py +++ b/test/py/tests/test_efi_secboot/test_signed.py @@ -53,9 +53,9 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add 1 HELLO1 host 0:1 /helloworld.efi.signed ""', @@ -74,7 +74,7 @@ class TestEfiSignedImage(object): # Test Case 2b, authenticated by db output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot next 2', @@ -97,11 +97,11 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add 1 HELLO host 0:1 /helloworld.efi.signed ""', @@ -114,7 +114,7 @@ class TestEfiSignedImage(object): # Test Case 3b, rejected by dbx even if db allows output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot next 1', @@ -133,13 +133,13 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 dbx_hash.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add 1 HELLO host 0:1 /helloworld.efi.signed ""', @@ -162,11 +162,11 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add 1 HELLO host 0:1 /helloworld.efi.signed_2sigs ""', @@ -178,7 +178,7 @@ class TestEfiSignedImage(object): # Test Case 5b, authenticated if both signatures are verified output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db1.auth', - 'setenv -e -nv -bs -rt -at -a -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot next 1', @@ -190,7 +190,7 @@ class TestEfiSignedImage(object): # certificate) is revoked output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx_hash.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot next 1', @@ -201,7 +201,7 @@ class TestEfiSignedImage(object): # Test Case 5d, rejected if both of signatures are revoked output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx_hash1.auth', - 'setenv -e -nv -bs -rt -at -a -i 4000000,$filesize dbx']) + 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot next 1', @@ -220,11 +220,11 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 db_hello_signed.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add 1 HELLO host 0:1 /helloworld.efi.signed ""', @@ -236,7 +236,7 @@ class TestEfiSignedImage(object): # Test Case 6b, rejected by TEST_db certificate in dbx output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx_db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot next 1', @@ -248,9 +248,9 @@ class TestEfiSignedImage(object): # Test Case 6c, rejected by image's digest in dbx output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'fatload host 0:1 4000000 dbx_hello_signed.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot next 1', diff --git a/test/py/tests/test_efi_secboot/test_signed_intca.py b/test/py/tests/test_efi_secboot/test_signed_intca.py index 1e5f4d04b3..70d6be00e8 100644 --- a/test/py/tests/test_efi_secboot/test_signed_intca.py +++ b/test/py/tests/test_efi_secboot/test_signed_intca.py @@ -31,11 +31,11 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 db_c.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ @@ -64,9 +64,9 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ @@ -80,7 +80,7 @@ class TestEfiSignedImageIntca(object): # Test Case 2b, signed and authenticated by root CA output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_b.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'efidebug boot next 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) @@ -90,7 +90,7 @@ class TestEfiSignedImageIntca(object): # Test Case 2c, signed and authenticated by root CA output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_c.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'efidebug boot next 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -106,13 +106,13 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 dbx_b.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', 'fatload host 0:1 4000000 db_c.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ @@ -128,7 +128,7 @@ class TestEfiSignedImageIntca(object): # Test Case 3b, revoked by root CA in dbx output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx_c.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', 'efidebug boot next 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) diff --git a/test/py/tests/test_efi_secboot/test_unsigned.py b/test/py/tests/test_efi_secboot/test_unsigned.py index c4c3f4c202..56f56e19eb 100644 --- a/test/py/tests/test_efi_secboot/test_unsigned.py +++ b/test/py/tests/test_efi_secboot/test_unsigned.py @@ -29,9 +29,9 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ @@ -56,11 +56,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 db_hello.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ @@ -80,11 +80,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 db_hello.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize dbx', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', 'fatload host 0:1 4000000 KEK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize KEK', + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 PK.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize PK']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ @@ -102,7 +102,7 @@ class TestEfiUnsignedImage(object): # Test Case 3b, rejected by dbx even if db allows output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_hello.auth', - 'setenv -e -nv -bs -rt -at -i 4000000,$filesize db']) + 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ diff --git a/test/py/tests/test_fs/test_squashfs/sqfs_common.py b/test/py/tests/test_fs/test_squashfs/sqfs_common.py index 2dc344d1b2..c96f92c1d8 100644 --- a/test/py/tests/test_fs/test_squashfs/sqfs_common.py +++ b/test/py/tests/test_fs/test_squashfs/sqfs_common.py @@ -5,6 +5,7 @@ import os import random import string +import subprocess def sqfs_get_random_letters(size): letters = [] @@ -19,24 +20,57 @@ def sqfs_generate_file(path, size): file.write(content) file.close() -# generate image with three files and a symbolic link -def sqfs_generate_image(cons): - src = os.path.join(cons.config.build_dir, "sqfs_src/") - dest = os.path.join(cons.config.build_dir, "sqfs") - os.mkdir(src) - sqfs_generate_file(src + "frag_only", 100) - sqfs_generate_file(src + "blks_frag", 5100) - sqfs_generate_file(src + "blks_only", 4096) - os.symlink("frag_only", src + "sym") - os.system("mksquashfs " + src + " " + dest + " -b 4096 -always-use-fragments") - -# removes all files created by sqfs_generate_image() -def sqfs_clean(cons): - src = os.path.join(cons.config.build_dir, "sqfs_src/") - dest = os.path.join(cons.config.build_dir, "sqfs") - os.remove(src + "frag_only") - os.remove(src + "blks_frag") - os.remove(src + "blks_only") - os.remove(src + "sym") - os.rmdir(src) - os.remove(dest) +class Compression: + def __init__(self, name, files, sizes, block_size = 4096): + self.name = name + self.files = files + self.sizes = sizes + self.mksquashfs_opts = " -b " + str(block_size) + " -comp " + self.name + + def add_opt(self, opt): + self.mksquashfs_opts += " " + opt + + def gen_image(self, build_dir): + src = os.path.join(build_dir, "sqfs_src/") + os.mkdir(src) + for (f, s) in zip(self.files, self.sizes): + sqfs_generate_file(src + f, s) + + # the symbolic link always targets the first file + os.symlink(self.files[0], src + "sym") + + sqfs_img = os.path.join(build_dir, "sqfs-" + self.name) + i_o = src + " " + sqfs_img + opts = self.mksquashfs_opts + try: + subprocess.run(["mksquashfs " + i_o + opts], shell = True, check = True) + except: + print("mksquashfs error. Compression type: " + self.name) + raise RuntimeError + + def clean_source(self, build_dir): + src = os.path.join(build_dir, "sqfs_src/") + for f in self.files: + os.remove(src + f) + os.remove(src + "sym") + os.rmdir(src) + + def cleanup(self, build_dir): + self.clean_source(build_dir) + sqfs_img = os.path.join(build_dir, "sqfs-" + self.name) + os.remove(sqfs_img) + +files = ["blks_only", "blks_frag", "frag_only"] +sizes = [4096, 5100, 100] +gzip = Compression("gzip", files, sizes) +zstd = Compression("zstd", files, sizes) +lzo = Compression("lzo", files, sizes) + +# use fragment blocks for files larger than block_size +gzip.add_opt("-always-use-fragments") +zstd.add_opt("-always-use-fragments") + +# avoid fragments if lzo is used +lzo.add_opt("-no-fragments") + +comp_opts = [gzip, zstd, lzo] diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py index eb1baae5c5..9e90062384 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py @@ -12,23 +12,35 @@ from sqfs_common import * @pytest.mark.buildconfigspec('fs_squashfs') @pytest.mark.requiredtool('mksquashfs') def test_sqfs_load(u_boot_console): - cons = u_boot_console - sqfs_generate_image(cons) + build_dir = u_boot_console.config.build_dir command = "sqfsload host 0 $kernel_addr_r " - path = os.path.join(cons.config.build_dir, "sqfs") - try: + for opt in comp_opts: + # generate and load the squashfs image + try: + opt.gen_image(build_dir) + except RuntimeError: + opt.clean_source(build_dir) + # skip unsupported compression types + continue + + path = os.path.join(build_dir, "sqfs-" + opt.name) output = u_boot_console.run_command("host bind 0 " + path) + output = u_boot_console.run_command(command + "xxx") assert "File not found." in output - output = u_boot_console.run_command(command + "frag_only") - assert "100 bytes read in" in output - output = u_boot_console.run_command(command + "blks_frag") - assert "5100 bytes read in" in output - output = u_boot_console.run_command(command + "blks_only") - assert "4096 bytes read in" in output + + for (f, s) in zip(opt.files, opt.sizes): + try: + output = u_boot_console.run_command(command + f) + assert str(s) in output + except: + assert False + opt.cleanup(build_dir) + + # test symbolic link output = u_boot_console.run_command(command + "sym") - assert "100 bytes read in" in output - except: - sqfs_clean(cons) - sqfs_clean(cons) + assert str(opt.sizes[0]) in output + + # remove generated files + opt.cleanup(build_dir) diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py index 3a7b75c778..a0dca2e2fc 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py @@ -12,16 +12,25 @@ from sqfs_common import * @pytest.mark.buildconfigspec('fs_squashfs') @pytest.mark.requiredtool('mksquashfs') def test_sqfs_ls(u_boot_console): - cons = u_boot_console - sqfs_generate_image(cons) - path = os.path.join(cons.config.build_dir, "sqfs") - try: + build_dir = u_boot_console.config.build_dir + for opt in comp_opts: + try: + opt.gen_image(build_dir) + except RuntimeError: + opt.clean_source(build_dir) + # skip unsupported compression types + continue + path = os.path.join(build_dir, "sqfs-" + opt.name) output = u_boot_console.run_command("host bind 0 " + path) - output = u_boot_console.run_command("sqfsls host 0") - assert "4 file(s), 0 dir(s)" in output - assert "<SYM> sym" in output - output = u_boot_console.run_command("sqfsls host 0 xxx") - assert "** Cannot find directory. **" in output - except: - sqfs_clean(cons) - sqfs_clean(cons) + + try: + # list files in root directory + output = u_boot_console.run_command("sqfsls host 0") + assert str(len(opt.files) + 1) + " file(s), 0 dir(s)" in output + assert "<SYM> sym" in output + output = u_boot_console.run_command("sqfsls host 0 xxx") + assert "** Cannot find directory. **" in output + except: + opt.cleanup(build_dir) + assert False + opt.cleanup(build_dir) |