From 92080c6ef6c753ca69c53f191a6baef53f98bd6b Mon Sep 17 00:00:00 2001 From: Sean Nyekjaer Date: Thu, 12 May 2022 20:37:14 +0200 Subject: fs/squashfs: use lldiv function for math MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When compling for x86: ld.bfd: fs/squashfs/sqfs.o: in function `sqfs_read': u-boot/fs/squashfs/sqfs.c:1443: undefined reference to `__udivmoddi4' ld.bfd: u-boot/fs/squashfs/sqfs.c:1521: undefined reference to `__udivmoddi4' Signed-off-by: Sean Nyekjaer Reviewed-by: Miquel Raynal Reviewed-by: Pali Rohár --- fs/squashfs/sqfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index b07c41e..b4484fa 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -1442,7 +1443,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, for (j = 0; j < datablk_count; j++) { char *data_buffer; - start = data_offset / ctxt.cur_dev->blksz; + start = lldiv(data_offset, ctxt.cur_dev->blksz); table_size = SQFS_BLOCK_SIZE(finfo.blk_sizes[j]); table_offset = data_offset - (start * ctxt.cur_dev->blksz); n_blks = DIV_ROUND_UP(table_size + table_offset, @@ -1516,7 +1517,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, goto out; } - start = frag_entry.start / ctxt.cur_dev->blksz; + start = lldiv(frag_entry.start, ctxt.cur_dev->blksz); table_size = SQFS_BLOCK_SIZE(frag_entry.size); table_offset = frag_entry.start - (start * ctxt.cur_dev->blksz); n_blks = DIV_ROUND_UP(table_size + table_offset, ctxt.cur_dev->blksz); -- cgit v1.1 From b898f6a6db7608785c34a127a2ec714ff4496621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 2 May 2022 18:36:38 +0200 Subject: powerpc: mpc85xx: Fix CONFIG_OF_SEPARATE support for NOR booting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit e8c0e0064c8a ("powerpc: mpc85xx: Fix CONFIG_OF_SEPARATE support") fixed SD card booting on mpc85xx boards but broke NOR booting on these boards. Reason is that U-Boot build system for NOR images uses binman and this binman ignores alignment defined in linker script. Instead it has own config file where is alignment defined. Fix binman alignment for mpc85xx boards to match what is _now_ defined in linker script. This change fixes building of U-Boot for NOR booting on P2020 board. Fixes: e8c0e0064c8a ("powerpc: mpc85xx: Fix CONFIG_OF_SEPARATE support") Signed-off-by: Pali Rohár --- arch/powerpc/dts/u-boot.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/dts/u-boot.dtsi b/arch/powerpc/dts/u-boot.dtsi index 9661f4d..67de476 100644 --- a/arch/powerpc/dts/u-boot.dtsi +++ b/arch/powerpc/dts/u-boot.dtsi @@ -20,7 +20,7 @@ u-boot-dtb-with-ucode { #ifdef CONFIG_MPC85xx - align = <256>; + align = <4>; #endif }; #ifdef CONFIG_MPC85XX_HAVE_RESET_VECTOR -- cgit v1.1 From 827a232623e9b00e7d1b4b62b46e803d7168bbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 2 May 2022 18:36:39 +0200 Subject: powerpc: mpc85xx: Fix CONFIG_OF_EMBED support for NOR booting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mpc85xx NOR binary contains also reset vector and therefore option CONFIG_MPC85XX_HAVE_RESET_VECTOR must be defined. When build system uses binman, it takes care of constructing final image which consist of u-boot-without-reset-vector, DTB and reset-vector. CONFIG_OF_EMBED does not use binman, there is no external DTB and Makefile produce directly final u-boot.bin binary. So in this case mpc85xx reset vector must not be stripped from the final u-boot.bin binary. Fix it. Signed-off-by: Pali Rohár --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e3ce287..107685e 100644 --- a/Makefile +++ b/Makefile @@ -1263,7 +1263,7 @@ spl/u-boot-spl.srec: spl/u-boot-spl FORCE OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ $(if $(CONFIG_X86_16BIT_INIT),-R .start16 -R .resetvec) \ - $(if $(CONFIG_MPC85XX_HAVE_RESET_VECTOR),-R .bootpg -R .resetvec) + $(if $(CONFIG_MPC85XX_HAVE_RESET_VECTOR),$(if $(CONFIG_OF_EMBED),,-R .bootpg -R .resetvec)) binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \ -- cgit v1.1 From 61708bb0a24caad99b0e79de52077dafb59688d6 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Wed, 30 Mar 2022 09:33:13 +0200 Subject: spi: spi-uclass: Add new spi_get_bus_and_cs() implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move legacy spi_get_bus_and_cs() code to _spi_get_bus_and_cs(). Add new spi_get_bus_and_cs() implementation which rely on DT for speed and mode and don't need any drv_name nor dev_name parameters. This will prepare the ground for next patch. Update all callers to use _spi_get_bus_and_cs() to keep the same behavior. Signed-off-by: Patrice Chotard Cc: Marek Behun Cc: Jagan Teki Cc: Vignesh R Cc: Joe Hershberger Cc: Ramon Fried Cc: Lukasz Majewski Cc: Marek Vasut Cc: Wolfgang Denk Cc: Simon Glass Cc: Stefan Roese Cc: "Pali Rohár" Cc: Konstantin Porotchkin Cc: Igal Liberman Cc: Bin Meng Cc: Pratyush Yadav Cc: Sean Anderson Cc: Anji J Cc: Biwen Li Cc: Priyanka Jain Cc: Chaitanya Sakinam --- board/CZ.NIC/turris_mox/turris_mox.c | 6 ++-- cmd/spi.c | 4 +-- drivers/mtd/spi/sf-uclass.c | 2 +- drivers/spi/spi-uclass.c | 66 +++++++++++++++++++++++++++++++++--- drivers/usb/gadget/max3420_udc.c | 4 +-- include/spi.h | 19 ++++++++++- test/dm/spi.c | 33 +++++++++--------- 7 files changed, 104 insertions(+), 30 deletions(-) diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index a4738b3..68bc315 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -149,9 +149,9 @@ static int mox_do_spi(u8 *in, u8 *out, size_t size) struct udevice *dev; int ret; - ret = spi_get_bus_and_cs(0, 1, 1000000, SPI_CPHA | SPI_CPOL, - "spi_generic_drv", "moxtet@1", &dev, - &slave); + ret = _spi_get_bus_and_cs(0, 1, 1000000, SPI_CPHA | SPI_CPOL, + "spi_generic_drv", "moxtet@1", &dev, + &slave); if (ret) goto fail; diff --git a/cmd/spi.c b/cmd/spi.c index 6dc3267..454ebe3 100644 --- a/cmd/spi.c +++ b/cmd/spi.c @@ -46,8 +46,8 @@ static int do_spi_xfer(int bus, int cs) str = strdup(name); if (!str) return -ENOMEM; - ret = spi_get_bus_and_cs(bus, cs, freq, mode, "spi_generic_drv", - str, &dev, &slave); + ret = _spi_get_bus_and_cs(bus, cs, freq, mode, "spi_generic_drv", + str, &dev, &slave); if (ret) return ret; #else diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index 63d1629..b45ba54 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -74,7 +74,7 @@ int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, snprintf(name, sizeof(name), "spi_flash@%d:%d", busnum, cs); str = strdup(name); #endif - ret = spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode, + ret = _spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode, "jedec_spi_nor", str, &bus, &slave); if (ret) return ret; diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index f8ec312..f2791c4 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -340,9 +340,65 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp, return ret; } -int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, - const char *drv_name, const char *dev_name, - struct udevice **busp, struct spi_slave **devp) +int spi_get_bus_and_cs(int busnum, int cs, struct udevice **busp, + struct spi_slave **devp) +{ + struct udevice *bus, *dev; + struct dm_spi_bus *bus_data; + struct spi_slave *slave; + int ret; + +#if CONFIG_IS_ENABLED(OF_PLATDATA) + ret = uclass_first_device_err(UCLASS_SPI, &bus); +#else + ret = uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus); +#endif + if (ret) { + log_err("Invalid bus %d (err=%d)\n", busnum, ret); + return ret; + } + ret = spi_find_chip_select(bus, cs, &dev); + if (ret) { + dev_err(bus, "Invalid chip select %d:%d (err=%d)\n", busnum, cs, ret); + return ret; + } + + if (!device_active(dev)) { + struct spi_slave *slave; + + ret = device_probe(dev); + if (ret) + goto err; + slave = dev_get_parent_priv(dev); + slave->dev = dev; + } + + slave = dev_get_parent_priv(dev); + bus_data = dev_get_uclass_priv(bus); + + /* + * In case the operation speed is not yet established by + * dm_spi_claim_bus() ensure the bus is configured properly. + */ + if (!bus_data->speed) { + ret = spi_claim_bus(slave); + if (ret) + goto err; + } + *busp = bus; + *devp = slave; + + return 0; + +err: + log_debug("%s: Error path, device '%s'\n", __func__, dev->name); + + return ret; +} + +int _spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, + const char *drv_name, const char *dev_name, + struct udevice **busp, struct spi_slave **devp) { struct udevice *bus, *dev; struct dm_spi_slave_plat *plat; @@ -453,8 +509,8 @@ struct spi_slave *spi_setup_slave(unsigned int busnum, unsigned int cs, struct udevice *dev; int ret; - ret = spi_get_bus_and_cs(busnum, cs, speed, mode, NULL, 0, &dev, - &slave); + ret = _spi_get_bus_and_cs(busnum, cs, speed, mode, NULL, 0, &dev, + &slave); if (ret) return NULL; diff --git a/drivers/usb/gadget/max3420_udc.c b/drivers/usb/gadget/max3420_udc.c index a16095f..fa655c9 100644 --- a/drivers/usb/gadget/max3420_udc.c +++ b/drivers/usb/gadget/max3420_udc.c @@ -830,8 +830,8 @@ static int max3420_udc_probe(struct udevice *dev) cs = slave_pdata->cs; speed = slave_pdata->max_hz; mode = slave_pdata->mode; - spi_get_bus_and_cs(busnum, cs, speed, mode, "spi_generic_drv", - NULL, &spid, &udc->slave); + _spi_get_bus_and_cs(busnum, cs, speed, mode, false, "spi_generic_drv", + NULL, &spid, &udc->slave); udc->dev = dev; udc->gadget.ep0 = &udc->ep[0].ep_usb; diff --git a/include/spi.h b/include/spi.h index fa9ab12..9a8c1fb 100644 --- a/include/spi.h +++ b/include/spi.h @@ -572,6 +572,23 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp, * Given a bus number and chip select, this finds the corresponding bus * device and slave device. * + * @busnum: SPI bus number + * @cs: Chip select to look for + * @busp: Returns bus device + * @devp: Return slave device + * @return 0 if found, -ve on error + */ +int spi_get_bus_and_cs(int busnum, int cs, + struct udevice **busp, struct spi_slave **devp); + +/** + * _spi_get_bus_and_cs() - Find and activate bus and slave devices by number + * As spi_flash_probe(), This is an old-style function. We should remove + * it when all SPI flash drivers use dm + * + * Given a bus number and chip select, this finds the corresponding bus + * device and slave device. + * * If no such slave exists, and drv_name is not NULL, then a new slave device * is automatically bound on this chip select with requested speed and mode. * @@ -588,7 +605,7 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp, * @devp: Return slave device * Return: 0 if found, -ve on error */ -int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, +int _spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, const char *drv_name, const char *dev_name, struct udevice **busp, struct spi_slave **devp); diff --git a/test/dm/spi.c b/test/dm/spi.c index ee4ad3a..7ab0820 100644 --- a/test/dm/spi.c +++ b/test/dm/spi.c @@ -46,19 +46,19 @@ static int dm_test_spi_find(struct unit_test_state *uts) /* This finds nothing because we removed the device */ ut_asserteq(-ENODEV, spi_find_bus_and_cs(busnum, cs, &bus, &dev)); - ut_asserteq(-ENODEV, spi_get_bus_and_cs(busnum, cs, speed, mode, - NULL, 0, &bus, &slave)); + ut_asserteq(-ENODEV, _spi_get_bus_and_cs(busnum, cs, speed, mode, + NULL, 0, &bus, &slave)); /* * This forces the device to be re-added, but there is no emulation * connected so the probe will fail. We require that bus is left - * alone on failure, and that the spi_get_bus_and_cs() does not add + * alone on failure, and that the _spi_get_bus_and_cs() does not add * a 'partially-inited' device. */ ut_asserteq(-ENODEV, spi_find_bus_and_cs(busnum, cs, &bus, &dev)); - ut_asserteq(-ENOENT, spi_get_bus_and_cs(busnum, cs, speed, mode, - "jedec_spi_nor", "name", &bus, - &slave)); + ut_asserteq(-ENOENT, _spi_get_bus_and_cs(busnum, cs, speed, mode, + "jedec_spi_nor", "name", &bus, + &slave)); sandbox_sf_unbind_emul(state_get_current(), busnum, cs); ut_assertok(spi_cs_info(bus, cs, &info)); ut_asserteq_ptr(NULL, info.dev); @@ -67,8 +67,8 @@ static int dm_test_spi_find(struct unit_test_state *uts) ut_assertok(sandbox_sf_bind_emul(state, busnum, cs, bus, node, "name")); ut_assertok(spi_find_bus_and_cs(busnum, cs, &bus, &dev)); - ut_assertok(spi_get_bus_and_cs(busnum, cs, speed, mode, - "jedec_spi_nor", "name", &bus, &slave)); + ut_assertok(_spi_get_bus_and_cs(busnum, cs, speed, mode, + "jedec_spi_nor", "name", &bus, &slave)); ut_assertok(spi_cs_info(bus, cs, &info)); ut_asserteq_ptr(info.dev, slave->dev); @@ -76,8 +76,9 @@ static int dm_test_spi_find(struct unit_test_state *uts) /* We should be able to add something to another chip select */ ut_assertok(sandbox_sf_bind_emul(state, busnum, cs_b, bus, node, "name")); - ut_asserteq(-EINVAL, spi_get_bus_and_cs(busnum, cs_b, speed, mode, - "jedec_spi_nor", "name", &bus, &slave)); + ut_asserteq(-EINVAL, _spi_get_bus_and_cs(busnum, cs_b, speed, mode, + "jedec_spi_nor", "name", &bus, + &slave)); ut_asserteq(-EINVAL, spi_cs_info(bus, cs_b, &info)); ut_asserteq_ptr(NULL, info.dev); @@ -145,11 +146,11 @@ static int dm_test_spi_claim_bus(struct unit_test_state *uts) const int busnum = 0, cs_a = 0, cs_b = 1, mode = 0; /* Get spi slave on CS0 */ - ut_assertok(spi_get_bus_and_cs(busnum, cs_a, 1000000, mode, NULL, 0, - &bus, &slave_a)); + ut_assertok(_spi_get_bus_and_cs(busnum, cs_a, 1000000, mode, NULL, 0, + &bus, &slave_a)); /* Get spi slave on CS1 */ - ut_assertok(spi_get_bus_and_cs(busnum, cs_b, 1000000, mode, NULL, 0, - &bus, &slave_b)); + ut_assertok(_spi_get_bus_and_cs(busnum, cs_b, 1000000, mode, NULL, 0, + &bus, &slave_b)); /* Different max_hz, different mode. */ ut_assert(slave_a->max_hz != slave_b->max_hz); @@ -182,8 +183,8 @@ static int dm_test_spi_xfer(struct unit_test_state *uts) const char dout[5] = {0x9f}; unsigned char din[5]; - ut_assertok(spi_get_bus_and_cs(busnum, cs, 1000000, mode, NULL, 0, - &bus, &slave)); + ut_assertok(_spi_get_bus_and_cs(busnum, cs, 1000000, mode, NULL, 0, + &bus, &slave)); ut_assertok(spi_claim_bus(slave)); ut_assertok(spi_xfer(slave, 40, dout, din, SPI_XFER_BEGIN | SPI_XFER_END)); -- cgit v1.1 From 3feea0ba196ac686090acc48c77cf02b996a8589 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Wed, 30 Mar 2022 09:33:14 +0200 Subject: spi: spi_flash_probe_bus_cs() rely on DT for spi speed and mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now, spi_flash_probe_bus_cs() relies on DT for spi speed and mode and logically calls spi_get_bus_and_cs(). In case spi mode and speed are not read from DT, make usage of spi_flash_probe() instead. To sum-up: - Previous call tree was: spi_flash_probe() -> spi_flash_probe_bus_cs() -> spi_get_bus_and_cs() - Current call tree is: spi_flash_probe() -> _spi_get_bus_and_cs() spi_flash_probe_bus_cs() -> spi_get_bus_and_cs() This patch impacts the following : - cmd/sf.c: if spi mode and/or speed is passed in argument of do_spi_flash_probe(), call spi_flash_probe() otherwise call spi_flash_probe_bus_cs(). - drivers/net/fm/fm.c: as by default spi speed and mode was set to 0 and a comment indicates that speed and mode are read from DT, use spi_flash_probe_bus_cs(). - drivers/net/pfe_eth/pfe_firmware.c: spi speed and mode are not read from DT by all platforms using this driver, so keep legacy and replace spi_flash_probe_bus_cs() by spi_flash_probe(); - drivers/net/sni_netsec.c : spi speed and mode are not read from DT, so replace spi_flash_probe_bus_cs() by spi_flash_probe(). - drivers/usb/gadget/max3420_udc.c: Can't find any platform which make usage of this driver, nevertheless, keep legacy and replace spi_get_bus_and_cs() by _spi_get_bus_and_cs(). - env/sf.c: a comment indicates that speed and mode are read from DT. So use spi_flash_probe_bus_cs(). Signed-off-by: Patrice Chotard Cc: Marek Behun Cc: Jagan Teki Cc: Vignesh R Cc: Joe Hershberger Cc: Ramon Fried Cc: Lukasz Majewski Cc: Marek Vasut Cc: Wolfgang Denk Cc: Simon Glass Cc: Stefan Roese Cc: "Pali Rohár" Cc: Konstantin Porotchkin Cc: Igal Liberman Cc: Bin Meng Cc: Pratyush Yadav Cc: Sean Anderson Cc: Anji J Cc: Biwen Li Cc: Priyanka Jain Cc: Chaitanya Sakinam --- cmd/sf.c | 15 +++++++++++---- drivers/mtd/spi/sf-uclass.c | 33 +++++++++++++++++---------------- drivers/net/fm/fm.c | 4 ++-- drivers/net/pfe_eth/pfe_firmware.c | 19 ++++--------------- drivers/net/sni_netsec.c | 6 ++---- env/sf.c | 1 - include/spi_flash.h | 1 - 7 files changed, 36 insertions(+), 43 deletions(-) diff --git a/cmd/sf.c b/cmd/sf.c index 8bdebd9..8713736 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -91,6 +91,7 @@ static int do_spi_flash_probe(int argc, char *const argv[]) unsigned int speed = CONFIG_SF_DEFAULT_SPEED; unsigned int mode = CONFIG_SF_DEFAULT_MODE; char *endp; + bool use_dt = true; #if CONFIG_IS_ENABLED(DM_SPI_FLASH) struct udevice *new, *bus_dev; int ret; @@ -117,11 +118,13 @@ static int do_spi_flash_probe(int argc, char *const argv[]) speed = simple_strtoul(argv[2], &endp, 0); if (*argv[2] == 0 || *endp != 0) return -1; + use_dt = false; } if (argc >= 4) { mode = hextoul(argv[3], &endp); if (*argv[3] == 0 || *endp != 0) return -1; + use_dt = false; } #if CONFIG_IS_ENABLED(DM_SPI_FLASH) @@ -131,14 +134,18 @@ static int do_spi_flash_probe(int argc, char *const argv[]) device_remove(new, DM_REMOVE_NORMAL); } flash = NULL; - ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new); - if (ret) { + if (use_dt) { + spi_flash_probe_bus_cs(bus, cs, &new); + flash = dev_get_uclass_priv(new); + } else { + flash = spi_flash_probe(bus, cs, speed, mode); + } + + if (!flash) { printf("Failed to initialize SPI flash at %u:%u (error %d)\n", bus, cs, ret); return 1; } - - flash = dev_get_uclass_priv(new); #else if (flash) spi_flash_free(flash); diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index b45ba54..e6e650e 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -46,25 +46,12 @@ int spl_flash_get_sw_write_prot(struct udevice *dev) * TODO(sjg@chromium.org): This is an old-style function. We should remove * it when all SPI flash drivers use dm */ -struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, +struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, unsigned int max_hz, unsigned int spi_mode) { - struct udevice *dev; - - if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev)) - return NULL; - - return dev_get_uclass_priv(dev); -} - -int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode, - struct udevice **devp) -{ struct spi_slave *slave; struct udevice *bus; char *str; - int ret; #if defined(CONFIG_SPL_BUILD) && CONFIG_IS_ENABLED(USE_TINY_PRINTF) str = "spi_flash"; @@ -74,8 +61,22 @@ int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, snprintf(name, sizeof(name), "spi_flash@%d:%d", busnum, cs); str = strdup(name); #endif - ret = _spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode, - "jedec_spi_nor", str, &bus, &slave); + + if (_spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode, + "jedec_spi_nor", str, &bus, &slave)) + return NULL; + + return dev_get_uclass_priv(slave->dev); +} + +int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, + struct udevice **devp) +{ + struct spi_slave *slave; + struct udevice *bus; + int ret; + + ret = spi_get_bus_and_cs(busnum, cs, &bus, &slave); if (ret) return ret; diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c index f825612..d0b492b 100644 --- a/drivers/net/fm/fm.c +++ b/drivers/net/fm/fm.c @@ -388,7 +388,7 @@ int fm_init_common(int index, struct ccsr_fman *reg) /* speed and mode will be read from DT */ ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, - CONFIG_SF_DEFAULT_CS, 0, 0, &new); + CONFIG_SF_DEFAULT_CS, &new); ucode_flash = dev_get_uclass_priv(new); #else @@ -475,7 +475,7 @@ int fm_init_common(int index, struct ccsr_fman *reg) /* speed and mode will be read from DT */ ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, - 0, 0, &new); + &new); ucode_flash = dev_get_uclass_priv(new); #else diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c index 6669048..82a4aa8 100644 --- a/drivers/net/pfe_eth/pfe_firmware.c +++ b/drivers/net/pfe_eth/pfe_firmware.c @@ -172,31 +172,20 @@ static int pfe_fit_check(void) int pfe_spi_flash_init(void) { struct spi_flash *pfe_flash; - struct udevice *new; int ret = 0; void *addr = malloc(CONFIG_SYS_LS_PFE_FW_LENGTH); if (!addr) return -ENOMEM; - ret = spi_flash_probe_bus_cs(CONFIG_SYS_FSL_PFE_SPI_BUS, - CONFIG_SYS_FSL_PFE_SPI_CS, - CONFIG_SYS_FSL_PFE_SPI_MAX_HZ, - CONFIG_SYS_FSL_PFE_SPI_MODE, - &new); - if (ret) { - printf("SF: failed to probe spi\n"); - free(addr); - device_remove(new, DM_REMOVE_NORMAL); - return ret; - } - + pfe_flash = spi_flash_probe(CONFIG_SYS_FSL_PFE_SPI_BUS, + CONFIG_SYS_FSL_PFE_SPI_CS, + CONFIG_SYS_FSL_PFE_SPI_MAX_HZ, + CONFIG_SYS_FSL_PFE_SPI_MODE); - pfe_flash = dev_get_uclass_priv(new); if (!pfe_flash) { printf("SF: probe for pfe failed\n"); free(addr); - device_remove(new, DM_REMOVE_NORMAL); return -ENODEV; } diff --git a/drivers/net/sni_netsec.c b/drivers/net/sni_netsec.c index 24caacf..9780f20 100644 --- a/drivers/net/sni_netsec.c +++ b/drivers/net/sni_netsec.c @@ -621,12 +621,10 @@ static int netsec_stop_gmac(struct netsec_priv *priv) static void netsec_spi_read(char *buf, loff_t len, loff_t offset) { - struct udevice *new; struct spi_flash *flash; - spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, - CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE, &new); - flash = dev_get_uclass_priv(new); + flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, + CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE); spi_flash_read(flash, offset, len, buf); } diff --git a/env/sf.c b/env/sf.c index d2c07cd..4b76854 100644 --- a/env/sf.c +++ b/env/sf.c @@ -48,7 +48,6 @@ static int setup_flash_device(struct spi_flash **env_flash) /* speed and mode will be read from DT */ ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE, &new); if (ret) { env_set_default("spi_flash_probe_bus_cs() failed", 0); diff --git a/include/spi_flash.h b/include/spi_flash.h index d33d0dd..10d19fd 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -102,7 +102,6 @@ int spl_flash_get_sw_write_prot(struct udevice *dev); int spi_flash_std_probe(struct udevice *dev); int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode, struct udevice **devp); /* Compatibility function - this is the old U-Boot API */ -- cgit v1.1 From 012afa83ae8b47ce4019d5d9c85ed308c61645fc Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Wed, 30 Mar 2022 09:33:15 +0200 Subject: test: dm: spi: Replace _spi_get_bus_and_cs() by spi_get_bus_and_cs() in some case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case _spi_get_bus_and_cs()'s parameters drv_name and dev_name are respectively set to NULL and 0, use spi_get_bus_and_cs() instead. Signed-off-by: Patrice Chotard Cc: Marek Behun Cc: Jagan Teki Cc: Vignesh R Cc: Joe Hershberger Cc: Ramon Fried Cc: Lukasz Majewski Cc: Marek Vasut Cc: Wolfgang Denk Cc: Simon Glass Cc: Stefan Roese Cc: "Pali Rohár" Cc: Konstantin Porotchkin Cc: Igal Liberman Cc: Bin Meng Cc: Pratyush Yadav Cc: Sean Anderson Cc: Anji J Cc: Biwen Li Cc: Priyanka Jain Cc: Chaitanya Sakinam --- test/dm/spi.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/test/dm/spi.c b/test/dm/spi.c index 7ab0820..325799b 100644 --- a/test/dm/spi.c +++ b/test/dm/spi.c @@ -46,8 +46,7 @@ static int dm_test_spi_find(struct unit_test_state *uts) /* This finds nothing because we removed the device */ ut_asserteq(-ENODEV, spi_find_bus_and_cs(busnum, cs, &bus, &dev)); - ut_asserteq(-ENODEV, _spi_get_bus_and_cs(busnum, cs, speed, mode, - NULL, 0, &bus, &slave)); + ut_asserteq(-ENODEV, spi_get_bus_and_cs(busnum, cs, &bus, &slave)); /* * This forces the device to be re-added, but there is no emulation @@ -143,14 +142,12 @@ static int dm_test_spi_claim_bus(struct unit_test_state *uts) struct udevice *bus; struct spi_slave *slave_a, *slave_b; struct dm_spi_slave_plat *slave_plat; - const int busnum = 0, cs_a = 0, cs_b = 1, mode = 0; + const int busnum = 0, cs_a = 0, cs_b = 1; /* Get spi slave on CS0 */ - ut_assertok(_spi_get_bus_and_cs(busnum, cs_a, 1000000, mode, NULL, 0, - &bus, &slave_a)); + ut_assertok(spi_get_bus_and_cs(busnum, cs_a, &bus, &slave_a)); /* Get spi slave on CS1 */ - ut_assertok(_spi_get_bus_and_cs(busnum, cs_b, 1000000, mode, NULL, 0, - &bus, &slave_b)); + ut_assertok(spi_get_bus_and_cs(busnum, cs_b, &bus, &slave_b)); /* Different max_hz, different mode. */ ut_assert(slave_a->max_hz != slave_b->max_hz); @@ -179,12 +176,11 @@ static int dm_test_spi_xfer(struct unit_test_state *uts) { struct spi_slave *slave; struct udevice *bus; - const int busnum = 0, cs = 0, mode = 0; + const int busnum = 0, cs = 0; const char dout[5] = {0x9f}; unsigned char din[5]; - ut_assertok(_spi_get_bus_and_cs(busnum, cs, 1000000, mode, NULL, 0, - &bus, &slave)); + ut_assertok(spi_get_bus_and_cs(busnum, cs, &bus, &slave)); ut_assertok(spi_claim_bus(slave)); ut_assertok(spi_xfer(slave, 40, dout, din, SPI_XFER_BEGIN | SPI_XFER_END)); -- cgit v1.1 From 2d25f63cc02e42f3e4a798bd5385e9cd73e51fd4 Mon Sep 17 00:00:00 2001 From: Sai Pavan Boddu Date: Wed, 11 May 2022 10:39:07 +0200 Subject: arm: gic_v2: Skip gic_init_secure when cpu is not in el3 This would prevent configuring non-secure regs in case gic security extensions are not emulated in Qemu. Signed-off-by: Sai Pavan Boddu Signed-off-by: Michal Simek --- arch/arm/lib/gic_64.S | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm/lib/gic_64.S b/arch/arm/lib/gic_64.S index 155212a..86cd882 100644 --- a/arch/arm/lib/gic_64.S +++ b/arch/arm/lib/gic_64.S @@ -40,6 +40,8 @@ ENTRY(gic_init_secure) sub w10, w10, #0x1 cbnz w10, 0b #elif defined(CONFIG_GICV2) + switch_el x1, 2f, 1f, 1f +2: mov w9, #0x3 /* EnableGrp0 | EnableGrp1 */ str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */ ldr w9, [x0, GICD_TYPER] @@ -141,6 +143,8 @@ ENTRY(gic_init_secure_percpu) * x0: Distributor Base * x1: Cpu Interface Base */ + switch_el x2, 4f, 5f, 5f +4: mov w9, #~0 /* Config SGIs and PPIs as Grp1 */ str w9, [x0, GICD_IGROUPRn] /* GICD_IGROUPR0 */ mov w9, #0x1 /* Enable SGI 0 */ @@ -155,6 +159,7 @@ ENTRY(gic_init_secure_percpu) mov w9, #0x1 << 7 /* Non-Secure access to GICC_PMR */ str w9, [x1, GICC_PMR] #endif +5: ret ENDPROC(gic_init_secure_percpu) -- cgit v1.1 From c1abf7659c9b29874d9d718df6890de1638cedba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Wed, 11 May 2022 20:28:28 +0200 Subject: mmc: fsl_esdhc_spl: Fix checking for number of read sectors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 0980cbba7b3c ("mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support") changed number of sectors which are read but did not adjusted error check. Fix it and check for if correct number of sectors were read. Fixes: 0980cbba7b3c ("mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support") Signed-off-by: Pali Rohár Reviewed-by: Jaehoon Chung --- drivers/mmc/fsl_esdhc_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/fsl_esdhc_spl.c b/drivers/mmc/fsl_esdhc_spl.c index ea8f4cd6..760f13d 100644 --- a/drivers/mmc/fsl_esdhc_spl.c +++ b/drivers/mmc/fsl_esdhc_spl.c @@ -106,7 +106,7 @@ again: blk_off = (sector * 512) % mmc->read_bl_len; blk_cnt = DIV_ROUND_UP(512, mmc->read_bl_len); err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt, tmp_buf); - if (err != 1) { + if (err != blk_cnt) { puts("spl: mmc read failed!!\n"); hang(); } -- cgit v1.1