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

Commit 29759e9d authored by Bill Yi's avatar Bill Yi
Browse files

Merge commit '25c2b2f6' into HEAD

parents 558f2700 25c2b2f6
Loading
Loading
Loading
Loading
+3 −15
Original line number Diff line number Diff line
@@ -424,20 +424,18 @@ int WriteToPartition(unsigned char* data, size_t len,
        {
            size_t start = 0;
            int success = 0;
            int fd = open(partition, O_RDWR | O_SYNC);
            int fd = open(partition, O_RDWR);
            if (fd < 0) {
                printf("failed to open %s: %s\n", partition, strerror(errno));
                return -1;
            }
            int attempt;

            for (attempt = 0; attempt < 10; ++attempt) {
                size_t next_sync = start + (1<<20);
                printf("raw O_SYNC write %s attempt %d start at %d\n", partition, attempt+1, start);
            for (attempt = 0; attempt < 2; ++attempt) {
                lseek(fd, start, SEEK_SET);
                while (start < len) {
                    size_t to_write = len - start;
                    if (to_write > 4096) to_write = 4096;
                    if (to_write > 1<<20) to_write = 1<<20;

                    ssize_t written = write(fd, data+start, to_write);
                    if (written < 0) {
@@ -450,10 +448,6 @@ int WriteToPartition(unsigned char* data, size_t len,
                        }
                    }
                    start += written;
                    if (start >= next_sync) {
                        fsync(fd);
                        next_sync = start + (1<<20);
                    }
                }
                fsync(fd);

@@ -506,8 +500,6 @@ int WriteToPartition(unsigned char* data, size_t len,
                    success = true;
                    break;
                }

                sleep(2);
            }

            if (!success) {
@@ -519,11 +511,7 @@ int WriteToPartition(unsigned char* data, size_t len,
                printf("error closing %s (%s)\n", partition, strerror(errno));
                return -1;
            }
            // hack: sync and sleep after closing in hopes of getting
            // the data actually onto flash.
            printf("sleeping after close\n");
            sync();
            sleep(5);
            break;
        }
    }
+14 −1
Original line number Diff line number Diff line
@@ -38,11 +38,24 @@ extern "C" {
 * The recovery field is only written by linux and used
 * for the system to send a message to recovery or the
 * other way around.
 *
 * The stage field is written by packages which restart themselves
 * multiple times, so that the UI can reflect which invocation of the
 * package it is.  If the value is of the format "#/#" (eg, "1/3"),
 * the UI will add a simple indicator of that status.
 */
struct bootloader_message {
    char command[32];
    char status[32];
    char recovery[1024];
    char recovery[768];

    // The 'recovery' field used to be 1024 bytes.  It has only ever
    // been used to store the recovery command line, so 768 bytes
    // should be plenty.  We carve off the last 256 bytes to store the
    // stage string (for multistage packages) and possible future
    // expansion.
    char stage[32];
    char reserved[224];
};

/* Read and write the bootloader command from the "misc" partition.
+18 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ static const struct option OPTIONS[] = {
  { "show_text", no_argument, NULL, 't' },
  { "just_exit", no_argument, NULL, 'x' },
  { "locale", required_argument, NULL, 'l' },
  { "stages", required_argument, NULL, 'g' },
  { "shutdown_after", no_argument, NULL, 'p' },
  { NULL, 0, NULL, 0 },
};
@@ -77,6 +78,7 @@ static const char *SIDELOAD_TEMP_DIR = "/tmp/sideload";
RecoveryUI* ui = NULL;
char* locale = NULL;
char recovery_version[PROPERTY_VALUE_MAX+1];
char* stage = NULL;

/*
 * The recovery tool communicates with the main system through /cache files.
@@ -173,6 +175,7 @@ get_args(int *argc, char ***argv) {
    struct bootloader_message boot;
    memset(&boot, 0, sizeof(boot));
    get_bootloader_message(&boot);  // this may fail, leaving a zeroed structure
    stage = strndup(boot.stage, sizeof(boot.stage));

    if (boot.command[0] != 0 && boot.command[0] != 255) {
        LOGI("Boot command: %.*s\n", (int)sizeof(boot.command), boot.command);
@@ -959,6 +962,14 @@ main(int argc, char **argv) {
        case 't': show_text = 1; break;
        case 'x': just_exit = true; break;
        case 'l': locale = optarg; break;
        case 'g': {
            if (stage == NULL || *stage == '\0') {
                char buffer[20] = "1/";
                strncat(buffer, optarg, sizeof(buffer)-3);
                stage = strdup(buffer);
            }
            break;
        }
        case 'p': shutdown_after = true; break;
        case '?':
            LOGE("Invalid command argument\n");
@@ -970,6 +981,7 @@ main(int argc, char **argv) {
        load_locale_from_cache();
    }
    printf("locale is [%s]\n", locale);
    printf("stage is [%s]\n", stage, stage);

    Device* device = make_device();
    ui = device->GetUI();
@@ -977,6 +989,12 @@ main(int argc, char **argv) {

    ui->SetLocale(locale);
    ui->Init();

    int st_cur, st_max;
    if (stage != NULL && sscanf(stage, "%d/%d", &st_cur, &st_max) == 2) {
        ui->SetStage(st_cur, st_max);
    }

    ui->SetBackground(RecoveryUI::NONE);
    if (show_text) ui->ShowText(true);

+322 B
Loading image diff...
+258 B
Loading image diff...
Loading