Lines Matching refs:offset
99 static int flash_sam0_valid_range(off_t offset, size_t len) in flash_sam0_valid_range() argument
101 if (offset < 0) { in flash_sam0_valid_range()
102 LOG_WRN("0x%lx: before start of flash", (long)offset); in flash_sam0_valid_range()
105 if ((offset + len) > CONFIG_FLASH_SIZE * 1024) { in flash_sam0_valid_range()
106 LOG_WRN("0x%lx: ends past the end of flash", (long)offset); in flash_sam0_valid_range()
124 static int flash_sam0_check_status(off_t offset) in flash_sam0_check_status() argument
141 LOG_ERR("programming error at 0x%lx", (long)offset); in flash_sam0_check_status()
144 LOG_ERR("lock error at 0x%lx", (long)offset); in flash_sam0_check_status()
147 LOG_ERR("NVM error at 0x%lx", (long)offset); in flash_sam0_check_status()
161 static int flash_sam0_write_page(const struct device *dev, off_t offset, in flash_sam0_write_page() argument
166 uint32_t *dst = FLASH_MEM(offset); in flash_sam0_write_page()
187 err = flash_sam0_check_status(offset); in flash_sam0_write_page()
192 if (memcmp(data, FLASH_MEM(offset), len) != 0) { in flash_sam0_write_page()
193 LOG_ERR("verify error at offset 0x%lx", (long)offset); in flash_sam0_write_page()
200 static int flash_sam0_erase_row(const struct device *dev, off_t offset) in flash_sam0_erase_row() argument
202 *FLASH_MEM(offset) = 0U; in flash_sam0_erase_row()
208 return flash_sam0_check_status(offset); in flash_sam0_erase_row()
236 static int flash_sam0_write(const struct device *dev, off_t offset, in flash_sam0_write() argument
243 LOG_DBG("0x%lx: len %zu", (long)offset, len); in flash_sam0_write()
245 err = flash_sam0_valid_range(offset, len); in flash_sam0_write()
261 off_t start = offset % sizeof(ctx->buf); in flash_sam0_write()
262 off_t base = offset - start; in flash_sam0_write()
272 offset += len_step; in flash_sam0_write()
289 static int flash_sam0_write(const struct device *dev, off_t offset, in flash_sam0_write() argument
295 err = flash_sam0_valid_range(offset, len); in flash_sam0_write()
300 if ((offset % FLASH_WRITE_BLK_SZ) != 0) { in flash_sam0_write()
301 LOG_WRN("0x%lx: not on a write block boundary", (long)offset); in flash_sam0_write()
315 size_t eop_len = FLASH_PAGE_SIZE - (offset % FLASH_PAGE_SIZE); in flash_sam0_write()
319 err = flash_sam0_write_page(dev, offset, pdata, write_len); in flash_sam0_write()
324 offset += write_len; in flash_sam0_write()
344 static int flash_sam0_read(const struct device *dev, off_t offset, void *data, in flash_sam0_read() argument
349 err = flash_sam0_valid_range(offset, len); in flash_sam0_read()
354 memcpy(data, (uint8_t *)CONFIG_FLASH_BASE_ADDRESS + offset, len); in flash_sam0_read()
359 static int flash_sam0_erase(const struct device *dev, off_t offset, in flash_sam0_erase() argument
364 err = flash_sam0_valid_range(offset, ROW_SIZE); in flash_sam0_erase()
369 if ((offset % ROW_SIZE) != 0) { in flash_sam0_erase()
370 LOG_WRN("0x%lx: not on a page boundary", (long)offset); in flash_sam0_erase()
383 for (size_t addr = offset; addr < offset + size; in flash_sam0_erase()
405 off_t offset; in flash_sam0_write_protection() local
408 for (offset = 0; offset < CONFIG_FLASH_SIZE * 1024; in flash_sam0_write_protection()
409 offset += LOCK_REGION_SIZE) { in flash_sam0_write_protection()
410 NVMCTRL->ADDR.reg = offset + CONFIG_FLASH_BASE_ADDRESS; in flash_sam0_write_protection()
429 err = flash_sam0_check_status(offset); in flash_sam0_write_protection()