Move all AOSP code out of recovery binary

Improves license compatibility between GPL and Apache

Change-Id: I2b165aa575bb6213af6b07936f99610c113443f0
This commit is contained in:
Dees_Troy
2013-04-02 20:22:16 +00:00
parent a13d74fc95
commit 2673cec07a
59 changed files with 1480 additions and 1192 deletions
+65 -2
View File
@@ -33,7 +33,7 @@ static int get_bootloader_message_block(struct bootloader_message *out, const Vo
static int set_bootloader_message_block(const struct bootloader_message *in, const Volume* v);
int get_bootloader_message(struct bootloader_message *out) {
Volume* v = volume_for_path("/misc");
Volume* v = NULL;//volume_for_path("/misc");
if (v == NULL) {
LOGE("Cannot load volume /misc!\n");
return -1;
@@ -48,7 +48,7 @@ int get_bootloader_message(struct bootloader_message *out) {
}
int set_bootloader_message(const struct bootloader_message *in) {
Volume* v = volume_for_path("/misc");
Volume* v = NULL;//volume_for_path("/misc");
if (v == NULL) {
LOGE("Cannot load volume /misc!\n");
return -1;
@@ -139,6 +139,49 @@ static int set_bootloader_message_mtd(const struct bootloader_message *in,
return 0;
}
int set_bootloader_message_mtd_name(const struct bootloader_message *in,
const char* mtd_name) {
size_t write_size;
mtd_scan_partitions();
const MtdPartition *part = mtd_find_partition_by_name(mtd_name);
if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) {
printf("Can't find %s\n", mtd_name);
return -1;
}
MtdReadContext *read = mtd_read_partition(part);
if (read == NULL) {
printf("Can't open %s\n(%s)\n", mtd_name, strerror(errno));
return -1;
}
ssize_t size = write_size * MISC_PAGES;
char data[size];
ssize_t r = mtd_read_data(read, data, size);
if (r != size) printf("Can't read %s\n(%s)\n", mtd_name, strerror(errno));
mtd_read_close(read);
if (r != size) return -1;
memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in));
MtdWriteContext *write = mtd_write_partition(part);
if (write == NULL) {
printf("Can't open %s\n(%s)\n", mtd_name, strerror(errno));
return -1;
}
if (mtd_write_data(write, data, size) != size) {
printf("Can't write %s\n(%s)\n", mtd_name, strerror(errno));
mtd_write_close(write);
return -1;
}
if (mtd_write_close(write)) {
printf("Can't finish %s\n(%s)\n", mtd_name, strerror(errno));
return -1;
}
printf("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : "");
return 0;
}
// ------------------------------------
// for misc partitions on block devices
@@ -202,3 +245,23 @@ static int set_bootloader_message_block(const struct bootloader_message *in,
}
return 0;
}
int set_bootloader_message_block_name(const struct bootloader_message *in,
const char* block_name) {
wait_for_device(block_name);
FILE* f = fopen(block_name, "wb");
if (f == NULL) {
printf("Can't open %s\n(%s)\n", block_name, strerror(errno));
return -1;
}
int count = fwrite(in, sizeof(*in), 1, f);
if (count != 1) {
printf("Failed writing %s\n(%s)\n", block_name, strerror(errno));
return -1;
}
if (fclose(f) != 0) {
printf("Failed closing %s\n(%s)\n", block_name, strerror(errno));
return -1;
}
return 0;
}