blob: 3734005bd1690def582fb3d4209e3274f8e24d49 [file] [log] [blame]
/*
* Copyright (C) 2015 Amlogic, Inc. All rights reserved.
*
*/
#include <common.h>
#include <command.h>
#include <image.h>
#include <android_image.h>
//#define OS_IDENT_DEBUG
#ifdef OS_IDENT_DEBUG
#define debug_print(...) printf(__VA_ARGS__)
#else
#define debug_print(...) ((void)0)
#endif
static int do_os_ident(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int ret = -1;
if (argc < 2) {
printf("Err! OS hdr addr not specified!\n");
return ret;
}
const void *img_addr = simple_strtoul(argv[1], NULL, 16);
debug_print("os hdr addr: 0x%lx\n", (ulong)img_addr);
ret = genimg_get_format(img_addr);
switch (ret) {
case IMAGE_FORMAT_LEGACY:
debug_print("IMAGE_FORMAT_LEGACY format\n");
env_set("os_type", "rtos");
break;
case IMAGE_FORMAT_FIT:
debug_print("IMAGE_FORMAT_FIT format\n");
/* ignore fdt format, it's not an OS */
//env_set("os_type", "fdt");
break;
case IMAGE_FORMAT_ANDROID:
debug_print("IMAGE_FORMAT_ANDROID format\n");
env_set("os_type", "kernel");
break;
case IMAGE_FORMAT_INVALID:
debug_print("IMAGE_FORMAT_INVALID format\n");
#ifdef CONFIG_G_AB_SYSTEM
/* In A/B system, we modify os_type to force bootm load image,
* then boot according to a/b flow:
* 1. verify image failure
* 2. retry again
* 3. switch to other slot
*/
env_set("os_type", "kernel");
#else
env_set("os_type", "invalid");
#endif
break;
default:
debug_print("default format\n");
break;
}
return ret;
}
U_BOOT_CMD(
os_ident, CONFIG_SYS_MAXARGS, 1, do_os_ident,
"identify OS type",
"[addr]\n"
);