/* Read values defined by a type string from a buffer, and write these values to environment variables. */
int type_string_write_vars(const char *type_str, u8 *data, char *const vars[])
/* Read values defined by a type string from a buffer, and write these values to environment variables. */
int type_string_write_vars(const char *type_str, u8 *data, char *const vars[])
{
	size_t offset;
	u32 value;
	for (offset = 0; *type_str; type_str++, vars++) {
		switch (*type_str) {
		case 'b':
			value = data[offset];
			offset += 1;
			break;
		case 'w':
			value = get_unaligned_be16(data + offset);
			offset += 2;
			break;
		case 'd':
			value = get_unaligned_be32(data + offset);
			offset += 4;
			break;
		default:
			return -1;
		}
		if (env_set_ulong(*vars, value))
			return -1;
	}
	return 0;
}