ESP8266 ROM XTOS

来自Jack's Lab
(版本间的差异)
跳转到: 导航, 搜索
(SYSTEM_RTC_MEM_READ)
(SYSTEM_RTC_MEM_WRITE)
第65行: 第65行:
 
   
 
   
 
     return 1;
 
     return 1;
 +
}
 +
</source>
 +
 +
<br><br>
 +
 +
=== SYSTEM_GET_RST_INFO ===
 +
 +
<source lang=cpp>
 +
struct rst_info {
 +
    uint32 reason;
 +
    uint32 exccause;
 +
    uint32 epc1;
 +
    uint32 epc2;
 +
    uint32 epc3;
 +
    uint32 excvaddr;
 +
    uint32 depc;
 +
};
 +
 +
struct rst_info system_get_rst_info()
 +
{
 +
    struct rst_info rst;
 +
    system_rtc_mem_read(0, &rst, sizeof(struct rst_info);
 +
    if (rst.reason >= 7) {
 +
        ets_memset(&rst, 0, sizeof(struct rst_info));
 +
    }
 +
    if (rtc_get_reset_reason() == 2) {
 +
        ets_memset(&rst, 0, sizeof(struct rst_info));
 +
        rst.reason = 6;
 +
    }
 +
    return rst;
 
}
 
}
 
</source>
 
</source>
  
 
<br><br>
 
<br><br>

2015年12月11日 (五) 00:18的版本

目录

1 逆向工程



2 探索

2.1 SYSTEM_RTC_MEM_READ

uint32 system_rtc_mem_read(int32 addr, void *buff, int32 length)
{
    int32 blocks;
     
    // validate reading a user block
    //if (addr < 64) return 0;
    if (buff == 0) return 0;
    // validate 4 byte aligned
    if (((uint32)buff & 0x3) != 0) return 0;
    // validate length is multiple of 4
    if ((length & 0x3) != 0) return 0;
     
    // check valid length from specified starting point
    if (length > (0x300 - (addr * 4))) return 0;
 
    // copy the data
    for (blocks = (length >> 2) - 1; blocks >= 0; blocks--) {
        volatile uint32 *ram = ((uint32*)buff) + blocks;
        volatile uint32 *rtc = ((uint32*)0x60001100) + addr + blocks;
        *ram = *rtc;
    }
 
    return 1;
}



2.2 SYSTEM_RTC_MEM_WRITE

uint32 system_rtc_mem_write(int32 addr, void *buff, int32 length)
{
    int32 blocks;
     
    // validate reading a user block
    if (addr < 64) return 0;
    if (buff == 0) return 0;
    // validate 4 byte aligned
    if (((uint32)buff & 0x3) != 0) return 0;
    // validate length is multiple of 4
    if ((length & 0x3) != 0) return 0;
     
    // check valid length from specified starting point
    if (length > (0x300 - (addr * 4))) return 0;
 
    // copy the data
    for (blocks = (length >> 2) - 1; blocks >= 0; blocks--) {
        volatile uint32 *ram = ((uint32*)buff) + blocks;
        volatile uint32 *rtc = ((uint32*)0x60001100) + addr + blocks;
        *rtc = *ram;
    }
 
    return 1;
}



2.3 SYSTEM_GET_RST_INFO

struct rst_info {
    uint32 reason;
    uint32 exccause;
    uint32 epc1;
    uint32 epc2;
    uint32 epc3;
    uint32 excvaddr;
    uint32 depc;
};
 
struct rst_info system_get_rst_info()
{
    struct rst_info rst;
    system_rtc_mem_read(0, &rst, sizeof(struct rst_info);
    if (rst.reason >= 7) {
        ets_memset(&rst, 0, sizeof(struct rst_info));
    }
    if (rtc_get_reset_reason() == 2) {
        ets_memset(&rst, 0, sizeof(struct rst_info));
        rst.reason = 6;
    }
    return rst;
}



个人工具
名字空间

变换
操作
导航
工具箱