min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR MIT) |
| 2 | /* |
| 3 | * Copyright (c) 2019 Amlogic, Inc. All rights reserved. |
| 4 | */ |
| 5 | #include <common.h> |
| 6 | #include <command.h> |
min.ye | 7bad0fc | 2024-11-26 16:17:46 +0800 | [diff] [blame] | 7 | #include "../include/amlogic/ini.h" |
| 8 | |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 9 | static int do_afm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 10 | { |
| 11 | const char *str_cmd, *str_value = NULL; |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame] | 12 | if (argc == 2 && !strcmp(argv[1], "print")) |
| 13 | { |
min.ye | 4d19c3e | 2024-11-29 17:17:17 +0800 | [diff] [blame^] | 14 | char *serialno = env_get("usid"); |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame] | 15 | char *mac = env_get("mac"); |
| 16 | char *silent = env_get("silent"); |
| 17 | char *powermode = env_get("powermode"); |
| 18 | char *otg_device = env_get("otg_device"); |
| 19 | char *selinux = env_get("EnableSelinux"); |
min.ye | 7bad0fc | 2024-11-26 16:17:46 +0800 | [diff] [blame] | 20 | char model_name[50] = {0}, model1_name[50] = {0}, model2_name[50] = {0}, modelt_name[150] = {0}; |
| 21 | handle_model_get("0", model_name); |
| 22 | handle_model_get("1", model1_name); |
| 23 | handle_model_get("2", model2_name); |
| 24 | if (strlen(model_name) != 0) |
| 25 | { |
| 26 | strcat(modelt_name, model_name); |
| 27 | } |
| 28 | if (strlen(model1_name) != 0) { |
| 29 | strcat(modelt_name, "|"); |
| 30 | strcat(modelt_name, model1_name); |
| 31 | } |
| 32 | if (strlen(model2_name) !=0 ) { |
| 33 | strcat(modelt_name, "|"); |
| 34 | strcat(modelt_name, model2_name); |
| 35 | } |
| 36 | //printf("current %s: %s\n", str, model_name); |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame] | 37 | printf("\n" |
min.ye | 7bad0fc | 2024-11-26 16:17:46 +0800 | [diff] [blame] | 38 | "model_name : %s\n" |
min.ye | 4d19c3e | 2024-11-29 17:17:17 +0800 | [diff] [blame^] | 39 | "serialno : %s\n" |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame] | 40 | "mac : %s\n" |
| 41 | "console : \n" |
| 42 | "silent : %s\n" |
| 43 | "powermode : %s\n" |
| 44 | "otg_device : %s\n" |
| 45 | "selinux : %s\n" |
min.ye | 7bad0fc | 2024-11-26 16:17:46 +0800 | [diff] [blame] | 46 | , strlen(modelt_name) != 0 ? modelt_name : "" |
min.ye | 4d19c3e | 2024-11-29 17:17:17 +0800 | [diff] [blame^] | 47 | , serialno != NULL? serialno : "" |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame] | 48 | , mac != NULL? mac : "" |
| 49 | , silent != NULL? (!strcmp(silent, "0")? "on" : "off") : "on" |
| 50 | , powermode != NULL? powermode : "" |
| 51 | , otg_device != NULL? otg_device : "" |
| 52 | , selinux != NULL? selinux : ""); |
| 53 | return 0; |
| 54 | } |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 55 | if (argc != 3) |
| 56 | return CMD_RET_USAGE; |
| 57 | str_cmd = argv[1]; |
| 58 | /* Strip off leading 'afm' command argument */ |
| 59 | argc -= 2; |
| 60 | argv += 2; |
| 61 | //if (argc > 0) |
| 62 | str_value = *argv; |
| 63 | if (!strcmp(str_cmd, "otg_device")) { |
| 64 | if (!strcmp(str_value, "1")) { |
| 65 | run_command("setenv otg_device 1", 0); |
| 66 | } else if (!strcmp(str_value, "0")) { |
| 67 | run_command("setenv otg_device 0", 0); |
| 68 | } else { |
| 69 | printf("invalid value\n"); |
| 70 | return CMD_RET_USAGE; |
| 71 | } |
| 72 | run_command("saveenv", 0); |
| 73 | return 0; |
min.ye | 4d19c3e | 2024-11-29 17:17:17 +0800 | [diff] [blame^] | 74 | } else if (!strcmp(str_cmd, "serialno")) { |
| 75 | char result[50] = "keyman write usid str ";//size 21 |
| 76 | if (strlen(str_value) > 17) {//str_value size 17 |
| 77 | printf("invalid no\n"); |
| 78 | return CMD_RET_USAGE; |
| 79 | } |
| 80 | strcat(result, str_value); |
| 81 | run_command(result, 0); |
| 82 | run_command("keyman read usid $loadaddr str; printenv usid", 0); |
| 83 | return 0; |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 84 | } else if (!strcmp(str_cmd, "mac")) { |
| 85 | char result[50] = "keyman write mac str ";//size 21 |
| 86 | |
| 87 | if (strlen(str_value) != 17) {//str_value size 17 |
| 88 | printf("invalid address\n"); |
| 89 | return CMD_RET_USAGE; |
| 90 | } |
| 91 | strcat(result, str_value); |
| 92 | run_command(result, 0); |
| 93 | run_command("keyman read mac $loadaddr str; printenv mac", 0); |
| 94 | return 0; |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame] | 95 | } else if (!strcmp(str_cmd, "silent")) { |
| 96 | if (!strcmp(str_value, "on")) { |
| 97 | run_command("setenv silent 0", 0); |
| 98 | } else if (!strcmp(str_value, "off")) { |
| 99 | run_command("setenv silent 1", 0); |
| 100 | } else { |
| 101 | printf("invalid value\n"); |
| 102 | return CMD_RET_USAGE; |
| 103 | } |
| 104 | run_command("saveenv", 0); |
| 105 | } else if (!strcmp(str_cmd, "powermode")) { |
| 106 | if (!strcmp(str_value, "on")) { |
| 107 | run_command("setenv powermode on", 0); |
| 108 | } else if (!strcmp(str_value, "standby")) { |
| 109 | run_command("setenv powermode standby", 0); |
| 110 | } else { |
| 111 | printf("invalid value\n"); |
| 112 | return CMD_RET_USAGE; |
| 113 | } |
| 114 | run_command("saveenv", 0); |
| 115 | } else if (!strcmp(str_cmd, "selinux")) { |
| 116 | if (!strcmp(str_value, "enforcing")) { |
| 117 | run_command("setenv EnableSelinux enforcing", 0); |
| 118 | } else if (!strcmp(str_value, "permissive")) { |
| 119 | run_command("setenv EnableSelinux permissive", 0); |
| 120 | } else if (!strcmp(str_value, "disabled")) { |
| 121 | run_command("setenv EnableSelinux disabled", 0); |
| 122 | } else { |
| 123 | printf("invalid value\n"); |
| 124 | return CMD_RET_USAGE; |
| 125 | } |
| 126 | run_command("saveenv", 0); |
min.ye | 7bad0fc | 2024-11-26 16:17:46 +0800 | [diff] [blame] | 127 | } else if (!strcmp(str_cmd, "model_name")) { |
| 128 | handle_model_set("model_name", str_value); |
| 129 | } else if (!strcmp(str_cmd, "model1_name")) { |
| 130 | handle_model_set("model1_name", str_value); |
| 131 | } else if (!strcmp(str_cmd, "model2_name")) { |
| 132 | handle_model_set("model2_name", str_value); |
| 133 | } else { |
| 134 | printf("invalid value\n"); |
| 135 | return CMD_RET_USAGE; |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 136 | } |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | U_BOOT_CMD(afm, CONFIG_SYS_MAXARGS, 0, do_afm, |
| 141 | "Factory related command/usage", |
| 142 | "\n" |
| 143 | "afm model_name <ModelName> - modify screen parameters\n" |
| 144 | "afm serialno <serial no> - modify serial no\n" |
| 145 | "afm mac <mac address> - modify mac address\n" |
| 146 | "afm console <on|off> - modify console state\n" |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 147 | "afm silent <on|off> - modify the print state of uboot bl33 serial port\n" |
| 148 | "afm powermode <on|standby> - modify power on mode\n" |
| 149 | "afm otg_device <1|0> - modify the USB host/device state\n" |
| 150 | "afm selinux <0|1|2(permissive|enforcing|disabled)> - modify the selinux mode\n" |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame] | 151 | "afm print - Print the values of all parameters\n" |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 152 | ); |