Lines Matching +full:- +full:x

1 // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
6 // http://www.apache.org/licenses/LICENSE-2.0
30 ESP_LOGE(TAG,"%s(%d): result = 0x%08x", __FUNCTION__, __LINE__, result); \
45 free(this->temp_buff); in ~WL_Flash()
50 …_addr=0x%08x, full_mem_size=0x%08x, page_size=0x%08x, sector_size=0x%08x, updaterate=0x%08x, wr_si… in config()
51 (uint32_t) cfg->start_addr, in config()
52 cfg->full_mem_size, in config()
53 cfg->page_size, in config()
54 cfg->sector_size, in config()
55 cfg->updaterate, in config()
56 cfg->wr_size, in config()
57 cfg->version, in config()
58 (uint32_t) cfg->temp_buff_size); in config()
60 …cfg->crc = crc32::crc32_le(WL_CFG_CRC_CONST, (const unsigned char *)cfg, offsetof(wl_config_t, crc… in config()
62 memcpy(&this->cfg, cfg, sizeof(wl_config_t)); in config()
63 if (this->cfg.temp_buff_size < this->cfg.wr_size) { in config()
64 this->cfg.temp_buff_size = this->cfg.wr_size; in config()
66 this->configured = false; in config()
70 this->flash_drv = flash_drv; in config()
74 if ((this->cfg.sector_size % this->cfg.temp_buff_size) != 0) { in config()
77 if (this->cfg.page_size < this->cfg.sector_size) { in config()
82 this->state_size = this->cfg.sector_size; in config()
83 …if (this->state_size < (sizeof(wl_state_t) + (this->cfg.full_mem_size / this->cfg.sector_size)*thi… in config()
84 …this->state_size = ((sizeof(wl_state_t) + (this->cfg.full_mem_size / this->cfg.sector_size) * this in config()
85 this->state_size = this->state_size * this->cfg.sector_size; in config()
87 this->cfg_size = (sizeof(wl_config_t) + this->cfg.sector_size - 1) / this->cfg.sector_size; in config()
88 this->cfg_size = cfg_size * this->cfg.sector_size; in config()
90 this->addr_cfg = this->cfg.start_addr + this->cfg.full_mem_size - this->cfg_size; in config()
91 …this->addr_state1 = this->cfg.start_addr + this->cfg.full_mem_size - this->state_size * 2 - this->… in config()
92 …this->addr_state2 = this->cfg.start_addr + this->cfg.full_mem_size - this->state_size * 1 - this->… in config()
94 …t flash_sz = ((this->cfg.full_mem_size - this->state_size * 2 - this->cfg_size) / this->cfg.page_s… in config()
95 …this->flash_size = ((this->cfg.full_mem_size - this->state_size * 2 - this->cfg_size) / this->cfg.… in config()
97 …OGD(TAG, "%s - config result: state_size=0x%08x, cfg_size=0x%08x, addr_cfg=0x%08x, addr_state1=0x%… in config()
98 (uint32_t) this->state_size, in config()
99 (uint32_t) this->cfg_size, in config()
100 (uint32_t) this->addr_cfg, in config()
101 (uint32_t) this->addr_state1, in config()
102 (uint32_t) this->addr_state2, in config()
103 (uint32_t) this->flash_size in config()
110 this->temp_buff = (uint8_t *)malloc(this->cfg.temp_buff_size); in config()
111 if (this->temp_buff == NULL) { in config()
115 this->configured = true; in config()
122 if (this->configured == false) { in init()
127 this->initialized = false; in init()
129 this->flash_drv->read(this->addr_state1, &this->state, sizeof(wl_state_t)); in init()
132 result = this->flash_drv->read(this->addr_state2, state_copy, sizeof(wl_state_t)); in init()
137 uint32_t crc1 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, check_size); in init()
140 …ESP_LOGD(TAG, "%s - config ID=%i, stored ID=%i, access_count=%i, block_size=%i, max_count=%i, pos=… in init()
142 this->cfg.version, in init()
143 this->state.version, in init()
144 this->state.access_count, in init()
145 this->state.block_size, in init()
146 this->state.max_count, in init()
147 this->state.pos, in init()
148 this->state.move_count); in init()
150x%08x, crc2 = 0x%08x, this->state.crc= 0x%08x, state_copy->crc= 0x%08x, version=%i, read_version=%… in init()
151 if ((crc1 == this->state.crc) && (crc2 == state_copy->crc)) { in init()
153 if (this->state.version != this->cfg.version) { in init()
154 result = this->initSections(); in init()
156 result = this->recoverPos(); in init()
160 result = this->flash_drv->erase_range(this->addr_state2, this->state_size); in init()
162 … result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); in init()
164 …for (size_t i = 0; i < ((this->cfg.full_mem_size / this->cfg.sector_size)*this->cfg.wr_size); i++)… in init()
166 …result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, thi… in init()
168 pos_bits = this->OkBuffSet(i); in init()
170 //this->fillOkBuff(i); in init()
171 …result = this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wr_size, th… in init()
176 …ESP_LOGD(TAG, "%s: crc1=0x%08x, crc2 = 0x%08x, result= 0x%08x", __func__, crc1, crc2, (uint32_t)re… in init()
177 result = this->recoverPos(); in init()
180 …} else if ((crc1 != this->state.crc) && (crc2 != state_copy->crc)) { // This is just new flash or … in init()
182 …ESP_LOGD(TAG, "%s: try to update version - crc1= 0x%08x, crc2 = 0x%08x, result= 0x%08x", __func__,… in init()
183 result = this->updateVersion(); in init()
186 result = this->initSections(); in init()
189 result = this->recoverPos(); in init()
193 if (crc1 == this->state.crc) {// we have to recover state 2 in init()
194 result = this->flash_drv->erase_range(this->addr_state2, this->state_size); in init()
196 result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); in init()
198 …for (size_t i = 0; i < ((this->cfg.full_mem_size / this->cfg.sector_size) * this->cfg.wr_size); i+… in init()
200 …result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, thi… in init()
202 pos_bits = this->OkBuffSet(i); in init()
204 …result = this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wr_size, th… in init()
208 result = this->flash_drv->read(this->addr_state2, &this->state, sizeof(wl_state_t)); in init()
211 result = this->flash_drv->erase_range(this->addr_state1, this->state_size); in init()
213 result = this->flash_drv->write(this->addr_state1, state_copy, sizeof(wl_state_t)); in init()
215 …for (size_t i = 0; i < ((this->cfg.full_mem_size / this->cfg.sector_size) * this->cfg.wr_size); i+… in init()
217 …result = this->flash_drv->read(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wr_size, thi… in init()
220 pos_bits = this->OkBuffSet(i); in init()
222 …result = this->flash_drv->write(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, th… in init()
226 result = this->flash_drv->read(this->addr_state1, &this->state, sizeof(wl_state_t)); in init()
228 this->state.pos = this->state.max_pos - 1; in init()
232 if (this->state.version != this->cfg.version) { in init()
233 result = this->initSections(); in init()
238 this->initialized = false; in init()
239 ESP_LOGE(TAG, "%s: returned 0x%08x", __func__, (uint32_t)result); in init()
242 this->initialized = true; in init()
243 ESP_LOGD(TAG, "%s - move_count= 0x%08x", __func__, (uint32_t)this->state.move_count); in init()
252 for (size_t i = 0; i < this->state.max_pos; i++) { in recoverPos()
255 …result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, thi… in recoverPos()
256 pos_bits = this->OkBuffSet(i); in recoverPos()
258 …ESP_LOGV(TAG, "%s - check pos: result=0x%08x, position= %i, pos_bits= 0x%08x", __func__, (uint32_t… in recoverPos()
264 this->state.pos = position; in recoverPos()
265 if (this->state.pos == this->state.max_pos) { in recoverPos()
266 this->state.pos--; in recoverPos()
268- this->state.pos= 0x%08x, position= 0x%08x, result= 0x%08x, max_pos= 0x%08x", __func__, (uint32_t… in recoverPos()
276 this->state.pos = 0; in initSections()
277 this->state.access_count = 0; in initSections()
278 this->state.move_count = 0; in initSections()
280 this->state.max_count = this->flash_size / this->state_size * this->cfg.updaterate; in initSections()
281 if (this->cfg.updaterate != 0) { in initSections()
282 this->state.max_count = this->cfg.updaterate; in initSections()
284 this->state.version = this->cfg.version; in initSections()
285 this->state.block_size = this->cfg.page_size; in initSections()
286 this->state.device_id = esp_random(); in initSections()
287 memset(this->state.reserved, 0, sizeof(this->state.reserved)); in initSections()
289 this->state.max_pos = 1 + this->flash_size / this->cfg.page_size; in initSections()
291 … this->state.crc = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, WL_STATE_CRC_LEN_V2); in initSections()
293 result = this->flash_drv->erase_range(this->addr_state1, this->state_size); in initSections()
295 result = this->flash_drv->write(this->addr_state1, &this->state, sizeof(wl_state_t)); in initSections()
298 result = this->flash_drv->erase_range(this->addr_state2, this->state_size); in initSections()
300 result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); in initSections()
303 result = this->flash_drv->erase_range(this->addr_cfg, this->cfg_size); in initSections()
305 result = this->flash_drv->write(this->addr_cfg, &this->cfg, sizeof(wl_config_t)); in initSections()
308 …ESP_LOGD(TAG, "%s - this->state->max_count= 0x%08x, this->state->max_pos= 0x%08x", __func__, this- in initSections()
309 ESP_LOGD(TAG, "%s - result= 0x%08x", __func__, result); in initSections()
317 result = this->updateV1_V2(); in updateVersion()
332 uint32_t crc1 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, check_size); in updateV1_V2()
335 result = this->flash_drv->read(this->addr_state2, state_copy, sizeof(wl_state_t)); in updateV1_V2()
340 uint32_t v1_crc1 = this->state.device_id; in updateV1_V2()
341 uint32_t v1_crc2 = state_copy->device_id; in updateV1_V2()
343 …OGD(TAG, "%s - process crc1=0x%08x, crc2=0x%08x, v1_crc1=0x%08x, v1_crc2=0x%08x, version=%i", __fu… in updateV1_V2()
345 …rc1) && (crc2 == v1_crc2) && (v1_crc1 == v1_crc2) && (this->state.version == 1) && (state_copy->ve… in updateV1_V2()
347 ESP_LOGI(TAG, "%s Update from V1 to V2, crc=0x%08x, ", __func__, crc1); in updateV1_V2()
350 for (size_t i = 0; i < this->state.max_pos; i++) { in updateV1_V2()
352 …result = this->flash_drv->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, &po… in updateV1_V2()
354 …ESP_LOGV(TAG, "%s- result= 0x%08x, pos= %i, pos_bits= 0x%08x", __func__, (uint32_t)result, (uint32… in updateV1_V2()
360 ….ver=%i", __func__, (uint32_t)this->state.max_pos, (uint32_t)pos, (uint32_t)this->state.version, (… in updateV1_V2()
361 if (pos == this->state.max_pos) { in updateV1_V2()
362 pos--; in updateV1_V2()
366 this->state.version = 2; in updateV1_V2()
367 this->state.pos = 0; in updateV1_V2()
368 this->state.device_id = esp_random(); in updateV1_V2()
369 memset(this->state.reserved, 0, sizeof(this->state.reserved)); in updateV1_V2()
370 … this->state.crc = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, WL_STATE_CRC_LEN_V2); in updateV1_V2()
372 result = this->flash_drv->erase_range(this->addr_state1, this->state_size); in updateV1_V2()
374 result = this->flash_drv->write(this->addr_state1, &this->state, sizeof(wl_state_t)); in updateV1_V2()
377 memset(this->temp_buff, 0, this->cfg.wr_size); in updateV1_V2()
379 this->fillOkBuff(i); in updateV1_V2()
380 …result = this->flash_drv->write(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wr_size, th… in updateV1_V2()
384 result = this->flash_drv->erase_range(this->addr_state2, this->state_size); in updateV1_V2()
386 result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); in updateV1_V2()
388 …ESP_LOGD(TAG, "%s - move_count= 0x%08x, pos= 0x%08x", __func__, this->state.move_count, this->stat… in updateV1_V2()
390 memset(this->temp_buff, 0, this->cfg.wr_size); in updateV1_V2()
392 this->fillOkBuff(i); in updateV1_V2()
393 …result = this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + i * this->cfg.wr_size, th… in updateV1_V2()
396 this->state.pos = pos; in updateV1_V2()
405 uint32_t *buff = (uint32_t *)this->temp_buff; in fillOkBuff()
408 buff[i] = this->state.device_id + n * 4 + i; in fillOkBuff()
416 uint32_t *data_buff = (uint32_t *)this->temp_buff; in OkBuffSet()
418 uint32_t data = this->state.device_id + n * 4 + i; in OkBuffSet()
431 this->state.access_count++; in updateWL()
432 if (this->state.access_count < this->state.max_count) { in updateWL()
436 this->state.access_count = 0; in updateWL()
437 …ESP_LOGV(TAG, "%s - access_count= 0x%08x, pos= 0x%08x", __func__, this->state.access_count, this->… in updateWL()
439 size_t data_addr = this->state.pos + 1; // next block, [pos+1] copy to [pos] in updateWL()
440 if (data_addr >= this->state.max_pos) { in updateWL()
443 data_addr = this->cfg.start_addr + data_addr * this->cfg.page_size; in updateWL()
444 this->dummy_addr = this->cfg.start_addr + this->state.pos * this->cfg.page_size; in updateWL()
445 result = this->flash_drv->erase_range(this->dummy_addr, this->cfg.page_size); in updateWL()
447 ESP_LOGE(TAG, "%s - erase wl dummy sector result= 0x%08x", __func__, result); in updateWL()
448 this->state.access_count = this->state.max_count - 1; // we will update next time in updateWL()
452 size_t copy_count = this->cfg.page_size / this->cfg.temp_buff_size; in updateWL()
454 …result = this->flash_drv->read(data_addr + i * this->cfg.temp_buff_size, this->temp_buff, this->cf… in updateWL()
456 …ESP_LOGE(TAG, "%s - not possible to read buffer, will try next time, result= 0x%08x", __func__, re… in updateWL()
457 this->state.access_count = this->state.max_count - 1; // we will update next time in updateWL()
460 …result = this->flash_drv->write(this->dummy_addr + i * this->cfg.temp_buff_size, this->temp_buff, … in updateWL()
462 …ESP_LOGE(TAG, "%s - not possible to write buffer, will try next time, result= 0x%08x", __func__, r… in updateWL()
463 this->state.access_count = this->state.max_count - 1; // we will update next time in updateWL()
470 uint32_t byte_pos = this->state.pos * this->cfg.wr_size; in updateWL()
471 this->fillOkBuff(this->state.pos); in updateWL()
473 …result |= this->flash_drv->write(this->addr_state1 + sizeof(wl_state_t) + byte_pos, this->temp_buf… in updateWL()
475 ESP_LOGE(TAG, "%s - update position 1 result= 0x%08x", __func__, result); in updateWL()
476 this->state.access_count = this->state.max_count - 1; // we will update next time in updateWL()
479 this->fillOkBuff(this->state.pos); in updateWL()
480 …result |= this->flash_drv->write(this->addr_state2 + sizeof(wl_state_t) + byte_pos, this->temp_buf… in updateWL()
482 ESP_LOGE(TAG, "%s - update position 2 result= 0x%08x", __func__, result); in updateWL()
483 this->state.access_count = this->state.max_count - 1; // we will update next time in updateWL()
487 this->state.pos++; in updateWL()
488 if (this->state.pos >= this->state.max_pos) { in updateWL()
489 this->state.pos = 0; in updateWL()
491 this->state.move_count++; in updateWL()
492 if (this->state.move_count >= (this->state.max_pos - 1)) { in updateWL()
493 this->state.move_count = 0; in updateWL()
496 … this->state.crc = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, WL_STATE_CRC_LEN_V2); in updateWL()
498 result = this->flash_drv->erase_range(this->addr_state1, this->state_size); in updateWL()
500 result = this->flash_drv->write(this->addr_state1, &this->state, sizeof(wl_state_t)); in updateWL()
502 result = this->flash_drv->erase_range(this->addr_state2, this->state_size); in updateWL()
504 result = this->flash_drv->write(this->addr_state2, &this->state, sizeof(wl_state_t)); in updateWL()
506 …ESP_LOGD(TAG, "%s - move_count= 0x%08x, pos= 0x%08x, ", __func__, this->state.move_count, this->st… in updateWL()
510 ESP_LOGV(TAG, "%s - result= 0x%08x", __func__, result); in updateWL()
512 ESP_LOGE(TAG, "%s - result= 0x%08x", __func__, result); in updateWL()
519 …size_t result = (this->flash_size - this->state.move_count * this->cfg.page_size + addr) % this->f… in calcAddr()
520 size_t dummy_addr = this->state.pos * this->cfg.page_size; in calcAddr()
523 result += this->cfg.page_size; in calcAddr()
525 …ESP_LOGV(TAG, "%s - addr= 0x%08x -> result= 0x%08x, dummy_addr= 0x%08x", __func__, (uint32_t) addr… in calcAddr()
532 if (!this->configured) { in chip_size()
535 return this->flash_size; in chip_size()
539 if (!this->configured) { in sector_size()
542 return this->cfg.sector_size; in sector_size()
549 if (!this->initialized) { in erase_sector()
552 ESP_LOGD(TAG, "%s - sector= 0x%08x", __func__, (uint32_t) sector); in erase_sector()
553 result = this->updateWL(); in erase_sector()
555 size_t virt_addr = this->calcAddr(sector * this->cfg.sector_size); in erase_sector()
556 …result = this->flash_drv->erase_sector((this->cfg.start_addr + virt_addr) / this->cfg.sector_size); in erase_sector()
563 if (!this->initialized) { in erase_range()
566 …ESP_LOGD(TAG, "%s - start_address= 0x%08x, size= 0x%08x", __func__, (uint32_t) start_address, (uin… in erase_range()
567 size_t erase_count = (size + this->cfg.sector_size - 1) / this->cfg.sector_size; in erase_range()
568 size_t start_sector = start_address / this->cfg.sector_size; in erase_range()
570 result = this->erase_sector(start_sector + i); in erase_range()
573 ESP_LOGV(TAG, "%s - result= 0x%08x", __func__, result); in erase_range()
580 if (!this->initialized) { in write()
583 …ESP_LOGD(TAG, "%s - dest_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) dest_addr, (uint32_t) s… in write()
584 uint32_t count = (size - 1) / this->cfg.page_size; in write()
586 size_t virt_addr = this->calcAddr(dest_addr + i * this->cfg.page_size); in write()
587 …result = this->flash_drv->write(this->cfg.start_addr + virt_addr, &((uint8_t *)src)[i * this->cfg.… in write()
590 size_t virt_addr_last = this->calcAddr(dest_addr + count * this->cfg.page_size); in write()
591 …result = this->flash_drv->write(this->cfg.start_addr + virt_addr_last, &((uint8_t *)src)[count * t… in write()
599 if (!this->initialized) { in read()
602 …ESP_LOGD(TAG, "%s - src_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) src_addr, (uint32_t) siz… in read()
603 uint32_t count = (size - 1) / this->cfg.page_size; in read()
605 size_t virt_addr = this->calcAddr(src_addr + i * this->cfg.page_size); in read()
606 …ESP_LOGV(TAG, "%s - real_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) (this->cfg.start_addr +… in read()
607 …result = this->flash_drv->read(this->cfg.start_addr + virt_addr, &((uint8_t *)dest)[i * this->cfg.… in read()
610 size_t virt_addr_last = this->calcAddr(src_addr + count * this->cfg.page_size); in read()
611 …result = this->flash_drv->read(this->cfg.start_addr + virt_addr_last, &((uint8_t *)dest)[count * t… in read()
618 return this->flash_drv; in get_drv()
622 return &this->cfg; in get_cfg()
628 this->state.access_count = this->state.max_count - 1; in flush()
629 result = this->updateWL(); in flush()
630 …ESP_LOGD(TAG, "%s - result= 0x%08x, move_count= 0x%08x", __func__, result, this->state.move_count); in flush()