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

Commit 26321284 authored by Colin Cross's avatar Colin Cross Committed by Android Git Automerger
Browse files

am 02ac0bfd: Merge changes...

am 02ac0bfd: Merge changes I28ce0288,I86482e16,Ib957fae8,I1a27459b,I3e9c53c3,I91082f58,I395e5361,I6a01ff6f,I0ca31094,I56408690,Ieabdcb1c,Ib9b21771,I10927f48,I49ba2ba2

* commit '02ac0bfd':
  Fix fastbootd's <linux/kexec.h> reference.
  Fastbootd: Comments and general cleaning
  Fastbootd: General fixes and changes
  Revert "Revert "Fastbootd: flashing certification""
  Fastbootd: auto ssh server start
  Fastbootd: network auto discovery
  Fastbootd: socket and network transport
  Fastbootd: build breakage fix
  Revert "Fastbootd: flashing certification"
  Fastbootd: flashing certification
  Fastbootd: improved operations on gpt
  Remove a homebrew mmap64.
  Fastbootd: fixed missing file in Android.mk
  fastbootd: erase, boot and partitioning commands
parents 0ddf436e 02ac0bfd
Loading
Loading
Loading
Loading
+68 −2
Original line number Diff line number Diff line
@@ -16,23 +16,89 @@ LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := \
    external/openssl/include \
    external/mdnsresponder/mDNSShared \
    $(LOCAL_PATH)/include \
    external/zlib/ \

LOCAL_SRC_FILES := \
    config.c \
    commands.c \
    commands/boot.c \
    commands/flash.c \
    commands/partitions.c \
    commands/virtual_partitions.c \
    fastbootd.c \
    protocol.c \
    network_discovery.c \
    socket_client.c \
    secure.c \
    transport.c \
    usb_linux_client.c
    transport_socket.c \
    trigger.c \
    usb_linux_client.c \
    utils.c \

LOCAL_MODULE := fastbootd
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter -DFLASH_CERT
LOCAL_LDFLAGS := -ldl

LOCAL_SHARED_LIBRARIES := \
    libhardware \
    libcrypto \
    libhardware_legacy \
    libmdnssd

LOCAL_STATIC_LIBRARIES := \
    libsparse_static \
    libc \
    libcutils \
    libz

#LOCAL_FORCE_STATIC_EXECUTABLE := true

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES := \
    external/zlib/

LOCAL_SRC_FILES := \
    commands/partitions.c \
    other/gptedit.c \
    utils.c

LOCAL_MODULE := gptedit
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter

LOCAL_STATIC_LIBRARIES := \
    libsparse_static \
    libc \
    libcutils
    libcutils \
    libz

LOCAL_FORCE_STATIC_EXECUTABLE := true

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/include \

LOCAL_STATIC_LIBRARIES := \
    $(EXTRA_STATIC_LIBS) \
    libcutils

LOCAL_SRC_FILES := \
    other/vendor_trigger.c

LOCAL_MODULE := libvendortrigger.default
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter


include $(BUILD_SHARED_LIBRARY)
+250 −48
Original line number Diff line number Diff line
@@ -32,114 +32,304 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <fcntl.h>

#include "bootimg.h"
#include "commands/boot.h"
#include "commands/flash.h"
#include "commands/partitions.h"
#include "commands/virtual_partitions.h"
#include "debug.h"
#include "protocol.h"
#include "trigger.h"
#include "utils.h"

#define ATAGS_LOCATION "/proc/atags"

