| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- /*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /* Copyright Statement:
- *
- * This software/firmware and related documentation ("MediaTek Software") are
- * protected under relevant copyright laws. The information contained herein
- * is confidential and proprietary to MediaTek Inc. and/or its licensors.
- * Without the prior written permission of MediaTek inc. and/or its licensors,
- * any reproduction, modification, use or disclosure of MediaTek Software,
- * and information contained herein, in whole or in part, shall be strictly prohibited.
- */
- /* MediaTek Inc. (C) 2017. All rights reserved.
- *
- * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
- * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
- * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
- * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
- * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
- * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * The following software/firmware and/or related documentation ("MediaTek Software")
- * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
- * applicable license agreements with MediaTek Inc.
- */
- #ifndef __BOOTIMG_H__
- #define __BOOTIMG_H__
- #include <pal_typedefs.h>
- #define BOOTIMG_MAGIC "ANDROID!"
- #define BOOTIMG_MAGIC_SZ (8)
- #define BOOTIMG_NAME_SZ (16)
- #define BOOTIMG_ARGS_SZ (512)
- #define BOOT_EXTRA_ARGS_SIZE (1024)
- #define VENDOR_BOOT_MAGIC "VNDRBOOT"
- #define VENDOR_BOOT_MAGIC_SIZE 8
- #define VENDOR_BOOT_ARGS_SIZE 2048
- #define VENDOR_BOOT_NAME_SIZE 16
- #define BOOT_HEADER_VERSION_ZERO 0
- #define BOOT_HEADER_VERSION_ONE 1
- #define BOOT_HEADER_VERSION_TWO 2
- #define BOOT_HEADER_VERSION_THREE 3
- #define BOOT_IMAGE_HEADER_V1_SIZE 1648
- #define BOOT_IMAGE_HEADER_V2_SIZE 1660
- #define BOOT_IMAGE_HEADER_V3_SIZE 1596
- #define VENDOR_BOOT_IMAGE_HEADER_V3_SIZE 2108
- #define BOOT_IMAGE_HEADER_V3_PAGESIZE 4096
- #define BOOTIMG_HDR_SZ (0x800)
- /* When the boot image header has a version of 2, the structure of the boot
- * image is as follows:
- *
- * +---------------------+
- * | boot header | 1 page
- * +---------------------+
- * | kernel | n pages
- * +---------------------+
- * | ramdisk | m pages
- * +---------------------+
- * | second stage | o pages
- * +---------------------+
- * | recovery dtbo/acpio | p pages
- * +---------------------+
- * | dtb | q pages
- * +---------------------+
- * n = (kernel_size + page_size - 1) / page_size
- * m = (ramdisk_size + page_size - 1) / page_size
- * o = (second_size + page_size - 1) / page_size
- * p = (recovery_dtbo_size + page_size - 1) / page_size
- * q = (dtb_size + page_size - 1) / page_size
- *
- * 0. all entities are page_size aligned in flash
- * 1. kernel, ramdisk and DTB are required (size != 0)
- * 2. recovery_dtbo/recovery_acpio is required for recovery.img in non-A/B
- * devices(recovery_dtbo_size != 0)
- * 3. second is optional (second_size == 0 -> no second)
- * 4. load each element (kernel, ramdisk, second, dtb) at
- * the specified physical address (kernel_addr, etc)
- * 5. If booting to recovery mode in a non-A/B device, extract recovery
- * dtbo/acpio and apply the correct set of overlays on the base device tree
- * depending on the hardware/product revision.
- * 6. prepare tags at tag_addr. kernel_args[] is
- * appended to the kernel commandline in the tags.
- * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
- * 8. if second_size != 0: jump to second_addr
- * else: jump to kernel_addr
- */
- struct bootimg_hdr {
- uint8_t magic[BOOTIMG_MAGIC_SZ];
- uint32_t kernel_sz; /* size in bytes */
- uint32_t kernel_addr; /* physical load addr */
- uint32_t ramdisk_sz; /* size in bytes */
- uint32_t ramdisk_addr; /* physical load addr */
- uint32_t second_sz; /* size in bytes */
- uint32_t second_addr; /* physical load addr */
- uint32_t tags_addr; /* physical addr for kernel tags */
- uint32_t page_sz; /* flash page size we assume */
- uint32_t header_version;
- uint32_t os_version;
- uint8_t name[BOOTIMG_NAME_SZ]; /* asciiz product name */
- uint8_t cmdline[BOOTIMG_ARGS_SZ];
- uint32_t id[8]; /* timestamp / checksum / sha1 / etc */
- uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE];
- uint32_t recovery_dtbo_size; /* size of recovery dtbo image */
- uint64_t recovery_dtbo_offset; /* physical load addr */
- uint32_t header_size; /* size of boot image header in bytes */
- uint32_t dtb_size; /* size in bytes for DTB image */
- uint64_t dtb_addr; /* physical load address for DTB image */
- } __attribute__((packed));
- /* When the boot image header has a version of 3, the structure of the boot
- * image is as follows:
- *
- * +---------------------+
- * | boot header | 4096 bytes
- * +---------------------+
- * | kernel | m
- * +---------------------+
- * | ramdisk | n
- * +---------------------+
- *
- * m = (kernel_size + 4096 - 1) / 4096
- * n = (ramdisk_size + 4096 - 1) / 4096
- *
- * Note that in version 3 of the boot image header, page size is fixed at 4096 bytes.
- *
- * The structure of the vendor boot image (introduced with version 3 and
- * required to be present when a v3 boot image is used) is as follows:
- *
- * +---------------------+
- * | vendor boot header | 1 page
- * +---------------------+
- * | vendor ramdisk | o pages
- * +---------------------+
- * | dtb | p pages
- * +---------------------+
- * o = (vendor_ramdisk_size + page_size - 1) / page_size
- * p = (dtb_size + page_size - 1) / page_size
- *
- * 0. all entities in the boot image are 4096-byte aligned in flash, all
- * entities in the vendor boot image are page_size (determined by the vendor
- * and specified in the vendor boot image header) aligned in flash
- * 1. kernel, ramdisk, vendor ramdisk, and DTB are required (size != 0)
- * 2. load the kernel and DTB at the specified physical address (kernel_addr,
- * dtb_addr)
- * 3. load the vendor ramdisk at ramdisk_addr
- * 4. load the generic ramdisk immediately following the vendor ramdisk in
- * memory
- * 5. prepare tags at tag_addr. kernel_args[] is appended to the kernel
- * commandline in the tags.
- * 6. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
- * 7. if the platform has a second stage bootloader jump to it (must be
- * contained outside boot and vendor boot partitions), otherwise
- * jump to kernel_addr
- */
- struct boot_img_hdr_v3 {
- // Must be BOOT_MAGIC.
- uint8_t magic[BOOTIMG_MAGIC_SZ];
- uint32_t kernel_size; /* size in bytes */
- uint32_t ramdisk_size; /* size in bytes */
- // Operating system version and security patch level.
- // For version "A.B.C" and patch level "Y-M-D":
- // (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M)
- // os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0]
- uint32_t os_version;
- uint32_t header_size;
- uint32_t reserved[4];
- // Version of the boot image header.
- uint32_t header_version;
- uint8_t cmdline[BOOTIMG_ARGS_SZ + BOOT_EXTRA_ARGS_SIZE];
- } __attribute__((packed));
- struct vendor_boot_img_hdr_v3 {
- // Must be VENDOR_BOOT_MAGIC.
- uint8_t magic[VENDOR_BOOT_MAGIC_SIZE];
- // Version of the vendor boot image header.
- uint32_t header_version;
- uint32_t page_size; /* flash page size we assume */
- uint32_t kernel_addr; /* physical load addr */
- uint32_t ramdisk_addr; /* physical load addr */
- uint32_t vendor_ramdisk_size; /* size in bytes */
- uint8_t cmdline[VENDOR_BOOT_ARGS_SIZE];
- uint32_t tags_addr; /* physical addr for kernel tags */
- uint8_t name[VENDOR_BOOT_NAME_SIZE]; /* asciiz product name */
- uint32_t header_size;
- uint32_t dtb_size; /* size in bytes for DTB image */
- uint64_t dtb_addr; /* physical load address for DTB image */
- } __attribute__((packed));
- #endif /* __BOOTIMG_H__ */
|