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

Commit 59fbceda authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "trusty: apploader: Log errors to logcat" am: 817f8971 am: e23f80b7 am: 6f3e556a

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1660506

Change-Id: I77e127b41926408bcfeb023c0e35fc28b92b1f1e
parents 90d7719e 6f3e556a
Loading
Loading
Loading
Loading
+19 −19
Original line number Original line Diff line number Diff line
@@ -96,13 +96,13 @@ static unique_fd read_file(const char* file_name, off64_t* out_file_size) {


    unique_fd file_fd(TEMP_FAILURE_RETRY(open(file_name, O_RDONLY)));
    unique_fd file_fd(TEMP_FAILURE_RETRY(open(file_name, O_RDONLY)));
    if (!file_fd.ok()) {
    if (!file_fd.ok()) {
        fprintf(stderr, "Error opening file '%s': %s\n", file_name, strerror(errno));
        PLOG(ERROR) << "Error opening file " << file_name;
        return {};
        return {};
    }
    }


    rc = fstat64(file_fd, &st);
    rc = fstat64(file_fd, &st);
    if (rc < 0) {
    if (rc < 0) {
        fprintf(stderr, "Error calling stat on file '%s': %s\n", file_name, strerror(errno));
        PLOG(ERROR) << "Error calling stat on file '" << file_name << "'";
        return {};
        return {};
    }
    }


@@ -115,14 +115,14 @@ static unique_fd read_file(const char* file_name, off64_t* out_file_size) {
        file_page_offset = page_size - file_page_offset;
        file_page_offset = page_size - file_page_offset;
    }
    }
    if (__builtin_add_overflow(file_size, file_page_offset, &file_page_size)) {
    if (__builtin_add_overflow(file_size, file_page_offset, &file_page_size)) {
        fprintf(stderr, "Failed to page-align file size\n");
        LOG(ERROR) << "Failed to page-align file size";
        return {};
        return {};
    }
    }


    BufferAllocator alloc;
    BufferAllocator alloc;
    unique_fd dmabuf_fd(alloc.Alloc(kDmabufSystemHeapName, file_page_size));
    unique_fd dmabuf_fd(alloc.Alloc(kDmabufSystemHeapName, file_page_size));
    if (!dmabuf_fd.ok()) {
    if (!dmabuf_fd.ok()) {
        fprintf(stderr, "Error creating dmabuf: %d\n", dmabuf_fd.get());
        LOG(ERROR) << "Error creating dmabuf: " << dmabuf_fd.get();
        return dmabuf_fd;
        return dmabuf_fd;
    }
    }


@@ -137,12 +137,12 @@ static unique_fd read_file(const char* file_name, off64_t* out_file_size) {
                pread(file_fd, (char*)shm + file_offset, file_size - file_offset, file_offset));
                pread(file_fd, (char*)shm + file_offset, file_size - file_offset, file_offset));


        if (num_read < 0) {
        if (num_read < 0) {
            fprintf(stderr, "Error reading package file '%s': %s\n", file_name, strerror(errno));
            PLOG(ERROR) << "Error reading package file '" << file_name << "'";
            break;
            break;
        }
        }


        if (num_read == 0) {
        if (num_read == 0) {
            fprintf(stderr, "Unexpected end of file '%s'\n", file_name);
            LOG(ERROR) << "Unexpected end of file '" << file_name << "'";
            break;
            break;
        }
        }