static void cmd_boot(struct protocol_handle *phandle, const char *arg)
{
#if 0
    int sz, atags_sz, new_atags_sz;
    int rv;
    unsigned kernel_actual;
    unsigned ramdisk_actual;
    static struct boot_img_hdr hdr;
    char *ptr = ((char*) data);
    unsigned second_actual;
    void *kernel_ptr;
    void *ramdisk_ptr;
    void *second_ptr;
    struct boot_img_hdr *hdr;
    char *ptr = NULL;
    char *atags_ptr = NULL;
    char *new_atags = NULL;
    int data_fd = 0;

    D(DEBUG, "cmd_boot %s\n", arg);

    if (sz < sizeof(hdr)) {
        fastboot_fail(phandle, "invalid bootimage header");
    if (phandle->download_fd < 0) {
        fastboot_fail(phandle, "no kernel file");
        return;
    }

    atags_ptr = read_atags(ATAGS_LOCATION, &atags_sz);
    if (atags_ptr == NULL) {
        fastboot_fail(phandle, "atags read error");
        goto error;
    }

    // TODO: With cms we can also verify partition name included as
    // cms signed attribute
    if (flash_validate_certificate(phandle->download_fd, &data_fd) != 1) {
        fastboot_fail(phandle, "Access forbiden you need the certificate");
        return;
    }

    memcpy(&hdr, data, sizeof(hdr));
    sz = get_file_size(data_fd);

    ptr = (char *) mmap(NULL, sz, PROT_READ,
                        MAP_POPULATE | MAP_PRIVATE, data_fd, 0);

    hdr = (struct boot_img_hdr *) ptr;

    if (ptr == MAP_FAILED) {
        fastboot_fail(phandle, "internal fastbootd error");
        goto error;
    }

    if ((size_t) sz < sizeof(*hdr)) {
        fastboot_fail(phandle, "invalid bootimage header");
        goto error;
    }

    kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, hdr->page_size);
    ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, hdr->page_size);
    second_actual = ROUND_TO_PAGE(hdr->second_size, hdr->page_size);

    /* ensure commandline is terminated */
    hdr.cmdline[BOOT_ARGS_SIZE-1] = 0;
    new_atags = (char *) create_atags((unsigned *) atags_ptr, atags_sz, hdr, &new_atags_sz);

    kernel_actual = ROUND_TO_PAGE(hdr.kernel_size);
    ramdisk_actual = ROUND_TO_PAGE(hdr.ramdisk_size);
    if (new_atags == NULL) {
        fastboot_fail(phandle, "atags generate error");
        goto error;
    }
    if (new_atags_sz > 0x4000) {
        fastboot_fail(phandle, "atags file to large");
        goto error;
    }

    if (2048 + kernel_actual + ramdisk_actual < sz) {
    if ((int) (hdr->page_size + kernel_actual + ramdisk_actual) < sz) {
        fastboot_fail(phandle, "incomplete bootimage");
        return;
        goto error;
    }

    /*memmove((void*) KERNEL_ADDR, ptr + 2048, hdr.kernel_size);
    memmove((void*) RAMDISK_ADDR, ptr + 2048 + kernel_actual, hdr.ramdisk_size);*/
    kernel_ptr = (void *)((unsigned) ptr + hdr->page_size);
    ramdisk_ptr = (void *)((unsigned) kernel_ptr + kernel_actual);
    second_ptr = (void *)((unsigned) ramdisk_ptr + ramdisk_actual);

    D(INFO, "preparing to boot");
    // Prepares boot physical address. Addresses from header are ignored
    rv = prepare_boot_linux(hdr->kernel_addr, kernel_ptr, kernel_actual,
                            hdr->ramdisk_addr, ramdisk_ptr, ramdisk_actual,
                            hdr->second_addr, second_ptr, second_actual,
                            hdr->tags_addr, new_atags, ROUND_TO_PAGE(new_atags_sz, hdr->page_size));
    if (rv < 0) {
        fastboot_fail(phandle, "kexec prepare failed");
        goto error;
    }

    fastboot_okay(phandle, "");
    udc_stop();

    free(atags_ptr);
    munmap(ptr, sz);
    free(new_atags);
    close(data_fd);

    D(INFO, "Kexec going to reboot");
    reboot(LINUX_REBOOT_CMD_KEXEC);

    fastboot_fail(phandle, "reboot error");

    return;

error:

    if (atags_ptr != NULL)
        free(atags_ptr);
    if (ptr != NULL)
        munmap(ptr, sz);

    /*boot_linux((void*) KERNEL_ADDR, (void*) TAGS_ADDR,
           (const char*) hdr.cmdline, LINUX_MACHTYPE,
           (void*) RAMDISK_ADDR, hdr.ramdisk_size);*/
#endif
}

