blob: 4f6295d49531271e89f10ea8cc55a7633a123428 [file] [log] [blame] [edit]
/*
* common/cmd_factory_boot.c
*
* Copyright (C) 2018 Amlogic, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <common.h>
#include <command.h>
#include <amlogic/flash_ts.h>
int set_factory_boot (char * const value)
{
int ret = 1;
if(is_flash_inited()) {
flash_ts_init();
char key[] = "bootloader.command";
ret = flash_ts_set(key, value);
printf("FTS set:\n%s -> %s\nReturn: %d\n", key, value, ret);
}
return ret;
}
int do_factory_boot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char value[] = "boot-factory";
return set_factory_boot(value);
}
int do_not_factory_boot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char value[] = "";
return set_factory_boot(value);
}
#ifdef CONFIG_CMD_USB_MODE
int set_usb_controller (char * const value)
{
int ret = 1;
if(is_flash_inited()) {
flash_ts_init();
char key[] = "usb_controller_type";
ret = flash_ts_set(key, value);
printf("FTS set:\n%s -> %s\nReturn: %d\n", key, value, ret);
}
return ret;
}
int do_set_usb_device_mode (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char value[] = "device";
return set_usb_controller(value);
}
int do_set_usb_host_mode (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char value[] = "host";
return set_usb_controller(value);
}
#endif
int do_update_boot_count(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int ret = 0;
int crash_counter = 0;
char fts_value[256] = { 0 };
char new_fts_value[256] = { 0 };
char *endp;
const char *android_fts_key = "crashcounter.android";
const char *command_fts_key = "bootloader.command";
const char *recovery_fts_value = "boot-recovery";
char factory_fts_value[256] = { 0 };
if (is_flash_inited()) {
flash_ts_init();
flash_ts_get(command_fts_key, factory_fts_value, sizeof(factory_fts_value));
if (!strncmp(fts_value, "boot-factory", sizeof(fts_value))) {
return 0;
}
flash_ts_get(android_fts_key, fts_value, sizeof(fts_value));
crash_counter = simple_strtoul(fts_value, &endp, 10);
crash_counter++;
pr_info("crashcounter.android: %d\n", crash_counter);
if (crash_counter > 10) {
pr_info("force FDR due to crashcounter.android: %d\n", crash_counter);
ret = flash_ts_set(command_fts_key, recovery_fts_value);
crash_counter = 0;
}
snprintf(new_fts_value, 16, "%d", crash_counter);
ret = flash_ts_set(android_fts_key, new_fts_value);
}
return ret;
}
U_BOOT_CMD(
enable_factory_boot, 1, 0, do_factory_boot,
"Set FTS flag to enable factory boot.",
"enable_factory_boot\n"
);
U_BOOT_CMD(
disable_factory_boot, 1, 0, do_not_factory_boot,
"Resets FTS flag to disable factory boot.",
"disable_factory_boot\n"
);
#ifdef CONFIG_CMD_USB_MODE
U_BOOT_CMD(
set_usb_device_mode, 1, 0, do_set_usb_device_mode,
"SET FTS flag to set usb mode to device.",
"set_usb_device_mode\n"
);
U_BOOT_CMD(
set_usb_host_mode, 1, 0, do_set_usb_host_mode,
"SET FTS flag to set usb mode to host.",
"set_usb_host_mode\n"
);
#endif
U_BOOT_CMD(
update_boot_count, 1, 0, do_update_boot_count,
"Update FTS flag crashcounter.android.",
"update_boot_count\n"
);