Lines Matching full:ctx
26 struct stream_flash_ctx *ctx = (struct stream_flash_ctx *) param; in settings_direct_loader() local
34 if (cb_len != sizeof(ctx->bytes_written)) { in settings_direct_loader()
40 if (bytes_written >= ctx->bytes_written) { in settings_direct_loader()
41 ctx->bytes_written = bytes_written; in settings_direct_loader()
44 bytes_written, ctx->bytes_written); in settings_direct_loader()
51 off_t offset = (off_t) (ctx->offset + ctx->bytes_written) - 1; in settings_direct_loader()
56 if (ctx->bytes_written > 0) { in settings_direct_loader()
57 rc = flash_get_page_info_by_offs(ctx->fdev, offset, in settings_direct_loader()
63 ctx->last_erased_page_start_offset = page.start_offset; in settings_direct_loader()
65 ctx->last_erased_page_start_offset = -1; in settings_direct_loader()
77 int stream_flash_erase_page(struct stream_flash_ctx *ctx, off_t off) in stream_flash_erase_page() argument
83 if (off < ctx->offset || (off - ctx->offset) >= ctx->available) { in stream_flash_erase_page()
90 const struct flash_parameters *fparams = flash_get_parameters(ctx->fdev); in stream_flash_erase_page()
97 rc = flash_get_page_info_by_offs(ctx->fdev, off, &page); in stream_flash_erase_page()
103 if (ctx->last_erased_page_start_offset == page.start_offset) { in stream_flash_erase_page()
109 rc = flash_erase(ctx->fdev, page.start_offset, page.size); in stream_flash_erase_page()
114 ctx->last_erased_page_start_offset = page.start_offset; in stream_flash_erase_page()
125 static int flash_sync(struct stream_flash_ctx *ctx) in flash_sync() argument
128 size_t write_addr = ctx->offset + ctx->bytes_written; in flash_sync()
134 if (ctx->buf_bytes == 0) { in flash_sync()
140 rc = stream_flash_erase_page(ctx, in flash_sync()
141 write_addr + ctx->buf_bytes - 1); in flash_sync()
149 fill_length = ctx->write_block_size; in flash_sync()
150 if (ctx->buf_bytes % fill_length) { in flash_sync()
151 fill_length -= ctx->buf_bytes % fill_length; in flash_sync()
152 filler = ctx->erase_value; in flash_sync()
154 memset(ctx->buf + ctx->buf_bytes, filler, fill_length); in flash_sync()
159 buf_bytes_aligned = ctx->buf_bytes + fill_length; in flash_sync()
160 rc = flash_write(ctx->fdev, write_addr, ctx->buf, buf_bytes_aligned); in flash_sync()
170 if (ctx->callback) { in flash_sync()
174 for (int i = 0; i < ctx->buf_bytes; i++) { in flash_sync()
175 ctx->buf[i] = ~ctx->buf[i]; in flash_sync()
178 rc = flash_read(ctx->fdev, write_addr, ctx->buf, in flash_sync()
179 ctx->buf_bytes); in flash_sync()
185 rc = ctx->callback(ctx->buf, ctx->buf_bytes, write_addr); in flash_sync()
194 ctx->bytes_written += ctx->buf_bytes; in flash_sync()
195 ctx->buf_bytes = 0U; in flash_sync()
200 int stream_flash_buffered_write(struct stream_flash_ctx *ctx, const uint8_t *data, in stream_flash_buffered_write() argument
207 if (!ctx) { in stream_flash_buffered_write()
211 if (ctx->bytes_written + ctx->buf_bytes + len > ctx->available) { in stream_flash_buffered_write()
216 (buf_empty_bytes = ctx->buf_len - ctx->buf_bytes)) { in stream_flash_buffered_write()
217 memcpy(ctx->buf + ctx->buf_bytes, data + processed, in stream_flash_buffered_write()
220 ctx->buf_bytes = ctx->buf_len; in stream_flash_buffered_write()
221 rc = flash_sync(ctx); in stream_flash_buffered_write()
230 /* place rest of the data into ctx->buf */ in stream_flash_buffered_write()
232 memcpy(ctx->buf + ctx->buf_bytes, in stream_flash_buffered_write()
234 ctx->buf_bytes += len - processed; in stream_flash_buffered_write()
237 if (flush && ctx->buf_bytes > 0) { in stream_flash_buffered_write()
238 rc = flash_sync(ctx); in stream_flash_buffered_write()
244 size_t stream_flash_bytes_written(const struct stream_flash_ctx *ctx) in stream_flash_bytes_written() argument
246 return ctx->bytes_written; in stream_flash_bytes_written()
257 struct _inspect_flash *ctx = (struct _inspect_flash *) data; in find_flash_total_size() local
259 if (ctx->buf_len > info->size) { in find_flash_total_size()
261 ctx->total_size = 0; in find_flash_total_size()
265 ctx->total_size += info->size; in find_flash_total_size()
270 int stream_flash_init(struct stream_flash_ctx *ctx, const struct device *fdev, in stream_flash_init() argument
275 if (!ctx || !fdev || !buf) { in stream_flash_init()
294 ctx->write_block_size = params->write_block_size; in stream_flash_init()
296 if (buf_len % ctx->write_block_size) { in stream_flash_init()
310 offset % ctx->write_block_size) { in stream_flash_init()
316 ctx->fdev = fdev; in stream_flash_init()
317 ctx->buf = buf; in stream_flash_init()
318 ctx->buf_len = buf_len; in stream_flash_init()
319 ctx->bytes_written = 0; in stream_flash_init()
320 ctx->buf_bytes = 0U; in stream_flash_init()
321 ctx->offset = offset; in stream_flash_init()
322 ctx->available = (size == 0 ? inspect_flash_ctx.total_size - offset : in stream_flash_init()
328 ctx->callback = cb; in stream_flash_init()
332 ctx->last_erased_page_start_offset = -1; in stream_flash_init()
334 ctx->erase_value = params->erase_value; in stream_flash_init()
341 int stream_flash_progress_load(struct stream_flash_ctx *ctx, in stream_flash_progress_load() argument
344 if (!ctx || !settings_key) { in stream_flash_progress_load()
350 (void *) ctx); in stream_flash_progress_load()
360 int stream_flash_progress_save(const struct stream_flash_ctx *ctx, in stream_flash_progress_save() argument
363 if (!ctx || !settings_key) { in stream_flash_progress_save()
368 &ctx->bytes_written, in stream_flash_progress_save()
369 sizeof(ctx->bytes_written)); in stream_flash_progress_save()
379 int stream_flash_progress_clear(const struct stream_flash_ctx *ctx, in stream_flash_progress_clear() argument
382 if (!ctx || !settings_key) { in stream_flash_progress_clear()