Skip to content

[RFC] qdl: introduce allow-fusing parameter #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 53 additions & 12 deletions program.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s
return 0;
}

static struct program *program_find_partition(const char *partition)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write somewhat sensible commit message, descring why do you need to perform these changes and/or what kind of refactoring was performed

{
struct program *program;
const char *label;

for (program = programes; program; program = program->next) {
label = program->label;
if (!label)
continue;

if (!strcmp(label, partition))
return program;
}

return NULL;
}

/**
* program_find_bootable_partition() - find one bootable partition
*
Expand All @@ -232,30 +249,54 @@ int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s
int program_find_bootable_partition(bool *multiple_found)
{
struct program *program;
const char *label;
int part = -ENOENT;

*multiple_found = false;

for (program = programes; program; program = program->next) {
label = program->label;
if (!label)
continue;
program = program_find_partition("xbl");
if (program)
part = program->partition;

if (!strcmp(label, "xbl") || !strcmp(label, "xbl_a") ||
!strcmp(label, "sbl1")) {
if (part != -ENOENT) {
*multiple_found = true;
continue;
}
program = program_find_partition("xbl_a");
if (program) {
if (part != -ENOENT)
*multiple_found = true;
else
part = program->partition;
}

program = program_find_partition("sbl1");
if (program) {
if (part != -ENOENT)
*multiple_found = true;
else
part = program->partition;
}
}

return part;
}

/**
* program_is_sec_partition_flashed() - find if secdata partition is flashed
*
* Returns true if filename for secdata is set in program*.xml,
* or false otherwise.
*/
int program_is_sec_partition_flashed(void)
{
struct program *program;

program = program_find_partition("secdata");
if (!program)
return false;

if (program->filename)
return true;

return false;
}


void free_programs(void)
{
struct program *program = programes;
Expand Down
2 changes: 2 additions & 0 deletions program.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ int program_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl,
const char *incdir, bool allow_missing);
int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program));
int program_find_bootable_partition(bool *multiple_found);
int program_is_sec_partition_flashed(void);

void free_programs(void);

#endif
10 changes: 10 additions & 0 deletions qdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "qdl.h"
#include "patch.h"
#include "program.h"
#include "ufs.h"

#define MAX_USBFS_BULK_SIZE (16*1024)
Expand Down Expand Up @@ -120,6 +121,7 @@ int main(int argc, char **argv)
int ret;
int opt;
bool qdl_finalize_provisioning = false;
bool allow_fusing = false;
bool allow_missing = false;
long out_chunk_size;

Expand All @@ -132,6 +134,7 @@ int main(int argc, char **argv)
{"serial", required_argument, 0, 'S'},
{"storage", required_argument, 0, 's'},
{"allow-missing", no_argument, 0, 'f'},
{"allow-fusing", no_argument, 0, 'c'},
{0, 0, 0, 0}
};

Expand All @@ -152,6 +155,9 @@ int main(int argc, char **argv)
case 'l':
qdl_finalize_provisioning = true;
break;
case 'c':
allow_fusing = true;
break;
case OPT_OUT_CHUNK_SIZE:
out_chunk_size = strtol(optarg, NULL, 10);
qdl_set_out_chunk_size(&qdl, out_chunk_size);
Expand Down Expand Up @@ -196,6 +202,10 @@ int main(int argc, char **argv)
ret = program_load(argv[optind], !strcmp(storage, "nand"));
if (ret < 0)
errx(1, "program_load %s failed", argv[optind]);

if (!allow_fusing && program_is_sec_partition_flashed())
errx(1, "secdata partition to be programmed, which can lead to irreversible"
" changes. Allow explicitly with --allow-fusing parameter");
break;
case QDL_FILE_READ:
ret = read_op_load(argv[optind]);
Expand Down