Lines Matching refs:ctx
125 static void fcalculate_cluster(struct bootuf2_data *ctx) in fcalculate_cluster() argument
133 ctx->DBR->BPB.BytesPerSector * in fcalculate_cluster()
134 ctx->DBR->BPB.SectorsPerCluster); in fcalculate_cluster()
208 static int bootuf2_flash_flush(struct bootuf2_data *ctx) in bootuf2_flash_flush() argument
212 if (ctx->cached_bytes == 0) { in bootuf2_flash_flush()
216 err = bootuf2_flash_write(ctx->cached_address, ctx->cache, ctx->cached_bytes); in bootuf2_flash_flush()
220 err, ctx->cached_address, ctx->cached_bytes); in bootuf2_flash_flush()
224 ctx->cached_bytes = 0; in bootuf2_flash_flush()
229 int bootuf2_flash_write_internal(struct bootuf2_data *ctx, struct bootuf2_BLOCK *uf2) in bootuf2_flash_write_internal() argument
233 if ((ctx->cached_bytes && ((ctx->cached_address + ctx->cached_bytes) != uf2->TargetAddress)) || in bootuf2_flash_write_internal()
234 (ctx->cached_bytes == ctx->cache_size)) { in bootuf2_flash_write_internal()
235 int err = bootuf2_flash_flush(ctx); in bootuf2_flash_write_internal()
241 memcpy(ctx->cache + ctx->cached_bytes, uf2->Data, uf2->PayloadSize); in bootuf2_flash_write_internal()
243 ctx->cached_address = uf2->TargetAddress - ctx->cached_bytes; in bootuf2_flash_write_internal()
244 ctx->cached_bytes += uf2->PayloadSize; in bootuf2_flash_write_internal()
251 struct bootuf2_data *ctx; in bootuf2_init() local
253 ctx = &bootuf2_disk; in bootuf2_init()
255 fcalculate_cluster(ctx); in bootuf2_init()
257 ctx->cached_bytes = 0; in bootuf2_init()
258 ctx->cached_address = 0; in bootuf2_init()
263 struct bootuf2_data *ctx; in boot2uf2_read_sector() local
265 ctx = &bootuf2_disk; in boot2uf2_read_sector()
268 memset(buff, 0, ctx->DBR->BPB.BytesPerSector); in boot2uf2_read_sector()
274 memcpy(buff, ctx->DBR, sizeof(struct bootuf2_DBR)); in boot2uf2_read_sector()
279 else if (start_sector < BOOTUF2_SECTOR_FAT_END(ctx->DBR)) { in boot2uf2_read_sector()
282 sector_relative -= BOOTUF2_SECTOR_RSVD_END(ctx->DBR); in boot2uf2_read_sector()
285 while (sector_relative >= ctx->DBR->BPB.SectorsPerFAT) { in boot2uf2_read_sector()
286 sector_relative -= ctx->DBR->BPB.SectorsPerFAT; in boot2uf2_read_sector()
291 BOOTUF2_FAT16_PER_SECTOR(ctx->DBR); in boot2uf2_read_sector()
295 i < BOOTUF2_FAT16_PER_SECTOR(ctx->DBR); in boot2uf2_read_sector()
305 buff[0] = ctx->DBR->BPB.MediaDescriptor; in boot2uf2_read_sector()
316 if (idx < BOOTUF2_FAT16_PER_SECTOR(ctx->DBR)) { in boot2uf2_read_sector()
323 else if (start_sector < BOOTUF2_SECTOR_ROOT_END(ctx->DBR)) { in boot2uf2_read_sector()
324 sector_relative -= BOOTUF2_SECTOR_FAT_END(ctx->DBR); in boot2uf2_read_sector()
327 int remain_entries = BOOTUF2_ENTRY_PER_SECTOR(ctx->DBR); in boot2uf2_read_sector()
333 fname_copy(ent->Name, (char const *)ctx->DBR->BPB.VolumeLabel, 11); in boot2uf2_read_sector()
340 file_index_first = sector_relative * BOOTUF2_ENTRY_PER_SECTOR(ctx->DBR) - 1; in boot2uf2_read_sector()
369 else if (start_sector < BOOTUF2_SECTOR_DATA_END(ctx->DBR)) { in boot2uf2_read_sector()
370 sector_relative -= BOOTUF2_SECTOR_ROOT_END(ctx->DBR); in boot2uf2_read_sector()
372 int fid = ffind_by_cluster(2 + sector_relative / ctx->DBR->BPB.SectorsPerCluster); in boot2uf2_read_sector()
379 (files[fid].ClusterBeg - 2) * ctx->DBR->BPB.SectorsPerCluster; in boot2uf2_read_sector()
381 size_t fcontent_offset = sector_relative_file * ctx->DBR->BPB.BytesPerSector; in boot2uf2_read_sector()
388 if (copy_size > ctx->DBR->BPB.BytesPerSector) { in boot2uf2_read_sector()
389 copy_size = ctx->DBR->BPB.BytesPerSector; in boot2uf2_read_sector()
400 buff += ctx->DBR->BPB.BytesPerSector; in boot2uf2_read_sector()
408 struct bootuf2_data *ctx; in bootuf2_write_sector() local
410 ctx = &bootuf2_disk; in bootuf2_write_sector()
424 if (bootuf2block_check_writable(ctx->STATE, uf2, CONFIG_BOOTUF2_FLASHMAX)) { in bootuf2_write_sector()
425 bootuf2_flash_write_internal(ctx, uf2); in bootuf2_write_sector()
426 bootuf2block_state_update(ctx->STATE, uf2, CONFIG_BOOTUF2_FLASHMAX); in bootuf2_write_sector()
438 buff += ctx->DBR->BPB.BytesPerSector; in bootuf2_write_sector()