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> |
| 7 | static int do_afm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 8 | { |
| 9 | const char *str_cmd, *str_value = NULL; |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame^] | 10 | if (argc == 2 && !strcmp(argv[1], "print")) |
| 11 | { |
| 12 | char *mac = env_get("mac"); |
| 13 | char *silent = env_get("silent"); |
| 14 | char *powermode = env_get("powermode"); |
| 15 | char *otg_device = env_get("otg_device"); |
| 16 | char *selinux = env_get("EnableSelinux"); |
| 17 | printf("\n" |
| 18 | "model_name : \n" |
| 19 | "serialno : \n" |
| 20 | "mac : %s\n" |
| 21 | "console : \n" |
| 22 | "silent : %s\n" |
| 23 | "powermode : %s\n" |
| 24 | "otg_device : %s\n" |
| 25 | "selinux : %s\n" |
| 26 | , mac != NULL? mac : "" |
| 27 | , silent != NULL? (!strcmp(silent, "0")? "on" : "off") : "on" |
| 28 | , powermode != NULL? powermode : "" |
| 29 | , otg_device != NULL? otg_device : "" |
| 30 | , selinux != NULL? selinux : ""); |
| 31 | return 0; |
| 32 | } |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 33 | if (argc != 3) |
| 34 | return CMD_RET_USAGE; |
| 35 | str_cmd = argv[1]; |
| 36 | /* Strip off leading 'afm' command argument */ |
| 37 | argc -= 2; |
| 38 | argv += 2; |
| 39 | //if (argc > 0) |
| 40 | str_value = *argv; |
| 41 | if (!strcmp(str_cmd, "otg_device")) { |
| 42 | if (!strcmp(str_value, "1")) { |
| 43 | run_command("setenv otg_device 1", 0); |
| 44 | } else if (!strcmp(str_value, "0")) { |
| 45 | run_command("setenv otg_device 0", 0); |
| 46 | } else { |
| 47 | printf("invalid value\n"); |
| 48 | return CMD_RET_USAGE; |
| 49 | } |
| 50 | run_command("saveenv", 0); |
| 51 | return 0; |
| 52 | } else if (!strcmp(str_cmd, "mac")) { |
| 53 | char result[50] = "keyman write mac str ";//size 21 |
| 54 | |
| 55 | if (strlen(str_value) != 17) {//str_value size 17 |
| 56 | printf("invalid address\n"); |
| 57 | return CMD_RET_USAGE; |
| 58 | } |
| 59 | strcat(result, str_value); |
| 60 | run_command(result, 0); |
| 61 | run_command("keyman read mac $loadaddr str; printenv mac", 0); |
| 62 | return 0; |
min.ye | 3402c93 | 2024-11-25 11:41:40 +0800 | [diff] [blame^] | 63 | } else if (!strcmp(str_cmd, "silent")) { |
| 64 | if (!strcmp(str_value, "on")) { |
| 65 | run_command("setenv silent 0", 0); |
| 66 | } else if (!strcmp(str_value, "off")) { |
| 67 | run_command("setenv silent 1", 0); |
| 68 | } else { |
| 69 | printf("invalid value\n"); |
| 70 | return CMD_RET_USAGE; |
| 71 | } |
| 72 | run_command("saveenv", 0); |
| 73 | } else if (!strcmp(str_cmd, "powermode")) { |
| 74 | if (!strcmp(str_value, "on")) { |
| 75 | run_command("setenv powermode on", 0); |
| 76 | } else if (!strcmp(str_value, "standby")) { |
| 77 | run_command("setenv powermode standby", 0); |
| 78 | } else { |
| 79 | printf("invalid value\n"); |
| 80 | return CMD_RET_USAGE; |
| 81 | } |
| 82 | run_command("saveenv", 0); |
| 83 | } else if (!strcmp(str_cmd, "selinux")) { |
| 84 | if (!strcmp(str_value, "enforcing")) { |
| 85 | run_command("setenv EnableSelinux enforcing", 0); |
| 86 | } else if (!strcmp(str_value, "permissive")) { |
| 87 | run_command("setenv EnableSelinux permissive", 0); |
| 88 | } else if (!strcmp(str_value, "disabled")) { |
| 89 | run_command("setenv EnableSelinux disabled", 0); |
| 90 | } else { |
| 91 | printf("invalid value\n"); |
| 92 | return CMD_RET_USAGE; |
| 93 | } |
| 94 | run_command("saveenv", 0); |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 95 | } |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | U_BOOT_CMD(afm, CONFIG_SYS_MAXARGS, 0, do_afm, |
| 100 | "Factory related command/usage", |
| 101 | "\n" |
| 102 | "afm model_name <ModelName> - modify screen parameters\n" |
| 103 | "afm serialno <serial no> - modify serial no\n" |
| 104 | "afm mac <mac address> - modify mac address\n" |
| 105 | "afm console <on|off> - modify console state\n" |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 106 | "afm silent <on|off> - modify the print state of uboot bl33 serial port\n" |
| 107 | "afm powermode <on|standby> - modify power on mode\n" |
| 108 | "afm otg_device <1|0> - modify the USB host/device state\n" |
| 109 | "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^] | 110 | "afm print - Print the values of all parameters\n" |
min.ye | 0187a5b | 2024-11-07 21:24:25 +0800 | [diff] [blame] | 111 | ); |