blob: b74b1db43dce683849618c52c062e26bff6fc1b7 [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4 */
5
6#include <common.h>
7#include <command.h>
8#include <image.h>
9#include <android_image.h>
10
11//#define OS_IDENT_DEBUG
12
13#ifdef OS_IDENT_DEBUG
14#define debug_print(...) printf(__VA_ARGS__)
15#else
16#define debug_print(...) ((void)0)
17#endif
18
19static int do_os_ident(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
20{
21 int ret = -1;
22
23 if (argc < 2) {
24 printf("Err! OS hdr addr not specified!\n");
25 return ret;
26 }
27
28 const void *img_addr = (const void *)simple_strtoul(argv[1], NULL, 16);
29 debug_print("os hdr addr: 0x%lx\n", (ulong)img_addr);
30
31 ret = genimg_get_format(img_addr);
32 switch (ret) {
33 case IMAGE_FORMAT_LEGACY:
34 debug_print("IMAGE_FORMAT_LEGACY format\n");
35 env_set("os_type", "rtos");
36 break;
37 case IMAGE_FORMAT_FIT:
38 debug_print("IMAGE_FORMAT_FIT format\n");
39 /* ignore fdt format, it's not an OS */
40 //env_set("os_type", "fdt");
41 break;
42 case IMAGE_FORMAT_ANDROID:
43 debug_print("IMAGE_FORMAT_ANDROID format\n");
44 env_set("os_type", "kernel");
45 break;
46 case IMAGE_FORMAT_INVALID:
47 debug_print("IMAGE_FORMAT_INVALID format\n");
48 env_set("os_type", "invalid");
49 break;
50 default:
51 debug_print("default format\n");
52 break;
53 }
54
55 return ret;
56}
57
58U_BOOT_CMD(
59 os_ident, CONFIG_SYS_MAXARGS, 1, do_os_ident,
60 "identify OS type",
61 "[addr]\n"
62);