X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=env%2Fsf.c;h=e51b1ae189164f9a0247ca5f2b12b6d7c1776600;hb=9b643e312d528f291966c1f30b0d90bf3b1d43dc;hp=8f81cf5e40298b6b46be63c60b459d3803fd1a8c;hpb=4415f1d1f1c57d43f6bc8ff156554c2b2da45b52;p=people%2Fms%2Fu-boot.git diff --git a/env/sf.c b/env/sf.c index 8f81cf5e40..e51b1ae189 100644 --- a/env/sf.c +++ b/env/sf.c @@ -48,8 +48,6 @@ static ulong env_new_offset = CONFIG_ENV_OFFSET_REDUND; DECLARE_GLOBAL_DATA_PTR; -char *env_name_spec = "SPI Flash"; - static struct spi_flash *env_flash; static int setup_flash_device(void) @@ -63,7 +61,7 @@ static int setup_flash_device(void) 0, 0, &new); if (ret) { set_default_env("!spi_flash_probe_bus_cs() failed"); - return 1; + return ret; } env_flash = dev_get_uclass_priv(new); @@ -75,7 +73,7 @@ static int setup_flash_device(void) CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); if (!env_flash) { set_default_env("!spi_flash_probe() failed"); - return 1; + return -EIO; } } #endif @@ -84,7 +82,7 @@ static int setup_flash_device(void) #if defined(CONFIG_ENV_OFFSET_REDUND) #ifdef CMD_SAVEENV -int saveenv(void) +static int env_sf_save(void) { env_t env_new; char *saved_buffer = NULL, flag = OBSOLETE_FLAG; @@ -97,7 +95,7 @@ int saveenv(void) ret = env_export(&env_new); if (ret) - return ret; + return -EIO; env_new.flags = ACTIVE_FLAG; if (gd->env_valid == ENV_VALID) { @@ -114,7 +112,7 @@ int saveenv(void) saved_offset = env_new_offset + CONFIG_ENV_SIZE; saved_buffer = memalign(ARCH_DMA_MINALIGN, saved_size); if (!saved_buffer) { - ret = 1; + ret = -ENOMEM; goto done; } ret = spi_flash_read(env_flash, saved_offset, @@ -164,7 +162,7 @@ int saveenv(void) } #endif /* CMD_SAVEENV */ -void env_relocate_spec(void) +static int env_sf_load(void) { int ret; int crc1_ok = 0, crc2_ok = 0; @@ -178,6 +176,7 @@ void env_relocate_spec(void) CONFIG_ENV_SIZE); if (!tmp_env1 || !tmp_env2) { set_default_env("!malloc() failed"); + ret = -EIO; goto out; } @@ -204,6 +203,7 @@ void env_relocate_spec(void) if (!crc1_ok && !crc2_ok) { set_default_env("!bad CRC"); + ret = -EIO; goto err_read; } else if (crc1_ok && !crc2_ok) { gd->env_valid = ENV_VALID; @@ -236,7 +236,7 @@ void env_relocate_spec(void) ret = env_import((char *)ep, 0); if (!ret) { - error("Cannot import environment: errno = %d\n", errno); + pr_err("Cannot import environment: errno = %d\n", errno); set_default_env("!env_import failed"); } @@ -246,10 +246,12 @@ err_read: out: free(tmp_env1); free(tmp_env2); + + return ret; } #else #ifdef CMD_SAVEENV -int saveenv(void) +static int env_sf_save(void) { u32 saved_size, saved_offset, sector; char *saved_buffer = NULL; @@ -310,7 +312,7 @@ int saveenv(void) } #endif /* CMD_SAVEENV */ -void env_relocate_spec(void) +static int env_sf_load(void) { int ret; char *buf = NULL; @@ -318,7 +320,7 @@ void env_relocate_spec(void) buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); if (!buf) { set_default_env("!malloc() failed"); - return; + return -EIO; } ret = setup_flash_device(); @@ -341,24 +343,16 @@ err_read: env_flash = NULL; out: free(buf); -} -#endif - -int env_init(void) -{ - /* SPI flash isn't usable before relocation */ - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = ENV_VALID; - return 0; + return ret; } +#endif U_BOOT_ENV_LOCATION(sf) = { .location = ENVL_SPI_FLASH, - .get_char = env_get_char_spec, - .load = env_relocate_spec, + ENV_NAME("SPI Flash") + .load = env_sf_load, #ifdef CMD_SAVEENV - .save = env_save_ptr(saveenv), + .save = env_save_ptr(env_sf_save), #endif - .init = env_init, };