Lines Matching refs:context
33 int init_flash_dev(struct mbox_context *context) in init_flash_dev() argument
53 context->fds[MTD_FD].fd = fd; in init_flash_dev()
56 if (ioctl(fd, MEMGETINFO, &context->mtd_info) == -1) { in init_flash_dev()
63 if (context->flash_size == 0) { in init_flash_dev()
84 context->mtd_info.size); in init_flash_dev()
85 context->flash_size = context->mtd_info.size; in init_flash_dev()
89 context->erase_size_shift = log_2(context->mtd_info.erasesize); in init_flash_dev()
90 context->flash_bmap = calloc(context->flash_size >> in init_flash_dev()
91 context->erase_size_shift, in init_flash_dev()
92 sizeof(*context->flash_bmap)); in init_flash_dev()
93 MSG_DBG("Flash erase size: 0x%.8x\n", context->mtd_info.erasesize); in init_flash_dev()
100 void free_flash_dev(struct mbox_context *context) in free_flash_dev() argument
102 free(context->flash_bmap); in free_flash_dev()
103 close(context->fds[MTD_FD].fd); in free_flash_dev()
115 static inline bool flash_is_erased(struct mbox_context *context, in flash_is_erased() argument
118 return context->flash_bmap[offset >> context->erase_size_shift] in flash_is_erased()
134 int set_flash_bytemap(struct mbox_context *context, uint32_t offset, in set_flash_bytemap() argument
137 if ((offset + count) > context->flash_size) { in set_flash_bytemap()
143 memset(context->flash_bmap + (offset >> context->erase_size_shift), in set_flash_bytemap()
145 align_up(count, 1 << context->erase_size_shift) >> in set_flash_bytemap()
146 context->erase_size_shift); in set_flash_bytemap()
159 int erase_flash(struct mbox_context *context, uint32_t offset, uint32_t count) in erase_flash() argument
161 const uint32_t erase_size = 1 << context->erase_size_shift; in erase_flash()
175 if (!flash_is_erased(context, offset)) { /* Need to erase */ in erase_flash()
184 rc = ioctl(context->fds[MTD_FD].fd, MEMERASE, in erase_flash()
192 set_flash_bytemap(context, erase_info.start, in erase_flash()
205 rc = ioctl(context->fds[MTD_FD].fd, MEMERASE, &erase_info); in erase_flash()
212 set_flash_bytemap(context, erase_info.start, erase_info.length, in erase_flash()
231 int64_t copy_flash(struct mbox_context *context, uint32_t offset, void *mem, in copy_flash() argument
239 if (lseek(context->fds[MTD_FD].fd, offset, SEEK_SET) != offset) { in copy_flash()
246 size_read = read(context->fds[MTD_FD].fd, mem, in copy_flash()
270 int write_flash(struct mbox_context *context, uint32_t offset, void *buf, in write_flash() argument
278 if (lseek(context->fds[MTD_FD].fd, offset, SEEK_SET) != offset) { in write_flash()
285 rc = write(context->fds[MTD_FD].fd, buf + buf_offset, count); in write_flash()
292 set_flash_bytemap(context, offset + buf_offset, rc, in write_flash()