Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 171e4bd8 authored by Matt Mower's avatar Matt Mower Committed by Ethan Chen
Browse files

Fixup custom bootloader msg offset in block misc

Globally define BOARD_RECOVERY_BLDRMSG_OFFSET with a decimal integer
to offset the read/write location in misc where the bootloader message
should appear. Example:

  BOARD_GLOBAL_CFLAGS := -DBOARD_RECOVERY_BLDRMSG_OFFSET=2048

Edify commands get_stage and set_stage need to be aware of the
custom bootloader msg offset because they write the stage directly
to the BCB.

Change-Id: I6f3de1c2e3745c5535c3b95399abb8b2e2d01446
parent 1a296fef
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -144,10 +144,6 @@ ifeq ($(BOARD_HAS_DOWNLOAD_MODE), true)
    LOCAL_CFLAGS += -DDOWNLOAD_MODE
endif

ifneq ($(BOARD_RECOVERY_BLDRMSG_OFFSET),)
    LOCAL_CFLAGS += -DBOARD_RECOVERY_BLDRMSG_OFFSET=$(BOARD_RECOVERY_BLDRMSG_OFFSET)
endif

ifeq ($(TARGET_BUILD_VARIANT),user)
    LOCAL_CFLAGS += -DRELEASE_BUILD
endif
+4 −1
Original line number Diff line number Diff line
@@ -113,7 +113,10 @@ static bool write_misc_partition(const void* p, size_t size, size_t offset, std:
  if (misc_blk_device.empty()) {
    return false;
  }
  android::base::unique_fd fd(open(misc_blk_device.c_str(), O_WRONLY | O_SYNC));
  int open_flags = O_WRONLY | O_SYNC;
  if (offset > 0)
    open_flags = O_RDWR | O_APPEND | O_SYNC;
  android::base::unique_fd fd(open(misc_blk_device.c_str(), open_flags));
  if (fd.get() == -1) {
    *err = android::base::StringPrintf("failed to open %s: %s", misc_blk_device.c_str(),
                                       strerror(errno));
+5 −0
Original line number Diff line number Diff line
@@ -25,8 +25,13 @@
// 16K - 64K    Used by uncrypt and recovery to store wipe_package for A/B devices
// Note that these offsets are admitted by bootloader,recovery and uncrypt, so they
// are not configurable without changing all of them.
#ifdef BOARD_RECOVERY_BLDRMSG_OFFSET
static const size_t BOOTLOADER_MESSAGE_OFFSET_IN_MISC = BOARD_RECOVERY_BLDRMSG_OFFSET;
static const size_t WIPE_PACKAGE_OFFSET_IN_MISC = 16 * 1024 + BOOTLOADER_MESSAGE_OFFSET_IN_MISC;
#else
static const size_t BOOTLOADER_MESSAGE_OFFSET_IN_MISC = 0;
static const size_t WIPE_PACKAGE_OFFSET_IN_MISC = 16 * 1024;
#endif

/* Bootloader Message
 *
+0 −4
Original line number Diff line number Diff line
@@ -49,10 +49,6 @@ LOCAL_STATIC_LIBRARIES += \
LOCAL_C_INCLUDES += external/e2fsprogs/lib
LOCAL_STATIC_LIBRARIES += libext2_blkid libext2_uuid

ifneq ($(BOARD_RECOVERY_BLDRMSG_OFFSET),)
    LOCAL_CFLAGS += -DBOARD_RECOVERY_BLDRMSG_OFFSET=$(BOARD_RECOVERY_BLDRMSG_OFFSET)
endif

ifeq ($(BOARD_SUPPRESS_EMMC_WIPE),true)
    LOCAL_CFLAGS += -DSUPPRESS_EMMC_WIPE
endif
+3 −9
Original line number Diff line number Diff line
@@ -1527,9 +1527,7 @@ Value* RebootNowFn(const char* name, State* state, int argc, Expr* argv[]) {
    memset(buffer, 0, sizeof(((struct bootloader_message*)0)->command));
    FILE* f = fopen(filename, "r+b");
    fseek(f, offsetof(struct bootloader_message, command), SEEK_SET);
#ifdef BOARD_RECOVERY_BLDRMSG_OFFSET
    fseek(f, BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_CUR);
#endif
    fseek(f, BOOTLOADER_MESSAGE_OFFSET_IN_MISC, SEEK_CUR);
    ota_fwrite(buffer, sizeof(((struct bootloader_message*)0)->command), 1, f);
    fclose(f);
    free(filename);
@@ -1577,9 +1575,7 @@ Value* SetStageFn(const char* name, State* state, int argc, Expr* argv[]) {
    // package installation.
    FILE* f = fopen(filename, "r+b");
    fseek(f, offsetof(struct bootloader_message, stage), SEEK_SET);
#ifdef BOARD_RECOVERY_BLDRMSG_OFFSET
    fseek(f, BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_CUR);
#endif
    fseek(f, BOOTLOADER_MESSAGE_OFFSET_IN_MISC, SEEK_CUR);
    int to_write = strlen(stagestr)+1;
    int max_size = sizeof(((struct bootloader_message*)0)->stage);
    if (to_write > max_size) {
@@ -1606,9 +1602,7 @@ Value* GetStageFn(const char* name, State* state, int argc, Expr* argv[]) {
    char buffer[sizeof(((struct bootloader_message*)0)->stage)];
    FILE* f = fopen(filename, "rb");
    fseek(f, offsetof(struct bootloader_message, stage), SEEK_SET);
#ifdef BOARD_RECOVERY_BLDRMSG_OFFSET
    fseek(f, BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_CUR);
#endif
    fseek(f, BOOTLOADER_MESSAGE_OFFSET_IN_MISC, SEEK_CUR);
    ota_fread(buffer, sizeof(buffer), 1, f);
    fclose(f);
    buffer[sizeof(buffer)-1] = '\0';