summaryrefslogtreecommitdiffstats
path: root/bootloader.cpp
diff options
context:
space:
mode:
authorDees_Troy <dees_troy@teamw.in>2013-04-02 22:22:16 +0200
committerDees_Troy <dees_troy@teamw.in>2013-04-04 20:57:34 +0200
commit2673cec07a4740f86438b50cfe1b70b258a9a8c8 (patch)
tree3133d98e33eba4fab9760f9a4a54aeac83107119 /bootloader.cpp
parentAdd partition list GUI element (diff)
downloadandroid_bootable_recovery-2673cec07a4740f86438b50cfe1b70b258a9a8c8.tar
android_bootable_recovery-2673cec07a4740f86438b50cfe1b70b258a9a8c8.tar.gz
android_bootable_recovery-2673cec07a4740f86438b50cfe1b70b258a9a8c8.tar.bz2
android_bootable_recovery-2673cec07a4740f86438b50cfe1b70b258a9a8c8.tar.lz
android_bootable_recovery-2673cec07a4740f86438b50cfe1b70b258a9a8c8.tar.xz
android_bootable_recovery-2673cec07a4740f86438b50cfe1b70b258a9a8c8.tar.zst
android_bootable_recovery-2673cec07a4740f86438b50cfe1b70b258a9a8c8.zip
Diffstat (limited to 'bootloader.cpp')
-rw-r--r--bootloader.cpp67
1 files changed, 65 insertions, 2 deletions
diff --git a/bootloader.cpp b/bootloader.cpp
index 6f4f83abf..6b42b947a 100644
--- a/bootloader.cpp
+++ b/bootloader.cpp
@@ -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;
+}