blob: 5c14e45be156b26668e38189f0d13882669c36e5 [file] [log] [blame]
Gaurav Shahf67bcaa2010-02-28 19:18:24 -08001/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
Gaurav Shahed9c96a2010-03-30 18:56:07 -07005 * API definitions for a generating and manipulating verified boot kernel images.
6 * (Userland portion.)
Gaurav Shahf67bcaa2010-02-28 19:18:24 -08007 */
8
9#ifndef VBOOT_REFERENCE_KERNEL_IMAGE_H_
10#define VBOOT_REFERENCE_KERNEL_IMAGE_H_
11
Gaurav Shahed9c96a2010-03-30 18:56:07 -070012#include "kernel_image_fw.h"
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080013
14/* Allocate and return a new KernelImage structure. */
15KernelImage* KernelImageNew(void);
16
17/* Deep free the contents of [image]. */
18void KernelImageFree(KernelImage* image);
19
20/* Read kernel data from file named [input_file].
21 *
22 * Returns a filled up KernelImage on success, NULL on error.
23 */
24KernelImage* ReadKernelImage(const char* input_file);
25
Gaurav Shah80d129b2010-03-03 17:58:43 -080026/* Get the length of the header for kernel image [image]. */
27int GetKernelHeaderLen(const KernelImage* image);
28
Gaurav Shah528a2c12010-03-18 13:10:10 -070029/* Calculate and store the kernel header checksum of [image]
30 * in [header_checksum].
31 *
32 * [header_checksum] must be a valid pointer to a buffer of
33 * SHA512_DIGEST_SIZE.
34 */
35void CalculateKernelHeaderChecksum(const KernelImage* image,
36 uint8_t* header_checksum);
37
Gaurav Shahf5564fa2010-03-02 15:40:01 -080038/* Get kernel header binary blob from an [image].
39 *
40 * Caller owns the returned pointer and must Free() it.
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080041 */
Gaurav Shahf5564fa2010-03-02 15:40:01 -080042uint8_t* GetKernelHeaderBlob(const KernelImage* image);
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080043
Gaurav Shahf5564fa2010-03-02 15:40:01 -080044/* Get kernel config binary blob from an [image].
45 *
46 * Caller owns the returned pointer and must Free() it.
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080047 */
Gaurav Shahf5564fa2010-03-02 15:40:01 -080048uint8_t* GetKernelConfigBlob(const KernelImage* image);
49
50/* Get a verified kernel binary blob from an [image] and fill
51 * its length into blob_len.
52 *
53 * Caller owns the returned pointer and must Free() it.
54 */
Gaurav Shah13937112010-03-22 17:59:09 -070055uint8_t* GetKernelBlob(const KernelImage* image, uint64_t* blob_len);
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080056
Gaurav Shahb85b06b2010-05-27 13:29:20 -070057
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080058/* Write kernel data from [image] to a file named [input_file].
Gaurav Shah67660cd2010-05-29 01:58:07 -070059 *
60 * If [is_only_vblock] is non-zero, only the verification block (excluding the
61 * actual kernel data) is output.
62 * If [is_subkey_out] is non-zero, only the kernel key verification (subkey)
63 * header is output.
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080064 *
Gaurav Shahf5564fa2010-03-02 15:40:01 -080065 * Return 1 on success, 0 on error.
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080066 */
Gaurav Shahf5564fa2010-03-02 15:40:01 -080067int WriteKernelImage(const char* input_file,
Gaurav Shah2480a182010-04-26 11:41:53 -070068 const KernelImage* image,
Gaurav Shahb85b06b2010-05-27 13:29:20 -070069 int is_only_vblock,
70 int is_subkey_out);
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080071
Bill Richardsonf5db4b82010-05-27 11:15:14 -070072/* Create a kernel_data blob from its components and fill
73 * its length into blob_len, plus some information about the bootloader.
74 *
75 * Caller owns the returned pointer and must Free() it.
76 */
77uint8_t* GenerateKernelBlob(const char* vmlinuz_file,
78 const char* config_file,
79 const char* bootloader_file,
80 uint64_t* blob_len,
81 uint64_t* bootloader_offset,
82 uint64_t* bootloader_size);
83
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080084/* Pretty print the contents of [image]. Only headers and metadata information
85 * is printed.
86 */
87void PrintKernelImage(const KernelImage* image);
88
Gaurav Shahf67bcaa2010-02-28 19:18:24 -080089/* Performs a chained verify of the kernel [image]. If [dev_mode] is
90 * 0 (inactive), then the [firmware_signing_key] is used to verify the signature
91 * of the signing key, else the check is skipped.
92 *
93 * Returns 0 on success, error code on failure.
94 */
95int VerifyKernelImage(const RSAPublicKey* firmware_signing_key,
96 const KernelImage* image,
97 int dev_mode);
98
99
100/* Maps error codes from VerifyKernel*() to error description. */
101const char* VerifyKernelErrorString(int error);
102
103/* Add a kernel signing key signature to the key header to a kernel image
104 * [image] using the private key in file [firmware_key_file].
105 *
106 * Return 1 on success, 0 on failure.
107 */
108int AddKernelKeySignature(KernelImage* image, const char* firmware_key_file);
109
110/* Add a kernel and kernel config signature to a kernel image [image]
111 * using the private signing key in file [kernel_sigining_key_file].
112 *
113 * Return 1 on success, 0 on failure.
114 */
Gaurav Shahf5564fa2010-03-02 15:40:01 -0800115int AddKernelSignature(KernelImage* image,
116 const char* kernel_sigining_key_file);
Gaurav Shahf67bcaa2010-02-28 19:18:24 -0800117
Gaurav Shahf67bcaa2010-02-28 19:18:24 -0800118#endif /* VBOOT_REFERENCE_KERNEL_IMAGE_H_ */