From 27daf8303f96f8e880868b504d10499170494570 Mon Sep 17 00:00:00 2001 From: Cristian Niculescu Date: Thu, 13 Mar 2025 16:48:18 -0700 Subject: [PATCH 1/2] Fix missing last operation per partition thread_queue[section_i].end is non-inclusive so by substracting 1 from ops_in_part, last partition(aka job) op is never processed. Tested by adding prints showing queued operations per thread per slot, and confirming it matches partition total ops. --- src/ota_tool.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ota_tool.cc b/src/ota_tool.cc index fbf2326..a75b39e 100644 --- a/src/ota_tool.cc +++ b/src/ota_tool.cc @@ -203,7 +203,7 @@ INIT_FUNC(apply) { int ops_in_part = update.manifest.partitions(jobs[job].part_number).operations_size(); int ops_left = ops_in_part - used; if (ops_left <= ops_needed) { - thread_queue[section_i].end = ops_in_part - 1; + thread_queue[section_i].end = ops_in_part; job++; used = 0; ops_needed -= ops_left; From 244072068f316c524dbf0f9f64dc09762044780a Mon Sep 17 00:00:00 2001 From: Cristian Niculescu Date: Thu, 13 Mar 2025 16:55:06 -0700 Subject: [PATCH 2/2] Failure reporting during apply Summary: When 'apply' fails, the program returns an errorcode. This mapes ota-tool script friendly. --- src/ota_tool.cc | 11 ++++++++--- src/payload.cc | 10 ++++++---- src/payload.h | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ota_tool.cc b/src/ota_tool.cc index a75b39e..ab4c8cb 100644 --- a/src/ota_tool.cc +++ b/src/ota_tool.cc @@ -130,19 +130,24 @@ void launch_apply(char *partition) { jobs[job_count++].out = out; total_operations += part.operations_size(); + if (partition != NULL) { return; } } } } + +int ret_code = 0; + void* run_apply(void *a) { section *queue = (section*)a; FILE *f = fopen(args.update_file, "rb"); - while (queue->part != NULL) { - apply_section(&update, queue, f); + while (queue->part != NULL && !ret_code) { + if (apply_section(&update, queue, f)) + ret_code = 1; queue++; } @@ -241,7 +246,7 @@ INIT_FUNC(apply) { close(jobs[job].out); } - return 0; + return ret_code; } INIT_FUNC(main) { diff --git a/src/payload.cc b/src/payload.cc index c0c336a..5893134 100644 --- a/src/payload.cc +++ b/src/payload.cc @@ -115,7 +115,8 @@ char* get_src(int in, unsigned int *size, return src; } -void apply_section(payload *update, section *section, FILE *data_file) { +int apply_section(payload *update, section *section, FILE *data_file) { + int ret = 1; const char* part_name = update->manifest.partitions(section->part->part_number).partition_name().data(); while (section->start < section->end) { chromeos_update_engine::InstallOperation op = update->manifest.partitions(section->part->part_number).operations(section->start++); @@ -180,7 +181,7 @@ void apply_section(payload *update, section *section, FILE *data_file) { break; default: log_err(part_name, "Unknown Operation Type"); - return; + goto end; } write_out(section->part->out, &op, output); @@ -188,6 +189,8 @@ void apply_section(payload *update, section *section, FILE *data_file) { if (output != src && output != data) { free(output); } + + ret = 0; end: if (data != 0) { free(data); @@ -196,6 +199,5 @@ void apply_section(payload *update, section *section, FILE *data_file) { free(src); } } + return ret; } - - diff --git a/src/payload.h b/src/payload.h index 0d00066..e43a364 100644 --- a/src/payload.h +++ b/src/payload.h @@ -71,7 +71,7 @@ char* output_buffer(const chromeos_update_engine::InstallOperation *op, unsigned char* get_src(int in, unsigned int *size, const chromeos_update_engine::InstallOperation *op); -void apply_section(payload *update, section *section, FILE *data_file); +int apply_section(payload *update, section *section, FILE *data_file); #endif /* ifndef _H_PAYLOAD */