@@ -182,17 +182,17 @@ static ssize_t read_response(int tipc_fd) {
    struct apploader_resp resp;
    struct apploader_resp resp;
    ssize_t rc = read(tipc_fd, &resp, sizeof(resp));
    ssize_t rc = read(tipc_fd, &resp, sizeof(resp));
    if (rc < 0) {
    if (rc < 0) {
        fprintf(stderr, "Failed to read response: %zd\n", rc);
        PLOG(ERROR) << "Failed to read response";
        return rc;
        return rc;
    }
    }


    if (rc < sizeof(resp)) {
    if (rc < sizeof(resp)) {
        fprintf(stderr, "Not enough data in response: %zd\n", rc);
        LOG(ERROR) << "Not enough data in response: " << rc;
        return -EIO;
        return -EIO;
    }
    }


    if (resp.hdr.cmd != (APPLOADER_CMD_LOAD_APPLICATION | APPLOADER_RESP_BIT)) {
    if (resp.hdr.cmd != (APPLOADER_CMD_LOAD_APPLICATION | APPLOADER_RESP_BIT)) {
        fprintf(stderr, "Invalid command in response: %u\n", resp.hdr.cmd);
        LOG(ERROR) << "Invalid command in response: " << resp.hdr.cmd;
        return -EINVAL;
        return -EINVAL;
    }
    }


@@ -200,28 +200,28 @@ static ssize_t read_response(int tipc_fd) {
        case APPLOADER_NO_ERROR:
        case APPLOADER_NO_ERROR:
            break;
            break;
        case APPLOADER_ERR_UNKNOWN_CMD:
        case APPLOADER_ERR_UNKNOWN_CMD:
            fprintf(stderr, "Error: unknown command\n");
            LOG(ERROR) << "Error: unknown command";
            break;
            break;
        case APPLOADER_ERR_INVALID_CMD:
        case APPLOADER_ERR_INVALID_CMD:
            fprintf(stderr, "Error: invalid command arguments\n");
            LOG(ERROR) << "Error: invalid command arguments";
            break;
            break;
        case APPLOADER_ERR_NO_MEMORY:
        case APPLOADER_ERR_NO_MEMORY:
            fprintf(stderr, "Error: out of Trusty memory\n");
            LOG(ERROR) << "Error: out of Trusty memory";
            break;
            break;
        case APPLOADER_ERR_VERIFICATION_FAILED:
        case APPLOADER_ERR_VERIFICATION_FAILED:
            fprintf(stderr, "Error: failed to verify the package\n");
            LOG(ERROR) << "Error: failed to verify the package";
            break;
            break;
        case APPLOADER_ERR_LOADING_FAILED:
        case APPLOADER_ERR_LOADING_FAILED:
            fprintf(stderr, "Error: failed to load the package\n");
            LOG(ERROR) << "Error: failed to load the package";
            break;
            break;
        case APPLOADER_ERR_ALREADY_EXISTS:
        case APPLOADER_ERR_ALREADY_EXISTS:
            fprintf(stderr, "Error: application already exists\n");
            LOG(ERROR) << "Error: application already exists";
            break;
            break;
        case APPLOADER_ERR_INTERNAL:
        case APPLOADER_ERR_INTERNAL:
            fprintf(stderr, "Error: internal apploader error\n");
            LOG(ERROR) << "Error: internal apploader error";
            break;
            break;
        default:
        default:
            fprintf(stderr, "Unrecognized error: %u\n", resp.error);
            LOG(ERROR) << "Unrecognized error: " << resp.error;
            break;
            break;
    }
    }


@@ -241,14 +241,14 @@ static ssize_t send_app_package(const char* package_file_name) {


    tipc_fd = tipc_connect(dev_name, APPLOADER_PORT);
    tipc_fd = tipc_connect(dev_name, APPLOADER_PORT);
    if (tipc_fd < 0) {
    if (tipc_fd < 0) {
        fprintf(stderr, "Failed to connect to Trusty app loader: %s\n", strerror(-tipc_fd));
        LOG(ERROR) << "Failed to connect to Trusty app loader: " << strerror(-tipc_fd);
        rc = tipc_fd;
        rc = tipc_fd;
        goto err_tipc_connect;
        goto err_tipc_connect;
    }
    }


    rc = send_load_message(tipc_fd, package_fd, package_size);
    rc = send_load_message(tipc_fd, package_fd, package_size);
    if (rc < 0) {
    if (rc < 0) {
        fprintf(stderr, "Failed to send package: %zd\n", rc);
        LOG(ERROR) << "Failed to send package: " << rc;
        goto err_send;
        goto err_send;
    }
    }