Skip to content

Commit

Permalink
fix and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
pvvx committed Nov 11, 2023
1 parent 1709eb9 commit 56fb924
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 74 deletions.
Binary file modified ATC_v45.bin
Binary file not shown.
Binary file modified BTH_v45.bin
Binary file not shown.
Binary file modified CGDK2_v45.bin
Binary file not shown.
Binary file modified CGG1M_v45.bin
Binary file not shown.
Binary file modified CGG1_v45.bin
Binary file not shown.
Binary file modified MHO_C122_v45.bin
Binary file not shown.
Binary file modified MHO_C401N_v45.bin
Binary file not shown.
Binary file modified MHO_C401_v45.bin
Binary file not shown.
9 changes: 9 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ build: pre-build main-build
flash: $(BIN_FILE)
@$(PYTHON) $(PROJECT_PATH)/../TlsrPgm.py -p$(PGM_PORT) -t50 -a2750 -m -w we 0 $(BIN_FILE)

flash_hi: $(BIN_FILE)
@$(PYTHON) $(PROJECT_PATH)/../TlsrPgm.py -p$(PGM_PORT) -t50 -a2750 -s we 0x40000 $(BIN_FILE)

erase_fw:
@$(PYTHON) $(PROJECT_PATH)/../TlsrPgm.py -p$(PGM_PORT) -t50 -a2750 -m -w es 0 0x40000

erase:
@$(PYTHON) $(PROJECT_PATH)/../TlsrPgm.py -p$(PGM_PORT) -z11 -s ea

reset:
@$(PYTHON) $(PROJECT_PATH)/../TlsrPgm.py -p$(PGM_PORT) -t50 -a2750 -m -w i

Expand Down
4 changes: 1 addition & 3 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,7 @@ void user_init_normal(void) {//this will get executed one time after power up
start_tst_battery();
flash_unlock();
random_generator_init(); //must
#if (DEVICE_TYPE == DEVICE_MJWSD05MMC)
test_first_ota(); // MJWSD05MMC: Correct FW OTA address? Reformat Big OTA to Low OTA
#endif // (DEVICE_TYPE == DEVICE_MJWSD05MMC)
big_to_low_ota(); // Correct FW OTA address? Reformat Big OTA to Low OTA
#if defined(MI_HW_VER_FADDR) && (MI_HW_VER_FADDR)
uint32_t hw_ver = get_mi_hw_version();
#endif // (DEVICE_TYPE == DEVICE_LYWSD03MMC) || (DEVICE_TYPE == DEVICE_MJWSD05MMC)
Expand Down
104 changes: 43 additions & 61 deletions src/ext_ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,54 @@

#define OTA1_FADDR 0x00000
#define OTA2_FADDR 0x20000
#define SIZE_LOW_OTA OTA2_FADDR
#define OTA2_FADDR_ID (OTA2_FADDR + 8)
#define BIG_OTA2_FADDR 0x40000 // Big OTA2
#define BIG_OTA2_FADDR_ID (BIG_OTA2_FADDR + 8)
#define MI_HW_SAVE_FADDR (CFG_ADR_MAC+0xfe0) // check flash_erase_mac_sector()

/* Reformat Big OTA to Low OTA */
void big_to_low_ota(void) {
// find the real FW flash address
uint32_t id = ID_BOOTABLE;
uint32_t size;
uint32_t faddrr = OTA1_FADDR;
uint32_t faddrw = OTA1_FADDR;
uint32_t buf_blk[64];
do {
flash_read_page(faddrr, 16, (unsigned char *) &buf_blk);
if(buf_blk[2] == id)
return;
faddrr += SIZE_LOW_OTA;
} while(faddrr < BIG_OTA2_FADDR);
// faddrr = BIG_OTA2_FADDR
flash_read_page(faddrr, sizeof(buf_blk), (unsigned char *) &buf_blk);
if(buf_blk[2] == id && buf_blk[6] > FLASH_SECTOR_SIZE && buf_blk[6] < SIZE_LOW_OTA) {
buf_blk[2] &= 0xffffffff; // clear id "bootable"
size = buf_blk[6];
size += FLASH_SECTOR_SIZE - 1;
size &= ~(FLASH_SECTOR_SIZE - 1);
flash_erase_sector(faddrw); // 45 ms, 4 mA
flash_write_page(faddrw, sizeof(buf_blk), (unsigned char *) &buf_blk);
faddrr += sizeof(buf_blk);
// size += faddrw;
faddrw += sizeof(buf_blk);
while(faddrw < size) {
if((faddrw & (FLASH_SECTOR_SIZE - 1)) == 0)
flash_erase_sector(faddrw); // 45 ms, 4 mA
// rd-wr 4kB - 20 ms, 4 mA
flash_read_page(faddrr, sizeof(buf_blk), (unsigned char *) &buf_blk);
faddrr += sizeof(buf_blk);
flash_write_page(faddrw, sizeof(buf_blk), (unsigned char *) &buf_blk);
faddrw += sizeof(buf_blk);
}
// set id "bootable" to new segment
flash_write_page(OTA1_FADDR+8, sizeof(id), (unsigned char *) &id);
// clear the "bootable" identifier on the current OTA segment?
while(1)
start_reboot();
}
}

// #if (DEVICE_TYPE == DEVICE_LYWSD03MMC) || (DEVICE_TYPE == DEVICE_MJWSD05MMC) || (DEVICE_TYPE == DEVICE_MHO_C401)
#if defined(MI_HW_VER_FADDR) && (MI_HW_VER_FADDR)
Expand Down Expand Up @@ -105,67 +148,6 @@ void set_SerialStr(void) {
#endif // defined(MI_HW_VER_FADDR) && (MI_HW_VER_FADDR)


#if (DEVICE_TYPE == DEVICE_MJWSD05MMC)

extern unsigned char *_icload_size_div_16_;
extern unsigned char *_bin_size_;

// Current OTA header:
static const uint32_t head_id[4] = {
0x00008026, // asm("tj __reset")
0x025d0000, // id OTA ver
ID_BOOTABLE, // id "bootable" = "KNLT"
(uint32_t)(&_icload_size_div_16_ ) + 0x00880000 };
/* Reformat Big OTA to Low OTA */
void test_first_ota(void) {
// find the real FW flash address
uint32_t buf_blk[64], id, size, faddrw = OTA2_FADDR, faddrr = BIG_OTA2_FADDR;
flash_unlock();
flash_read_page(faddrr, 0x20, (unsigned char *) &buf_blk);
#if USE_FLASH_MEMO
if(buf_blk[0] == MEMO_SEC_ID)
return;
#endif
if(memcmp(&buf_blk, &head_id, sizeof(head_id)) == 0) {
// calculate size OTA
size = (uint32_t)(&_bin_size_);
size += 15;
size &= ~15;
size += 4;
if(buf_blk[6] == size) { // OTA bin size
// bls_ota_clearNewFwDataArea();
flash_erase_sector(faddrw); // 45 ms, 4 mA
flash_read_page(faddrr, sizeof(buf_blk), (unsigned char *) &buf_blk);
buf_blk[2] &= 0xffffffff; // clear id "bootable"
faddrr += sizeof(buf_blk);
flash_write_page(faddrw, sizeof(buf_blk), (unsigned char *) &buf_blk);
size += faddrw;
faddrw += sizeof(buf_blk);
while(faddrw < size) {
if((faddrw & (FLASH_SECTOR_SIZE - 1)) == 0)
flash_erase_sector(faddrw); // 45 ms, 4 mA
// rd-wr 4kB - 20 ms, 4 mA
flash_read_page(faddrr, sizeof(buf_blk), (unsigned char *) &buf_blk);
faddrr += sizeof(buf_blk);
flash_write_page(faddrw, sizeof(buf_blk), (unsigned char *) &buf_blk);
faddrw += sizeof(buf_blk);
}
// set id "bootable" to new segment
id = head_id[2]; // = "KNLT"
flash_write_page(OTA2_FADDR_ID, sizeof(id), (unsigned char *) &id);
// clear the "bootable" identifier on the current OTA segment
id = 0;
flash_write_page(BIG_OTA2_FADDR_ID, 1, (unsigned char *) &id);
//flash_erase_sector(CFG_ADR_BIND); // Pair & Security info
while(1)
start_reboot();
}
}
}

#endif // DEVICE_TYPE == DEVICE_MJWSD05MMC


#if USE_EXT_OTA // Compatible BigOTA

RAM ext_ota_t ext_ota;
Expand Down
4 changes: 1 addition & 3 deletions src/ext_ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

#include "app_config.h"

#if (DEVICE_TYPE == DEVICE_MJWSD05MMC)
void test_first_ota(void);
#endif
void big_to_low_ota(void);

#if defined(MI_HW_VER_FADDR) && (MI_HW_VER_FADDR)
uint32_t get_mi_hw_version(void);
Expand Down
14 changes: 7 additions & 7 deletions src/zb_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ enum {
#endif

/* Chip IDs */
#define TLSR_8267 0x00
#define TLSR_8269 0x01
#define TLSR_8258_512K 0x02
#define TLSR_8258_1M 0x03
#define TLSR_8278 0x04
#define TLSR_B91 0x05
#define CHIP_TYPE_8267 0x00
#define CHIP_TYPE_8269 0x01
#define CHIP_TYPE_8258 0x02
#define CHIP_TYPE_8258_1M 0x03
#define CHIP_TYPE_8278 0x04
#define CHIP_TYPE_B91 0x05


#define MANUFACTURER_CODE_TELINK 0x1141 // Telink ID

#define CHIP_TYPE TLSR_8258_512K
#define CHIP_TYPE CHIP_TYPE_8258

#define IMAGE_TYPE ((CHIP_TYPE << 8) | DEVICE_TYPE)
#define FILE_VERSION ((APP_RELEASE << 24) | (APP_BUILD << 16) | (STACK_RELEASE << 8) | STACK_BUILD)
Binary file modified zigbee_ota/1141-0201-99993001-MHO_C401_v45.zigbee
Binary file not shown.
Binary file modified zigbee_ota/1141-0202-99993001-CGG1M_v45.zigbee
Binary file not shown.
Binary file modified zigbee_ota/1141-0202-99993001-CGG1_v45.zigbee
Binary file not shown.
Binary file modified zigbee_ota/1141-0206-99993001-CGDK2_v45.zigbee
Binary file not shown.
Binary file modified zigbee_ota/1141-0208-99993001-MHO_C401N_v45.zigbee
Binary file not shown.
Binary file modified zigbee_ota/1141-0209-99993001-BTH_v45.zigbee
Binary file not shown.
Binary file modified zigbee_ota/1141-020a-99993001-ATC_v45.zigbee
Binary file not shown.
Binary file modified zigbee_ota/1141-020b-99993001-MHO_C122_v45.zigbee
Binary file not shown.

0 comments on commit 56fb924

Please sign in to comment.