硬件物料有问题导致无法烧写安全key,改为安全key(A50)

2021-09-01  本文已影响0人  gale_小米

烧写模式决定烧号工具把 key 信息存储到设备端的物理位置:(可以串口连接方式来调试)

私有 key:存储在私有逻辑分区,该分区的数据无法通过重刷固件来重置,但可以在系统层进行挂载操作。

安全 key:存储在物理分区,该分区的数据无法通过重刷固件来重置,只能使用烧号工具进行操作。

混合 key:包含私有 key 和安全 key,配置子项为私有 key 或者安全 key。

Index: lichee/brandy/u-boot-2014.07/board/sunxi/common/board_common.c

===================================================================

--- lichee/brandy/u-boot-2014.07/board/sunxi/common/board_common.c (revision 9678)

+++ lichee/brandy/u-boot-2014.07/board/sunxi/common/board_common.c (revision 9704)

@@ -837,11 +837,14 @@

#endif

#ifdef CONFIG_SUNXI_MAC

+ pr_error("CONFIG_SUNXI_MAC\n");

extern int update_sunxi_mac(void);

update_sunxi_mac();

#endif

#ifdef CONFIG_SUNXI_SERIAL

+ pr_error("CONFIG_SUNXI_SERIAL\n");

+ extern int sunxi_set_serial_num(void);

sunxi_set_serial_num();

#endif

return 0;

Index: lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_serial.c

===================================================================

--- lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_serial.c (revision 9678)

+++ lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_serial.c (revision 9704)

@@ -28,7 +28,7 @@

char *bmp_argv[6] = { "fatload", "sunxi_flash", part_info,

addr_info, file_info, NULL };

- ret = script_parser_fetch("serial_feature", "sn_filename",

+ ret = script_parser_fetch("serial_feature", "snum_filename",

(int *)file_info, sizeof(file_info)/4);

if ((ret < 0) || (strlen(file_info) == 0)) {

pr_notice("sunxi_serial: sn_filename is not set\n");

@@ -144,19 +144,20 @@

int sunxi_set_serial_num(void)

{

+ printf("sunxi_set_serial_num\n");

char serial[128] = {0};

char* p = NULL;

-

- p = getenv("snum");

- if (p != NULL)

- return 0;

-

+

if (get_serial_num_from_file(serial))

get_serial_num_from_chipid(serial);

- pr_msg("serial num is: %s\n", serial);

- if (setenv("snum", serial))

+ pr_error("serial num is: %s\n", serial);

+ if (setenv("snum", serial)){

pr_error("error:set env snum fail\n");

-

+ //优先读取私有key,没有再读取安全key

+ p = getenv("snum");

+ if (p != NULL)

+ return 0;

+ }

return 0;

}

Index: lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_serial.h

===================================================================

--- lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_serial.h (revision 9678)

+++ lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_serial.h (revision 9704)

@@ -2,7 +2,7 @@

#ifndef SUNXI_SERIAL_H_H_

#define SUNXI_SERIAL_H_H_

-int sunxi_set_serial_num(void);

+extern int sunxi_set_serial_num(void);

#endif

Index: lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_mac.c

===================================================================

--- lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_mac.c (revision 9678)

+++ lichee/brandy/u-boot-2014.07/board/sunxi/common/sunxi_mac.c (revision 9704)

@@ -7,6 +7,7 @@

  */

#include <common.h>

#include <smc.h>

+#include "sunxi_string.h"

#include <u-boot/md5.h>

#include <sunxi_board.h>

#include <sys_partition.h>

@@ -99,11 +100,22 @@

/* get data from file */

sprintf(part_info, "%x:0", partno);

sprintf(addr_info, "%lx", (ulong)mac);

- if (do_fat_fsload(0, 0, 6, bmp_argv)) {

- pr_error("load file(%s) error.\n", bmp_argv[4]);

- return -1;

+

+ pr_error("filename : %s\n", filename);

+ if( strcmp(filename,"imei")==0 || strcmp(filename,"snum")==0){

+ if (do_fat_fsload(0, 0, 5, bmp_argv)) {

+ printf("load file(%s) error\n", bmp_argv[4]);

+ return -1;

+ }

+ //mac[16] = 0;

+ }else{

+ if (do_fat_fsload(0, 0, 6, bmp_argv)) {

+ pr_error("load file(%s) error.\n", bmp_argv[4]);

+ return -1;

+ }

+ mac[18] = 0;

}

- mac[18] = 0;

+ pr_error("strcmp : %s=%s\n", filename, mac);

return 0;

}

@@ -110,31 +122,44 @@

int update_sunxi_mac(void)

{

- char addr_str[128] = {0};

+

+ pr_error("update_sunxi_mac\n");

+

char *p = NULL;

int i = 0;

char *envtab[] = {

+ "snum",

+ "imei",

"mac",

"wifi_mac",

- "bt_mac",

- "imei"};

+ "bt_mac"};

- int checktab[] = {1, 1, 0, 1};

+ int checktab[] = {1,1,1, 1, 0};

for (i = 0; i < sizeof(envtab) / sizeof(envtab[0]); i++) {

+

+ char addr_str[128] = {0};

+

+ if( strcmp(envtab[i],"imei")==0 || strcmp(envtab[i],"snum")==0){

+ if (get_macaddr_from_file(envtab[i], addr_str) == 0) {

+ setenv(envtab[i], addr_str);

+ pr_error("Private key: %s=%s\n", envtab[i], addr_str);

+ continue;

+ }

+ }else if ((get_macaddr_from_file(envtab[i], addr_str) == 0) &&

+ (addr_parse(addr_str, checktab[i]) == 0)) {

+ setenv(envtab[i], addr_str);

+ pr_error("Private key: %s=%s\n", envtab[i], addr_str);

+ continue;

+ }

+

+ //修改默认读取私有key

p = getenv(envtab[i]);

if ((p != NULL) && (addr_parse(p, checktab[i]) == 0)) {

pr_error("Secure key: %s=%s\n", envtab[i], p);

continue;

}

-

- if ((get_macaddr_from_file(envtab[i], addr_str) == 0) &&

- (addr_parse(addr_str, checktab[i]) == 0)) {

- setenv(envtab[i], addr_str);

- pr_error("Private key: %s=%s\n", envtab[i], addr_str);

- continue;

- }

pr_error("Ignore key:%s=%s\n", envtab[i], p);

}

上一篇 下一篇

猜你喜欢

热点阅读