coreboot-kgpe-d16/util/cbfstool/fmaptool.c

273 lines
7.4 KiB
C
Raw Normal View History

/* fmaptool, CLI utility for converting plaintext fmd files into fmap blobs */
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 */
#include "common.h"
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
#include "cbfs_sections.h"
#include "fmap_from_fmd.h"
#include <stdio.h>
#include <string.h>
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
#include <unistd.h>
#define STDIN_FILENAME_SENTINEL "-"
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
#define HEADER_FMAP_OFFSET "FMAP_OFFSET"
#define HEADER_FMAP_SIZE "FMAP_SIZE"
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
enum fmaptool_return {
FMAPTOOL_EXIT_SUCCESS = 0,
FMAPTOOL_EXIT_BAD_ARGS,
FMAPTOOL_EXIT_BAD_INPUT_PATH,
FMAPTOOL_EXIT_BAD_OUTPUT_PATH,
FMAPTOOL_EXIT_FAILED_DESCRIPTOR,
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
FMAPTOOL_EXIT_MISSING_FMAP_SECTION,
FMAPTOOL_EXIT_MISSING_PRIMARY_CBFS,
FMAPTOOL_EXIT_FAILED_FMAP_CONVERSION,
FMAPTOOL_EXIT_UNKNOWN_FMAP_SIZE,
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
FMAPTOOL_EXIT_FAILED_WRITING_OUTPUT,
FMAPTOOL_EXIT_FAILED_WRITING_HEADER,
};
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
static void usage(const char *invoked_as)
{
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
fputs("fmaptool: Compiler for fmd (flashmap descriptor) files\n",
stderr);
fputs("\nUSAGE:\n", stderr);
fprintf(stderr,
"\t%s [-h <header output file>] [-R <region output file>] <fmd input file> <binary output file>\n",
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
invoked_as);
fputs("\nMANDATORY ARGUMENTS:\n", stderr);
fprintf(stderr,
"<fmd input file> may be '%s' to read from standard input\n",
STDIN_FILENAME_SENTINEL);
fputs("<binary output file> must be a regular file\n", stderr);
fputs("\nOPTIONAL SWITCHES:\n", stderr);
fprintf(stderr,
"-h\tAlso produce a C header defining %s to the FMAP section's flash offset.\n",
HEADER_FMAP_OFFSET);
fprintf(stderr,
"-R\tAlso produce a text file listing the CBFS regions, comma separated.\n");
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
fputs("\nOUTPUT:\n", stderr);
fputs("A successful invocation prints a summary of work done to standard error, and a comma-separated list\n",
stderr);
fputs("of those sections that contain CBFSes, starting with the primary such section, to standard output.\n",
stderr);
}
static void list_cbfs_section_names(FILE *out)
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
{
cbfs_section_iterator_t cbfs_it = cbfs_sections_iterator();
assert(cbfs_it);
bool subsequent = false;
while (cbfs_it) {
const char *cur_name =
cbfs_sections_iterator_deref(cbfs_it)->name;
if (cbfs_sections_iterator_advance(&cbfs_it) && subsequent)
fputc(',', out);
fputs(cur_name, out);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
subsequent = true;
}
fputc('\n', out);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
}
static void write_header_fmap_sections(FILE *header, const struct flashmap_descriptor *root,
unsigned int offset)
{
assert(root);
/*
* The offset may only be unknown for the root node in a system where the flash isn't
* memory-mapped.
*/
if (!root->offset_known && offset != 0)
return;
const unsigned int current_offset = offset + (root->offset_known ? root->offset : 0);
fprintf(header, "#define FMAP_SECTION_%s_START %#x\n", root->name, current_offset);
if (!root->size_known)
return;
fprintf(header, "#define FMAP_SECTION_%s_SIZE %#x\n", root->name, root->size);
fmd_foreach_child(child, root)
write_header_fmap_sections(header, child, current_offset);
}
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
static bool write_header(const char *out_fname,
const struct flashmap_descriptor *root,
const int fmap_size)
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
{
assert(out_fname);
FILE *header = fopen(out_fname, "w");
if (!header) {
fprintf(stderr, "FATAL: Unable to open file '%s' for writing\n",
out_fname);
return false;
}
unsigned fmap_offset =
fmd_calc_absolute_offset(root, SECTION_NAME_FMAP);
assert(fmap_offset != FMD_NOTFOUND);
fputs("#ifndef FMAPTOOL_GENERATED_HEADER_H_\n", header);
fputs("#define FMAPTOOL_GENERATED_HEADER_H_\n\n", header);
fprintf(header, "#define %s %#x\n", HEADER_FMAP_OFFSET, fmap_offset);
fprintf(header, "#define %s %#x\n\n", HEADER_FMAP_SIZE, fmap_size);
write_header_fmap_sections(header, root, 0);
fputs("\n", header);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
fputs("#endif\n", header);
fclose(header);
return true;
}
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
static void full_fmd_cleanup(struct flashmap_descriptor **victim)
{
assert(victim);
cbfs_sections_cleanup();
fmd_cleanup(*victim);
*victim = NULL;
}
int main(int argc, char **argv)
{
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
struct {
// Mandatory
const char *fmd_filename;
const char *fmap_filename;
// Optional
const char *header_filename;
const char *region_filename;
} args = {NULL, NULL, NULL, NULL};
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
bool show_usage = false;
int each_arg;
while (!show_usage && (each_arg = getopt(argc, argv, ":h:R:")) != -1) {
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
switch (each_arg) {
case 'h':
args.header_filename = optarg;
break;
case 'R':
args.region_filename = optarg;
break;
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
case ':':
fprintf(stderr, "-%c: Expected an accompanying value\n",
optopt);
show_usage = true;
break;
default:
fprintf(stderr, "-%c: Unexpected command-line switch\n",
optopt);
show_usage = true;
}
}
if (show_usage || argc - optind != 2) {
usage(argv[0]);
return FMAPTOOL_EXIT_BAD_ARGS;
}
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
args.fmd_filename = argv[optind];
args.fmap_filename = argv[optind + 1];
FILE *fmd_file = stdin;
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
if (strcmp(args.fmd_filename, STDIN_FILENAME_SENTINEL) != 0) {
fmd_file = fopen(args.fmd_filename, "r");
if (!fmd_file) {
fprintf(stderr, "FATAL: Unable to open file '%s'\n",
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
args.fmd_filename);
return FMAPTOOL_EXIT_BAD_INPUT_PATH;
}
}
struct flashmap_descriptor *descriptor = fmd_create(fmd_file);
fclose(fmd_file);
if (!descriptor) {
fputs("FATAL: Failed while processing provided descriptor\n",
stderr);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_FAILED_DESCRIPTOR;
}
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
if (!fmd_find_node(descriptor, SECTION_NAME_FMAP)) {
fprintf(stderr,
"FATAL: Flashmap descriptor must have an '%s' section\n",
SECTION_NAME_FMAP);
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_MISSING_FMAP_SECTION;
}
if (!cbfs_sections_primary_cbfs_accounted_for()) {
fprintf(stderr,
"FATAL: Flashmap descriptor must have a '%s' section that is annotated with '(%s)'\n",
SECTION_NAME_PRIMARY_CBFS,
SECTION_ANNOTATION_CBFS);
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_MISSING_PRIMARY_CBFS;
}
struct fmap *flashmap = fmap_from_fmd(descriptor);
if (!flashmap) {
fputs("FATAL: Failed while constructing FMAP section\n",
stderr);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_FAILED_FMAP_CONVERSION;
}
int size = fmap_size(flashmap);
if (size < 0) {
fputs("FATAL: Failed to determine FMAP section size\n",
stderr);
fmap_destroy(flashmap);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_UNKNOWN_FMAP_SIZE;
}
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
FILE *fmap_file = fopen(args.fmap_filename, "wb");
if (!fmap_file) {
fprintf(stderr, "FATAL: Unable to open file '%s' for writing\n",
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
args.fmap_filename);
fmap_destroy(flashmap);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_BAD_OUTPUT_PATH;
}
if (!fwrite(flashmap, size, 1, fmap_file)) {
fputs("FATAL: Failed to write final FMAP to file\n", stderr);
fclose(fmap_file);
fmap_destroy(flashmap);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_FAILED_WRITING_OUTPUT;
}
fclose(fmap_file);
fmap_destroy(flashmap);
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
if (args.header_filename &&
!write_header(args.header_filename, descriptor, size)) {
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_FAILED_WRITING_HEADER;
}
fprintf(stderr, "SUCCESS: Wrote %d bytes to file '%s'%s\n", size,
args.fmap_filename,
args.header_filename ? " (and generated header)" : "");
fputs("The sections containing CBFSes are: ", stderr);
list_cbfs_section_names(stdout);
if (args.region_filename) {
FILE *region_file = fopen(args.region_filename, "w");
if (region_file == NULL)
return FMAPTOOL_EXIT_FAILED_WRITING_OUTPUT;
list_cbfs_section_names(region_file);
fclose(region_file);
}
fmaptool: Add listing of annotated CBFS sections and generate header The fmd compiler now processes "(CBFS)" annotations, distilling them into a comma-separated list of the names of sections containing CBFSes. This list is the only thing printed to standard output to enable easy capture and machine consumption by other tools. Additionally, the ability to generate a tiny header with a define for the primary CBFS's size is implemented and can be requested via a new command-line switch. Here's an example of how to use the new features: $ ./fmaptool -h layout.h layout_arm_8192.fmd layout.fmap 2>/dev/null FW_MAIN_A,FW_MAIN_B,COREBOOT The hypothetical fmd file contains three sections annotated as (CBFS), the names of which are printed to standard output. As before, a binary FMAP file named layout.fmap is created; however, because the command was invoked with -h, a header #define ing the offset of its FMAP section (i.e. where it will be relative to the base of flash once the boot image is assembled) is also generated. BUG=chromium:470407 TEST=Verify that fmd files without a "COREBOOT" section or with one that isn't annotated as "(CBFS)" are not accepted. Ensure that the list of CBFS sections matches the descriptor file's annotations and is led by the "COREBOOT" section. Invoke with the header generation switch and check that output file for reasonableness. BRANCH=None Change-Id: I496dd937f69467bfd9233c28df59c7608e89538f Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 9227698adecf675770b2983380eb570676c2b5d2 Original-Change-Id: I8b32f6ef19cabe2f6760106e676683c4565bbaad Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262956 Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/9967 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2015-03-18 18:13:48 +01:00
full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_SUCCESS;
}