Page 1 of 1

【已解决】KV DB初始化失败

Posted: 2022年 Dec 9日 14:38
by shb3014

kv flash 读写都是正常的。初始化DB时,在读取 SIMPLE_FLASH_KEY_ADDR 这个地址后会报[simple_flash.c:479] key data is not matched magic(0x3a2d3e45),crc32(0xe2d8782c)这个错误。
自己试了试,SIMPLE_FLASH_KEY_ADDR区域前16个字节的内容不同,magic和crc32的值也会不同。SDK的程序从未对SIMPLE_FLASH_KEY_ADDR区域进行过写入。
接着程序报[simple_flash.c:493] flash is encrypted or empty。后续相关程序似乎都是因为这里失败报错。
接口的flash分配如下(与给的例程一致):

Code: Select all

#define  PARTITION_SIZE (1 << 12) /* 4KB */
#define FLH_BLOCK_SZ PARTITION_SIZE

// flash map   0x0      
#define SIMPLE_FLASH_START 0x0 //相对地址 #define SIMPLE_FLASH_SIZE 0x10000 // 64K #define SIMPLE_FLASH_SWAP_START 0x20000 #define SIMPLE_FLASH_SWAP_SIZE 0x4000 // 16k #define SIMPLE_FLASH_KEY_ADDR (SIMPLE_FLASH_SWAP_START + SIMPLE_FLASH_SWAP_SIZE) #define SIMPLE_FLASH_KEY_SIZE 0x1000 // 4k #define UF_FILE_FLASH_START_ADDR (SIMPLE_FLASH_START + SIMPLE_FLASH_SIZE) #define UF_FILE_FLASH_SIZE 0x8000

以下是日志:

Code: Select all

