aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/dlmalloc.c22
-rw-r--r--common/env_sf.c29
2 files changed, 51 insertions, 0 deletions
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index b5bb05191c..2b964d16b1 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -2829,6 +2829,28 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
nb = request2size(bytes);
m = (char*)(mALLOc(nb + alignment + MINSIZE));
+ /*
+ * The attempt to over-allocate (with a size large enough to guarantee the
+ * ability to find an aligned region within allocated memory) failed.
+ *
+ * Try again, this time only allocating exactly the size the user wants. If
+ * the allocation now succeeds and just happens to be aligned, we can still
+ * fulfill the user's request.
+ */
+ if (m == NULL) {
+ /*
+ * Use bytes not nb, since mALLOc internally calls request2size too, and
+ * each call increases the size to allocate, to account for the header.
+ */
+ m = (char*)(mALLOc(bytes));
+ /* Aligned -> return it */
+ if ((((unsigned long)(m)) % alignment) == 0)
+ return m;
+ /* Otherwise, fail */
+ fREe(m);
+ return NULL;
+ }
+
if (m == NULL) return NULL; /* propagate failure */
p = mem2chunk(m);
diff --git a/common/env_sf.c b/common/env_sf.c
index 940983124f..892e6cbfb8 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -16,6 +16,7 @@
#include <spi_flash.h>
#include <search.h>
#include <errno.h>
+#include <dm/device-internal.h>
#ifndef CONFIG_ENV_SPI_BUS
# define CONFIG_ENV_SPI_BUS 0
@@ -51,6 +52,19 @@ int saveenv(void)
char *saved_buffer = NULL, flag = OBSOLETE_FLAG;
u32 saved_size, saved_offset, sector = 1;
int ret;
+#ifdef CONFIG_DM_SPI_FLASH
+ struct udevice *new;
+
+ 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) {
+ 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,
@@ -61,6 +75,7 @@ int saveenv(void)
return 1;
}
}
+#endif
ret = env_export(&env_new);
if (ret)
@@ -227,6 +242,19 @@ int saveenv(void)
char *saved_buffer = NULL;
int ret = 1;
env_t env_new;
+#ifdef CONFIG_DM_SPI_FLASH
+ struct udevice *new;
+
+ 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) {
+ 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,
@@ -237,6 +265,7 @@ int saveenv(void)
return 1;
}
}
+#endif
/* Is the sector larger than the env (i.e. embedded) */
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {