From 54ee5ae84191aa7c53c9de709f6c66411d3e2dda Mon Sep 17 00:00:00 2001 From: Rogier Stam Date: Wed, 11 May 2022 23:20:28 +0200 Subject: [PATCH 01/13] Add SCSI scan for ENV in EXT4 or FAT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When having environment stored in EXT4 or FAT and using an AHCI or SCSI device / partition the scan would not be performed early enough and hence the device would not be recognized. This change adds the scan when the interface is "scsi" in a similar way to mmc_initialize. Signed-off-by: Rogier Stam Reviewed-by: Pali Rohár --- env/ext4.c | 5 +++++ env/fat.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/env/ext4.c b/env/ext4.c index 9f65afb8a4..47e05a4891 100644 --- a/env/ext4.c +++ b/env/ext4.c @@ -31,6 +31,7 @@ #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -146,6 +147,10 @@ static int env_ext4_load(void) if (!strcmp(ifname, "mmc")) mmc_initialize(NULL); #endif +#if defined(CONFIG_AHCI) || defined(CONFIG_SCSI) + if (!strcmp(ifname, "scsi")) + scsi_scan(true); +#endif part = blk_get_device_part_str(ifname, dev_and_part, &dev_desc, &info, 1); diff --git a/env/fat.c b/env/fat.c index 6251d9649b..3172130d75 100644 --- a/env/fat.c +++ b/env/fat.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -128,7 +129,12 @@ static int env_fat_load(void) if (!strcmp(ifname, "mmc")) mmc_initialize(NULL); #endif - +#ifndef CONFIG_SPL_BUILD +#if defined(CONFIG_AHCI) || defined(CONFIG_SCSI) + if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "scsi")) + scsi_scan(true); +#endif +#endif part = blk_get_device_part_str(ifname, dev_and_part, &dev_desc, &info, 1); if (part < 0) From 69ca709d0fb001851f443b0b744c6d65bb6c22c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 30 May 2022 11:09:11 +0200 Subject: [PATCH 02/13] ubifs: Fix reference count leak in ubifsumount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original ubifs code was designed that after ubifs_umount() call it is required to also call ubi_close_volume() which closes underlying UBI volume. But U-Boot ubifs modification have not implemented it properly which caused that ubifsumount command contains resource leak. It can be observed by calling simple sequence of commands: => ubi part mtd2 ubi0: attaching mtd2 ... => ubifsmount ubi0 => ubifsumount Unmounting UBIFS volume rootfs! => ubi detach ubi0 error: ubi_detach_mtd_dev: ubi0 reference count 1, destroy anyway ubi0: detaching mtd2 ubi0: mtd2 is detached Fix this issue by calling ubi_close_volume() and mutex_unlock() in directly in ubifs_umount() function before freeing U-Boot's global ubifs_sb. And remove duplicate calls of these two functions in remaining places. Note that when ubifs_umount() is not called then during error handling is still needed to call ubi_close_volume() and mutex_unlock. With this change ubifsumount command does not throw that error anymore: => ubi part rootfs ubi0: attaching mtd2 ... => ubifsmount ubi0 => ubifsumount Unmounting UBIFS volume rootfs! => ubi detach ubi0: detaching mtd2 ubi0: mtd2 is detached Signed-off-by: Pali Rohár --- fs/ubifs/super.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index e3a4c0bca2..034c41a703 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -1757,6 +1757,8 @@ void ubifs_umount(struct ubifs_info *c) kfree(c->bottom_up_buf); ubifs_debugging_exit(c); #ifdef __UBOOT__ + ubi_close_volume(c->ubi); + mutex_unlock(&c->umount_mutex); /* Finally free U-Boot's global copy of superblock */ if (ubifs_sb != NULL) { free(ubifs_sb->s_fs_info); @@ -2058,9 +2060,9 @@ static void ubifs_put_super(struct super_block *sb) ubifs_umount(c); #ifndef __UBOOT__ bdi_destroy(&c->bdi); -#endif ubi_close_volume(c->ubi); mutex_unlock(&c->umount_mutex); +#endif } #endif @@ -2327,6 +2329,9 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent) out_umount: ubifs_umount(c); +#ifdef __UBOOT__ + goto out; +#endif out_unlock: mutex_unlock(&c->umount_mutex); #ifndef __UBOOT__ From e6ca148104fe66ccc5991b06a88f431c9537c366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Tue, 31 May 2022 10:32:36 +0200 Subject: [PATCH 03/13] distroboot: Fix ubifs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix multiple issues in ubifs distroboot code: U-Boot supports attaching only one MTD device as UBI at the time. So always call 'ubifsmount ubi0:${bootubivol}' for mounting UBI volume ${bootubivol}. Usage of 'ubi${devnum}' is incorrect as 'ubi part' command attach MTD device always as UBI device ubi0. Set distroboot ${bootfstype} variable to ubifs in ubifs_boot command. Distroboot scripts require ${bootfstype} variable to be properly set and it is already set for all other boot types. Set distroboot ${distro_bootpart} variable to ${bootubivol} value. UBI device does not have partitions, but has volumes. Distroboot scripts require something to be set in ${distro_bootpart} variable, so set it to the UBI volume which is currently mounted by ubifs. Set distroboot ${devnum} variable to fixed string "ubi0". ubifs code differs from the other partition code that it requires "ubi" prefix before number. Explicitly unmount ubifs volume after loading all data from it. This allows to detach UBI device from MTD device. Move definition of MTD device with UBI and UBI volume with ubifs filesystem from global env variables ${bootubipart} and ${bootubivol} into the distroboot "func" macro, defined in board include config files. UBIFS distroboot macros then set ${bootubipart} and ${bootubivol} local variables for compatibility with existing distroboot scripts. This last change allows to define more UBIFS target devices and make it clear what is boot MTD/UBI device. All board include config files are adjusted to use this new scheme of specifying boot MTD/UBI device. Signed-off-by: Pali Rohár Acked-by: Frieder Schrempf --- include/config_distro_bootcmd.h | 27 ++++++++++++++++----------- include/configs/am335x_guardian.h | 3 +-- include/configs/colibri-imx6ull.h | 1 - include/configs/colibri_imx7.h | 1 - include/configs/kontron-sl-mx6ul.h | 2 +- include/configs/mys_6ulx.h | 2 +- include/configs/npi_imx6ull.h | 2 +- include/configs/omap3_beagle.h | 4 +--- include/configs/omap3_evm.h | 4 +--- include/configs/pcl063.h | 2 +- include/configs/stm32mp15_common.h | 2 +- include/configs/uniphier.h | 2 +- 12 files changed, 25 insertions(+), 27 deletions(-) diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h index c55023889c..c6e9c49741 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -70,18 +70,23 @@ #ifdef CONFIG_CMD_UBIFS #define BOOTENV_SHARED_UBIFS \ "ubifs_boot=" \ - "env exists bootubipart || " \ - "env set bootubipart UBI; " \ - "env exists bootubivol || " \ - "env set bootubivol boot; " \ "if ubi part ${bootubipart} && " \ - "ubifsmount ubi${devnum}:${bootubivol}; " \ + "ubifsmount ubi0:${bootubivol}; " \ "then " \ "devtype=ubi; " \ + "devnum=ubi0; " \ + "bootfstype=ubifs; " \ + "distro_bootpart=${bootubivol}; " \ "run scan_dev_for_boot; " \ + "ubifsumount; " \ "fi\0" -#define BOOTENV_DEV_UBIFS BOOTENV_DEV_BLKDEV -#define BOOTENV_DEV_NAME_UBIFS BOOTENV_DEV_NAME_BLKDEV +#define BOOTENV_DEV_UBIFS(devtypeu, devtypel, instance, bootubipart, bootubivol) \ + "bootcmd_ubifs" #instance "=" \ + "bootubipart=" #bootubipart "; " \ + "bootubivol=" #bootubivol "; " \ + "run ubifs_boot\0" +#define BOOTENV_DEV_NAME_UBIFS(devtypeu, devtypel, instance, bootubipart, bootubivol) \ + #devtypel #instance " " #else #define BOOTENV_SHARED_UBIFS #define BOOTENV_DEV_UBIFS \ @@ -411,13 +416,13 @@ BOOT_TARGET_DEVICES_references_PXE_without_CONFIG_CMD_DHCP_or_PXE #endif -#define BOOTENV_DEV_NAME(devtypeu, devtypel, instance) \ - BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance) +#define BOOTENV_DEV_NAME(devtypeu, devtypel, instance, ...) \ + BOOTENV_DEV_NAME_##devtypeu(devtypeu, devtypel, instance, ## __VA_ARGS__) #define BOOTENV_BOOT_TARGETS \ "boot_targets=" BOOT_TARGET_DEVICES(BOOTENV_DEV_NAME) "\0" -#define BOOTENV_DEV(devtypeu, devtypel, instance) \ - BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance) +#define BOOTENV_DEV(devtypeu, devtypel, instance, ...) \ + BOOTENV_DEV_##devtypeu(devtypeu, devtypel, instance, ## __VA_ARGS__) #define BOOTENV \ BOOTENV_SHARED_HOST \ BOOTENV_SHARED_MMC \ diff --git a/include/configs/am335x_guardian.h b/include/configs/am335x_guardian.h index 7a9928fba7..7fa1847c1f 100644 --- a/include/configs/am335x_guardian.h +++ b/include/configs/am335x_guardian.h @@ -27,7 +27,7 @@ "ramdisk_addr_r=0x88080000\0" \ #define BOOT_TARGET_DEVICES(func) \ - func(UBIFS, ubifs, 0) + func(UBIFS, ubifs, 0, UBI, rootfs) #define AM335XX_BOARD_FDTFILE "fdtfile=" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" @@ -51,7 +51,6 @@ BOOTENV \ GUARDIAN_DEFAULT_PROD_ENV \ "backlight_brightness=50\0" \ - "bootubivol=rootfs\0" \ "distro_bootcmd=" \ "setenv rootflags \"bulk_read,chk_data_crc\"; " \ "setenv ethact usb_ether; " \ diff --git a/include/configs/colibri-imx6ull.h b/include/configs/colibri-imx6ull.h index 528c7c98d2..04cde9530a 100644 --- a/include/configs/colibri-imx6ull.h +++ b/include/configs/colibri-imx6ull.h @@ -90,7 +90,6 @@ UBI_BOOTCMD \ UBOOT_UPDATE \ "boot_script_dhcp=boot.scr\0" \ - "bootubipart=ubi\0" \ "console=ttymxc0\0" \ "defargs=user_debug=30\0" \ "fdt_board=eval-v3\0" \ diff --git a/include/configs/colibri_imx7.h b/include/configs/colibri_imx7.h index 8a6536eec8..9543e0233e 100644 --- a/include/configs/colibri_imx7.h +++ b/include/configs/colibri_imx7.h @@ -130,7 +130,6 @@ UBOOT_UPDATE \ "boot_file=zImage\0" \ "boot_script_dhcp=boot.scr\0" \ - "bootubipart=ubi\0" \ "console=ttymxc0\0" \ "defargs=\0" \ "fdt_board=eval-v3\0" \ diff --git a/include/configs/kontron-sl-mx6ul.h b/include/configs/kontron-sl-mx6ul.h index 512cef09f8..7aac5d3f5a 100644 --- a/include/configs/kontron-sl-mx6ul.h +++ b/include/configs/kontron-sl-mx6ul.h @@ -37,7 +37,7 @@ #define BOOT_TARGET_DEVICES(func) \ func(MMC, mmc, 1) \ func(MMC, mmc, 0) \ - func(UBIFS, ubifs, 0) \ + func(UBIFS, ubifs, 0, UBI, boot) \ func(USB, usb, 0) \ func(PXE, pxe, na) \ func(DHCP, dhcp, na) diff --git a/include/configs/mys_6ulx.h b/include/configs/mys_6ulx.h index b968923819..4162ee8caa 100644 --- a/include/configs/mys_6ulx.h +++ b/include/configs/mys_6ulx.h @@ -50,7 +50,7 @@ #define BOOT_TARGET_DEVICES(func) \ func(MMC, mmc, 0) \ - func(UBIFS, ubifs, 0) \ + func(UBIFS, ubifs, 0, UBI, boot) \ func(PXE, pxe, na) \ func(DHCP, dhcp, na) diff --git a/include/configs/npi_imx6ull.h b/include/configs/npi_imx6ull.h index 6cdb1afcd9..217427a302 100644 --- a/include/configs/npi_imx6ull.h +++ b/include/configs/npi_imx6ull.h @@ -58,7 +58,7 @@ #define BOOT_TARGET_DEVICES(func) \ func(MMC, mmc, 0) \ - func(UBIFS, ubifs, 0) \ + func(UBIFS, ubifs, 0, UBI, boot) \ func(PXE, pxe, na) \ func(DHCP, dhcp, na) diff --git a/include/configs/omap3_beagle.h b/include/configs/omap3_beagle.h index ab742798b9..2cd42e5a1d 100644 --- a/include/configs/omap3_beagle.h +++ b/include/configs/omap3_beagle.h @@ -62,7 +62,7 @@ #define BOOT_TARGET_DEVICES(func) \ func(MMC, mmc, 0) \ func(LEGACY_MMC, legacy_mmc, 0) \ - func(UBIFS, ubifs, 0) \ + func(UBIFS, ubifs, 0, rootfs, rootfs) \ func(NAND, nand, 0) #else /* !CONFIG_MTD_RAW_NAND */ @@ -84,8 +84,6 @@ "bootenv=uEnv.txt\0" \ "bootfile=zImage\0" \ "bootpart=0:2\0" \ - "bootubivol=rootfs\0" \ - "bootubipart=rootfs\0" \ "usbtty=cdc_acm\0" \ "mpurate=auto\0" \ "buddy=none\0" \ diff --git a/include/configs/omap3_evm.h b/include/configs/omap3_evm.h index 1b94f8efa2..2683d4c7ea 100644 --- a/include/configs/omap3_evm.h +++ b/include/configs/omap3_evm.h @@ -56,7 +56,7 @@ #define BOOT_TARGET_DEVICES(func) \ func(MMC, mmc, 0) \ func(LEGACY_MMC, legacy_mmc, 0) \ - func(UBIFS, ubifs, 0) \ + func(UBIFS, ubifs, 0, rootfs, rootfs) \ func(NAND, nand, 0) #else /* !CONFIG_MTD_RAW_NAND */ @@ -82,8 +82,6 @@ "bootenv=uEnv.txt\0" \ "bootfile=zImage\0" \ "bootpart=0:2\0" \ - "bootubivol=rootfs\0" \ - "bootubipart=rootfs\0" \ "optargs=\0" \ "nandroot=ubi0:rootfs ubi.mtd=rootfs rw noinitrd\0" \ "nandrootfstype=ubifs rootwait\0" \ diff --git a/include/configs/pcl063.h b/include/configs/pcl063.h index 6683f21d15..6e593da936 100644 --- a/include/configs/pcl063.h +++ b/include/configs/pcl063.h @@ -62,7 +62,7 @@ #define BOOT_TARGET_DEVICES(func) \ func(MMC, mmc, 0) \ - func(UBIFS, ubifs, 0) \ + func(UBIFS, ubifs, 0, UBI, boot) \ func(PXE, pxe, na) \ func(DHCP, dhcp, na) diff --git a/include/configs/stm32mp15_common.h b/include/configs/stm32mp15_common.h index 56fb4d38e4..c5412ffeb3 100644 --- a/include/configs/stm32mp15_common.h +++ b/include/configs/stm32mp15_common.h @@ -57,7 +57,7 @@ #endif #ifdef CONFIG_CMD_UBIFS -#define BOOT_TARGET_UBIFS(func) func(UBIFS, ubifs, 0) +#define BOOT_TARGET_UBIFS(func) func(UBIFS, ubifs, 0, UBI, boot) #else #define BOOT_TARGET_UBIFS(func) #endif diff --git a/include/configs/uniphier.h b/include/configs/uniphier.h index 15d41fba95..15ae0844c1 100644 --- a/include/configs/uniphier.h +++ b/include/configs/uniphier.h @@ -19,7 +19,7 @@ #endif #ifdef CONFIG_CMD_UBIFS -#define BOOT_TARGET_DEVICE_UBIFS(func) func(UBIFS, ubifs, 0) +#define BOOT_TARGET_DEVICE_UBIFS(func) func(UBIFS, ubifs, 0, UBI, boot) #else #define BOOT_TARGET_DEVICE_UBIFS(func) #endif From ebaa3d053e5e36bfc8c826e9a87a05d65a2b8ab0 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 12 Jun 2022 12:28:22 +0000 Subject: [PATCH 04/13] test: fix CONFIG_ACPIGEN dependencies Some tests cannot be built with CONFIG_ACPIGEN=n. Consider this in the Makefile. Signed-off-by: Heinrich Schuchardt --- test/dm/Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/dm/Makefile b/test/dm/Makefile index caea52f4e2..52fe178a82 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -18,9 +18,13 @@ obj-$(CONFIG_UT_DM) += core.o obj-$(CONFIG_UT_DM) += read.o obj-$(CONFIG_UT_DM) += phys2bus.o ifneq ($(CONFIG_SANDBOX),) -obj-$(CONFIG_ACPIGEN) += acpi.o -obj-$(CONFIG_ACPIGEN) += acpigen.o -obj-$(CONFIG_ACPIGEN) += acpi_dp.o +ifeq ($(CONFIG_ACPIGEN),y) +obj-y += acpi.o +obj-y += acpigen.o +obj-y += acpi_dp.o +obj-(CONFIG_DM_GPIO) += gpio.o +obj-y += irq.o +endif obj-$(CONFIG_ADC) += adc.o obj-$(CONFIG_SOUND) += audio.o obj-$(CONFIG_AXI) += axi.o @@ -43,11 +47,9 @@ ifneq ($(CONFIG_EFI_PARTITION),) obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o endif obj-$(CONFIG_FIRMWARE) += firmware.o -obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o obj-$(CONFIG_DM_I2C) += i2c.o obj-$(CONFIG_SOUND) += i2s.o -obj-y += irq.o obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o obj-$(CONFIG_IOMMU) += iommu.o obj-$(CONFIG_LED) += led.o From 3ca32c806b266d8fb0a3f4d7b8c7f6ef75f43cb3 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 12 Jun 2022 13:13:05 +0000 Subject: [PATCH 05/13] snd: enable building max98357a driver with ACPIGEN=n sandbox_defconfig builds the max98357a driver. It should be possible to build the sandbox without ACPI support. ACPI support in the max98357a driver is only needed when creating an ACPI table. Fix building with ACPIGEN=n. Fixes: 54bcca29737f ("sound: Add an ACPI driver for Maxim MAX98357ac") Signed-off-by: Heinrich Schuchardt --- drivers/sound/max98357a.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/sound/max98357a.c b/drivers/sound/max98357a.c index a2088f0301..bdf6dc236e 100644 --- a/drivers/sound/max98357a.c +++ b/drivers/sound/max98357a.c @@ -38,6 +38,7 @@ static int max98357a_of_to_plat(struct udevice *dev) return 0; } +__maybe_unused static int max98357a_acpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx) { @@ -137,10 +138,12 @@ static int max98357a_acpi_setup_nhlt(const struct udevice *dev, #endif struct acpi_ops max98357a_acpi_ops = { +#ifdef CONFIG_ACPIGEN .fill_ssdt = max98357a_acpi_fill_ssdt, #ifdef CONFIG_X86 .setup_nhlt = max98357a_acpi_setup_nhlt, #endif +#endif }; static const struct audio_codec_ops max98357a_ops = { From d1a03e6bbc4e025797af17168b4909b3b14a2590 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 12 Jun 2022 13:15:34 +0000 Subject: [PATCH 06/13] sound: enable building DA7219 driver with ACPIGEN=n sandbox_defconfig builds the DA7219 driver. It should be possible to build the sandbox without ACPI support. ACPI support in the DA7219 driver is only needed when creating an ACPI table. Fix building with ACPIGEN=n. Fixes: 0324b7123e22 ("sound: Add an ACPI driver for Dialog Semicondutor da7219") Signed-off-by: Heinrich Schuchardt --- drivers/sound/da7219.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/sound/da7219.c b/drivers/sound/da7219.c index 8d674bcb4f..c1edef4436 100644 --- a/drivers/sound/da7219.c +++ b/drivers/sound/da7219.c @@ -23,6 +23,7 @@ #define DA7219_ACPI_HID "DLGS7219" +__maybe_unused static int da7219_acpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx) { @@ -171,10 +172,12 @@ static int da7219_acpi_setup_nhlt(const struct udevice *dev, #endif struct acpi_ops da7219_acpi_ops = { +#ifdef CONFIG_ACPIGEN .fill_ssdt = da7219_acpi_fill_ssdt, #ifdef CONFIG_X86 .setup_nhlt = da7219_acpi_setup_nhlt, #endif +#endif }; static const struct udevice_id da7219_ids[] = { From 9b78c9297b3c9277089c1130363ed6b1bb38f57d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 16 Jun 2022 13:43:50 +0200 Subject: [PATCH 07/13] Makefile: respect CONFIG_CC_OPTIMIZE_FOR_DEBUG for host tools If CONFIG_CC_OPTIMIZE_FOR_DEBUG=y, the host tools should be built with debug symbols and with reduced optimization. Signed-off-by: Heinrich Schuchardt --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 93571d37d9..7f7dd81b02 100644 --- a/Makefile +++ b/Makefile @@ -673,6 +673,12 @@ else include/config/auto.conf: ; endif # $(dot-config) +ifdef CONFIG_CC_OPTIMIZE_FOR_DEBUG +KBUILD_HOSTCFLAGS := -Wall -Wstrict-prototypes -Og -g -fomit-frame-pointer \ + $(HOST_LFS_CFLAGS) $(HOSTCFLAGS) +KBUILD_HOSTCXXFLAGS := -Og -g $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) +endif + # # Xtensa linker script cannot be preprocessed with -ansi because of # preprocessor operations on strings that don't make C identifiers. From 8142c4554ffaa927529f24427a35f7ee2861793a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Thu, 16 Jun 2022 20:59:03 +0200 Subject: [PATCH 08/13] fw_env: add fallback to Linux's NVMEM based access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new DT binding for describing environment data block has been added in Linux's commit 5db1c2dbc04c ("dt-bindings: nvmem: add U-Boot environment variables binding"). Once we get a proper Linux NVMEM driver it'll be possible to use Linux's binary interface for user-space as documented in the: https://www.kernel.org/doc/html/latest/driver-api/nvmem.html This commits makes fw_env fallback to looking for a compatible NVMEM device in case config file isn't present. In a long term this may make config files redundant and avoid code (info) duplication. Signed-off-by: Rafał Miłecki --- tools/env/fw_env.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 31afef6f3b..908a162202 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1713,6 +1713,67 @@ static int check_device_config(int dev) return rc; } +static int find_nvmem_device(void) +{ + const char *path = "/sys/bus/nvmem/devices"; + struct dirent *dent; + char *nvmem = NULL; + char comp[256]; + char buf[32]; + int bytes; + DIR *dir; + + dir = opendir(path); + if (!dir) { + return -EIO; + } + + while (!nvmem && (dent = readdir(dir))) { + FILE *fp; + + if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) { + continue; + } + + bytes = snprintf(comp, sizeof(comp), "%s/%s/of_node/compatible", path, dent->d_name); + if (bytes < 0 || bytes == sizeof(comp)) { + continue; + } + + fp = fopen(comp, "r"); + if (!fp) { + continue; + } + + fread(buf, sizeof(buf), 1, fp); + + if (!strcmp(buf, "u-boot,env")) { + bytes = asprintf(&nvmem, "%s/%s/nvmem", path, dent->d_name); + if (bytes < 0) { + nvmem = NULL; + } + } + + fclose(fp); + } + + closedir(dir); + + if (nvmem) { + struct stat s; + + stat(nvmem, &s); + + DEVNAME(0) = nvmem; + DEVOFFSET(0) = 0; + ENVSIZE(0) = s.st_size; + + return 0; + } + + return -ENOENT; +} + static int parse_config(struct env_opts *opts) { int rc; @@ -1723,9 +1784,12 @@ static int parse_config(struct env_opts *opts) #if defined(CONFIG_FILE) /* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */ if (get_config(opts->config_file)) { - fprintf(stderr, "Cannot parse config file '%s': %m\n", - opts->config_file); - return -1; + if (find_nvmem_device()) { + fprintf(stderr, "Cannot parse config file '%s': %m\n", + opts->config_file); + fprintf(stderr, "Failed to find NVMEM device\n"); + return -1; + } } #else DEVNAME(0) = DEVICE1_NAME; From 7886c45d422ca92f86a88580442bd526435bec25 Mon Sep 17 00:00:00 2001 From: Kory Maincent Date: Wed, 22 Jun 2022 11:11:45 +0200 Subject: [PATCH 09/13] mtd: rawnand: Add support to dedicated function to set timings With the current code if the board has an ONFI compliant NAND without support to the get and set features, U-boot returns an ENOTSUP error when trying to tune the timings which prevents the probe of the device. Indeed onfi_set_features() return ENOTSUP error if set/get features is not supported. In the case of timings we should not return ENOTSUP because we can use the default timings. The NAND is already capable of listening at its highest supported rate, so we assume in this case that it is fine to skip the operation. Fix it by adding an intermediate nand_onfi_set_timings() function which does not error out if set/get feature is not supported. Signed-off-by: Kory Maincent Reviewed-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 6f81257cf1..e8ece0a4a0 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -974,6 +974,22 @@ static int nand_reset_data_interface(struct nand_chip *chip, int chipnr) return ret; } +static int nand_onfi_set_timings(struct mtd_info *mtd, struct nand_chip *chip) +{ + if (!chip->onfi_version || + !(le16_to_cpu(chip->onfi_params.opt_cmd) + & ONFI_OPT_CMD_SET_GET_FEATURES)) + return 0; + + u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = { + chip->onfi_timing_mode_default, + }; + + return chip->onfi_set_features(mtd, chip, + ONFI_FEATURE_ADDR_TIMING_MODE, + tmode_param); +} + /** * nand_setup_data_interface - Setup the best data interface and timings * @chip: The NAND chip @@ -999,17 +1015,9 @@ static int nand_setup_data_interface(struct nand_chip *chip, int chipnr) * Ensure the timing mode has been changed on the chip side * before changing timings on the controller side. */ - if (chip->onfi_version) { - u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = { - chip->onfi_timing_mode_default, - }; - - ret = chip->onfi_set_features(mtd, chip, - ONFI_FEATURE_ADDR_TIMING_MODE, - tmode_param); - if (ret) - goto err; - } + ret = nand_onfi_set_timings(mtd, chip); + if (ret) + goto err; ret = chip->setup_data_interface(mtd, chipnr, chip->data_interface); err: From e3812b5b083e39f3dd11009579cc7d44008adaf5 Mon Sep 17 00:00:00 2001 From: Stefan Herbrechtsmeier Date: Thu, 23 Jun 2022 11:25:29 +0200 Subject: [PATCH 10/13] led: pwm: Use NOP uclass driver for top-level node The top level DT node of pwm-leds is not a LED itself, bind NOP uclass driver to it, and bind different LED uclass driver to its subnodes which represent the actual LEDs. This change removes the top-level node from the 'led list' command output and is based on the commit 01074697801b ("led: gpio: Use NOP uclass driver for top-level node"). Signed-off-by: Stefan Herbrechtsmeier --- drivers/led/led_pwm.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/led/led_pwm.c b/drivers/led/led_pwm.c index 10bd1636c3..0ebae358eb 100644 --- a/drivers/led/led_pwm.c +++ b/drivers/led/led_pwm.c @@ -95,27 +95,17 @@ static enum led_state_t led_pwm_get_state(struct udevice *dev) static int led_pwm_probe(struct udevice *dev) { struct led_pwm_priv *priv = dev_get_priv(dev); - struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); - - /* Ignore the top-level LED node */ - if (!uc_plat->label) - return 0; return led_pwm_set_state(dev, (priv->enabled) ? LEDST_ON : LEDST_OFF); } static int led_pwm_of_to_plat(struct udevice *dev) { - struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); struct led_pwm_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args args; uint def_brightness, max_brightness; int ret; - /* Ignore the top-level LED node */ - if (!uc_plat->label) - return 0; - ret = dev_read_phandle_with_args(dev, "pwms", "#pwm-cells", 0, 0, &args); if (ret) return ret; @@ -173,10 +163,15 @@ static const struct udevice_id led_pwm_ids[] = { U_BOOT_DRIVER(led_pwm) = { .name = LEDS_PWM_DRIVER_NAME, .id = UCLASS_LED, - .of_match = led_pwm_ids, .ops = &led_pwm_ops, .priv_auto = sizeof(struct led_pwm_priv), - .bind = led_pwm_bind, .probe = led_pwm_probe, .of_to_plat = led_pwm_of_to_plat, }; + +U_BOOT_DRIVER(led_pwm_wrap) = { + .name = LEDS_PWM_DRIVER_NAME "_wrap", + .id = UCLASS_NOP, + .of_match = led_pwm_ids, + .bind = led_pwm_bind, +}; From 5e998b4de33fed22da29e3a12e2856f9c00eaebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Thu, 23 Jun 2022 14:13:56 +0200 Subject: [PATCH 11/13] serial: ns16550: Wait in debug_uart_init until tx buffer is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit d293759d55cc ("serial: ns16550: Add support for SPL_DEBUG_UART_BASE") fixed support for setting correct early debug UART base address in SPL. But after this commit, output from Marvell A385 BootROM is truncated or lost and not fully present on serial console. Debugging this issue showed that BootROM just put bytes into UART HW output buffer and does not wait until UART HW transmit all characters. U-Boot ns16550 early debug is initialized very early and during its initialization is resetting UART HW and flushing remaining transmit buffer (which still contains BootROM output). Fix this issue by waiting in init function prior resetting UART HW until TxEmpty bit in UART Line Status Register is set. TxEmpty is set when all remaining bytes from HW buffer are transmitted. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese [trini: Add comment, move ';' to new line per checkpatch.pl] Signed-off-by: Tom Rini --- drivers/serial/ns16550.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 78bfe6281c..47bad6f8e2 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -328,6 +328,10 @@ static inline void _debug_uart_init(void) struct ns16550 *com_port = (struct ns16550 *)CONFIG_VAL(DEBUG_UART_BASE); int baud_divisor; + /* Wait until tx buffer is empty */ + while (!(serial_din(&com_port->lsr) & UART_LSR_TEMT)) + ; + /* * We copy the code from above because it is already horribly messy. * Trying to refactor to nicely remove the duplication doesn't seem From cc5dfdee6b8a2c558f5c52f11004e26eb55fd830 Mon Sep 17 00:00:00 2001 From: Ralph Siemsen Date: Fri, 24 Jun 2022 11:19:15 -0400 Subject: [PATCH 12/13] regmap: fix some comments Correct spelling and copy/paste errors in comments. Fixes 1c4db59d9b ("regmap: Add support for regmap fields") Signed-off-by: Ralph Siemsen Reviewed-by: Simon Glass --- include/regmap.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/regmap.h b/include/regmap.h index 8216de015d..e81a3602ae 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -460,7 +460,7 @@ struct reg_field { struct regmap_field; /** - * REG_FIELD() - A convenient way to initialize a 'struct reg_feild'. + * REG_FIELD() - A convenient way to initialize a 'struct reg_field'. * * @_reg: Offset of the register within the regmap bank * @_lsb: lsb of the register field. @@ -519,9 +519,9 @@ void devm_regmap_field_free(struct udevice *dev, struct regmap_field *field); int regmap_field_write(struct regmap_field *field, unsigned int val); /** - * regmap_read() - Read a 32-bit value from a regmap + * regmap_field_read() - Read a 32-bit value from a regmap * - * @field: Regmap field to write to + * @field: Regmap field to read from * @valp: Pointer to the buffer to receive the data read from the regmap * field * From 5004901efb3b47f7fb22b29cdd127245d3814fd2 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 25 Jun 2022 19:58:24 +0200 Subject: [PATCH 13/13] board_init: Do not reserve MALLOC_F area on stack if non-zero MALLOC_F_ADDR In case the MALLOC_F_ADDR is set to non-zero value, the early malloc area is not going to be placed just below stack top, but elsewhere. Do not reserve MALLOC_F bytes in this case, as that wastes stack space and may even cause insufficient stack space in SPL. This functionality is particularly useful on i.MX8M, where the insufficient stack space can be triggered. Signed-off-by: Marek Vasut Cc: Albert ARIBAUD Cc: Fabio Estevam Cc: Peng Fan Cc: Simon Glass Cc: Stefano Babic Cc: Thomas Chou Cc: Tom Rini --- common/init/board_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/init/board_init.c b/common/init/board_init.c index eab5ee1395..6a55026177 100644 --- a/common/init/board_init.c +++ b/common/init/board_init.c @@ -78,8 +78,10 @@ __weak void board_init_f_init_stack_protection(void) ulong board_init_f_alloc_reserve(ulong top) { /* Reserve early malloc arena */ +#ifndef CONFIG_MALLOC_F_ADDR #if CONFIG_VAL(SYS_MALLOC_F_LEN) top -= CONFIG_VAL(SYS_MALLOC_F_LEN); +#endif #endif /* LAST : reserve GD (rounded up to a multiple of 16 bytes) */ top = rounddown(top-sizeof(struct global_data), 16);