Skip to content

Commit c856721

Browse files
authored
Merge pull request #103 from igoropaniuk/allow_fusing
qdl: introduce allow-fusing parameter
2 parents 0b6b9e3 + 328e069 commit c856721

File tree

3 files changed

+65
-12
lines changed

3 files changed

+65
-12
lines changed

program.c

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,23 @@ int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s
221221
return 0;
222222
}
223223

224+
static struct program *program_find_partition(const char *partition)
225+
{
226+
struct program *program;
227+
const char *label;
228+
229+
for (program = programes; program; program = program->next) {
230+
label = program->label;
231+
if (!label)
232+
continue;
233+
234+
if (!strcmp(label, partition))
235+
return program;
236+
}
237+
238+
return NULL;
239+
}
240+
224241
/**
225242
* program_find_bootable_partition() - find one bootable partition
226243
*
@@ -234,30 +251,54 @@ int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s
234251
int program_find_bootable_partition(bool *multiple_found)
235252
{
236253
struct program *program;
237-
const char *label;
238254
int part = -ENOENT;
239255

240256
*multiple_found = false;
241257

242-
for (program = programes; program; program = program->next) {
243-
label = program->label;
244-
if (!label)
245-
continue;
258+
program = program_find_partition("xbl");
259+
if (program)
260+
part = program->partition;
246261

247-
if (!strcmp(label, "xbl") || !strcmp(label, "xbl_a") ||
248-
!strcmp(label, "sbl1")) {
249-
if (part != -ENOENT) {
250-
*multiple_found = true;
251-
continue;
252-
}
262+
program = program_find_partition("xbl_a");
263+
if (program) {
264+
if (part != -ENOENT)
265+
*multiple_found = true;
266+
else
267+
part = program->partition;
268+
}
253269

270+
program = program_find_partition("sbl1");
271+
if (program) {
272+
if (part != -ENOENT)
273+
*multiple_found = true;
274+
else
254275
part = program->partition;
255-
}
256276
}
257277

258278
return part;
259279
}
260280

281+
/**
282+
* program_is_sec_partition_flashed() - find if secdata partition is flashed
283+
*
284+
* Returns true if filename for secdata is set in program*.xml,
285+
* or false otherwise.
286+
*/
287+
int program_is_sec_partition_flashed(void)
288+
{
289+
struct program *program;
290+
291+
program = program_find_partition("secdata");
292+
if (!program)
293+
return false;
294+
295+
if (program->filename)
296+
return true;
297+
298+
return false;
299+
}
300+
301+
261302
void free_programs(void)
262303
{
263304
struct program *program = programes;

program.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ int program_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl,
2626
const char *incdir, bool allow_missing);
2727
int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program));
2828
int program_find_bootable_partition(bool *multiple_found);
29+
int program_is_sec_partition_flashed(void);
30+
2931
void free_programs(void);
3032

3133
#endif

qdl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include "qdl.h"
4242
#include "patch.h"
43+
#include "program.h"
4344
#include "ufs.h"
4445
#include "oscompat.h"
4546

@@ -124,6 +125,7 @@ int main(int argc, char **argv)
124125
int ret;
125126
int opt;
126127
bool qdl_finalize_provisioning = false;
128+
bool allow_fusing = false;
127129
bool allow_missing = false;
128130
long out_chunk_size;
129131

@@ -136,6 +138,7 @@ int main(int argc, char **argv)
136138
{"serial", required_argument, 0, 'S'},
137139
{"storage", required_argument, 0, 's'},
138140
{"allow-missing", no_argument, 0, 'f'},
141+
{"allow-fusing", no_argument, 0, 'c'},
139142
{0, 0, 0, 0}
140143
};
141144

@@ -156,6 +159,9 @@ int main(int argc, char **argv)
156159
case 'l':
157160
qdl_finalize_provisioning = true;
158161
break;
162+
case 'c':
163+
allow_fusing = true;
164+
break;
159165
case OPT_OUT_CHUNK_SIZE:
160166
out_chunk_size = strtol(optarg, NULL, 10);
161167
qdl_set_out_chunk_size(&qdl, out_chunk_size);
@@ -200,6 +206,10 @@ int main(int argc, char **argv)
200206
ret = program_load(argv[optind], !strcmp(storage, "nand"));
201207
if (ret < 0)
202208
errx(1, "program_load %s failed", argv[optind]);
209+
210+
if (!allow_fusing && program_is_sec_partition_flashed())
211+
errx(1, "secdata partition to be programmed, which can lead to irreversible"
212+
" changes. Allow explicitly with --allow-fusing parameter");
203213
break;
204214
case QDL_FILE_READ:
205215
ret = read_op_load(argv[optind]);

0 commit comments

Comments
 (0)