[TOS_DBG]tuya_esp_flash_init ok, addr:0x3b0000, size:0x28000
xxxxxxxxxxxx flash read 0x011000 | 4096
xxxxxxxxxxxx flash read 0x010000 | 4096
xxxxxxxxxxxx flash read 0x010000 | 4096
[01-01 18:12:15 TUYA I][mqc_app.c:350] mqc app init ...
[01-01 18:12:15 TUYA I][uni_thread.c:220] thread_create name:sys_timer,stackDepth:4096,totalstackDepth:4096,priority:5
[01-01 18:12:15 TUYA D][uni_thread.c:247] Thread:sys_timer Exec Start. Set to Running Stat
[01-01 18:12:15 TUYA I][uni_thread.c:220] thread_create name:cmmod,stackDepth:4096,totalstackDepth:8192,priority:4
[01-01 18:12:15 TUYA D][uni_thread.c:247] Thread:cmmod Exec Start. Set to Running Stat
[01-01 18:12:15 TUYA D][mqc_app.c:144] mq_pro:5 cnt:1
[01-01 18:12:15 TUYA D][mqc_app.c:144] mq_pro:31 cnt:2
[01-01 18:12:15 TUYA D][svc_online_log.c:295] svc online log init success
xxxxxxxxxxxx flash read 0x010000 | 4096
xxxxxxxxxxxx flash read 0x010000 | 4096
[01-01 18:12:16 TUYA E][log_seq.c:871] logseq empty
[01-01 18:12:16 TUYA I][uni_thread.c:220] thread_create name:wk_th-0,stackDepth:5120,totalstackDepth:13312,priority:3
[01-01 18:12:16 TUYA D][uni_thread.c:247] Thread:wk_th-0 Exec Start. Set to Running Stat
[  1980][D][tuya_main.cpp:219] tuya_init(): init param over
[01-01 18:12:16 TUYA D][tuya_ws_db.c:450] init fs. Path: /tuya 
[01-01 18:12:16 TUYA D][kv_storge.c:46] *****************kvs_init. 
[01-01 18:12:16 TUYA N][simple_flash.c:459] key_addr: 0x24000   block_sz 4096
xxxxxxxxxxxx flash read 0x024000 | 4096
[01-01 18:12:16 TUYA E][simple_flash.c:479] key data is not matched magic(0x3a2d3e45),crc32(0xe2d8782c)
xxxxxxxxxxxx flash read 00000000 | 4096
[01-01 18:12:16 TUYA E][simple_flash.c:493] flash is encrypted or empty
[01-01 18:12:16 TUYA E][simple_flash_app.c:306] create_flash_hand_and_init err 10
[01-01 18:12:16 TUYA E][tuya_ws_db.c:454] db init fails -1
[01-01 18:12:16 TUYA E][tuya_iot_com_api.c:454] db init fails -1
[01-01 18:12:16 TUYA E][tuya_main.cpp:222] ret:-1
[  2430][D][tuya_main.cpp:223] tuya_init(): kv flash init over
[01-01 18:12:16 TUYA E][ws_db_gw.c:80] wd_protected_read fails gw_bi -1
[01-01 18:12:16 TUYA D][ws_db_gw.c:208] gw base read finish:-1
[01-01 18:12:16 TUYA D][ws_db_gw.c:61] write buf:
这里模糊处理了{"uuid":"xxxxxxxxxxx","psk_key":null,"auth_key":xxxxx","ap_ssid":"SmartLife_Ivy","ap_passwd":"xxxx","country_code":null,"prod_test":false,"fac_pin":null }
[01-01 18:12:16 TUYA E][ws_db_gw.c:66] wd_protected_write fails gw_bi -1
[01-01 18:12:16 TUYA E][ws_db_gw.c:145] gw base write fail:-1
[01-01 18:12:16 TUYA E][tuya_main.cpp:225] ret:-1
[  2486][I][tuya_main.cpp:141] device_init(): device init start
这里模糊处理了
[01-01 18:12:16 TUYA N][tuya_iot_wifi_api.c:276] wifi soc init. pid:xxxxx5 firmwarekey:xxxx ver:1.1.3
[01-01 18:12:16 TUYA D][tuya_svc_upgrade.c:791] tuya svc upgrade init success!
[01-01 18:12:16 TUYA N][tuya_devos_entry.c:1752] Last reset reason: 0
[01-01 18:12:16 TUYA E][ws_db_gw.c:80] wd_protected_read fails gw_bi -1
[01-01 18:12:16 TUYA D][ws_db_gw.c:208] gw base read finish:-1
[01-01 18:12:16 TUYA E][tuya_devos_entry.c:1087] base read fail:-1
[01-01 18:12:16 TUYA E][tuya_devos_entry.c:1757] ret:-7171
[01-01 18:12:16 TUYA E][tuya_devos_entry.c:1808] ERR_EXIT is Jumped!
[  2545][E][tuya_main.cpp:167] device_init(): tuya_iot_wf_soc_dev_init_param error,err_num:-7171

Re: KV DB初始化失败

Posted: 2022年 Dec 9日 14:42
by 一线长天

执行过产测流程么?KV必须经过产测才能正常使用


Re: KV DB初始化失败

Posted: 2022年 Dec 9日 14:50
by shb3014
一线长天 2022年 Dec 9日 14:42

执行过产测流程么?KV必须经过产测才能正常使用

感谢指教,您指的产测流程是会对烧录flash进行编写吗,我这边还没有做过相关操作。但在程序中我我有调用tuya_iot_set_wf_gw_prod_info接口。产测流程需要我这边具体做什么呢。感谢。
这是相关初始化部分的代码:

Code: Select all

    TY_INIT_PARAMS_S init_param = {0};
    init_param.init_db = FALSE;
    strcpy(init_param.sys_env, TARGET_PLATFORM);
    TUYA_CALL_ERR_LOG(tuya_iot_init_params(NULL, &init_param));
    log_d("init param over");

TUYA_CALL_ERR_LOG(tuya_iot_kv_flash_init("/tuya"));
log_d("kv flash init over");
这里模糊化处理了
WF_GW_PROD_INFO_S prod_info = {"xxx", "xxx", "SmartLife_Ivy",                                   "xxx"};
TUYA_CALL_ERR_LOG(tuya_iot_set_wf_gw_prod_info(&prod_info));

ty_subscribe_event(EVENT_INIT, "dev_init", tuya_dev_init_event_cb, FALSE);

TUYA_CALL_ERR_LOG(device_init());

Re: KV DB初始化失败

Posted: 2022年 Dec 9日 14:58
by 一线长天

如果没有执行过产测,需要在tuya_iot_set_wf_gw_prod_info前先执行OPERATE_RET ws_db_init_mf(VOID)
该接口仅用于调试初始化kv,正常的设备必须经过涂鸦产测流程


Re: KV DB初始化失败

Posted: 2022年 Dec 9日 15:17
by shb3014
一线长天 2022年 Dec 9日 14:58

如果没有执行过产测,需要在tuya_iot_set_wf_gw_prod_info前先执行OPERATE_RET ws_db_init_mf(VOID)
该接口仅用于调试初始化kv,正常的设备必须经过涂鸦产测流程

非常感谢!该问题已解决。