/* Export the environment and generate CRC for it. */ int env_export(env_t *env_out) { char *res; ssize_t len; int ret; res = (char *)env_out->data; len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } /* Encrypt the env if desired. */ ret = env_aes_cbc_crypt(env_out, 1); if (ret) return ret; env_out->crc = crc32(0, env_out->data, ENV_SIZE); #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT env_out->flags = ++env_flags; /* increase the serial */ #endif return 0; }
/* Emport the environment and generate CRC for it. */ int env_export(env_t *env_out) { char *res; ssize_t len; int ret; res = (char *)env_out->data; len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } /* Encrypt the env if desired. */ ret = env_aes_cbc_crypt(env_out, 1); if (ret) return ret; env_out->crc = crc32(0, env_out->data, ENV_SIZE); return 0; }
/* * Check if CRC is valid and (if yes) import the environment. * Note that "buf" may or may not be aligned. */ int env_import(const char *buf, int check) { env_t *ep = (env_t *)buf; int ret; if (check) { uint32_t crc; memcpy(&crc, &ep->crc, sizeof(crc)); if (crc32(0, ep->data, ENV_SIZE) != crc) { set_default_env("!bad CRC"); return 0; } } /* Decrypt the env if desired. */ ret = env_aes_cbc_crypt(ep, 0); if (ret) { error("Failed to decrypt env!\n"); set_default_env("!import failed"); return ret; } if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, 0, 0, NULL)) { gd->flags |= GD_FLG_ENV_READY; return 1; } error("Cannot import environment: errno = %d\n", errno); set_default_env("!import failed"); return 0; }