/* 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)
/* 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;
	if (check) {
		uint32_t crc;
		memcpy(&crc, &ep->crc, sizeof(crc));
		if (crc32(0, ep->data, ENV_SIZE) != crc) {
			env_set_default("bad CRC", 0);
			return -ENOMSG;
		}
	}
	if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, 0,
			0, NULL)) {
		gd->flags |= GD_FLG_ENV_READY;
		return 0;
	}
	pr_err("Cannot import environment: errno = %d\n", errno);
	env_set_default("import failed", 0);
	return -EIO;
}