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.
127 lines
4.0 KiB
127 lines
4.0 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2020. All rights reserved.
|
|
* Description: driver for serial
|
|
* Author: bsp
|
|
* Create: 2019-12-15
|
|
*/
|
|
#include "serialnum.h"
|
|
#include <malloc.h>
|
|
#include <asm/io.h>
|
|
#include <net.h>
|
|
#include <linux/string.h>
|
|
#include <linux/mtd/mtd.h>
|
|
#include "common_ext.h"
|
|
#include "exports.h"
|
|
|
|
#include "uapi_gpio.h"
|
|
#include "td_type.h"
|
|
#include "flash_ext.h"
|
|
#include "pdm_ext.h"
|
|
|
|
static char *set_param(const char *args, const char *paramName, const char *value)
|
|
{
|
|
char *args_buff = NULL;
|
|
int ret, strart_len, args_buff_len;
|
|
|
|
if ((args == NULL) || (paramName == NULL) || (value == NULL)) {
|
|
return NULL;
|
|
}
|
|
|
|
args_buff_len = (int)(strlen(args) + strlen(paramName) + strlen(value) + 5); /* 5 : len */
|
|
char *ptr = strstr(args, paramName);
|
|
if (ptr == NULL) {
|
|
args_buff = args_buff_len <= 0 ? NULL : (char *)malloc((size_t)args_buff_len * sizeof(char));
|
|
if (args_buff == NULL) {
|
|
printf("[%s] %d: malloc buf failed\n", __func__, __LINE__);
|
|
return NULL;
|
|
}
|
|
/* -1 means snprintf_s fail */
|
|
if (snprintf_s(args_buff, (size_t)args_buff_len, (size_t)(args_buff_len - 1),
|
|
"%s %s=%s", args, paramName, value) == -1) {
|
|
printf("[%s] %d: snprintf_s fail\n", __func__, __LINE__);
|
|
free(args_buff);
|
|
return NULL;
|
|
}
|
|
} else {
|
|
args_buff = args_buff_len <= 0 ? NULL : (char *)malloc((size_t)args_buff_len * sizeof(char));
|
|
if (args_buff != NULL) {
|
|
strart_len = (int)(ptr - args);
|
|
if (memcpy_s(args_buff, (size_t)args_buff_len, args, (size_t)strart_len) != 0) {
|
|
printf("[%s] %d: memcpy_s fail\n", __func__, __LINE__);
|
|
free(args_buff);
|
|
return NULL;
|
|
}
|
|
char *last = strstr(ptr, " ");
|
|
if (last == NULL) {
|
|
ret = snprintf_s(args_buff + strart_len, (size_t)(args_buff_len - strart_len),
|
|
(size_t)(args_buff_len - strart_len - 1), "%s=%s", paramName, value);
|
|
} else {
|
|
ret = snprintf_s(args_buff + strart_len, (size_t)(args_buff_len - strart_len),
|
|
(size_t)(args_buff_len - strart_len - 1), "%s=%s%s", paramName, value, last);
|
|
}
|
|
if (ret == -1) {
|
|
printf("[%s] %d: snprintf_s fail\n", __func__, __LINE__);
|
|
free(args_buff);
|
|
return NULL;
|
|
}
|
|
} else {
|
|
printf("[%s] %d: malloc buf failed\n", __func__, __LINE__);
|
|
return NULL;
|
|
}
|
|
}
|
|
return args_buff;
|
|
}
|
|
|
|
int set_serialno(void)
|
|
{
|
|
int ret;
|
|
ext_pdm_basic_info *pdm_info = NULL;
|
|
char *arg_merge = NULL;
|
|
char serialno[EXT_PDM_SERIAL_NUM_LEN + 1] = {0};
|
|
|
|
pdm_info = (ext_pdm_basic_info *)malloc(sizeof(ext_pdm_basic_info));
|
|
if (pdm_info == NULL) {
|
|
printf("malloc pdm_info buf failed\n");
|
|
return TD_FAILURE;
|
|
}
|
|
|
|
ext_drv_pdm_get_basic_info(pdm_info);
|
|
ret = memcpy_s(serialno, sizeof(serialno), pdm_info->serial_number, sizeof(pdm_info->serial_number));
|
|
free(pdm_info);
|
|
if (ret != 0) {
|
|
printf("[%s] %d: memcpy_s fail\n", __func__, __LINE__);
|
|
return TD_FAILURE;
|
|
}
|
|
|
|
serialno[EXT_PDM_SERIAL_NUM_LEN] = '\0';
|
|
|
|
ret = (int)strlen(serialno);
|
|
if ((ret == 0) || (ret >= (EXT_PDM_SERIAL_NUM_LEN))) {
|
|
printf("pdm serial is invalid \n");
|
|
return TD_FAILURE;
|
|
}
|
|
|
|
ret = 0;
|
|
arg_merge = set_param(env_get("bootargs"), "androidboot.serialno", serialno);
|
|
if (arg_merge != NULL) {
|
|
ret++;
|
|
env_set("bootargs", arg_merge);
|
|
free(arg_merge);
|
|
printf("serialno of bootargs update success\n");
|
|
}
|
|
|
|
arg_merge = set_param(env_get("bootargsb"), "androidboot.serialno", serialno);
|
|
if (arg_merge != NULL) {
|
|
ret++;
|
|
env_set("bootargsb", arg_merge);
|
|
free(arg_merge);
|
|
printf("serialno of bootargsb update success\n");
|
|
}
|
|
|
|
if (ret != 0) {
|
|
return TD_SUCCESS;
|
|
} else {
|
|
return TD_FAILURE;
|
|
}
|
|
}
|