diff options
author | Doug Zongker <dougz@android.com> | 2010-08-13 00:35:29 +0200 |
---|---|---|
committer | Doug Zongker <dougz@android.com> | 2010-08-13 00:35:29 +0200 |
commit | 04611da55b13f9697173d3aa947b3a735b96c01f (patch) | |
tree | a5340df3e931f5fc9bb7d53d092d8327de045ca0 /bootloader.c | |
parent | Working ASLR implementation (diff) | |
download | android_bootable_recovery-04611da55b13f9697173d3aa947b3a735b96c01f.tar android_bootable_recovery-04611da55b13f9697173d3aa947b3a735b96c01f.tar.gz android_bootable_recovery-04611da55b13f9697173d3aa947b3a735b96c01f.tar.bz2 android_bootable_recovery-04611da55b13f9697173d3aa947b3a735b96c01f.tar.lz android_bootable_recovery-04611da55b13f9697173d3aa947b3a735b96c01f.tar.xz android_bootable_recovery-04611da55b13f9697173d3aa947b3a735b96c01f.tar.zst android_bootable_recovery-04611da55b13f9697173d3aa947b3a735b96c01f.zip |
Diffstat (limited to '')
-rw-r--r-- | bootloader.c | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/bootloader.c b/bootloader.c index 38b5651bf..1e66c3e26 100644 --- a/bootloader.c +++ b/bootloader.c @@ -25,8 +25,6 @@ static const char *CACHE_NAME = "CACHE:"; static const char *MISC_NAME = "MISC:"; -static const int MISC_PAGES = 3; // number of pages to save -static const int MISC_COMMAND_PAGE = 1; // bootloader command is this page #ifdef LOG_VERBOSE static void dump_data(const char *data, int len) { @@ -41,6 +39,57 @@ static void dump_data(const char *data, int len) { } #endif +#ifdef USE_EXT4 +// Strictly speaking this doesn't have anything to do with ext4; we +// really just mean "misc is an emmc partition". We should have a +// more configurable way have describing partitions, filesystems, etc. + +static const char* MISC_PARTITION = + "/dev/block/platform/sdhci-tegra.3/by-name/misc"; + +int get_bootloader_message(struct bootloader_message* out) { + FILE* f = fopen(MISC_PARTITION, "rb"); + if (f == NULL) { + LOGE("Can't open %s\n(%s)\n", MISC_PARTITION, strerror(errno)); + return -1; + } + struct bootloader_message temp; + int count = fread(&temp, sizeof(temp), 1, f); + if (count != 1) { + LOGE("Failed reading %s\n(%s)\n", MISC_PARTITION, strerror(errno)); + return -1; + } + if (fclose(f) != 0) { + LOGE("Failed closing %s\n(%s)\n", MISC_PARTITION, strerror(errno)); + return -1; + } + memcpy(out, &temp, sizeof(temp)); + return 0; +} + +int set_bootloader_message(const struct bootloader_message* in) { + FILE* f = fopen(MISC_PARTITION, "wb"); + if (f == NULL) { + LOGE("Can't open %s\n(%s)\n", MISC_PARTITION, strerror(errno)); + return -1; + } + int count = fwrite(in, sizeof(*in), 1, f); + if (count != 1) { + LOGE("Failed writing %s\n(%s)\n", MISC_PARTITION, strerror(errno)); + return -1; + } + if (fclose(f) != 0) { + LOGE("Failed closing %s\n(%s)\n", MISC_PARTITION, strerror(errno)); + return -1; + } + return 0; +} + +#else // MTD partitions + +static const int MISC_PAGES = 3; // number of pages to save +static const int MISC_COMMAND_PAGE = 1; // bootloader command is this page + int get_bootloader_message(struct bootloader_message *out) { size_t write_size; const MtdPartition *part = get_root_mtd_partition(MISC_NAME); @@ -119,3 +168,5 @@ int set_bootloader_message(const struct bootloader_message *in) { LOGI("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : ""); return 0; } + +#endif |