You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
5.8 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2021. All rights reserved.
* Description: cmdline.c
* Author: Hisilicon
* Create: 2019-12-26
*/
#include "cmdline.h"
#include <common.h>
#include <malloc.h>
#include <environment.h>
#include "cmdline_ext.h"
#include "common_ext.h"
#include "fdt_support.h"
static build_variant g_build_variant = SOCT_NOT_INIT;
/*
* ret value:
* TD_SUCCESS - user mode
* TD_FAILURE - eng mode
*/
static td_s32 is_user_mode(td_void)
{
td_char *str = TD_NULL;
td_char *cmdline = TD_NULL;
cmdline = env_get("bootargs");
if (cmdline == NULL) {
printf("call getenv return null\n");
return TD_FAILURE;
}
if (g_build_variant == SOCT_USER_MODE) {
return TD_SUCCESS;
} else if (g_build_variant == SOCT_ENG_MODE) {
return TD_FAILURE;
} else {
str = strstr(cmdline, USER_MODE);
if (str == TD_NULL) {
g_build_variant = SOCT_ENG_MODE;
return TD_FAILURE;
}
}
g_build_variant = SOCT_USER_MODE;
return TD_SUCCESS;
}
static td_s32 create_loglevel_cmdline(td_void)
{
td_char *arg_merg = NULL;
td_char loglevel_str[STR_LOGLEVEL_LEN] = { 0 };
td_s32 loglevel;
if (is_user_mode() == TD_SUCCESS) {
loglevel = LOGLEVEL_USER_MODE;
} else {
loglevel = LOGLEVEL_ENG_MODE;
}
if (snprintf_s(loglevel_str, sizeof(loglevel_str), sizeof(loglevel_str) - 1,
"%s%d", "loglevel=", loglevel) < 0) {
printf("create loglevel fail\n");
return TD_FAILURE;
}
arg_merg = merge_args(env_get("bootargs"), loglevel_str, "bootargs", loglevel_str);
if (arg_merg == NULL) {
printf("[%s] %d: merge loglevel_str to bootargs fail\n", __func__, __LINE__);
return TD_FAILURE;
}
env_set("bootargs", arg_merg);
free(arg_merg);
return TD_SUCCESS;
}
static td_s32 create_fastbootversion_cmdline(td_void)
{
td_char *arg_merg = NULL;
char fastboot_version[MAX_VERSION_LEN + sizeof(FASTBOOT_VERSION_CMDLINE_STRING) + 1] = { 0 };
if (snprintf_s(fastboot_version, sizeof(fastboot_version), sizeof(fastboot_version) - 1,
"%s%s", FASTBOOT_VERSION_CMDLINE_STRING, FASTBOOT_VERSION) < 0) {
printf("%s\n", FASTBOOT_VERSION);
return TD_FAILURE;
}
arg_merg = merge_args(env_get("bootargs"), fastboot_version, "bootargs", fastboot_version);
if (arg_merg == NULL) {
printf("[%s] %d: merge fastboot_version to bootargs fail\n", __func__, __LINE__);
return TD_FAILURE;
}
env_set("bootargs", arg_merg);
free(arg_merg);
return TD_SUCCESS;
}
static td_s32 create_board_id_cmdline(td_void)
{
return TD_SUCCESS;
}
static td_s32 create_androidboot_dtbo_idx_cmdline(td_void)
{
return TD_SUCCESS;
}
static td_s32 create_androidboot_boot_reason_cmdline(td_void)
{
return TD_SUCCESS;
}
static td_s32 create_androidboot_boot_device_cmdline(td_void)
{
td_s32 ret;
td_char *arg_merg = NULL;
td_s32 boot_media = get_boot_media();
td_char boot_device[BOOT_DEVICE_MAX_LEN] = {0};
if (boot_media == BOOT_MEDIA_UFS) {
ret = snprintf_s(boot_device, sizeof(boot_device), sizeof(boot_device) - 1,
"%s%s", BOOT_DEVICE_STR, BOOT_DEVICE_UFS);
} else {
ret = snprintf_s(boot_device, sizeof(boot_device), sizeof(boot_device) - 1,
"%s%s", BOOT_DEVICE_STR, BOOT_DEVICE_EMMC);
}
if (ret < 0) {
printf("boot_media: %d\n", boot_media);
return TD_FAILURE;
}
arg_merg = merge_args(env_get("bootargs"), boot_device, "bootargs", boot_device);
if (arg_merg == NULL) {
printf("[%s] %d: merge boot_device to bootargs fail\n", __func__, __LINE__);
return TD_FAILURE;
}
env_set("bootargs", arg_merg);
free(arg_merg);
return TD_SUCCESS;
}
td_s32 create_cmdline(td_void)
{
td_s32 __maybe_unused ret;
#ifdef CONFIG_SOCT_POWER_SUPPORT
td_u32 charger_mode_support;
ret = ext_get_dts_config_u32_byname("charger_mode", "charger_mode_support", &charger_mode_support);
if (ret != TD_SUCCESS) {
charger_mode_support = 0;
soc_log_err("get_dts_config charger_mode_support fail!\n");
}
if (charger_mode_support) {
ret = create_charge_mode_cmdline();
if (ret != TD_SUCCESS) {
printf("Create charge_mode CMDLINE Failed\n");
return TD_FAILURE;
}
}
ret = create_coul_cali_gain_cmdline();
if (ret != TD_SUCCESS) {
printf("Create coul_cali cmdline Failed\n");
return TD_FAILURE;
}
ret = create_dc_gain_cmdline();
if (ret != TD_SUCCESS) {
printf("Create dc gain CMDLINE Failed\n");
return TD_FAILURE;
}
ret = create_cycle_cnt_cmdline();
if (ret != TD_SUCCESS) {
printf("Create cycle cnt CMDLINE Failed\n");
return TD_FAILURE;
}
#endif
ret = create_fastbootversion_cmdline();
if (ret != TD_SUCCESS) {
printf("Create CMDLINE Failed\n");
return TD_FAILURE;
}
ret = create_board_id_cmdline();
if (ret != TD_SUCCESS) {
printf("Create CMDLINE Failed\n");
return TD_FAILURE;
}
ret = create_androidboot_dtbo_idx_cmdline();
if (ret != TD_SUCCESS) {
printf("Create CMDLINE Failed\n");
return TD_FAILURE;
}
ret = create_androidboot_boot_reason_cmdline();
if (ret != TD_SUCCESS) {
printf("Create CMDLINE Failed\n");
return TD_FAILURE;
}
ret = create_androidboot_boot_device_cmdline();
if (ret != TD_SUCCESS) {
printf("Create CMDLINE Failed\n");
return TD_FAILURE;
}
ret = create_loglevel_cmdline();
if (ret != TD_SUCCESS) {
printf("Create CMDLINE Failed\n");
return TD_FAILURE;
}
return TD_SUCCESS;
}