static void cmd_erase(struct protocol_handle *phandle, const char *arg)
{
#if 0
    struct ptentry *ptn;
    struct ptable *ptable;
    int partition_fd;
    char path[PATH_MAX];
    D(DEBUG, "cmd_erase %s\n", arg);

    ptable = flash_get_ptable();
    if (ptable == NULL) {
    if (flash_find_entry(arg, path, PATH_MAX)) {
        fastboot_fail(phandle, "partition table doesn't exist");
        return;
    }

    ptn = ptable_find(ptable, arg);
    if (ptn == NULL) {
        fastboot_fail(phandle, "unknown partition name");
    if (path == NULL) {
        fastboot_fail(phandle, "Couldn't find partition");
        return;
    }

    if (flash_erase(ptn)) {
    partition_fd = flash_get_partiton(path);
    if (partition_fd < 0) {
        fastboot_fail(phandle, "partiton file does not exists");
    }

    if (flash_erase(partition_fd)) {
        fastboot_fail(phandle, "failed to erase partition");
        flash_close(partition_fd);
        return;
    }

    if (flash_close(partition_fd) < 0) {
        D(ERR, "could not close device %s", strerror(errno));
        fastboot_fail(phandle, "failed to erase partition");
        return;
    }
    fastboot_okay(phandle, "");
#endif
}

static int GPT_header_location() {
    const char *location_str = fastboot_getvar("gpt_sector");
    char *str;
    int location;

    if (!strcmp("", location_str)) {
        D(INFO, "GPT location not specified using second sector");
        return 1;
    }
    else {
        location = strtoul(location_str, &str, 10);
        D(INFO, "GPT location specified as %d", location);

        if (*str != '\0')
            return -1;

        return location - 1;
    }
}

static void cmd_gpt_layout(struct protocol_handle *phandle, const char *arg) {
    struct GPT_entry_table *oldtable;
    int location;
    struct GPT_content content;
    const char *device;
    device = fastboot_getvar("blockdev");

    if (!strcmp(device, "")) {
        fastboot_fail(phandle, "blockdev not defined in config file");
        return;
    }

    //TODO: add same verification as in cmd_flash
    if (phandle->download_fd < 0) {
        fastboot_fail(phandle, "no layout file");
        return;
    }

    location = GPT_header_location();
    oldtable = GPT_get_device(device, location);

    GPT_default_content(&content, oldtable);
    if (oldtable == NULL)
        D(WARN, "Could not get old gpt table");
    else
        GPT_release_device(oldtable);

    if (!GPT_parse_file(phandle->download_fd, &content)) {
        fastboot_fail(phandle, "Could not parse partition config file");
        return;
    }

    if (trigger_gpt_layout(&content)) {
        fastboot_fail(phandle, "Vendor forbids this opperation");
        GPT_release_content(&content);
        return;
    }

    if (!GPT_write_content(device, &content)) {
        fastboot_fail(phandle, "Unable to write gpt file");
        GPT_release_content(&content);
        return;
    }

    GPT_release_content(&content);
    fastboot_okay(phandle, "");
}

static void cmd_flash(struct protocol_handle *phandle, const char *arg)
{
#if 0
    struct ptentry *ptn;
    struct ptable *ptable;
    unsigned extra = 0;
    int partition;
    uint64_t sz;
    char data[BOOT_MAGIC_SIZE];
    char path[PATH_MAX];
    ssize_t header_sz = 0;
    int data_fd = 0;

    D(DEBUG, "cmd_flash %s\n", arg);

    ptable = flash_get_ptable();
    if (ptable == NULL) {
    if (try_handle_virtual_partition(phandle, arg)) {
        return;
    }

    if (phandle->download_fd < 0) {
        fastboot_fail(phandle, "no kernel file");
        return;
    }

    if (flash_find_entry(arg, path, PATH_MAX)) {
        fastboot_fail(phandle, "partition table doesn't exist");
        return;
    }

    ptn = ptable_find(ptable, arg);
    if (ptn == NULL) {
        fastboot_fail(phandle, "unknown partition name");
    if (flash_validate_certificate(phandle->download_fd, &data_fd) != 1) {
        fastboot_fail(phandle, "Access forbiden you need certificate");
        return;
    }

    if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) {
    // TODO: Maybe its goot idea to check whether the partition is bootable
    if (!strcmp(arg, "boot") || !strcmp(arg, "recovery")) {
        if (read_data_once(data_fd, data, BOOT_MAGIC_SIZE) < BOOT_MAGIC_SIZE) {
            fastboot_fail(phandle, "incoming data read error, cannot read boot header");
            return;
        }
        if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
            fastboot_fail(phandle, "image is not a boot image");
            return;
        }
    }

    if (!strcmp(ptn->name, "system") || !strcmp(ptn->name, "userdata"))
        extra = 64;
    else
        sz = ROUND_TO_PAGE(sz);
    partition = flash_get_partiton(path);

    D(INFO, "writing %d bytes to '%s'\n", sz, ptn->name);
    if (flash_write(ptn, extra, data, sz)) {
    sz = get_file_size64(data_fd);

    sz -= header_sz;

    if (sz > get_file_size64(partition)) {
        flash_close(partition);
        D(WARN, "size of file too large");
        fastboot_fail(phandle, "size of file too large");
        return;
    }

    D(INFO, "writing %lld bytes to '%s'\n", sz, arg);

    if (flash_write(partition, phandle->download_fd, sz, header_sz)) {
        fastboot_fail(phandle, "flash write failure");
        return;
    }
    D(INFO, "partition '%s' updated\n", ptn->name);
#endif
    D(INFO, "partition '%s' updated\n", arg);

    flash_close(partition);
    close(data_fd);

    fastboot_okay(phandle, "");
}

@@ -184,7 +374,6 @@ static void cmd_download(struct protocol_handle *phandle, const char *arg)

    phandle->download_fd = protocol_handle_download(phandle, len);
    if (phandle->download_fd < 0) {
        //handle->state = STATE_ERROR;
        fastboot_fail(phandle, "download failed");
        return;
    }
@@ -192,14 +381,27 @@ static void cmd_download(struct protocol_handle *phandle, const char *arg)
    fastboot_okay(phandle, "");
}

static void cmd_oem(struct protocol_handle *phandle, const char *arg) {
    const char *response = "";

    //TODO: Maybe it should get download descriptor also
    if (trigger_oem_cmd(arg, &response))
        fastboot_fail(phandle, response);
    else
        fastboot_okay(phandle, response);
}

void commands_init()
{
    virtual_partition_register("partition-table", cmd_gpt_layout);

    fastboot_register("boot", cmd_boot);
    fastboot_register("erase:", cmd_erase);
    fastboot_register("flash:", cmd_flash);
    fastboot_register("continue", cmd_continue);
    fastboot_register("getvar:", cmd_getvar);
    fastboot_register("download:", cmd_download);
    fastboot_register("oem", cmd_oem);
    //fastboot_publish("version", "0.5");
    //fastboot_publish("product", "swordfish");
    //fastboot_publish("kernel", "lk");
+254 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2009-2013, Google Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of Google, Inc. nor the names of its contributors
 *    may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/syscall.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>

#include "boot.h"
#include "debug.h"
#include "utils.h"
#include "bootimg.h"


#define KEXEC_ARM_ATAGS_OFFSET  0x1000
#define KEXEC_ARM_ZIMAGE_OFFSET 0x8000

#define MEMORY_SIZE 0x0800000
#define START_ADDRESS 0x44000000
#define KERNEL_START (START_ADDRESS + KEXEC_ARM_ZIMAGE_OFFSET)

#define ATAG_NONE_TYPE      0x00000000
#define ATAG_CORE_TYPE      0x54410001
#define ATAG_RAMDISK_TYPE   0x54410004
#define ATAG_INITRD2_TYPE   0x54420005
#define ATAG_CMDLINE_TYPE   0x54410009

#define MAX_ATAG_SIZE 0x4000

struct atag_info {
    unsigned size;
    unsigned type;
};

struct atag_initrd2 {
    unsigned start;
    unsigned size;
};

struct atag_cmdline {
    char cmdline[0];
};

struct atag {
    struct atag_info info;
    union {
        struct atag_initrd2 initrd2;
        struct atag_cmdline cmdline;
    } data;
};


long kexec_load(unsigned int entry, unsigned long nr_segments,
                struct kexec_segment *segment, unsigned long flags) {
   return syscall(__NR_kexec_load, entry, nr_segments, segment, flags);
}

/*
 * Prepares arguments for kexec
 * Kernel address is not set into kernel_phys
 * Ramdisk is set to position relative to kernel
 */
int prepare_boot_linux(unsigned kernel_phys, void *kernel_addr, int kernel_size,
                       unsigned ramdisk_phys, void *ramdisk_addr, int ramdisk_size,
                       unsigned second_phys, void *second_addr, int second_size,
                       unsigned atags_phys, void *atags_addr, int atags_size) {
    struct kexec_segment segment[4];
    int segment_count = 2;
    unsigned entry = START_ADDRESS + KEXEC_ARM_ZIMAGE_OFFSET;
    int rv;
    int page_size = getpagesize();

    segment[0].buf = kernel_addr;
    segment[0].bufsz = kernel_size;
    segment[0].mem = (void *) KERNEL_START;
    segment[0].memsz = ROUND_TO_PAGE(kernel_size, page_size);

    if (kernel_size > MEMORY_SIZE - KEXEC_ARM_ZIMAGE_OFFSET) {
        D(INFO, "Kernel image too big");
        return -1;
    }

    segment[1].buf = atags_addr;
    segment[1].bufsz = atags_size;
    segment[1].mem = (void *) (START_ADDRESS + KEXEC_ARM_ATAGS_OFFSET);
    segment[1].memsz = ROUND_TO_PAGE(atags_size, page_size);

    D(INFO, "Ramdisk size is %d", ramdisk_size);

    if (ramdisk_size != 0) {
        segment[segment_count].buf = ramdisk_addr;
        segment[segment_count].bufsz = ramdisk_size;
        segment[segment_count].mem = (void *) (KERNEL_START + ramdisk_phys - kernel_phys);
        segment[segment_count].memsz = ROUND_TO_PAGE(ramdisk_phys, page_size);
        ++segment_count;
    }

    D(INFO, "Ramdisk size is %d", ramdisk_size);
    if (second_size != 0) {
        segment[segment_count].buf = second_addr;
        segment[segment_count].bufsz = second_size;
        segment[segment_count].mem = (void *) (KERNEL_START + second_phys - kernel_phys);
        segment[segment_count].memsz = ROUND_TO_PAGE(second_size, page_size);
        entry = second_phys;
        ++segment_count;
    }

    rv = kexec_load(entry, segment_count, segment, KEXEC_ARCH_DEFAULT);

    if (rv != 0) {
        D(INFO, "Kexec_load returned non-zero exit code: %s\n", strerror(errno));
        return -1;
    }

    return 1;

}

unsigned *create_atags(unsigned *atags_position, int atag_size, const struct boot_img_hdr *hdr, int *size) {
    struct atag *current_tag = (struct atag *) atags_position;
    unsigned *current_tag_raw = atags_position;
    unsigned *new_atags = malloc(ROUND_TO_PAGE(atag_size + BOOT_ARGS_SIZE * sizeof(char),
                                               hdr->page_size));
    //This pointer will point into the beggining of buffer free space
    unsigned *natags_raw_buff = new_atags;
    int new_atags_size = 0;
    int current_size;
    int cmdl_length;

    // copy tags from current atag file
    while (current_tag->info.type != ATAG_NONE_TYPE) {
        switch (current_tag->info.type) {
            case ATAG_CMDLINE_TYPE:
            case ATAG_RAMDISK_TYPE:
            case ATAG_INITRD2_TYPE: break;
            default:
                memcpy((void *)natags_raw_buff, (void *)current_tag_raw, current_tag->info.size * sizeof(unsigned));
                natags_raw_buff += current_tag->info.size;
                new_atags_size += current_tag->info.size;
        }

        current_tag_raw += current_tag->info.size;
        current_tag = (struct atag *) current_tag_raw;

        if (current_tag_raw >= atags_position + atag_size) {
            D(ERR, "Critical error in atags");
            return NULL;
        }
    }

    // set INITRD2 tag
    if (hdr->ramdisk_size > 0) {
        current_size = (sizeof(struct atag_info) + sizeof(struct atag_initrd2)) / sizeof(unsigned);
        *((struct atag *) natags_raw_buff) = (struct atag) {
            .info = {
                .size = current_size,
                .type = ATAG_INITRD2_TYPE
            },
            .data = {
                .initrd2 = (struct atag_initrd2) {
                    .start = hdr->ramdisk_addr,
                    .size = hdr->ramdisk_size
                }
            }
        };

        new_atags_size += current_size;
        natags_raw_buff += current_size;
    }

    // set ATAG_CMDLINE
    cmdl_length = strnlen((char *) hdr->cmdline, BOOT_ARGS_SIZE - 1);
    current_size = sizeof(struct atag_info) + (1 + cmdl_length);
    current_size = (current_size + sizeof(unsigned) - 1) / sizeof(unsigned);
    *((struct atag *) natags_raw_buff) = (struct atag) {
        .info = {
            .size = current_size,
            .type = ATAG_CMDLINE_TYPE
        },
    };

    //copy cmdline and ensure that there is null character
    memcpy(((struct atag *) natags_raw_buff)->data.cmdline.cmdline,
           (char *) hdr->cmdline, cmdl_length);
    ((struct atag *) natags_raw_buff)->data.cmdline.cmdline[cmdl_length] = '\0';

    new_atags_size += current_size;
    natags_raw_buff += current_size;

    // set ATAG_NONE
    *((struct atag *) natags_raw_buff) = (struct atag) {
        .info = {
            .size = 0,
            .type = ATAG_NONE_TYPE
        },
    };
    new_atags_size += sizeof(struct atag_info) / sizeof(unsigned);
    natags_raw_buff += sizeof(struct atag_info) / sizeof(unsigned);

    *size = new_atags_size * sizeof(unsigned);
    return new_atags;
}

char *read_atags(const char * path, int *atags_sz) {
    int afd = -1;
    char *atags_ptr = NULL;

    afd = open(path, O_RDONLY);
    if (afd < 0) {
        D(ERR, "wrong atags file");
        return 0;
    }

    atags_ptr = (char *) malloc(MAX_ATAG_SIZE);
    if (atags_ptr == NULL) {
        D(ERR, "insufficient memory");
        return 0;
    }

    *atags_sz = read(afd, atags_ptr, MAX_ATAG_SIZE);

    close(afd);
    return atags_ptr;
}
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2009-2013, Google Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of Google, Inc. nor the names of its contributors
 *    may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef __FASTBOOT_BOOT_H
#define __FASTBOOT_BOOT_H

#include <sys/cdefs.h>
#include <linux/kexec.h>

#include "bootimg.h"

#define KEXEC_TYPE_DEFAULT 0
#define KEXEC_TYPE_CRASH   1

int prepare_boot_linux(unsigned, void *, int, unsigned, void *, int,
                       unsigned, void *, int, unsigned, void *, int);
unsigned *create_atags(unsigned *, int, const struct boot_img_hdr *, int *);
long kexec_load(unsigned int, unsigned long, struct kexec_segment *, unsigned long);
char *read_atags(const char *, int *);

#endif /* _SYS_KEXEC_H */
+161 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading