summaryrefslogtreecommitdiff
path: root/util/cbfstool/cbfs-mkpayload.c
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2013-01-28 15:04:30 +0800
committerDavid Hendricks <dhendrix@chromium.org>2013-02-01 06:06:41 +0100
commit05dccae75df4ed0c6a75867a89cf1a4055507e28 (patch)
treeffb7291d0975565da5d1a8cc40277459dc9cc3a5 /util/cbfstool/cbfs-mkpayload.c
parent4d87d4e09b38d152425f060f088f3a44b7dacfcb (diff)
cbfstool: move flat-binary parsing to cbfs-mkpayload.
The ELF parsing and payload building in add-flat-binary command should be isolated just like mkpayload and mkstage. Since the add-flat-binary command creates a payload in the end , move payload processing to cbfs-mkpayload.c. To test: cbfstool coreboot.rom add-flat-binary -f u-boot.bin -n fallback/payload \ -l 0x100000 -e 0x100020 To verify, get output from "cbfstool coreboot.rom print -v": fallback/payload 0x73ccc0 payload 124920 INFO: code (no compression, offset: 0x38, load: 0x1110000, length:..) Change-Id: Ia7bd2e6160507c0a1e8e20bc1d08397ce9826e0d Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: http://review.coreboot.org/2197 Tested-by: build bot (Jenkins) Reviewed-by: David Hendricks <dhendrix@chromium.org>
Diffstat (limited to 'util/cbfstool/cbfs-mkpayload.c')
-rw-r--r--util/cbfstool/cbfs-mkpayload.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c
index da04a75785..060e9ee283 100644
--- a/util/cbfstool/cbfs-mkpayload.c
+++ b/util/cbfstool/cbfs-mkpayload.c
@@ -202,3 +202,56 @@ int parse_elf_to_payload(unsigned char *input, unsigned char **output,
err:
return -1;
}
+
+int parse_flat_binary_to_payload(unsigned char *input, unsigned char **output,
+ int32_t input_size,
+ uint32_t loadaddress,
+ uint32_t entrypoint,
+ comp_algo algo)
+{
+ comp_func_ptr compress;
+ unsigned char *payload;
+ struct cbfs_payload_segment *segs;
+ int doffset, len = 0;
+
+ compress = compression_function(algo);
+ if (!compress)
+ return -1;
+
+ DEBUG("start: parse_flat_binary_to_payload\n");
+
+ /* FIXME compressed file size might be bigger than original file and
+ * causing buffer overflow. */
+ payload = calloc((2 * sizeof(struct cbfs_payload_segment)) + input_size, 1);
+ if (payload == NULL) {
+ ERROR("Could not allocate memory.\n");
+ return -1;
+ }
+
+ segs = (struct cbfs_payload_segment *)payload;
+ doffset = (2 * sizeof(*segs));
+
+ /* Prepare code segment */
+ segs[0].type = PAYLOAD_SEGMENT_CODE;
+ segs[0].load_addr = htonll(loadaddress);
+ segs[0].mem_len = htonl(input_size);
+ segs[0].offset = htonl(doffset);
+
+ compress((char*)input, input_size, (char*)payload + doffset, &len);
+ segs[0].compression = htonl(algo);
+ segs[0].len = htonl(len);
+
+ if ((unsigned int)len >= input_size) {
+ WARN("Compressing data would make it bigger - disabled.\n");
+ segs[0].compression = 0;
+ segs[0].len = htonl(input_size);
+ memcpy(payload + doffset, input, input_size);
+ }
+
+ /* prepare entry point segment */
+ segs[1].type = PAYLOAD_SEGMENT_ENTRY;
+ segs[1].load_addr = htonll(entrypoint);
+ *output = payload;
+
+ return doffset + ntohl(segs[0].len);
+}