From e39cecfdaf8ee6fa222a8209aa0183be978f370d Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Fri, 7 Apr 2017 13:42:06 +0200 Subject: scsi: make the LUN a parameter of scsi_detect_dev() This is a cosmetic change. target and LUN have kind of the same role in this function. One of them was passed as a parameter and the other was embedded in a structure. For consistency, pass both of them as parameters. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- common/scsi.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'common') diff --git a/common/scsi.c b/common/scsi.c index fb5b407f6b1..d55ba892a6f 100644 --- a/common/scsi.c +++ b/common/scsi.c @@ -473,14 +473,15 @@ static void scsi_init_dev_desc(struct blk_desc *dev_desc, int devnum) * scsi_detect_dev - Detect scsi device * * @target: target id + * @lun: target lun * @dev_desc: block device description * * The scsi_detect_dev detects and fills a dev_desc structure when the device is - * detected. The LUN number is taken from the struct blk_desc *dev_desc. + * detected. * * Return: 0 on success, error value otherwise */ -static int scsi_detect_dev(int target, struct blk_desc *dev_desc) +static int scsi_detect_dev(int target, int lun, struct blk_desc *dev_desc) { unsigned char perq, modi; lbaint_t capacity; @@ -488,7 +489,7 @@ static int scsi_detect_dev(int target, struct blk_desc *dev_desc) ccb *pccb = (ccb *)&tempccb; pccb->target = target; - pccb->lun = dev_desc->lun; + pccb->lun = lun; pccb->pdata = (unsigned char *)&tempbuff; pccb->datalen = 512; scsi_setup_inquiry(pccb); @@ -599,8 +600,7 @@ int scsi_scan(int mode) bdesc = dev_get_uclass_platdata(bdev); scsi_init_dev_desc_priv(bdesc); - bdesc->lun = lun; - ret = scsi_detect_dev(i, bdesc); + ret = scsi_detect_dev(i, lun, bdesc); if (ret) { device_unbind(bdev); continue; @@ -630,8 +630,8 @@ int scsi_scan(int mode) scsi_max_devs = 0; for (i = 0; i < CONFIG_SYS_SCSI_MAX_SCSI_ID; i++) { for (lun = 0; lun < CONFIG_SYS_SCSI_MAX_LUN; lun++) { - scsi_dev_desc[scsi_max_devs].lun = lun; - ret = scsi_detect_dev(i, &scsi_dev_desc[scsi_max_devs]); + ret = scsi_detect_dev(i, lun, + &scsi_dev_desc[scsi_max_devs]); if (ret) continue; -- cgit v1.3.1 From 1330a726ff0c8164cf6035ab4a6d1e31805f69d1 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Fri, 7 Apr 2017 13:42:07 +0200 Subject: scsi: move the partition initialization out of the scsi detection We might want to get information about the scsi device without initializing the partition. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- common/scsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/scsi.c b/common/scsi.c index d55ba892a6f..972ef338be6 100644 --- a/common/scsi.c +++ b/common/scsi.c @@ -540,7 +540,6 @@ static int scsi_detect_dev(int target, int lun, struct blk_desc *dev_desc) dev_desc->blksz = blksz; dev_desc->log2blksz = LOG2(dev_desc->blksz); dev_desc->type = perq; - part_init(&dev_desc[0]); removable: return 0; } @@ -605,6 +604,7 @@ int scsi_scan(int mode) device_unbind(bdev); continue; } + part_init(bdesc); if (mode == 1) { printf(" Device %d: ", 0); @@ -634,6 +634,7 @@ int scsi_scan(int mode) &scsi_dev_desc[scsi_max_devs]); if (ret) continue; + part_init(&scsi_dev_desc[scsi_max_devs]); if (mode == 1) { printf(" Device %d: ", 0); -- cgit v1.3.1 From 4e27b9a5845e9c061b315b7ca301eff982d6898f Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Fri, 7 Apr 2017 13:42:08 +0200 Subject: dm: scsi: fix divide-by-0 error in scsi_scan() With DM_SCSI enabled, blk_create_devicef() is called with blkz = 0, leading to a divide-by-0 exception. scsi_detect_dev() can be used to get the required parameters (block size and number of blocks) from the drive before calling blk_create_devicef(). Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- common/scsi.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/scsi.c b/common/scsi.c index 972ef338be6..d37222cc6b8 100644 --- a/common/scsi.c +++ b/common/scsi.c @@ -580,9 +580,19 @@ int scsi_scan(int mode) for (lun = 0; lun < plat->max_lun; lun++) { struct udevice *bdev; /* block device */ /* block device description */ + struct blk_desc _bd; struct blk_desc *bdesc; char str[10]; + scsi_init_dev_desc_priv(&_bd); + ret = scsi_detect_dev(i, lun, &_bd); + if (ret) + /* + * no device detected? + * check the next lun. + */ + continue; + /* * Create only one block device and do detection * to make sure that there won't be a lot of @@ -590,20 +600,27 @@ int scsi_scan(int mode) */ snprintf(str, sizeof(str), "id%dlun%d", i, lun); ret = blk_create_devicef(dev, "scsi_blk", - str, IF_TYPE_SCSI, - -1, 0, 0, &bdev); + str, IF_TYPE_SCSI, + -1, + _bd.blksz, + _bd.blksz * _bd.lba, + &bdev); if (ret) { debug("Can't create device\n"); return ret; } - bdesc = dev_get_uclass_platdata(bdev); - scsi_init_dev_desc_priv(bdesc); - ret = scsi_detect_dev(i, lun, bdesc); - if (ret) { - device_unbind(bdev); - continue; - } + bdesc = dev_get_uclass_platdata(bdev); + bdesc->target = i; + bdesc->lun = lun; + bdesc->removable = _bd.removable; + bdesc->type = _bd.type; + memcpy(&bdesc->vendor, &_bd.vendor, + sizeof(_bd.vendor)); + memcpy(&bdesc->product, &_bd.product, + sizeof(_bd.product)); + memcpy(&bdesc->revision, &_bd.revision, + sizeof(_bd.revision)); part_init(bdesc); if (mode == 1) { -- cgit v1.3.1 From 26d61195f87006f2d37915de7eee8bb0f537e8a0 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Fri, 28 Apr 2017 08:51:44 -0400 Subject: fdt: Move fdt_fixup_ethernet to a common place With 3f66149d9fb4 we no longer have a common call fdt_fixup_ethernet. This was fine to do on PowerPC as they largely had calls already in ft_cpu_fixup. On ARM however we largely relied on this call. Rather than introduce a large number of changes to ft_cpu_fixup / ft_board_fixup we recognize that this is a common enough call that we should be doing it in a central location. Do it early enough that we can do any further updates in ft_cpu_fixup / ft_board_fixup. Cc: Gerd Hoffmann Cc: Chen-Yu Tsai Cc: Maxime Ripard Cc: Thomas Chou (maintainer:NIOS) Cc: York Sun (maintainer:POWERPC MPC85XX) Cc: Stefan Roese (maintainer:POWERPC PPC4XX) Cc: Simon Glass Cc: Joakim Tjernlund Fixes: 3f66149d9fb4 ("Remove extra fdt_fixup_ethernet() call") Signed-off-by: Tom Rini Acked-by: Stefan Roese Acked-by: York Sun Reviewed-by: Simon Glass --- arch/arm/cpu/armv7/ls102xa/fdt.c | 2 -- arch/nios2/cpu/Makefile | 1 - arch/nios2/cpu/fdt.c | 38 -------------------------------------- arch/powerpc/cpu/mpc512x/cpu.c | 3 --- arch/powerpc/cpu/mpc8260/cpu.c | 5 ----- arch/powerpc/cpu/mpc83xx/fdt.c | 1 - arch/powerpc/cpu/mpc85xx/fdt.c | 2 -- arch/powerpc/cpu/mpc86xx/fdt.c | 5 ----- arch/powerpc/cpu/mpc8xx/fdt.c | 3 --- arch/powerpc/cpu/ppc4xx/fdt.c | 6 ------ common/bootm_os.c | 2 -- common/image-fdt.c | 2 ++ configs/10m50_defconfig | 1 - configs/3c120_defconfig | 1 - 14 files changed, 2 insertions(+), 70 deletions(-) delete mode 100644 arch/nios2/cpu/fdt.c (limited to 'common') diff --git a/arch/arm/cpu/armv7/ls102xa/fdt.c b/arch/arm/cpu/armv7/ls102xa/fdt.c index ae5e794230c..d21ad39f8ad 100644 --- a/arch/arm/cpu/armv7/ls102xa/fdt.c +++ b/arch/arm/cpu/armv7/ls102xa/fdt.c @@ -94,8 +94,6 @@ void ft_cpu_setup(void *blob, bd_t *bd) } #endif - fdt_fixup_ethernet(blob); - off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); while (off != -FDT_ERR_NOTFOUND) { val = gd->cpu_clk; diff --git a/arch/nios2/cpu/Makefile b/arch/nios2/cpu/Makefile index 185ca3cdb76..c859b46bf83 100644 --- a/arch/nios2/cpu/Makefile +++ b/arch/nios2/cpu/Makefile @@ -8,4 +8,3 @@ extra-y = start.o obj-y = exceptions.o obj-y += cpu.o interrupts.o traps.o -obj-y += fdt.o diff --git a/arch/nios2/cpu/fdt.c b/arch/nios2/cpu/fdt.c deleted file mode 100644 index a44f51a7f2a..00000000000 --- a/arch/nios2/cpu/fdt.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * (C) Copyright 2011, Missing Link Electronics - * Joachim Foerster - * - * Taken from arch/powerpc/cpu/ppc4xx/fdt.c: - * - * (C) Copyright 2007-2008 - * Stefan Roese, DENX Software Engineering, sr@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include - -#ifdef CONFIG_OF_BOARD_SETUP -#include -#include - -DECLARE_GLOBAL_DATA_PTR; - -int __ft_board_setup(void *blob, bd_t *bd) -{ - ft_cpu_setup(blob, bd); - - return 0; -} -int ft_board_setup(void *blob, bd_t *bd) - __attribute__((weak, alias("__ft_board_setup"))); - -void ft_cpu_setup(void *blob, bd_t *bd) -{ - /* - * Fixup all ethernet nodes - * Note: aliases in the dts are required for this - */ - fdt_fixup_ethernet(blob); -} -#endif /* CONFIG_OF_BOARD_SETUP */ diff --git a/arch/powerpc/cpu/mpc512x/cpu.c b/arch/powerpc/cpu/mpc512x/cpu.c index 4ee91e16f9c..ce524fcdc79 100644 --- a/arch/powerpc/cpu/mpc512x/cpu.c +++ b/arch/powerpc/cpu/mpc512x/cpu.c @@ -176,9 +176,6 @@ void ft_cpu_setup(void *blob, bd_t *bd) old_ft_cpu_setup(blob, bd); #endif ft_clock_setup(blob, bd); -#ifdef CONFIG_HAS_ETH0 - fdt_fixup_ethernet(blob); -#endif fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); } #endif diff --git a/arch/powerpc/cpu/mpc8260/cpu.c b/arch/powerpc/cpu/mpc8260/cpu.c index 58d1c0261cb..7302b37f209 100644 --- a/arch/powerpc/cpu/mpc8260/cpu.c +++ b/arch/powerpc/cpu/mpc8260/cpu.c @@ -294,11 +294,6 @@ void watchdog_reset (void) #ifdef CONFIG_OF_BOARD_SETUP void ft_cpu_setup (void *blob, bd_t *bd) { -#if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\ - defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) - fdt_fixup_ethernet(blob); -#endif - do_fixup_by_compat_u32(blob, "fsl,cpm2-brg", "clock-frequency", bd->bi_brgfreq, 1); diff --git a/arch/powerpc/cpu/mpc83xx/fdt.c b/arch/powerpc/cpu/mpc83xx/fdt.c index f249a585edf..3ac4eb1dd8f 100644 --- a/arch/powerpc/cpu/mpc83xx/fdt.c +++ b/arch/powerpc/cpu/mpc83xx/fdt.c @@ -53,7 +53,6 @@ void ft_cpu_setup(void *blob, bd_t *bd) #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\ defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) ||\ defined(CONFIG_HAS_ETH4) || defined(CONFIG_HAS_ETH5) - fdt_fixup_ethernet(blob); #ifdef CONFIG_MPC8313 /* * mpc8313e erratum IPIC1 swapped TSEC interrupt ID numbers on rev. 1 diff --git a/arch/powerpc/cpu/mpc85xx/fdt.c b/arch/powerpc/cpu/mpc85xx/fdt.c index 67140ba9ee1..a9ea947305f 100644 --- a/arch/powerpc/cpu/mpc85xx/fdt.c +++ b/arch/powerpc/cpu/mpc85xx/fdt.c @@ -612,8 +612,6 @@ void ft_cpu_setup(void *blob, bd_t *bd) } #endif - fdt_fixup_ethernet(blob); - fdt_add_enet_stashing(blob); #ifndef CONFIG_FSL_TBCLK_EXTRA_DIV diff --git a/arch/powerpc/cpu/mpc86xx/fdt.c b/arch/powerpc/cpu/mpc86xx/fdt.c index 5f9ad6b0b6d..30fbf14f1bd 100644 --- a/arch/powerpc/cpu/mpc86xx/fdt.c +++ b/arch/powerpc/cpu/mpc86xx/fdt.c @@ -32,11 +32,6 @@ void ft_cpu_setup(void *blob, bd_t *bd) fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); -#if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) \ - || defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) - fdt_fixup_ethernet(blob); -#endif - #ifdef CONFIG_SYS_NS16550 do_fixup_by_compat_u32(blob, "ns16550", "clock-frequency", CONFIG_SYS_NS16550_CLK, 1); diff --git a/arch/powerpc/cpu/mpc8xx/fdt.c b/arch/powerpc/cpu/mpc8xx/fdt.c index 97830e3c8bd..34d36478d30 100644 --- a/arch/powerpc/cpu/mpc8xx/fdt.c +++ b/arch/powerpc/cpu/mpc8xx/fdt.c @@ -23,8 +23,5 @@ void ft_cpu_setup(void *blob, bd_t *bd) do_fixup_by_compat_u32(blob, "fsl,cpm-brg", "clock-frequency", gd->arch.brg_clk, 1); - /* Fixup ethernet MAC addresses */ - fdt_fixup_ethernet(blob); - fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); } diff --git a/arch/powerpc/cpu/ppc4xx/fdt.c b/arch/powerpc/cpu/ppc4xx/fdt.c index c73509b3ee3..28080583a79 100644 --- a/arch/powerpc/cpu/ppc4xx/fdt.c +++ b/arch/powerpc/cpu/ppc4xx/fdt.c @@ -149,12 +149,6 @@ void ft_cpu_setup(void *blob, bd_t *bd) (void *)&gd->arch.uart_clk, 4); } - /* - * Fixup all ethernet nodes - * Note: aliases in the dts are required for this - */ - fdt_fixup_ethernet(blob); - /* * Fixup all available PCIe nodes by setting the device_type property */ diff --git a/common/bootm_os.c b/common/bootm_os.c index 6e463c317e8..e1024069766 100644 --- a/common/bootm_os.c +++ b/common/bootm_os.c @@ -288,8 +288,6 @@ void do_bootvx_fdt(bootm_headers_t *images) if (ret) return; - fdt_fixup_ethernet(*of_flat_tree); - ret = fdt_add_subnode(*of_flat_tree, 0, "chosen"); if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) { bootline = getenv("bootargs"); diff --git a/common/image-fdt.c b/common/image-fdt.c index 7468b902b8d..c6e8832d668 100644 --- a/common/image-fdt.c +++ b/common/image-fdt.c @@ -478,6 +478,8 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob, printf("ERROR: arch-specific fdt fixup failed\n"); goto err; } + /* Update ethernet nodes */ + fdt_fixup_ethernet(blob); if (IMAGE_OF_BOARD_SETUP) { fdt_ret = ft_board_setup(blob, gd->bd); if (fdt_ret) { diff --git a/configs/10m50_defconfig b/configs/10m50_defconfig index 68da5ff1108..ed9a867d728 100644 --- a/configs/10m50_defconfig +++ b/configs/10m50_defconfig @@ -2,7 +2,6 @@ CONFIG_NIOS2=y CONFIG_SYS_CONFIG_NAME="10m50_devboard" CONFIG_DEFAULT_DEVICE_TREE="10m50_devboard" CONFIG_FIT=y -CONFIG_OF_BOARD_SETUP=y CONFIG_SYS_CONSOLE_INFO_QUIET=y CONFIG_VERSION_VARIABLE=y CONFIG_HUSH_PARSER=y diff --git a/configs/3c120_defconfig b/configs/3c120_defconfig index 9adf97adb63..95e794afca8 100644 --- a/configs/3c120_defconfig +++ b/configs/3c120_defconfig @@ -2,7 +2,6 @@ CONFIG_NIOS2=y CONFIG_SYS_CONFIG_NAME="3c120_devboard" CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard" CONFIG_FIT=y -CONFIG_OF_BOARD_SETUP=y CONFIG_SYS_CONSOLE_INFO_QUIET=y CONFIG_VERSION_VARIABLE=y CONFIG_HUSH_PARSER=y -- cgit v1.3.1 From afa81a7750d63be9cb9eeb99a26c73bc93f4e1d9 Mon Sep 17 00:00:00 2001 From: Andreas Fenkart Date: Sat, 8 Apr 2017 11:59:31 +0200 Subject: env_sf: factor out prepare_flash_device copy&paste code found in single/double buffered code path Signed-off-by: Andreas Fenkart Reviewed-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Jagan Teki --- common/env_sf.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) (limited to 'common') diff --git a/common/env_sf.c b/common/env_sf.c index 27b4d1226a6..8af590a3d9a 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -45,15 +45,11 @@ char *env_name_spec = "SPI Flash"; static struct spi_flash *env_flash; -#if defined(CONFIG_ENV_OFFSET_REDUND) -int saveenv(void) +static int setup_flash_device(void) { - env_t env_new; - char *saved_buffer = NULL, flag = OBSOLETE_FLAG; - u32 saved_size, saved_offset, sector = 1; - int ret; #ifdef CONFIG_DM_SPI_FLASH struct udevice *new; + int ret; /* speed and mode will be read from DT */ ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, @@ -76,6 +72,20 @@ int saveenv(void) } } #endif + return 0; +} + +#if defined(CONFIG_ENV_OFFSET_REDUND) +int saveenv(void) +{ + env_t env_new; + char *saved_buffer = NULL, flag = OBSOLETE_FLAG; + u32 saved_size, saved_offset, sector = 1; + int ret; + + ret = setup_flash_device(); + if (ret) + return ret; ret = env_export(&env_new); if (ret) @@ -242,30 +252,10 @@ int saveenv(void) char *saved_buffer = NULL; int ret = 1; env_t env_new; -#ifdef CONFIG_DM_SPI_FLASH - struct udevice *new; - /* speed and mode will be read from DT */ - ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, - 0, 0, &new); - if (ret) { - set_default_env("!spi_flash_probe_bus_cs() failed"); - return 1; - } - - env_flash = dev_get_uclass_priv(new); -#else - - if (!env_flash) { - env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, - CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); - if (!env_flash) { - set_default_env("!spi_flash_probe() failed"); - return 1; - } - } -#endif + ret = setup_flash_device(); + if (ret) + return ret; /* Is the sector larger than the env (i.e. embedded) */ if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) { -- cgit v1.3.1 From 8fee8845e7543aec3edd64fcef2d6ff268d65a0d Mon Sep 17 00:00:00 2001 From: Andreas Fenkart Date: Sat, 8 Apr 2017 11:59:32 +0200 Subject: enf_sf: reuse setup_flash_device instead of open coding it setup_flash_device selects one of two code paths depending on the driver model being used (=CONFIG_DM_SPI_FLASH). env_relocate_spec only used the non driver-model code path. I'm unsure why, either none of the platforms that need relocation use the driver model, or - worse - the driver model is not yet usable when relocating. Signed-off-by: Andreas Fenkart Reviewed-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Jagan Teki --- common/env_sf.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/env_sf.c b/common/env_sf.c index 8af590a3d9a..a52fb734c85 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -176,12 +176,9 @@ void env_relocate_spec(void) goto out; } - env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); - if (!env_flash) { - set_default_env("!spi_flash_probe() failed"); + ret = setup_flash_device(); + if (ret) goto out; - } ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, tmp_env1); @@ -316,10 +313,9 @@ void env_relocate_spec(void) char *buf = NULL; buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); - env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); - if (!env_flash) { - set_default_env("!spi_flash_probe() failed"); + + ret = setup_flash_device(); + if (ret) { if (buf) free(buf); return; -- cgit v1.3.1 From c041c60c6c5c1eafcff21eec76e16ee958a7506e Mon Sep 17 00:00:00 2001 From: Andreas Fenkart Date: Sat, 8 Apr 2017 11:59:33 +0200 Subject: env_sf: re-order error handling in single-buffer env_relocate_spec this makes it easier comparable to the double-buffered version Signed-off-by: Andreas Fenkart Reviewed-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Jagan Teki --- common/env_sf.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/env_sf.c b/common/env_sf.c index a52fb734c85..6a1583ebec3 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -313,29 +313,31 @@ void env_relocate_spec(void) char *buf = NULL; buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); - - ret = setup_flash_device(); - if (ret) { - if (buf) - free(buf); + if (!buf) { + set_default_env("!malloc() failed"); return; } + ret = setup_flash_device(); + if (ret) + goto out; + ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf); if (ret) { set_default_env("!spi_flash_read() failed"); - goto out; + goto err_read; } ret = env_import(buf, 1); if (ret) gd->env_valid = 1; -out: + +err_read: spi_flash_free(env_flash); - if (buf) - free(buf); env_flash = NULL; +out: + free(buf); } #endif -- cgit v1.3.1 From 0b2e5bbe6a4f3d25522675198b8beb0093a2e750 Mon Sep 17 00:00:00 2001 From: Andreas Fenkart Date: Sat, 8 Apr 2017 11:59:34 +0200 Subject: env_sf: use DIV_ROUND_UP to calculate number of sectors to erase simpler to read Signed-off-by: Andreas Fenkart Reviewed-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Jagan Teki --- common/env_sf.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'common') diff --git a/common/env_sf.c b/common/env_sf.c index 6a1583ebec3..9944602367b 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -80,7 +80,7 @@ int saveenv(void) { env_t env_new; char *saved_buffer = NULL, flag = OBSOLETE_FLAG; - u32 saved_size, saved_offset, sector = 1; + u32 saved_size, saved_offset, sector; int ret; ret = setup_flash_device(); @@ -115,11 +115,7 @@ int saveenv(void) goto done; } - if (CONFIG_ENV_SIZE > CONFIG_ENV_SECT_SIZE) { - sector = CONFIG_ENV_SIZE / CONFIG_ENV_SECT_SIZE; - if (CONFIG_ENV_SIZE % CONFIG_ENV_SECT_SIZE) - sector++; - } + sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE); puts("Erasing SPI flash..."); ret = spi_flash_erase(env_flash, env_new_offset, @@ -245,7 +241,7 @@ out: #else int saveenv(void) { - u32 saved_size, saved_offset, sector = 1; + u32 saved_size, saved_offset, sector; char *saved_buffer = NULL; int ret = 1; env_t env_new; @@ -268,16 +264,12 @@ int saveenv(void) goto done; } - if (CONFIG_ENV_SIZE > CONFIG_ENV_SECT_SIZE) { - sector = CONFIG_ENV_SIZE / CONFIG_ENV_SECT_SIZE; - if (CONFIG_ENV_SIZE % CONFIG_ENV_SECT_SIZE) - sector++; - } - ret = env_export(&env_new); if (ret) goto done; + sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE); + puts("Erasing SPI flash..."); ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET, sector * CONFIG_ENV_SECT_SIZE); -- cgit v1.3.1 From 5bf5250e9d1555aa388a810213fd85106a60388e Mon Sep 17 00:00:00 2001 From: Vikas Manocha Date: Fri, 7 Apr 2017 15:38:13 -0700 Subject: spl: make image arg or fdt blob address reconfigurable At present fdt blob or argument address being passed to kernel is fixed at compile time using macro CONFIG_SYS_SPL_ARGS_ADDR. FDT blob from different media like nand, nor flash are copied to the address pointed by the macro. The problem is, it makes args/fdt blob compulsory to copy which is not required in cases like for NOR Flash. This patch removes this limitation. Signed-off-by: Vikas Manocha --- arch/arm/lib/spl.c | 7 +++---- arch/microblaze/cpu/spl.c | 6 +++--- arch/powerpc/lib/spl.c | 8 ++++---- common/spl/spl.c | 6 ++++-- common/spl/spl_nor.c | 8 +------- include/spl.h | 5 ++--- 6 files changed, 17 insertions(+), 23 deletions(-) (limited to 'common') diff --git a/arch/arm/lib/spl.c b/arch/arm/lib/spl.c index e606d470e38..8ff2c5065dd 100644 --- a/arch/arm/lib/spl.c +++ b/arch/arm/lib/spl.c @@ -44,22 +44,21 @@ void __weak board_init_f(ulong dummy) /* * This function jumps to an image with argument. Normally an FDT or ATAGS * image. - * arg: Pointer to paramter image in RAM */ #ifdef CONFIG_SPL_OS_BOOT -void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, void *arg) +void __noreturn jump_to_image_linux(struct spl_image_info *spl_image) { unsigned long machid = 0xffffffff; #ifdef CONFIG_MACH_TYPE machid = CONFIG_MACH_TYPE; #endif - debug("Entering kernel arg pointer: 0x%p\n", arg); + debug("Entering kernel arg pointer: 0x%p\n", spl_image->arg); typedef void (*image_entry_arg_t)(int, int, void *) __attribute__ ((noreturn)); image_entry_arg_t image_entry = (image_entry_arg_t)(uintptr_t) spl_image->entry_point; cleanup_before_linux(); - image_entry(0, machid, arg); + image_entry(0, machid, spl_image->arg); } #endif diff --git a/arch/microblaze/cpu/spl.c b/arch/microblaze/cpu/spl.c index 8e6d9269dac..3d57a5a8593 100644 --- a/arch/microblaze/cpu/spl.c +++ b/arch/microblaze/cpu/spl.c @@ -29,15 +29,15 @@ void spl_board_init(void) } #ifdef CONFIG_SPL_OS_BOOT -void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, void *arg) +void __noreturn jump_to_image_linux(struct spl_image_info *spl_image) { - debug("Entering kernel arg pointer: 0x%p\n", arg); + debug("Entering kernel arg pointer: 0x%p\n", spl_image->arg); typedef void (*image_entry_arg_t)(char *, ulong, ulong) __attribute__ ((noreturn)); image_entry_arg_t image_entry = (image_entry_arg_t)spl_image->entry_point; - image_entry(NULL, 0, (ulong)arg); + image_entry(NULL, 0, (ulong)spl_image->arg); } #endif /* CONFIG_SPL_OS_BOOT */ diff --git a/arch/powerpc/lib/spl.c b/arch/powerpc/lib/spl.c index 080b978799b..b93197030e3 100644 --- a/arch/powerpc/lib/spl.c +++ b/arch/powerpc/lib/spl.c @@ -14,18 +14,18 @@ DECLARE_GLOBAL_DATA_PTR; /* * This function jumps to an image with argument. Normally an FDT or ATAGS * image. - * arg: Pointer to paramter image in RAM */ #ifdef CONFIG_SPL_OS_BOOT -void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, void *arg) +void __noreturn jump_to_image_linux(struct spl_image_info *spl_image) { - debug("Entering kernel arg pointer: 0x%p\n", arg); + debug("Entering kernel arg pointer: 0x%p\n", spl_image->arg); typedef void (*image_entry_arg_t)(void *, ulong r4, ulong r5, ulong r6, ulong r7, ulong r8, ulong r9) __attribute__ ((noreturn)); image_entry_arg_t image_entry = (image_entry_arg_t)spl_image->entry_point; - image_entry(arg, 0, 0, EPAPR_MAGIC, CONFIG_SYS_BOOTMAPSZ, 0, 0); + image_entry(spl_image->arg, 0, 0, EPAPR_MAGIC, CONFIG_SYS_BOOTMAPSZ, + 0, 0); } #endif /* CONFIG_SPL_OS_BOOT */ diff --git a/common/spl/spl.c b/common/spl/spl.c index a3e73b87bc6..50828e60218 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -345,6 +345,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2) #endif memset(&spl_image, '\0', sizeof(spl_image)); +#ifdef CONFIG_SYS_SPL_ARGS_ADDR + spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR; +#endif board_boot_order(spl_boot_list); if (boot_from_devices(&spl_image, spl_boot_list, @@ -361,8 +364,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2) case IH_OS_LINUX: debug("Jumping to Linux\n"); spl_board_prepare_for_linux(); - jump_to_image_linux(&spl_image, - (void *)CONFIG_SYS_SPL_ARGS_ADDR); + jump_to_image_linux(&spl_image); #endif default: debug("Unsupported OS image.. Jumping nevertheless..\n"); diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index d07ca843824..1ef8ac8b89b 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -39,13 +39,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image, sizeof(struct image_header)), spl_image->size); - /* - * Copy DT blob (fdt) to SDRAM. Passing pointer to - * flash doesn't work - */ - memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR, - (void *)(CONFIG_SYS_FDT_BASE), - CONFIG_SYS_FDT_SIZE); + spl_image->arg = (void *)CONFIG_SYS_FDT_BASE; return 0; } else { diff --git a/include/spl.h b/include/spl.h index 2e5b885c8d6..d1638e9d7cb 100644 --- a/include/spl.h +++ b/include/spl.h @@ -27,6 +27,7 @@ struct spl_image_info { ulong entry_point; u32 size; u32 flags; + void *arg; }; /* @@ -106,10 +107,8 @@ int spl_board_ubi_load_image(u32 boot_device); * This jumps into a Linux kernel using the information in @spl_image. * * @spl_image: Image description to set up - * @arg: Argument to pass to Linux (typically a device tree pointer) */ -void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, - void *arg); +void __noreturn jump_to_image_linux(struct spl_image_info *spl_image); /** * spl_start_uboot() - Check if SPL should start the kernel or U-Boot -- cgit v1.3.1