util/: Replace GPLv2 boiler plate with SPDX header
Used commands:
perl -i -p0e 's|\/\*[\s*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-only */|' $(cat filelist)
perl -i -p0e 's|This[\s*]*program[\s*]*is[\s*]*free[\s*]*software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*either[\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License,[\s*]*or[\s*]*.at[\s*]*your[\s*]*option.*[\s*]*any[\s*]*later[\s*]*version.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-or-later */|' $(cat filelist)
perl -i -p0e 's|\/\*[\s*]*.*This[\s*#]*program[\s*#]*is[\s*#]*free[\s*#]*software[;:,][\s*#]*you[\s*#]*can[\s*#]*redistribute[\s*#]*it[\s*#]*and/or[\s*#]*modify[\s*#]*it[\s*#]*under[\s*#]*the[\s*#]*terms[\s*#]*of[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*as[\s*#]*published[\s*#]*by[\s*#]*the[\s*#]*Free[\s*#]*Software[\s*#]*Foundation[;:,][\s*#]*either[\s*#]*version[\s*#]*3[\s*#]*of[\s*#]*the[\s*#]*License[;:,][\s*#]*or[\s*#]*.at[\s*#]*your[\s*#]*option.*[\s*#]*any[\s*#]*later[\s*#]*version.[\s*#]*This[\s*#]*program[\s*#]*is[\s*#]*distributed[\s*#]*in[\s*#]*the[\s*#]*hope[\s*#]*that[\s*#]*it[\s*#]*will[\s*#]*be[\s*#]*useful[;:,][\s*#]*but[\s*#]*WITHOUT[\s*#]*ANY[\s*#]*WARRANTY[;:,][\s*#]*without[\s*#]*even[\s*#]*the[\s*#]*implied[\s*#]*warranty[\s*#]*of[\s*#]*MERCHANTABILITY[\s*#]*or[\s*#]*FITNESS[\s*#]*FOR[\s*#]*A[\s*#]*PARTICULAR[\s*#]*PURPOSE.[\s*#]*See[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*for[\s*#]*more[\s*#]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-3.0-or-later */|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w]*.*is free software[:;][\#\s]*you[\#\s]*can[\#\s]*redistribute[\#\s]*it[\#\s]*and\/or[\#\s]*modify[\#\s]*it[\s\#]*under[\s \#]*the[\s\#]*terms[\s\#]*of[\s\#]*the[\s\#]*GNU[\s\#]*General[\s\#]*Public[\s\#]*License[\s\#]*as[\s\#]*published[\s\#]*by[\s\#]*the[\s\#]*Free[\s\#]*Software[\s\#]*Foundation[;,][\s\#]*version[\s\#]*2[\s\#]*of[\s\#]*the[\s\#]*License.*[\s\#]*This[\s\#]*program[\s\#]*is[\s\#]*distributed[\s\#]*in[\s\#]*the[\s\#]*hope[\s\#]*that[\s\#]*it[\s\#]*will[\#\s]*be[\#\s]*useful,[\#\s]*but[\#\s]*WITHOUT[\#\s]*ANY[\#\s]*WARRANTY;[\#\s]*without[\#\s]*even[\#\s]*the[\#\s]*implied[\#\s]*warranty[\#\s]*of[\#\s]*MERCHANTABILITY[\#\s]*or[\#\s]*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.[\#\s]*See[\#\s]*the[\#\s]*GNU[\#\s]*General[\#\s]*Public[\#\s]*License[\#\s]*for[\#\s]*more[\#\s]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
Change-Id: I1008a63b804f355a916221ac994701d7584f60ff
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-08 20:48:04 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2013-08-27 20:22:21 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "cbfs.h"
|
|
|
|
#include "linux.h"
|
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
/* trampoline */
|
2015-12-02 02:58:08 +01:00
|
|
|
extern unsigned char trampoline[];
|
|
|
|
extern unsigned int trampoline_len;
|
2014-03-27 04:57:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Current max number of segments include:
|
|
|
|
*
|
|
|
|
* 1. parameters
|
|
|
|
* 2. kernel
|
|
|
|
* 3. trampoline
|
|
|
|
* 4. optional cmdline
|
|
|
|
* 5. optional initrd
|
|
|
|
* 6. terminating entry segment
|
|
|
|
*/
|
|
|
|
#define MAX_NUM_SEGMENTS 6
|
|
|
|
|
|
|
|
struct bzpayload {
|
|
|
|
/* Input variables. */
|
|
|
|
int num_segments;
|
|
|
|
struct cbfs_payload_segment segs[MAX_NUM_SEGMENTS];
|
|
|
|
struct buffer parameters;
|
|
|
|
struct buffer kernel;
|
|
|
|
struct buffer trampoline;
|
|
|
|
struct buffer cmdline;
|
|
|
|
struct buffer initrd;
|
|
|
|
/* Output variables. */
|
2020-03-14 00:43:34 +01:00
|
|
|
enum cbfs_compression algo;
|
2014-03-27 04:57:55 +01:00
|
|
|
comp_func_ptr compress;
|
|
|
|
struct buffer output;
|
|
|
|
size_t offset;
|
|
|
|
struct cbfs_payload_segment *out_seg;
|
|
|
|
};
|
|
|
|
|
2020-03-14 00:43:34 +01:00
|
|
|
static int bzp_init(struct bzpayload *bzp, enum cbfs_compression algo)
|
2014-03-27 04:57:55 +01:00
|
|
|
{
|
|
|
|
memset(bzp, 0, sizeof(*bzp));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Need at least the terminating entry segment.
|
|
|
|
*/
|
|
|
|
bzp->num_segments = 1;
|
|
|
|
|
|
|
|
bzp->algo = algo;
|
|
|
|
bzp->compress = compression_function(algo);
|
|
|
|
if (bzp->compress == NULL) {
|
|
|
|
ERROR("Invalid compression algorithm specified.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bzp_add_initrd(struct bzpayload *bzp, const char *fname)
|
|
|
|
{
|
|
|
|
if (fname == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (buffer_from_file(&bzp->initrd, fname)) {
|
|
|
|
ERROR("could not open initrd.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bzp->num_segments++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bzp_add_segment(struct bzpayload *bzp, struct buffer *b, void *data,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
buffer_init(b, NULL, data, size);
|
|
|
|
bzp->num_segments++;
|
|
|
|
}
|
|
|
|
|
2014-05-08 18:54:25 +02:00
|
|
|
static int bzp_add_trampoline(struct bzpayload *bzp)
|
|
|
|
{
|
2015-12-02 02:58:08 +01:00
|
|
|
bzp_add_segment(bzp, &bzp->trampoline, trampoline,
|
2015-12-02 02:58:58 +01:00
|
|
|
trampoline_len);
|
2014-05-08 18:54:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-03-27 04:57:55 +01:00
|
|
|
|
|
|
|
static int bzp_add_cmdline(struct bzpayload *bzp, char *cmdline)
|
|
|
|
{
|
|
|
|
if (cmdline == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bzp_add_segment(bzp, &bzp->cmdline, cmdline, strlen(cmdline) + 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bzp_add_params(struct bzpayload *bzp, struct linux_params *params)
|
|
|
|
{
|
|
|
|
bzp_add_segment(bzp, &bzp->parameters, params, sizeof(*params));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bzp_add_kernel(struct bzpayload *bzp, const struct buffer *in,
|
|
|
|
size_t setup_size)
|
|
|
|
{
|
|
|
|
char *input = buffer_get(in);
|
|
|
|
size_t kern_sz = buffer_size(in) - setup_size;
|
|
|
|
|
|
|
|
bzp_add_segment(bzp, &bzp->kernel, &input[setup_size], kern_sz);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bzp_init_output(struct bzpayload *bzp, const char *name)
|
|
|
|
{
|
|
|
|
size_t sz = 0;
|
|
|
|
|
|
|
|
sz += buffer_size(&bzp->parameters);
|
|
|
|
sz += buffer_size(&bzp->kernel);
|
|
|
|
sz += buffer_size(&bzp->trampoline);
|
|
|
|
sz += buffer_size(&bzp->cmdline);
|
|
|
|
sz += buffer_size(&bzp->initrd);
|
|
|
|
|
|
|
|
bzp->offset = bzp->num_segments * sizeof(struct cbfs_payload_segment);
|
|
|
|
sz += bzp->offset;
|
|
|
|
|
|
|
|
if (buffer_create(&bzp->output, sz, name) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
bzp->out_seg = &bzp->segs[0];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bzp_output_segment(struct bzpayload *bzp, struct buffer *b,
|
|
|
|
uint32_t type, uint64_t load_addr)
|
|
|
|
{
|
|
|
|
struct buffer out;
|
|
|
|
struct cbfs_payload_segment *seg;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
/* Don't process empty buffers. */
|
|
|
|
if (b != NULL && buffer_size(b) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
seg = bzp->out_seg;
|
|
|
|
seg->type = type;
|
|
|
|
seg->load_addr = load_addr;
|
|
|
|
bzp->out_seg++;
|
|
|
|
|
|
|
|
/* No buffer associated with segment. */
|
|
|
|
if (b == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Use a temp buffer for easier management. */
|
|
|
|
buffer_splice(&out, &bzp->output, bzp->offset, buffer_size(b));
|
|
|
|
|
|
|
|
seg->mem_len = buffer_size(b);
|
|
|
|
seg->offset = bzp->offset;
|
|
|
|
bzp->compress(buffer_get(b), buffer_size(b), buffer_get(&out), &len);
|
|
|
|
seg->compression = bzp->algo;
|
|
|
|
seg->len = len;
|
|
|
|
|
|
|
|
/* Update output offset. */
|
|
|
|
bzp->offset += len;
|
|
|
|
}
|
|
|
|
|
2013-08-27 20:22:21 +02:00
|
|
|
/* TODO:
|
|
|
|
* handle special arguments
|
|
|
|
* mem= argument - only affects loading decisions (kernel + initrd), not e820 -> build time
|
|
|
|
* vga= argument (FILO ignores this)
|
|
|
|
* add support for more parameters to trampoline:
|
|
|
|
* alt_mem_k, ext_mem_k (not strictly necessary since e820 takes precedence)
|
|
|
|
* framebuffer/console values
|
|
|
|
*
|
|
|
|
* larger work:
|
|
|
|
* is compress() safe to use in a size constrained buffer? ie. do(es) the
|
|
|
|
* compression algorithm(s) stop once the compression result reaches input
|
|
|
|
* size (ie. incompressible data)?
|
|
|
|
*/
|
|
|
|
int parse_bzImage_to_payload(const struct buffer *input,
|
|
|
|
struct buffer *output, const char *initrd_name,
|
2020-03-14 00:43:34 +01:00
|
|
|
char *cmdline, enum cbfs_compression algo)
|
2013-08-27 20:22:21 +02:00
|
|
|
{
|
2014-03-27 04:57:55 +01:00
|
|
|
struct bzpayload bzp;
|
|
|
|
unsigned int initrd_base = 64*1024*1024;
|
|
|
|
struct linux_header *hdr = (struct linux_header *)input->data;
|
|
|
|
unsigned int setup_size = 4 * 512;
|
2013-08-27 20:22:21 +02:00
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
if (bzp_init(&bzp, algo) != 0)
|
2013-08-27 20:22:21 +02:00
|
|
|
return -1;
|
|
|
|
|
2014-05-08 18:54:25 +02:00
|
|
|
if (bzp_add_trampoline(&bzp) != 0)
|
|
|
|
return -1;
|
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
if (bzp_add_initrd(&bzp, initrd_name) != 0)
|
|
|
|
return -1;
|
2013-08-27 20:22:21 +02:00
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
if (bzp_add_cmdline(&bzp, cmdline) != 0)
|
|
|
|
return -1;
|
2013-08-27 20:22:21 +02:00
|
|
|
|
|
|
|
if (hdr->setup_sects != 0) {
|
|
|
|
setup_size = (hdr->setup_sects + 1) * 512;
|
2016-09-28 19:43:12 +02:00
|
|
|
} else {
|
|
|
|
WARN("hdr->setup_sects is 0, which could cause boot problems.\n");
|
2013-08-27 20:22:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup parameter block. Imitate FILO. */
|
|
|
|
struct linux_params params;
|
2016-03-02 17:45:53 +01:00
|
|
|
|
|
|
|
memset(¶ms, 0, sizeof(struct linux_params));
|
2016-09-28 19:43:12 +02:00
|
|
|
|
2013-08-27 20:22:21 +02:00
|
|
|
params.mount_root_rdonly = hdr->root_flags;
|
|
|
|
params.orig_root_dev = hdr->root_dev;
|
2016-09-28 19:43:12 +02:00
|
|
|
params.init_size = hdr->init_size;
|
|
|
|
|
2013-08-27 20:22:21 +02:00
|
|
|
/* Sensible video defaults. Might be overridden on runtime by coreboot tables. */
|
|
|
|
params.orig_video_mode = 3;
|
|
|
|
params.orig_video_cols = 80;
|
|
|
|
params.orig_video_lines = 25;
|
|
|
|
params.orig_video_isVGA = 1;
|
|
|
|
params.orig_video_points = 16;
|
|
|
|
|
|
|
|
params.loader_type = 0xff; /* Unregistered Linux loader */
|
|
|
|
|
|
|
|
if (cmdline != NULL) {
|
|
|
|
if (hdr->protocol_version < 0x202) {
|
|
|
|
params.cl_magic = CL_MAGIC_VALUE;
|
|
|
|
params.cl_offset = COMMAND_LINE_LOC - LINUX_PARAM_LOC;
|
|
|
|
} else {
|
|
|
|
params.cmd_line_ptr = COMMAND_LINE_LOC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long kernel_base = 0x100000;
|
2016-11-14 20:19:30 +01:00
|
|
|
if ((hdr->protocol_version < 0x200) || !(hdr->loadflags & 1)) {
|
2013-08-27 20:22:21 +02:00
|
|
|
kernel_base = 0x1000; /* zImage kernel */
|
|
|
|
}
|
|
|
|
/* kernel prefers an address, so listen */
|
|
|
|
if ((hdr->protocol_version >= 0x20a) && (!(hdr->pref_address >> 32))) {
|
|
|
|
kernel_base = hdr->pref_address;
|
|
|
|
}
|
|
|
|
if (hdr->protocol_version >= 0x205) {
|
|
|
|
params.relocatable_kernel = hdr->relocatable_kernel;
|
|
|
|
params.kernel_alignment = hdr->kernel_alignment;
|
|
|
|
if (hdr->relocatable_kernel != 0) {
|
|
|
|
/* 16 MB should be way outside coreboot's playground,
|
|
|
|
* so if possible (relocatable kernel) use that to
|
|
|
|
* avoid a trampoline copy. */
|
|
|
|
kernel_base = ALIGN(16*1024*1024, params.kernel_alignment);
|
2016-09-28 19:43:12 +02:00
|
|
|
if (hdr->init_size == 0) {
|
|
|
|
ERROR("init_size 0 for relocatable kernel\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-27 20:22:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have a trampoline and use that, but it can simply use
|
|
|
|
* this information for its jump to real Linux. */
|
|
|
|
params.kernel_start = kernel_base;
|
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
if (bzp_add_kernel(&bzp, input, setup_size) != 0)
|
|
|
|
return -1;
|
2013-08-27 20:22:21 +02:00
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
if (buffer_size(&bzp.initrd) != 0) {
|
2013-08-27 20:22:21 +02:00
|
|
|
/* TODO: this is a bit of a hack. Linux recommends to store
|
|
|
|
* initrd near to end-of-mem, but that's hard to do on build
|
|
|
|
* time. It definitely fails to read the image if it's too
|
|
|
|
* close to the kernel, so give it some room.
|
|
|
|
*/
|
2014-03-27 04:57:55 +01:00
|
|
|
initrd_base = kernel_base + buffer_size(&bzp.kernel);
|
2016-07-31 07:23:11 +02:00
|
|
|
initrd_base = ALIGN(initrd_base, 64*1024*1024);
|
2013-08-27 20:22:21 +02:00
|
|
|
|
|
|
|
params.initrd_start = initrd_base;
|
2014-03-27 04:57:55 +01:00
|
|
|
params.initrd_size = buffer_size(&bzp.initrd);
|
2013-08-27 20:22:21 +02:00
|
|
|
}
|
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
if (bzp_add_params(&bzp, ¶ms) != 0)
|
2013-08-27 20:22:21 +02:00
|
|
|
return -1;
|
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
if (bzp_init_output(&bzp, input->name) != 0)
|
|
|
|
return -1;
|
2013-08-27 20:22:21 +02:00
|
|
|
|
|
|
|
/* parameter block */
|
2014-03-27 04:57:55 +01:00
|
|
|
bzp_output_segment(&bzp, &bzp.parameters,
|
|
|
|
PAYLOAD_SEGMENT_DATA, LINUX_PARAM_LOC);
|
2013-08-27 20:22:21 +02:00
|
|
|
|
|
|
|
/* code block */
|
2014-03-27 04:57:55 +01:00
|
|
|
bzp_output_segment(&bzp, &bzp.kernel,
|
|
|
|
PAYLOAD_SEGMENT_CODE, kernel_base);
|
2013-08-27 20:22:21 +02:00
|
|
|
|
|
|
|
/* trampoline */
|
2014-03-27 04:57:55 +01:00
|
|
|
bzp_output_segment(&bzp, &bzp.trampoline,
|
2014-08-29 19:43:36 +02:00
|
|
|
PAYLOAD_SEGMENT_CODE, TRAMPOLINE_ENTRY_LOC);
|
2013-08-27 20:22:21 +02:00
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
/* cmdline */
|
|
|
|
bzp_output_segment(&bzp, &bzp.cmdline,
|
|
|
|
PAYLOAD_SEGMENT_DATA, COMMAND_LINE_LOC);
|
2013-08-27 20:22:21 +02:00
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
/* initrd */
|
|
|
|
bzp_output_segment(&bzp, &bzp.initrd,
|
|
|
|
PAYLOAD_SEGMENT_DATA, initrd_base);
|
2013-08-27 20:22:21 +02:00
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
/* Terminating entry segment. */
|
2014-08-29 19:43:36 +02:00
|
|
|
bzp_output_segment(&bzp, NULL, PAYLOAD_SEGMENT_ENTRY, TRAMPOLINE_ENTRY_LOC);
|
2013-08-27 20:22:21 +02:00
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
/* Set size of buffer taking into account potential compression. */
|
|
|
|
buffer_set_size(&bzp.output, bzp.offset);
|
|
|
|
/* Make passed-in output buffer be valid. */
|
|
|
|
buffer_clone(output, &bzp.output);
|
2013-08-27 20:22:21 +02:00
|
|
|
|
2014-03-27 04:57:55 +01:00
|
|
|
/* Serialize the segments with the correct encoding. */
|
|
|
|
xdr_segs(output, bzp.segs, bzp.num_segments);
|
2013-08-27 20:22:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|