From e61b41517d2a91080f6416fdfb46efab9e5a55b4 Mon Sep 17 00:00:00 2001 From: Usama Arif Date: Tue, 11 Aug 2020 15:46:03 +0100 Subject: [PATCH 01/23] avb: Make AVB independent of fastboot AVB only uses CONFIG_FASTBOOT_BUF_ADDR from fastboot for memory. This memory is used for assigning temporary buffers. This can be assigned a new variable and used as CONFIG_AVB_BUF_ADDR. This is to support future boards that support AVB but dont support USB and therefore dont support FASTBOOT. Signed-off-by: Usama Arif Cc: Igor Opaniuk Reviewed-by: Tom Rini Acked-by: Igor Opaniuk [trini: Change defaults] Signed-off-by: Tom Rini --- common/Kconfig | 20 +++++++++++++++++++- common/avb_verify.c | 1 - include/avb_verify.h | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) 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 #include #include -#include #include #include #include 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) From 565add124de00c994652a0d2d6d1eb6b2a7c9553 Mon Sep 17 00:00:00 2001 From: Usama Arif Date: Wed, 12 Aug 2020 16:12:53 +0100 Subject: [PATCH 02/23] board: armltd: Add support for Total Compute platform Total Compute is based on ARM architecture and has the following features enabled in u-boot: - PL011 UART - PL180 MMC - NOR Flash - FIT image with Signature - AVB Signed-off-by: Usama Arif Reviewed-by: Tom Rini --- arch/arm/Kconfig | 11 +++ arch/arm/dts/Makefile | 2 + arch/arm/dts/total_compute.dts | 48 ++++++++++++ arch/arm/include/asm/gpio.h | 2 +- board/armltd/total_compute/Kconfig | 12 +++ board/armltd/total_compute/MAINTAINERS | 7 ++ board/armltd/total_compute/Makefile | 6 ++ board/armltd/total_compute/total_compute.c | 67 ++++++++++++++++ configs/total_compute_defconfig | 53 +++++++++++++ include/configs/total_compute.h | 89 ++++++++++++++++++++++ 10 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 arch/arm/dts/total_compute.dts create mode 100644 board/armltd/total_compute/Kconfig create mode 100644 board/armltd/total_compute/MAINTAINERS create mode 100644 board/armltd/total_compute/Makefile create mode 100644 board/armltd/total_compute/total_compute.c create mode 100644 configs/total_compute_defconfig create mode 100644 include/configs/total_compute.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 9b8dadce83..c5ebd59d34 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 @@ -1904,6 +1913,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..4bdfdf123d 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -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/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 #endif #include 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 +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 + +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 + */ + +#include +#include +#include +#include + +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/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/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 + */ + +#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 */ From 10e4d64e345b6b684d27d3da6ed8d887c8e45f76 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Thu, 13 Aug 2020 12:43:22 +0200 Subject: [PATCH 03/23] firmware: psci: Do not bind driver if U-Boot runs in EL3 There is no reason to bind psci driver if U-Boot runs in EL3 because SMC/HVC instructions can't be called. That's why detect this state and don't let user to crash from prompt by performing reset or poweroff commands (if enabled). Signed-off-by: Michal Simek --- drivers/firmware/psci.c | 6 ++++++ 1 file changed, 6 insertions(+) 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 #include #include +#include #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"); From 4a1f0b80adfc9465e8a3efcb884d397e5ab7f07f Mon Sep 17 00:00:00 2001 From: John Chau Date: Mon, 17 Aug 2020 15:53:01 +0800 Subject: [PATCH 04/23] cmd: fix clone coverity scan This patch fixes coverity scan MISSING_BREAK issues, and also an error on block size check. Signed-off-by: John Chau --- cmd/clone.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; From 10f7cf5f12a8721d6c985d4de11dac4d19e0e47e Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Tue, 18 Aug 2020 17:17:21 +0200 Subject: [PATCH 05/23] fs/squashfs: Add init and clean-up functions to decompression Add sqfs_decompressor_init() and sqfs_decompressor_cleanup(). These functions are called respectively in sqfs_probe() and sqfs_close(). For now, only ZSTD requires an initialization logic. ZSTD support will be added in a follow-up commit. Move squashfs_ctxt definition to sqfs_filesystem.h. This structure is passed to sqfs_decompressor_init() and sqfs_decompressor_cleanup(), so it can no longer be local to sqfs.c. Signed-off-by: Joao Marcos Costa --- fs/squashfs/sqfs.c | 15 +++++++++------ fs/squashfs/sqfs_decompressor.c | 34 ++++++++++++++++++++++++++++++--- fs/squashfs/sqfs_decompressor.h | 3 +++ fs/squashfs/sqfs_filesystem.h | 9 ++++++++- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 340e5ebdb9..598b42cd34 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) @@ -1023,6 +1017,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; } @@ -1525,6 +1527,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..633a8a1818 100644 --- a/fs/squashfs/sqfs_decompressor.c +++ b/fs/squashfs/sqfs_decompressor.c @@ -14,9 +14,37 @@ #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_ZLIB) + case SQFS_COMP_ZLIB: + 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_ZLIB) + case SQFS_COMP_ZLIB: + break; +#endif + } +} + #if IS_ENABLED(CONFIG_ZLIB) static void zlib_decompression_status(int ret) { @@ -35,14 +63,14 @@ static void zlib_decompression_status(int ret) #endif int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len, - void *source, u32 lenp) + void *source, u32 src_len) { int ret = 0; switch (comp_type) { #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; diff --git a/fs/squashfs/sqfs_decompressor.h b/fs/squashfs/sqfs_decompressor.h index 378965dda8..450257e5ce 100644 --- a/fs/squashfs/sqfs_decompressor.h +++ b/fs/squashfs/sqfs_decompressor.h @@ -9,6 +9,7 @@ #define SQFS_DECOMPRESSOR_H #include +#include "sqfs_filesystem.h" #define SQFS_COMP_ZLIB 1 #define SQFS_COMP_LZMA 2 @@ -54,5 +55,7 @@ union squashfs_compression_opts { int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len, void *source, u32 lenp); +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_filesystem.h b/fs/squashfs/sqfs_filesystem.h index d63e3a41ad..ff2b0b1d34 100644 --- a/fs/squashfs/sqfs_filesystem.h +++ b/fs/squashfs/sqfs_filesystem.h @@ -9,8 +9,9 @@ #define SQFS_FILESYSTEM_H #include -#include #include +#include +#include #define SQFS_UNCOMPRESSED_DATA 0x0002 #define SQFS_MAGIC_NUMBER 0x73717368 @@ -72,6 +73,12 @@ 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; +}; + struct squashfs_directory_index { u32 index; u32 start; From cdc114415cb9b326545aaaf6226ed3622e057067 Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Tue, 18 Aug 2020 17:17:22 +0200 Subject: [PATCH 06/23] fs/squashfs: replace sqfs_decompress() parameter Replace 'u16 comp_type' by a reference to squashfs_ctxt structure. Signed-off-by: Joao Marcos Costa --- fs/squashfs/sqfs.c | 25 +++++++++---------------- fs/squashfs/sqfs_decompressor.c | 5 +++-- fs/squashfs/sqfs_decompressor.h | 4 ++-- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 598b42cd34..9bd7b98d88 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -104,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; @@ -165,7 +163,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; @@ -629,13 +627,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; 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) / @@ -680,7 +677,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) { @@ -711,15 +708,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; 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); @@ -773,7 +768,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) { @@ -1197,7 +1192,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}; @@ -1213,8 +1208,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. @@ -1346,7 +1339,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; @@ -1396,7 +1389,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) { diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c index 633a8a1818..cf388ace58 100644 --- a/fs/squashfs/sqfs_decompressor.c +++ b/fs/squashfs/sqfs_decompressor.c @@ -62,9 +62,10 @@ static void zlib_decompression_status(int ret) } #endif -int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len, - void *source, u32 src_len) +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) { diff --git a/fs/squashfs/sqfs_decompressor.h b/fs/squashfs/sqfs_decompressor.h index 450257e5ce..892cfb6974 100644 --- a/fs/squashfs/sqfs_decompressor.h +++ b/fs/squashfs/sqfs_decompressor.h @@ -53,8 +53,8 @@ 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); From 9c948f536fec115b590760c2e9e333945dfde990 Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Tue, 18 Aug 2020 17:17:23 +0200 Subject: [PATCH 07/23] fs/squashfs: add support for ZSTD decompression Add call to ZSTD's ZSTD_decompressDCtx(). In this use case, the caller can upper bound the decompressed size, which will be the SquashFS data block (or metadata block) size, so there is no need to use streaming API. Add ZSTD's worskpace to squashfs_ctxt structure. Signed-off-by: Joao Marcos Costa --- fs/squashfs/sqfs_decompressor.c | 42 +++++++++++++++++++++++++++++++++ fs/squashfs/sqfs_filesystem.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c index cf388ace58..9457ee5f0f 100644 --- a/fs/squashfs/sqfs_decompressor.c +++ b/fs/squashfs/sqfs_decompressor.c @@ -13,6 +13,10 @@ #include #endif +#if IS_ENABLED(CONFIG_ZSTD) +#include +#endif + #include "sqfs_decompressor.h" #include "sqfs_utils.h" @@ -24,6 +28,13 @@ int sqfs_decompressor_init(struct squashfs_ctxt *ctxt) #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"); @@ -41,6 +52,11 @@ void sqfs_decompressor_cleanup(struct squashfs_ctxt *ctxt) #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 } } @@ -62,6 +78,22 @@ static void zlib_decompression_status(int ret) } #endif +#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) { @@ -79,6 +111,16 @@ int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest, 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_filesystem.h b/fs/squashfs/sqfs_filesystem.h index ff2b0b1d34..856cd15e34 100644 --- a/fs/squashfs/sqfs_filesystem.h +++ b/fs/squashfs/sqfs_filesystem.h @@ -77,6 +77,9 @@ 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 { From 6dfed163bd842bf98fd17875067bf8643819a879 Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Tue, 18 Aug 2020 17:17:24 +0200 Subject: [PATCH 08/23] fs/squashfs: add support for LZO decompression Add call to lzo's lzo1x_decompress_safe() into sqfs_decompress(). U-Boot's LZO sources may still have some unsolved issues that could make the decompression crash when dealing with fragmented files, so those should be avoided. The "-no-fragments" option can be passed to mksquashfs. Signed-off-by: Joao Marcos Costa --- fs/squashfs/sqfs_decompressor.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c index 9457ee5f0f..d69ddb24a4 100644 --- a/fs/squashfs/sqfs_decompressor.c +++ b/fs/squashfs/sqfs_decompressor.c @@ -9,6 +9,11 @@ #include #include #include + +#if IS_ENABLED(CONFIG_LZO) +#include +#endif + #if IS_ENABLED(CONFIG_ZLIB) #include #endif @@ -25,6 +30,10 @@ 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; @@ -49,6 +58,10 @@ 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; @@ -101,6 +114,18 @@ int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest, 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, src_len); From 91f6c1ca2e4400f30b5faee04f1dd9001abd326f Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Tue, 18 Aug 2020 17:17:25 +0200 Subject: [PATCH 09/23] test/py: Add tests for LZO and ZSTD Improve SquashFS tests architecture. Add 'Compression' class. LZO algorithm may crash if the file is fragmented, so the fragments are disabled when testing LZO. Signed-off-by: Joao Marcos Costa --- .../test_fs/test_squashfs/sqfs_common.py | 74 ++++++++++++++----- .../test_fs/test_squashfs/test_sqfs_load.py | 40 ++++++---- .../test_fs/test_squashfs/test_sqfs_ls.py | 33 ++++++--- 3 files changed, 101 insertions(+), 46 deletions(-) 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") +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 -# 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) + 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" 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" 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) From 6b0ddd1fbc6c8f7cbd0418e8a87d02404ad3dd9b Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Wed, 19 Aug 2020 18:07:32 +0900 Subject: [PATCH 10/23] virtio_blk: set log2blksz correctly 'log2blksz' in blk_desc structure must always be initialized, otherwise it will cause a lot of weird failures in file operations. For example, fs_set_blk_dev[_with_part]() examines a block device against every file system with its probe function. In particular, ext4 file system's ext4_probe() will calls fs_devread() to fetch a super block. If log2blksz is 0, the actual 'read' size, i.e. block_len >> log2blksz, is much bigger than a buffer's size, and it can end up with memory corruption. Signed-off-by: AKASHI Takahiro Fixes: f4802209e59d ("virtio: Add block driver support") Reviewed-by: Bin Meng --- drivers/virtio/virtio_blk.c | 1 + 1 file changed, 1 insertion(+) 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; From c9875a5fe85901b272c8e7db1b9bce513f02f1af Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Wed, 19 Aug 2020 18:28:41 +0200 Subject: [PATCH 11/23] fs/squashfs: Fix Coverity Scan defects Fix defects such as uninitialized variables and untrusted pointer operations. Most part of the tainted variables and the related defects actually comes from Linux's macro get_unaligned_le**, extensively used in SquashFS code. Add sanity checks for those variables. Signed-off-by: Joao Marcos Costa --- fs/squashfs/sqfs.c | 40 +++++++++++++++++++++++++++++----------- fs/squashfs/sqfs_dir.c | 3 +++ fs/squashfs/sqfs_inode.c | 5 ++++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 9bd7b98d88..f67f7c4a40 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -154,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; @@ -272,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) @@ -282,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++) { @@ -292,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; } /* @@ -428,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; @@ -630,7 +636,7 @@ static int sqfs_read_inode_table(unsigned char **inode_table) 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; table_size = get_unaligned_le64(&sblk->directory_table_start) - @@ -685,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); @@ -694,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; } @@ -712,7 +719,7 @@ static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list) 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; /* DIRECTORY TABLE */ @@ -781,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); @@ -790,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; } @@ -1138,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), @@ -1145,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)); } @@ -1168,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), @@ -1175,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)); } 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_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); From 626892a779addb9604387ece522e3410d3ef3aa5 Mon Sep 17 00:00:00 2001 From: Frank Wunderlich Date: Thu, 20 Aug 2020 16:37:52 +0200 Subject: [PATCH 12/23] phy: mtk-tphy: make shared reg optional for v1 make the shared reg optional when version is v1 for sata Suggested-by: Chunfeng Yun Signed-off-by: Frank Wunderlich Reviewed-by: Chunfeng Yun --- drivers/phy/phy-mtk-tphy.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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) { From a300d696caee9e97da5a0b835451d27c98e07f8f Mon Sep 17 00:00:00 2001 From: Frank Wunderlich Date: Thu, 20 Aug 2020 16:37:53 +0200 Subject: [PATCH 13/23] reset: drop unnecessary comment for pciesys after review from sam this comment should be removed Signed-off-by: Frank Wunderlich --- drivers/clk/mediatek/clk-mt7622.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/clk/mediatek/clk-mt7622.c b/drivers/clk/mediatek/clk-mt7622.c index d53ed69189..a1a35f72a3 100644 --- a/drivers/clk/mediatek/clk-mt7622.c +++ b/drivers/clk/mediatek/clk-mt7622.c @@ -599,7 +599,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"); From a7e0ef15ddee2751110766e2abc010d2ec9325f8 Mon Sep 17 00:00:00 2001 From: Frank Wunderlich Date: Thu, 20 Aug 2020 16:37:54 +0200 Subject: [PATCH 14/23] ahci: mediatek: fix copyright and author-lines after review of sam copyright should be on one line and link should not between author lines just remove the link and put ryder first as he is author of linux-driver Signed-off-by: Frank Wunderlich --- drivers/ata/mtk_ahci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 - * based on https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/ata/ahci_mtk.c * Author: Ryder Lee + * Author: Frank Wunderlich */ #include From 9f25aa13ea2f106885ea52a1039b9c6e7a677a35 Mon Sep 17 00:00:00 2001 From: Frank Wunderlich Date: Thu, 20 Aug 2020 16:37:55 +0200 Subject: [PATCH 15/23] clk: mt7622: add needed clocks for ssusb-node MT7622 needs additional clock definitions to work properly Signed-off-by: Frank Wunderlich --- drivers/clk/mediatek/clk-mt7622.c | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/clk/mediatek/clk-mt7622.c b/drivers/clk/mediatek/clk-mt7622.c index a1a35f72a3..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, @@ -630,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" }, { } @@ -670,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, @@ -746,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, +}; From 28e1b1df3bccc0fd47e9c2a2b058c0680b930e23 Mon Sep 17 00:00:00 2001 From: Frank Wunderlich Date: Thu, 20 Aug 2020 16:37:56 +0200 Subject: [PATCH 16/23] arm: dts: rename mt7622-bpi-r64.dts rename mt7622-bpi-r64.dts to mt7622-bananapi-bpi-r64.dts to follow naming convensions Signed-off-by: Frank Wunderlich --- arch/arm/dts/Makefile | 2 +- .../arm/dts/{mt7622-bpi-r64.dts => mt7622-bananapi-bpi-r64.dts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename arch/arm/dts/{mt7622-bpi-r64.dts => mt7622-bananapi-bpi-r64.dts} (100%) diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index 4bdfdf123d..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 \ diff --git a/arch/arm/dts/mt7622-bpi-r64.dts b/arch/arm/dts/mt7622-bananapi-bpi-r64.dts similarity index 100% rename from arch/arm/dts/mt7622-bpi-r64.dts rename to arch/arm/dts/mt7622-bananapi-bpi-r64.dts From a13666b20598a77931c6d9642ba9e8870d85e797 Mon Sep 17 00:00:00 2001 From: Frank Wunderlich Date: Thu, 20 Aug 2020 16:37:57 +0200 Subject: [PATCH 17/23] arm: dts: mt7622: add USB nodes Add DTS nodes for MT7622/BPI-R64 Signed-off-by: Frank Wunderlich Reviewed-by: Chunfeng Yun --- arch/arm/dts/mt7622-bananapi-bpi-r64.dts | 8 ++++ arch/arm/dts/mt7622-rfb.dts | 8 ++++ arch/arm/dts/mt7622.dtsi | 56 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/arch/arm/dts/mt7622-bananapi-bpi-r64.dts b/arch/arm/dts/mt7622-bananapi-bpi-r64.dts index 51287cea3a..4f2f04851d 100644 --- a/arch/arm/dts/mt7622-bananapi-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 = ; + 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>; From 35051db978b5f9ecd773601e5e596dbe092ab8d1 Mon Sep 17 00:00:00 2001 From: Frank Wunderlich Date: Thu, 20 Aug 2020 16:37:58 +0200 Subject: [PATCH 18/23] arm: dts: mt7623: add USB nodes This adds USB nodes for MT7623/BPI-R2 Signed-off-by: Frank Wunderlich Reviewed-by: Chunfeng Yun --- arch/arm/dts/mt7623.dtsi | 46 ++++++++++++++++++++++++ arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | 16 +++++++++ 2 files changed, 62 insertions(+) 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"; +}; From 4da1365d5cabcf25fc57f2abf6931d5a6cfc23a3 Mon Sep 17 00:00:00 2001 From: Anastasiia Lukianenko Date: Fri, 21 Aug 2020 12:10:00 +0300 Subject: [PATCH 19/23] board: xen: Remove unnecessary CONFIG_BOARD_EARLY_INIT_F define and board_early_init_f function Signed-off-by: Anastasiia Lukianenko Reviewed-by: Tom Rini --- board/xen/xenguest_arm64/xenguest_arm64.c | 5 ----- include/configs/xenguest_arm64.h | 2 -- 2 files changed, 7 deletions(-) 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/include/configs/xenguest_arm64.h b/include/configs/xenguest_arm64.h index db3059a82c..e88ab87a1d 100644 --- a/include/configs/xenguest_arm64.h +++ b/include/configs/xenguest_arm64.h @@ -9,8 +9,6 @@ #include #endif -#define CONFIG_BOARD_EARLY_INIT_F - #define CONFIG_EXTRA_ENV_SETTINGS #undef CONFIG_NR_DRAM_BANKS From 607274f7f67e14aca0f0d1cde55569faa48f0183 Mon Sep 17 00:00:00 2001 From: Anastasiia Lukianenko Date: Fri, 21 Aug 2020 12:10:01 +0300 Subject: [PATCH 20/23] MAINTAINERS: Add maintainers to XEN section Signed-off-by: Anastasiia Lukianenko Reviewed-by: Simon Glass --- MAINTAINERS | 16 ++++++++++++++++ board/xen/xenguest_arm64/MAINTAINERS | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) 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 +M: Oleksandr Andrushchenko +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 S: Maintained 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 +M: Anastasiia Lukianenko +M: Oleksandr Andrushchenko S: Maintained F: board/xen/xenguest_arm64/ F: doc/board/xen/ From 32eac63af3287674f73933dfff6eae22a5b77c76 Mon Sep 17 00:00:00 2001 From: Anastasiia Lukianenko Date: Fri, 21 Aug 2020 12:10:02 +0300 Subject: [PATCH 21/23] board: xen: Remove CONFIG_CMD_RUN define and clean xenguest_arm64_defconfig CONFIG_CMD_RUN is set on by default in Kconfig. Create xenguest_arm64_defconfig by using savedefconfig to avoid unnecessary options. Signed-off-by: Anastasiia Lukianenko Reviewed-by: Simon Glass --- configs/xenguest_arm64_defconfig | 75 ++++++++++++-------------------- include/configs/xenguest_arm64.h | 2 - 2 files changed, 27 insertions(+), 50 deletions(-) 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/include/configs/xenguest_arm64.h b/include/configs/xenguest_arm64.h index e88ab87a1d..f3092cb2f8 100644 --- a/include/configs/xenguest_arm64.h +++ b/include/configs/xenguest_arm64.h @@ -39,8 +39,6 @@ #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" \ From d226b3cd259baa8f39c595f1176d4770000cfcd5 Mon Sep 17 00:00:00 2001 From: Anastasiia Lukianenko Date: Fri, 21 Aug 2020 12:10:03 +0300 Subject: [PATCH 22/23] board: xen: Remove unnecessary CONFIG_INITRD_TAG and CONFIG_CMDLINE_TAG Signed-off-by: Anastasiia Lukianenko Reviewed-by: Simon Glass --- include/configs/xenguest_arm64.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/configs/xenguest_arm64.h b/include/configs/xenguest_arm64.h index f3092cb2f8..c44381e966 100644 --- a/include/configs/xenguest_arm64.h +++ b/include/configs/xenguest_arm64.h @@ -36,9 +36,6 @@ #define CONFIG_OF_SYSTEM_SETUP -#define CONFIG_CMDLINE_TAG 1 -#define CONFIG_INITRD_TAG 1 - #undef CONFIG_EXTRA_ENV_SETTINGS #define CONFIG_EXTRA_ENV_SETTINGS \ "loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \ From 3337b291442e31b1db0ff5975f74fec7d9741794 Mon Sep 17 00:00:00 2001 From: Anastasiia Lukianenko Date: Fri, 21 Aug 2020 12:10:04 +0300 Subject: [PATCH 23/23] xen: Code style conformity Cleaning up the following: ERROR: do not use assignment in if condition #281: FILE: drivers/xen/pvblock.c:260: + if ((err = xenbus_switch_state(XBT_NIL, nodename, CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "err" #52: FILE: drivers/xen/pvblock.c:298: + if (err != NULL) { ERROR: do not use assignment in if condition #176: FILE: drivers/xen/gnttab.c:103: + if ((flags = nflags) & (GTF_reading | GTF_writing)) { WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 #329: FILE: include/xen/gnttab.h:1: +/* WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead #330: FILE: include/xen/gnttab.h:2: + * SPDX-License-Identifier: GPL-2.0 ERROR: do not use assignment in if condition #630: FILE: lib/sscanf.c:558: + if ((n = inr) < width) { Signed-off-by: Anastasiia Lukianenko Reviewed-by: Simon Glass --- drivers/xen/gnttab.c | 3 ++- drivers/xen/pvblock.c | 12 ++++++------ include/xen/gnttab.h | 3 +-- lib/sscanf.c | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-) 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/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 * (C) 2006, Grzegorz Milos 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;