Fixes for SPI boot on SanCloud BBE Lite
cover Fixes for SPI boot on SanCloud BBE Lite
These two commits fix SPI boot on the SanCloud BBE Lite and are likely also required for SPI boot on other am335x boards.
Paul Barker (2):
dm: core: Fix iteration over driver_info records
configs: am335x_evm: Disable SPL_OF_CONTROL
configs/am335x_boneblack_vboot_defconfig | 1 - configs/am335x_evm_spiboot_defconfig | 1 - drivers/core/lists.c | 17 ++++++----------- 3 files changed, 6 insertions(+), 13 deletions(-)
base-commit: 0e49f5c26caf9972137a474065afd4bdfe5ec062
Signature · 1 line
2.25.1
PATCH 1/2 dm: core: Fix iteration over driver_info records
We should only perform additional iteration steps when needed to initialize the parent of a device. Other binding errors (such as a missing driver) should not lead to additional iteration steps.
Unnecessary iteration steps can cause issues when memory is tightly constrained (such as in the TPL/SPL) since device_bind_by_name() unconditionally allocates memory for a struct udevice. On the SanCloud BBE this led to boot failure caused by memory exhaustion in the SPL when booting from SPI flash.
--- drivers/core/lists.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/core/lists.c +6 -11
@@ -51,13 +51,13 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id)return NULL ; } -static int bind_drivers_pass (struct udevice *parent,bool pre_reloc_only) +static bool bind_drivers_pass (struct udevice *parent,bool pre_reloc_only, +int *result) {struct driver_info *info = ll_entry_start(struct driver_info, driver_info); const int n_ents = ll_entry_count(struct driver_info, driver_info);bool missing_parent = false; -int result =0 ;int idx;/*
@@ -98,12 +98,12 @@ static int bind_drivers_pass(struct udevice *parent, bool pre_reloc_only) drt->dev = dev; }else if (ret != -EPERM ) {dm_warn ("No match for driver '%s'\n" , entry->name); -if (!result || ret != -ENOENT ) - result = ret; +if (!*result || ret != -ENOENT ) + *result = ret; } } -return result ? result : missing_parent ? -EAGAIN :0 ; +return missing_parent; }int lists_bind_drivers (struct udevice *parent,bool pre_reloc_only)
@@ -117,13 +117,8 @@ int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)* always succeed on the first pass. */ for (pass =0 ; pass <10 ; pass++) { -int ret; - - ret =bind_drivers_pass (parent, pre_reloc_only); -if (!ret) +if (!bind_drivers_pass (parent, pre_reloc_only, &result))break ; -if (ret != -EAGAIN && !result) - result = ret; }return result;
Signature · 1 line
2.25.1
Re: [PATCH 1/2] dm: core: Fix iteration over driver_info records
Hi Paul,
Quoted 11 lines · Paul Barker
We should only perform additional iteration steps when needed to initialize the parent of a device. Other binding errors (such as a missing driver) should not lead to additional iteration steps.
Unnecessary iteration steps can cause issues when memory is tightly constrained (such as in the TPL/SPL) since
device_bind_by_name()unconditionally allocates memory for a struct udevice. On the SanCloud BBE this led to boot failure caused by memory exhaustion in the SPL when booting from SPI flash.
Quoted 4 lines
Signed-off-by Paul Barker <[email protected]>--- drivers/core/lists.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
Are you able to construct a test for this? See test/dm/core.c or test-fdt.c
Also, I think bind_drivers_pass() needs a function comment that describes in detail what is going on.
Would it be possible to achieve the same effect while keeping that function the same as now? See below.
Quoted 39 lines
drivers/core/lists.c +5
-5@@ -51,13 +51,13 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id)return NULL ; } -static int bind_drivers_pass (struct udevice *parent,bool pre_reloc_only) +static bool bind_drivers_pass (struct udevice *parent,bool pre_reloc_only, +int *result) {struct driver_info *info = ll_entry_start(struct driver_info, driver_info); const int n_ents = ll_entry_count(struct driver_info, driver_info);bool missing_parent = false; -int result =0 ;int idx;/* @@ -98,12 +98,12 @@ static int bind_drivers_pass(struct udevice *parent, bool pre_reloc_only) drt->dev = dev; }else if (ret != -EPERM ) {dm_warn ("No match for driver '%s'\n" , entry->name); -if (!result || ret != -ENOENT ) - result = ret; +if (!*result || ret != -ENOENT ) + *result = ret; } } -return result ? result : missing_parent ? -EAGAIN :0 ; +return missing_parent; }int lists_bind_drivers (struct udevice *parent,bool pre_reloc_only)@@ -117,13 +117,8 @@ int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)* always succeed on the first pass.
drivers/core/lists.c int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only) · line 126
Quoted 10 lines
drivers/core/lists.c +1
-6*/ for (pass =0 ; pass <10 ; pass++) { -int ret; - - ret =bind_drivers_pass (parent, pre_reloc_only); -if (!ret) +if (!bind_drivers_pass (parent, pre_reloc_only, &result))break ; -if (ret != -EAGAIN && !result) - result = ret;
If there were something like this, could we drop the other changes?
if (ret) {
if (ret == -EAGAIN)
continue;
else if (!result)
result = ret; }
Quoted 6 lines
drivers/core/lists.c +0
-1}return result; --2.25.1
Re: [PATCH 1/2] dm: core: Fix iteration over driver_info records
Quoted 14 lines · Simon Glass
Hi Paul,
Quoted 11 lines · Paul Barker
We should only perform additional iteration steps when needed to initialize the parent of a device. Other binding errors (such as a missing driver) should not lead to additional iteration steps.
Unnecessary iteration steps can cause issues when memory is tightly constrained (such as in the TPL/SPL) since
device_bind_by_name()unconditionally allocates memory for a struct udevice. On the SanCloud BBE this led to boot failure caused by memory exhaustion in the SPL when booting from SPI flash.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Paul Barker <[email protected]>--- drivers/core/lists.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)Are you able to construct a test for this? See
test/dm/core.cortest-fdt.c
I can't see how to construct a test case for this issue. What I observed was the SPL crashing during the pre-relocation lists_bind_drivers() call due to exhaustion of the available memory. On the AM335x SoC this is 64k of on-board SRAM which is available before main DRAM is initialised. I can't see how to reproduce this issue within the u-boot test framework as significantly more memory is available when running the u-boot sandbox and so memory exhaustion does not occur. If there are other side effects than memory leaking here then I'm not familiar enough with the u-boot device model to spot them.
Each call to bind_drivers_pass() calls device_bind_by_name() for every driver_info record, with no way of checking whether a particular driver_info record has already been handled by a previous call to bind_drivers_pass(). This leaks memory as each call to device_bind_by_name() allocates a new device object.
Quoted 3 lines
Also, I think
bind_drivers_pass()needs a function comment that describes in detail what is going on.
Agreed, I'll see what I can add when I revisit this.
Quoted 56 lines
Would it be possible to achieve the same effect while keeping that function the same as now? See below.
Quoted 39 lines
drivers/core/lists.c +5
-5@@ -51,13 +51,13 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id)return NULL ; } -static int bind_drivers_pass (struct udevice *parent,bool pre_reloc_only) +static bool bind_drivers_pass (struct udevice *parent,bool pre_reloc_only, +int *result) {struct driver_info *info = ll_entry_start(struct driver_info, driver_info); const int n_ents = ll_entry_count(struct driver_info, driver_info);bool missing_parent = false; -int result =0 ;int idx;/* @@ -98,12 +98,12 @@ static int bind_drivers_pass(struct udevice *parent, bool pre_reloc_only) drt->dev = dev; }else if (ret != -EPERM ) {dm_warn ("No match for driver '%s'\n" , entry->name); -if (!result || ret != -ENOENT ) - result = ret; +if (!*result || ret != -ENOENT ) + *result = ret; } } -return result ? result : missing_parent ? -EAGAIN :0 ; +return missing_parent; }int lists_bind_drivers (struct udevice *parent,bool pre_reloc_only)@@ -117,13 +117,8 @@ int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)* always succeed on the first pass. drivers/core/lists.c int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only) · line 126
Quoted 10 lines
drivers/core/lists.c +1
-6*/ for (pass =0 ; pass <10 ; pass++) { -int ret; - - ret =bind_drivers_pass (parent, pre_reloc_only); -if (!ret) +if (!bind_drivers_pass (parent, pre_reloc_only, &result))break ; -if (ret != -EAGAIN && !result) - result = ret;If there were something like this, could we drop the other changes?
Quoted 7 lines
if (ret) {
if (ret == -EAGAIN)
continue;
else if (!result)
result = ret;
}I don't think this works exactly, as we want to break when (ret == -EAGAIN) instead of continue. However I have a variant which I think is working which I can send as a v2.
Quoted 7 lines
Quoted 7 lines
drivers/core/lists.c +0
-1}return result; --2.25.1
Signature · 6 lines
Paul Barker Principal Software Engineer SanCloud Ltd e: [email protected] w: https://sancloud.com/
PATCH 2/2 configs: am335x_evm: Disable SPL_OF_CONTROL
In reply to Paul BarkerWhen CONFIG_SPL_OF_CONFIG is enabled on the BeagleBone Black and the SanCloud BBE, initialization of the I2C bus in ti_i2c_eeprom_get() fails. This prevents us from determining the board variant in enable_board_pin_mux(). As pinmux settings are not correctly configured this leads to boot failure.
--- configs/am335x_boneblack_vboot_defconfig | 1 - configs/am335x_evm_spiboot_defconfig | 1 - 2 files changed, 2 deletions(-)
configs/am335x_boneblack_vboot_defconfig +0 -1
@@ -43,7 +43,6 @@ CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2 # CONFIG_CMD_SETEXPR is not set CONFIG_BOOTP_DNS2=y CONFIG_OF_CONTROL=y -CONFIG_SPL_OF_CONTROL=y CONFIG_ENV_OVERWRITE=y CONFIG_ENV_IS_IN_MMC=y CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
configs/am335x_evm_spiboot_defconfig +0 -1
@@ -42,7 +42,6 @@ CONFIG_BOOTP_DNS2=y CONFIG_CMD_MTDPARTS=y # CONFIG_SPL_EFI_PARTITION is not set CONFIG_OF_CONTROL=y -CONFIG_SPL_OF_CONTROL=y CONFIG_OF_LIST="am335x-evm am335x-bone am335x-boneblack am335x-evmsk am335x-bonegreen am335x-icev2 am335x-pocketbeagle" CONFIG_ENV_OVERWRITE=y # CONFIG_ENV_IS_IN_FAT is not set
Signature · 1 line
2.25.1
Re: [PATCH 2/2] configs: am335x_evm: Disable SPL_OF_CONTROL
Hi Paul,
Quoted 7 lines · Paul Barker
When
CONFIG_SPL_OF_CONFIGis enabled on the BeagleBone Black and the SanCloud BBE, initialization of the I2C bus inti_i2c_eeprom_get()fails. This prevents us from determining the board variant inenable_board_pin_mux(). As pinmux settings are not correctly configured this leads to boot failure.
Quoted 5 lines
Signed-off-by Paul Barker <[email protected]>--- configs/am335x_boneblack_vboot_defconfig | 1 - configs/am335x_evm_spiboot_defconfig | 1 - 2 files changed, 2 deletions(-)
Instead I think you should fix the bug, perhaps in the i2c eeprom code?
Regards,
SImon