2009-09-14 15:29:27 +02:00
|
|
|
/*
|
|
|
|
* common utility functions for cbfstool
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 coresystems GmbH
|
|
|
|
* written by Patrick Georgi <patrick.georgi@coresystems.de>
|
2012-11-16 23:48:22 +01:00
|
|
|
* Copyright (C) 2012 Google, Inc.
|
2009-09-14 15:29:27 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-03-06 00:38:03 +01:00
|
|
|
#include <strings.h>
|
2014-08-11 09:27:18 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2010-02-10 20:52:35 +01:00
|
|
|
#include <libgen.h>
|
2009-09-14 15:29:27 +02:00
|
|
|
#include "common.h"
|
|
|
|
#include "cbfs.h"
|
|
|
|
|
2013-01-28 08:53:34 +01:00
|
|
|
/* Utilities */
|
2014-03-05 22:02:21 +01:00
|
|
|
int verbose = 0;
|
2013-01-28 08:53:34 +01:00
|
|
|
|
|
|
|
/* Small, OS/libc independent runtime check for endianess */
|
|
|
|
int is_big_endian(void)
|
|
|
|
{
|
|
|
|
static const uint32_t inttest = 0x12345678;
|
2015-03-06 00:38:03 +01:00
|
|
|
const uint8_t inttest_lsb = *(const uint8_t *)&inttest;
|
2013-01-28 08:53:34 +01:00
|
|
|
if (inttest_lsb == 0x12) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:27:18 +02:00
|
|
|
static off_t get_file_size(FILE *f)
|
|
|
|
{
|
2015-09-14 19:46:44 +02:00
|
|
|
off_t fsize;
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
fsize = ftell(f);
|
|
|
|
fseek(f, 0, SEEK_SET);
|
|
|
|
return fsize;
|
2014-08-11 09:27:18 +02:00
|
|
|
}
|
2013-01-29 17:43:46 +01:00
|
|
|
|
2015-09-14 19:46:44 +02:00
|
|
|
/* Buffer and file I/O */
|
2015-03-04 00:55:03 +01:00
|
|
|
int buffer_create(struct buffer *buffer, size_t size, const char *name)
|
|
|
|
{
|
2013-01-29 17:43:46 +01:00
|
|
|
buffer->name = strdup(name);
|
cbfstool: Add offset field to cbfstool directory's struct buffer
This allows calls to buffer_delete() to work on a buffer that has been
buffer_seek()ed or the buffer created by a buffer_splice(). The same
information could also be useful for other purposes, such as writing
slices back to a file at the offset they originally occupied.
BUG=chromium:470407
TEST=Attempt to perform the following sequence of buffer actions, then run it
through valgrind to check for memory errors:
for (int pos = 0; pos <= 3; ++pos) {
struct buffer seek_test;
buffer_create(&seek_test, 3, "seek_test");
if (pos == 0) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 1) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 2) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 3) {
buffer_delete(&seek_test);
continue;
}
}
for (int pos = 0; pos <= 14; ++pos) {
struct buffer slice_test;
buffer_create(&slice_test, 3, "slice_test");
if (pos == 0) {
buffer_delete(&slice_test);
continue;
}
struct buffer sliced_once;
buffer_splice(&sliced_once, &slice_test, 1, 2);
if (pos == 1) {
buffer_delete(&slice_test);
continue;
}
if (pos == 2) {
buffer_delete(&sliced_once);
continue;
}
struct buffer sliced_twice;
buffer_splice(&sliced_twice, &sliced_once, 2, 1);
if (pos == 3) {
buffer_delete(&slice_test);
continue;
}
if (pos == 4) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 5) {
buffer_delete(&sliced_twice);
continue;
}
struct buffer sliced_same;
buffer_splice(&sliced_same, &slice_test, 1, 1);
if (pos == 6) {
buffer_delete(&slice_test);
continue;
}
if (pos == 7) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 8) {
buffer_delete(&sliced_twice);
continue;
}
if (pos == 9) {
buffer_delete(&sliced_same);
continue;
}
struct buffer sliced_thrice;
buffer_splice(&sliced_thrice, &sliced_twice, 1, 0);
if (pos == 10) {
buffer_delete(&slice_test);
continue;
}
if (pos == 11) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 12) {
buffer_delete(&sliced_twice);
continue;
}
if (pos == 13) {
buffer_delete(&sliced_same);
continue;
}
if (pos == 14) {
buffer_delete(&sliced_thrice);
continue;
}
}
BRANCH=None
Change-Id: Id67734654a62302c0de37746d8a978d49b240505
Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Commit-Id: 00c40982a21a91a488587dd3cead7109f3a30d98
Original-Change-Id: Ie99839d36500d3270e4924a3477e076a6d27ffc8
Original-Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/267467
Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/10133
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-04-26 11:32:43 +02:00
|
|
|
buffer->offset = 0;
|
2013-01-29 17:43:46 +01:00
|
|
|
buffer->size = size;
|
|
|
|
buffer->data = (char *)malloc(buffer->size);
|
|
|
|
if (!buffer->data) {
|
|
|
|
fprintf(stderr, "buffer_create: Insufficient memory (0x%zx).\n",
|
|
|
|
size);
|
|
|
|
}
|
|
|
|
return (buffer->data == NULL);
|
|
|
|
}
|
|
|
|
|
2015-03-04 00:55:03 +01:00
|
|
|
int buffer_from_file(struct buffer *buffer, const char *filename)
|
|
|
|
{
|
2013-01-29 17:43:46 +01:00
|
|
|
FILE *fp = fopen(filename, "rb");
|
|
|
|
if (!fp) {
|
|
|
|
perror(filename);
|
|
|
|
return -1;
|
|
|
|
}
|
cbfstool: Add offset field to cbfstool directory's struct buffer
This allows calls to buffer_delete() to work on a buffer that has been
buffer_seek()ed or the buffer created by a buffer_splice(). The same
information could also be useful for other purposes, such as writing
slices back to a file at the offset they originally occupied.
BUG=chromium:470407
TEST=Attempt to perform the following sequence of buffer actions, then run it
through valgrind to check for memory errors:
for (int pos = 0; pos <= 3; ++pos) {
struct buffer seek_test;
buffer_create(&seek_test, 3, "seek_test");
if (pos == 0) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 1) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 2) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 3) {
buffer_delete(&seek_test);
continue;
}
}
for (int pos = 0; pos <= 14; ++pos) {
struct buffer slice_test;
buffer_create(&slice_test, 3, "slice_test");
if (pos == 0) {
buffer_delete(&slice_test);
continue;
}
struct buffer sliced_once;
buffer_splice(&sliced_once, &slice_test, 1, 2);
if (pos == 1) {
buffer_delete(&slice_test);
continue;
}
if (pos == 2) {
buffer_delete(&sliced_once);
continue;
}
struct buffer sliced_twice;
buffer_splice(&sliced_twice, &sliced_once, 2, 1);
if (pos == 3) {
buffer_delete(&slice_test);
continue;
}
if (pos == 4) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 5) {
buffer_delete(&sliced_twice);
continue;
}
struct buffer sliced_same;
buffer_splice(&sliced_same, &slice_test, 1, 1);
if (pos == 6) {
buffer_delete(&slice_test);
continue;
}
if (pos == 7) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 8) {
buffer_delete(&sliced_twice);
continue;
}
if (pos == 9) {
buffer_delete(&sliced_same);
continue;
}
struct buffer sliced_thrice;
buffer_splice(&sliced_thrice, &sliced_twice, 1, 0);
if (pos == 10) {
buffer_delete(&slice_test);
continue;
}
if (pos == 11) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 12) {
buffer_delete(&sliced_twice);
continue;
}
if (pos == 13) {
buffer_delete(&sliced_same);
continue;
}
if (pos == 14) {
buffer_delete(&sliced_thrice);
continue;
}
}
BRANCH=None
Change-Id: Id67734654a62302c0de37746d8a978d49b240505
Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Commit-Id: 00c40982a21a91a488587dd3cead7109f3a30d98
Original-Change-Id: Ie99839d36500d3270e4924a3477e076a6d27ffc8
Original-Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/267467
Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/10133
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-04-26 11:32:43 +02:00
|
|
|
buffer->offset = 0;
|
2016-12-14 16:16:47 +01:00
|
|
|
off_t file_size = get_file_size(fp);
|
|
|
|
if (file_size < 0) {
|
2014-08-11 09:27:18 +02:00
|
|
|
fprintf(stderr, "could not determine size of %s\n", filename);
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-12-14 16:16:47 +01:00
|
|
|
buffer->size = file_size;
|
2013-01-29 17:43:46 +01:00
|
|
|
buffer->name = strdup(filename);
|
|
|
|
buffer->data = (char *)malloc(buffer->size);
|
|
|
|
assert(buffer->data);
|
|
|
|
if (fread(buffer->data, 1, buffer->size, fp) != buffer->size) {
|
|
|
|
fprintf(stderr, "incomplete read: %s\n", filename);
|
|
|
|
fclose(fp);
|
cbfstool: Restructure around support for reading/writing portions of files
The buffer API that cbfstool uses to read and write files only directly supports
one-shot operations on whole files. This adds an intermediate partitioned_file
module that sits on top of the buffer system and has an awareness of FMAP
entries. It provides an easy way to get a buffer for an individual region of a
larger image file based on FMAP section name, as well as incrementally write
those smaller buffers back to the backing file at the appropriate offset. The
module has two distinct modes of operation:
- For new images whose layout is described exclusively by an FMAP section, all
the aforementioned functionality will be available.
- For images in the current format, where the CBFS master header serves as the
root of knowledge of the image's size and layout, the module falls back to a
legacy operation mode, where it only allows manipulation of the entire image
as one unit, but exposes this support through the same interface by mapping
the region named SECTION_NAME_PRIMARY_CBFS ("COREBOOT") to the whole file.
The tool is presently only ported onto the new module running in legacy mode:
higher-level support for true "partitioned" images will be forthcoming. However,
as part of this change, the crusty cbfs_image_from_file() and
cbfs_image_write_file() abstractions are removed and replaced with a single
cbfs_image function, cbfs_image_from_buffer(), as well as centralized image
reading/writing directly in cbfstool's main() function. This reduces the
boilerplate required to implement each new action, makes the create action much
more similar to the others, and will make implementing additional actions and
adding in support for the new format much easier.
BUG=chromium:470407
TEST=Build panther and nyan_big coreboot.rom images with and without this patch
and diff their hexdumps. Ensure that no differences occur at different locations
from the diffs between subsequent builds of an identical source tree. Then flash
a full new build onto nyan_big and watch it boot normally.
BRANCH=None
Change-Id: I25578c7b223bc8434c3074cb0dd8894534f8c500
Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Commit-Id: 7e1c96a48e7a27fc6b90289d35e6e169d5e7ad20
Original-Change-Id: Ia4a1a4c48df42b9ec2d6b9471b3a10eb7b24bb39
Original-Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/265581
Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/10134
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-25 21:40:08 +01:00
|
|
|
buffer_delete(buffer);
|
2013-01-29 17:43:46 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-04 00:55:03 +01:00
|
|
|
int buffer_write_file(struct buffer *buffer, const char *filename)
|
|
|
|
{
|
2013-01-29 17:43:46 +01:00
|
|
|
FILE *fp = fopen(filename, "wb");
|
|
|
|
if (!fp) {
|
|
|
|
perror(filename);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
assert(buffer && buffer->data);
|
|
|
|
if (fwrite(buffer->data, 1, buffer->size, fp) != buffer->size) {
|
|
|
|
fprintf(stderr, "incomplete write: %s\n", filename);
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-04 00:55:03 +01:00
|
|
|
void buffer_delete(struct buffer *buffer)
|
|
|
|
{
|
2013-01-29 17:43:46 +01:00
|
|
|
assert(buffer);
|
|
|
|
if (buffer->name) {
|
|
|
|
free(buffer->name);
|
|
|
|
buffer->name = NULL;
|
|
|
|
}
|
|
|
|
if (buffer->data) {
|
2015-11-11 18:43:11 +01:00
|
|
|
free(buffer_get_original_backing(buffer));
|
2013-01-29 17:43:46 +01:00
|
|
|
buffer->data = NULL;
|
|
|
|
}
|
cbfstool: Add offset field to cbfstool directory's struct buffer
This allows calls to buffer_delete() to work on a buffer that has been
buffer_seek()ed or the buffer created by a buffer_splice(). The same
information could also be useful for other purposes, such as writing
slices back to a file at the offset they originally occupied.
BUG=chromium:470407
TEST=Attempt to perform the following sequence of buffer actions, then run it
through valgrind to check for memory errors:
for (int pos = 0; pos <= 3; ++pos) {
struct buffer seek_test;
buffer_create(&seek_test, 3, "seek_test");
if (pos == 0) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 1) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 2) {
buffer_delete(&seek_test);
continue;
}
buffer_seek(&seek_test, 1);
if (pos == 3) {
buffer_delete(&seek_test);
continue;
}
}
for (int pos = 0; pos <= 14; ++pos) {
struct buffer slice_test;
buffer_create(&slice_test, 3, "slice_test");
if (pos == 0) {
buffer_delete(&slice_test);
continue;
}
struct buffer sliced_once;
buffer_splice(&sliced_once, &slice_test, 1, 2);
if (pos == 1) {
buffer_delete(&slice_test);
continue;
}
if (pos == 2) {
buffer_delete(&sliced_once);
continue;
}
struct buffer sliced_twice;
buffer_splice(&sliced_twice, &sliced_once, 2, 1);
if (pos == 3) {
buffer_delete(&slice_test);
continue;
}
if (pos == 4) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 5) {
buffer_delete(&sliced_twice);
continue;
}
struct buffer sliced_same;
buffer_splice(&sliced_same, &slice_test, 1, 1);
if (pos == 6) {
buffer_delete(&slice_test);
continue;
}
if (pos == 7) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 8) {
buffer_delete(&sliced_twice);
continue;
}
if (pos == 9) {
buffer_delete(&sliced_same);
continue;
}
struct buffer sliced_thrice;
buffer_splice(&sliced_thrice, &sliced_twice, 1, 0);
if (pos == 10) {
buffer_delete(&slice_test);
continue;
}
if (pos == 11) {
buffer_delete(&sliced_once);
continue;
}
if (pos == 12) {
buffer_delete(&sliced_twice);
continue;
}
if (pos == 13) {
buffer_delete(&sliced_same);
continue;
}
if (pos == 14) {
buffer_delete(&sliced_thrice);
continue;
}
}
BRANCH=None
Change-Id: Id67734654a62302c0de37746d8a978d49b240505
Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Commit-Id: 00c40982a21a91a488587dd3cead7109f3a30d98
Original-Change-Id: Ie99839d36500d3270e4924a3477e076a6d27ffc8
Original-Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/267467
Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/10133
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-04-26 11:32:43 +02:00
|
|
|
buffer->offset = 0;
|
2013-01-29 17:43:46 +01:00
|
|
|
buffer->size = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-16 23:48:22 +01:00
|
|
|
static struct {
|
|
|
|
uint32_t arch;
|
|
|
|
const char *name;
|
|
|
|
} arch_names[] = {
|
2014-04-29 01:39:40 +02:00
|
|
|
{ CBFS_ARCHITECTURE_AARCH64, "arm64" },
|
ARM: Generalize armv7 as arm.
There are ARM systems which are essentially heterogeneous multicores where
some cores implement a different ARM architecture version than other cores. A
specific example is the tegra124 which boots on an ARMv4 coprocessor while
most code, including most of the firmware, runs on the main ARMv7 core. To
support SOCs like this, the plan is to generalize the ARM architecture so that
all versions are available, and an SOC/CPU can then select what architecture
variant should be used for each component of the firmware; bootblock,
romstage, and ramstage.
Old-Change-Id: I22e048c3bc72bd56371e14200942e436c1e312c2
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://chromium-review.googlesource.com/171338
Reviewed-by: Gabe Black <gabeblack@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
(cherry picked from commit 8423a41529da0ff67fb9873be1e2beb30b09ae2d)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
ARM: Split out ARMv7 code and make it possible to have other arch versions.
We don't always want to use ARMv7 code when building for ARM, so we should
separate out the ARMv7 code so it can be excluded, and also make it possible
to include code for some other version of the architecture instead, all per
build component for cases where we need more than one architecture version
at a time.
The tegra124 bootblock will ultimately need to be ARMv4, but until we have
some ARMv4 code to switch over to we can leave it set to ARMv7.
Old-Change-Id: Ia982c91057fac9c252397b7c866224f103761cc7
Reviewed-on: https://chromium-review.googlesource.com/171400
Reviewed-by: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
(cherry picked from commit 799514e6060aa97acdcf081b5c48f965be134483)
Squashed two related patches for splitting ARM support into general
ARM support and ARMv7 specific pieces.
Change-Id: Ic6511507953a2223c87c55f90252c4a4e1dd6010
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6782
Tested-by: build bot (Jenkins)
2013-10-01 08:00:33 +02:00
|
|
|
{ CBFS_ARCHITECTURE_ARM, "arm" },
|
2014-06-14 00:56:45 +02:00
|
|
|
{ CBFS_ARCHITECTURE_MIPS, "mips" },
|
2015-12-11 19:19:52 +01:00
|
|
|
{ CBFS_ARCHITECTURE_PPC64, "ppc64" },
|
|
|
|
/* power8 is a reasonable alias */
|
|
|
|
{ CBFS_ARCHITECTURE_PPC64, "power8" },
|
2014-10-16 12:55:39 +02:00
|
|
|
{ CBFS_ARCHITECTURE_RISCV, "riscv" },
|
2012-11-16 23:48:22 +01:00
|
|
|
{ CBFS_ARCHITECTURE_X86, "x86" },
|
|
|
|
{ CBFS_ARCHITECTURE_UNKNOWN, "unknown" }
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t string_to_arch(const char *arch_string)
|
|
|
|
{
|
2016-05-26 23:41:02 +02:00
|
|
|
size_t i;
|
2012-11-16 23:48:22 +01:00
|
|
|
uint32_t ret = CBFS_ARCHITECTURE_UNKNOWN;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(arch_names); i++) {
|
|
|
|
if (!strcasecmp(arch_string, arch_names[i].name)) {
|
|
|
|
ret = arch_names[i].arch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-13 23:34:57 +01:00
|
|
|
const char *arch_to_string(uint32_t a)
|
|
|
|
{
|
2016-05-26 23:41:02 +02:00
|
|
|
size_t i;
|
2013-11-13 23:34:57 +01:00
|
|
|
const char *ret = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(arch_names); i++) {
|
|
|
|
if (a == arch_names[i].arch) {
|
|
|
|
ret = arch_names[i].name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-04-08 15:05:09 +02:00
|
|
|
void print_supported_architectures(void)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(arch_names); i++) {
|
|
|
|
printf(i == 0? " ":", ");
|
|
|
|
printf("%s", arch_names[i].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2010-04-24 23:24:06 +02:00
|
|
|
void print_supported_filetypes(void)
|
|
|
|
{
|
|
|
|
int i, number = ARRAY_SIZE(filetypes);
|
|
|
|
|
|
|
|
for (i=0; i<number; i++) {
|
2018-04-08 15:05:09 +02:00
|
|
|
printf(" %s%c", filetypes[i].name, (i==(number-1))?'\n':',');
|
2010-04-24 23:24:06 +02:00
|
|
|
if ((i%8) == 7)
|
2018-04-08 15:05:09 +02:00
|
|
|
printf("\n");
|
2010-04-24 23:24:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-14 15:29:27 +02:00
|
|
|
uint64_t intfiletype(const char *name)
|
|
|
|
{
|
2012-07-17 21:17:15 +02:00
|
|
|
size_t i;
|
2015-09-09 16:46:00 +02:00
|
|
|
for (i = 0; i < (sizeof(filetypes) / sizeof(struct typedesc_t)); i++)
|
2009-09-14 15:29:27 +02:00
|
|
|
if (strcmp(filetypes[i].name, name) == 0)
|
|
|
|
return filetypes[i].type;
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-01 15:52:56 +02:00
|
|
|
|
|
|
|
char *bintohex(uint8_t *data, size_t len)
|
|
|
|
{
|
|
|
|
static const char translate[16] = "0123456789abcdef";
|
|
|
|
|
|
|
|
char *result = malloc(len * 2 + 1);
|
|
|
|
if (result == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
result[len*2] = '\0';
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
result[i*2] = translate[(data[i] >> 4) & 0xf];
|
|
|
|
result[i*2+1] = translate[data[i] & 0xf];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|