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

Commit 61fc1954 authored by Andres Morales's avatar Andres Morales
Browse files

mkbootimg: make mkbootimg print image cksum to stdout

used by the build system as a fingerprint for the image

Change-Id: Ifaf230b881e68d921a8158ed2e8a3ee41f27a4b3
parent f85f1116
Loading
Loading
Loading
Loading
+54 −34
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdbool.h>

#include "mincrypt/sha.h"
#include "bootimg.h"
@@ -65,6 +66,7 @@ int usage(void)
            "       [ --board <boardname> ]\n"
            "       [ --base <address> ]\n"
            "       [ --pagesize <pagesize> ]\n"
            "       [ --id ]\n"
            "       -o|--output <filename>\n"
            );
    return 1;
@@ -74,6 +76,14 @@ int usage(void)

static unsigned char padding[16384] = { 0, };

static void print_id(const uint8_t *id, size_t id_len) {
    printf("0x");
    for (unsigned i = 0; i < id_len; i++) {
        printf("%02x", id[i]);
    }
    printf("\n");
}

int write_padding(int fd, unsigned pagesize, unsigned itemsize)
{
    unsigned pagemask = pagesize - 1;
@@ -121,12 +131,15 @@ int main(int argc, char **argv)

    memset(&hdr, 0, sizeof(hdr));

    bool get_id = false;
    while(argc > 0){
        char *arg = argv[0];
        if (!strcmp(arg, "--id")) {
            get_id = true;
            argc -= 1;
            argv += 1;
        } else if(argc >= 2) {
            char *val = argv[1];
        if(argc < 2) {
            return usage();
        }
            argc -= 2;
            argv += 2;
            if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) {
@@ -161,6 +174,9 @@ int main(int argc, char **argv)
            } else {
                return usage();
            }
        } else {
            return usage();
        }
    }
    hdr.page_size = pagesize;

@@ -266,6 +282,10 @@ int main(int argc, char **argv)
        if(write_padding(fd, pagesize, hdr.second_size)) goto fail;
    }

    if (get_id) {
        print_id(sha, sizeof(hdr.id));
    }

    return 0;

fail: