summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Lojewski <github@meklort.com>2019-05-05 19:09:47 -0600
committerEvan Lojewski <github@meklort.com>2019-05-05 19:09:47 -0600
commit72eaf56f7ffaeb2d57cfdf63f32963bd08bfb290 (patch)
tree48c3bc01cb6e6cdf4f8e6816d0b2f8e9bb633b52
parent553c58d05e2abb6ad71f04cae392b1e339dcae68 (diff)
downloadbcm5719-ortega-72eaf56f7ffaeb2d57cfdf63f32963bd08bfb290.tar.gz
bcm5719-ortega-72eaf56f7ffaeb2d57cfdf63f32963bd08bfb290.zip
Run ape utilities through clang-format.
-rw-r--r--utils/ape2elf/main.cpp214
-rw-r--r--utils/elf2ape/main.cpp226
2 files changed, 210 insertions, 230 deletions
diff --git a/utils/ape2elf/main.cpp b/utils/ape2elf/main.cpp
index 801f4a9..1fbb427 100644
--- a/utils/ape2elf/main.cpp
+++ b/utils/ape2elf/main.cpp
@@ -42,50 +42,46 @@
/// @endcond
////////////////////////////////////////////////////////////////////////////////
+#include <Compress.h>
#include <NVRam.h>
-#include <bcm5719_eeprom.h>
-
#include <OptionParser.h>
-#include <Compress.h>
-
-
+#include <bcm5719_eeprom.h>
#include <elfio/elfio.hpp>
#define ENTRYPOINT_SYMBOL "__start"
#define VERSION_SYMBOL "VERSION"
-#define STACK_END_SYMBOL "_estack"
+#define STACK_END_SYMBOL "_estack"
#define THUMB_CODE_SYMBOL "$t"
using namespace std;
using namespace ELFIO;
using optparse::OptionParser;
-#define MAX_SIZE (1024u * 256u) /* 256KB - max NVRAM */
+#define MAX_SIZE (1024u * 256u) /* 256KB - max NVRAM */
int main(int argc, char const *argv[])
{
union {
uint8_t bytes[MAX_SIZE];
- uint32_t words[MAX_SIZE/4];
+ uint32_t words[MAX_SIZE / 4];
APEHeader_t header;
} ape;
OptionParser parser = OptionParser().description("BCM APE to elf Utility");
parser.add_option("-i", "--input")
- .dest("input")
- .help("Read from the input ape binary")
- .metavar("FILE");
-
+ .dest("input")
+ .help("Read from the input ape binary")
+ .metavar("FILE");
parser.add_option("-o", "--output")
- .dest("output")
- .help("Save to the specified output elf file")
- .metavar("FILE");
+ .dest("output")
+ .help("Save to the specified output elf file")
+ .metavar("FILE");
optparse::Values options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
- if(!options.is_set("input"))
+ if (!options.is_set("input"))
{
cerr << "Please specify an ape binary to use." << endl;
parser.print_help();
@@ -94,14 +90,14 @@ int main(int argc, char const *argv[])
fstream infile;
infile.open(options["input"], fstream::in | fstream::binary);
- if(infile.is_open())
+ if (infile.is_open())
{
- infile.read((char*)ape.bytes, MAX_SIZE);
+ infile.read((char *)ape.bytes, MAX_SIZE);
- if(ape.words[0] == be32toh(APE_HEADER_MAGIC))
+ if (ape.words[0] == be32toh(APE_HEADER_MAGIC))
{
// The file is swapped... fix it.
- for(int i = 0; i < sizeof(ape)/sizeof(ape.words[0]); i++)
+ for (int i = 0; i < sizeof(ape) / sizeof(ape.words[0]); i++)
{
ape.words[i] = be32toh(ape.words[i]);
}
@@ -115,40 +111,39 @@ int main(int argc, char const *argv[])
exit(-1);
}
-
elfio writer;
-
+
// Setup the elf header
- writer.create( ELFCLASS32, ELFDATA2LSB );
- writer.set_os_abi( ELFOSABI_NONE );
- writer.set_type( ET_EXEC );
- writer.set_machine( EM_ARM );
+ writer.create(ELFCLASS32, ELFDATA2LSB);
+ writer.set_os_abi(ELFOSABI_NONE);
+ writer.set_type(ET_EXEC);
+ writer.set_machine(EM_ARM);
// Create code section
- section* text_sec = writer.sections.add( ".text" );
- segment* text_seg = writer.segments.add();
- text_sec->set_type( SHT_PROGBITS );
- text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR );
- text_sec->set_addr_align( 0x4 );
-
- section* bss_sec = writer.sections.add( ".bss" );
- segment* bss_seg = writer.segments.add();
- bss_sec->set_type( SHT_PROGBITS );
- bss_sec->set_flags( SHF_ALLOC | SHF_WRITE );
- bss_sec->set_addr_align( 0x4 );
-
- section* data_sec = writer.sections.add( ".data" );
- segment* data_seg = writer.segments.add();
- data_sec->set_type( SHT_PROGBITS );
- data_sec->set_flags( SHF_ALLOC | SHF_WRITE );
- data_sec->set_addr_align( 0x4 );
+ section *text_sec = writer.sections.add(".text");
+ segment *text_seg = writer.segments.add();
+ text_sec->set_type(SHT_PROGBITS);
+ text_sec->set_flags(SHF_ALLOC | SHF_EXECINSTR);
+ text_sec->set_addr_align(0x4);
+
+ section *bss_sec = writer.sections.add(".bss");
+ segment *bss_seg = writer.segments.add();
+ bss_sec->set_type(SHT_PROGBITS);
+ bss_sec->set_flags(SHF_ALLOC | SHF_WRITE);
+ bss_sec->set_addr_align(0x4);
+
+ section *data_sec = writer.sections.add(".data");
+ segment *data_seg = writer.segments.add();
+ data_sec->set_type(SHT_PROGBITS);
+ data_sec->set_flags(SHF_ALLOC | SHF_WRITE);
+ data_sec->set_addr_align(0x4);
printf("=== Header ===\n");
printf("Magic: 0x%08X\n", ape.header.magic);
printf("UNK0: 0x%08X\n", ape.header.unk0);
char name[sizeof(ape.header.name) + 1] = {0};
- strncpy(name, (char*)ape.header.name, sizeof(ape.header.name));
+ strncpy(name, (char *)ape.header.name, sizeof(ape.header.name));
printf("Name: %s\n", name);
printf("Version: 0x%08X\n", ape.header.version);
printf("Start: 0x%08X\n", ape.header.entrypoint);
@@ -164,35 +159,36 @@ int main(int argc, char const *argv[])
uint32_t calculated_crc = NVRam_crc(ape.bytes, (4 * ape.header.words), 0);
printf("Calculated CRC: 0x%08X\n", calculated_crc);
- for(int i = 0; i < ape.header.sections; i++)
+ for (int i = 0; i < ape.header.sections; i++)
{
- uint8_t * inBufferPtr = NULL;
- uint8_t * outBufferPtr = NULL;
+ uint8_t *inBufferPtr = NULL;
+ uint8_t *outBufferPtr = NULL;
ssize_t inBufferSize;
ssize_t outBufferSize;
- size_t out_length;
+ size_t out_length;
- APESection_t* section = &ape.header.section[i];
+ APESection_t *section = &ape.header.section[i];
printf("\n=== Section %i ===\n", i);
printf("Load Addr: 0x%08X\n", section->loadAddr);
printf("Offset: 0x%08X\n", section->offset);
printf("Flags: 0x%08X\n", section->flags);
- if(section->flags & APE_SECTION_FLAG_COMPRESSED)
+ if (section->flags & APE_SECTION_FLAG_COMPRESSED)
{
printf(" compressed\n");
}
- if(section->flags & APE_SECTION_FLAG_CHECKSUM_IS_CRC32)
+ if (section->flags & APE_SECTION_FLAG_CHECKSUM_IS_CRC32)
{
printf(" crc32\n");
}
- printf(" %s\n", section->flags & APE_SECTION_FLAG_CODE ? "code" : "data");
- if(section->flags & APE_SECTION_FLAG_UNK0)
+ printf(" %s\n",
+ section->flags & APE_SECTION_FLAG_CODE ? "code" : "data");
+ if (section->flags & APE_SECTION_FLAG_UNK0)
{
printf(" unknown\n");
}
- if(section->flags & APE_SECTION_FLAG_ZERO_ON_FAST_BOOT)
+ if (section->flags & APE_SECTION_FLAG_ZERO_ON_FAST_BOOT)
{
printf(" bss\n");
}
@@ -204,99 +200,97 @@ int main(int argc, char const *argv[])
inBufferSize = section->compressedSize;
outBufferPtr = (uint8_t *)malloc(section->decompressedSize);
outBufferSize = section->decompressedSize;
- out_length = decompress(outBufferPtr, outBufferSize, inBufferPtr, inBufferSize);
+ out_length =
+ decompress(outBufferPtr, outBufferSize, inBufferPtr, inBufferSize);
calculated_crc = NVRam_crc(outBufferPtr, outBufferSize, 0);
printf("out_length: 0x%08zX\n", out_length);
printf("out CRC: 0x%08X\n", calculated_crc);
- if(ape.header.sections == 4 && i == 0) continue;
- if(section->flags & APE_SECTION_FLAG_ZERO_ON_FAST_BOOT)
+ if (ape.header.sections == 4 && i == 0)
+ continue;
+ if (section->flags & APE_SECTION_FLAG_ZERO_ON_FAST_BOOT)
{
- bss_sec->set_data((const char*)outBufferPtr, out_length);
- bss_seg->set_type( PT_LOAD );
- bss_seg->set_virtual_address( section->loadAddr );
- bss_seg->set_physical_address( section->loadAddr );
- bss_seg->set_flags( PF_W | PF_R );
- bss_seg->set_align( 0x4 );
+ bss_sec->set_data((const char *)outBufferPtr, out_length);
+ bss_seg->set_type(PT_LOAD);
+ bss_seg->set_virtual_address(section->loadAddr);
+ bss_seg->set_physical_address(section->loadAddr);
+ bss_seg->set_flags(PF_W | PF_R);
+ bss_seg->set_align(0x4);
// Add data section into data segment
- bss_seg->add_section_index( bss_sec->get_index(), bss_sec->get_addr_align() );
+ bss_seg->add_section_index(bss_sec->get_index(),
+ bss_sec->get_addr_align());
}
- else if(!(section->flags & APE_SECTION_FLAG_CODE))
+ else if (!(section->flags & APE_SECTION_FLAG_CODE))
{
- data_sec->set_data((const char*)outBufferPtr, out_length);
- data_seg->set_type( PT_LOAD );
- data_seg->set_virtual_address( section->loadAddr );
- data_seg->set_physical_address( section->loadAddr );
- data_seg->set_flags( PF_W | PF_R );
- data_seg->set_align( 0x4 );
+ data_sec->set_data((const char *)outBufferPtr, out_length);
+ data_seg->set_type(PT_LOAD);
+ data_seg->set_virtual_address(section->loadAddr);
+ data_seg->set_physical_address(section->loadAddr);
+ data_seg->set_flags(PF_W | PF_R);
+ data_seg->set_align(0x4);
// Add data section into data segment
- data_seg->add_section_index( data_sec->get_index(), data_sec->get_addr_align() );
+ data_seg->add_section_index(data_sec->get_index(),
+ data_sec->get_addr_align());
}
else
{
- text_sec->set_data((const char*)outBufferPtr, out_length);
- text_seg->set_type( PT_LOAD );
- text_seg->set_virtual_address( section->loadAddr );
- text_seg->set_physical_address( section->loadAddr );
- text_seg->set_flags( PF_X | PF_R );
- text_seg->set_align( 0x4 );
+ text_sec->set_data((const char *)outBufferPtr, out_length);
+ text_seg->set_type(PT_LOAD);
+ text_seg->set_virtual_address(section->loadAddr);
+ text_seg->set_physical_address(section->loadAddr);
+ text_seg->set_flags(PF_X | PF_R);
+ text_seg->set_align(0x4);
// Add code section into program segment
- text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() );
-
+ text_seg->add_section_index(text_sec->get_index(),
+ text_sec->get_addr_align());
}
}
- if(options.is_set("output"))
+ if (options.is_set("output"))
{
// REcord entry-point address
writer.set_entry(ape.header.entrypoint);
// Create string table section
- section* str_sec = writer.sections.add( ".strtab" );
- str_sec->set_type ( SHT_STRTAB );
+ section *str_sec = writer.sections.add(".strtab");
+ str_sec->set_type(SHT_STRTAB);
// Create string table writer
- string_section_accessor stra( str_sec );
+ string_section_accessor stra(str_sec);
// Create symbol table section
- section* sym_sec = writer.sections.add( ".symtab" );
- sym_sec->set_type ( SHT_SYMTAB );
- sym_sec->set_info ( 2 );
- sym_sec->set_addr_align( 0x4 );
- sym_sec->set_entry_size( writer.get_default_entry_size( SHT_SYMTAB ) );
- sym_sec->set_link ( str_sec->get_index() );
+ section *sym_sec = writer.sections.add(".symtab");
+ sym_sec->set_type(SHT_SYMTAB);
+ sym_sec->set_info(2);
+ sym_sec->set_addr_align(0x4);
+ sym_sec->set_entry_size(writer.get_default_entry_size(SHT_SYMTAB));
+ sym_sec->set_link(str_sec->get_index());
// Create symbol table writer
- symbol_section_accessor syma( writer, sym_sec );
-
+ symbol_section_accessor syma(writer, sym_sec);
// Add label name
- Elf32_Word _start = stra.add_string( ENTRYPOINT_SYMBOL );
- Elf32_Word _thumb = stra.add_string( THUMB_CODE_SYMBOL );
- Elf32_Word _version = stra.add_string( VERSION_SYMBOL );
+ Elf32_Word _start = stra.add_string(ENTRYPOINT_SYMBOL);
+ Elf32_Word _thumb = stra.add_string(THUMB_CODE_SYMBOL);
+ Elf32_Word _version = stra.add_string(VERSION_SYMBOL);
// Add symbol entry
- syma.add_symbol( _start, ape.header.entrypoint, 0, STB_GLOBAL,
- STT_FUNC, 0,
- text_sec->get_index() );
-
- syma.add_symbol( _thumb, ape.header.entrypoint & 0xfffffffe, 0, STB_LOCAL,
- STT_OBJECT, 0,
- text_sec->get_index() );
+ syma.add_symbol(_start, ape.header.entrypoint, 0, STB_GLOBAL, STT_FUNC,
+ 0, text_sec->get_index());
- syma.add_symbol( _version, ape.header.version, 0, STB_GLOBAL,
- STT_OBJECT, 0,
- text_sec->get_index() );
+ syma.add_symbol(_thumb, ape.header.entrypoint & 0xfffffffe, 0,
+ STB_LOCAL, STT_OBJECT, 0, text_sec->get_index());
- uint32_t* vectors = (uint32_t*)text_sec->get_data();
- Elf32_Word index = stra.add_string( STACK_END_SYMBOL );
- syma.add_symbol( index, vectors[0], 0, STB_GLOBAL,
- STT_OBJECT, 0,
- data_sec->get_index() );
+ syma.add_symbol(_version, ape.header.version, 0, STB_GLOBAL, STT_OBJECT,
+ 0, text_sec->get_index());
+ uint32_t *vectors = (uint32_t *)text_sec->get_data();
+ Elf32_Word index = stra.add_string(STACK_END_SYMBOL);
+ syma.add_symbol(index, vectors[0], 0, STB_GLOBAL, STT_OBJECT, 0,
+ data_sec->get_index());
// Create ELF file
writer.save(options["output"]);
diff --git a/utils/elf2ape/main.cpp b/utils/elf2ape/main.cpp
index 7a372ba..f824eb5 100644
--- a/utils/elf2ape/main.cpp
+++ b/utils/elf2ape/main.cpp
@@ -42,13 +42,10 @@
/// @endcond
////////////////////////////////////////////////////////////////////////////////
-
-
-#include <bcm5719_eeprom.h>
-#include <NVRam.h>
#include <Compress.h>
-
+#include <NVRam.h>
#include <OptionParser.h>
+#include <bcm5719_eeprom.h>
#include <elfio/elfio.hpp>
using namespace ELFIO;
@@ -56,43 +53,43 @@ using namespace ELFIO;
using namespace std;
using optparse::OptionParser;
-
-
-uint64_t get_symbol_value(const char* search, elfio &reader)
+uint64_t get_symbol_value(const char *search, elfio &reader)
{
- const symbol_section_accessor* psyms = NULL;
+ const symbol_section_accessor *psyms = NULL;
Elf_Half sec_num = reader.sections.size();
- for ( int
- i = 0; i < sec_num; ++i ) {
- section* psec = reader.sections[i];
+ for (int i = 0; i < sec_num; ++i)
+ {
+ section *psec = reader.sections[i];
// Check section type
- if ( psec->get_type() == SHT_SYMTAB ) {
- psyms = new symbol_section_accessor( reader, psec );
+ if (psec->get_type() == SHT_SYMTAB)
+ {
+ psyms = new symbol_section_accessor(reader, psec);
break;
}
}
- if(psyms)
+ if (psyms)
{
- for ( unsigned int j = 0; j < psyms->get_symbols_num(); ++j ) {
- std::string name;
- Elf64_Addr value;
- Elf_Xword size;
+ for (unsigned int j = 0; j < psyms->get_symbols_num(); ++j)
+ {
+ std::string name;
+ Elf64_Addr value;
+ Elf_Xword size;
unsigned char bind;
unsigned char type;
- Elf_Half section_index;
+ Elf_Half section_index;
unsigned char other;
-
+
// Read symbol properties
- psyms->get_symbol( j, name, value, size, bind,
- type, section_index, other );
+ psyms->get_symbol(j, name, value, size, bind, type, section_index,
+ other);
// std::cout << j << " " << name << " " << value << std::endl;
- if(name == search)
+ if (name == search)
{
return value;
- }
+ }
}
delete psyms;
@@ -101,11 +98,11 @@ uint64_t get_symbol_value(const char* search, elfio &reader)
return 0;
}
-bool save_to_file(const char* filename, void* buffer, size_t size)
+bool save_to_file(const char *filename, void *buffer, size_t size)
{
cout << "Writing to " << filename << "." << endl;
- FILE* out = fopen(filename, "w+");
- if(out)
+ FILE *out = fopen(filename, "w+");
+ if (out)
{
fwrite(buffer, size, 1, out);
fclose(out);
@@ -118,144 +115,132 @@ bool save_to_file(const char* filename, void* buffer, size_t size)
}
}
-#define MAX_SIZE (1024u * 256u) /* 256KB - max NVRAM */
+#define MAX_SIZE (1024u * 256u) /* 256KB - max NVRAM */
int main(int argc, char const *argv[])
{
uint32_t byteOffset = 0;
int numSections = 0;
union {
- uint8_t bytes[MAX_SIZE];
- uint32_t words[MAX_SIZE/4];
+ uint8_t bytes[MAX_SIZE];
+ uint32_t words[MAX_SIZE / 4];
APEHeader_t header;
} ape;
OptionParser parser = OptionParser().description("BCM elf 2 APE Utility");
parser.add_option("-i", "--input")
- .dest("input")
- .help("Input elf file to convert")
- .metavar("FILE");
-
+ .dest("input")
+ .help("Input elf file to convert")
+ .metavar("FILE");
parser.add_option("-o", "--output")
- .dest("output")
- .help("Output ape binary")
- .metavar("FILE");
+ .dest("output")
+ .help("Output ape binary")
+ .metavar("FILE");
optparse::Values options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
- if(!options.is_set("input"))
+ if (!options.is_set("input"))
{
cerr << "Please specify an input elf file to use." << endl;
parser.print_help();
exit(-1);
}
- if(!options.is_set("output"))
+ if (!options.is_set("output"))
{
cerr << "Please specify an output binary to write." << endl;
parser.print_help();
exit(-1);
}
-
elfio reader;
-
- if(!reader.load(options["input"]))
+
+ if (!reader.load(options["input"]))
{
- printf( "File %s is not found or it is not a valid ELF file\n", argv[1] );
+ printf("File %s is not found or it is not a valid ELF file\n", argv[1]);
return 1;
}
- // writer.set_os_abi( ELFOSABI_LINUX );
+ // writer.set_os_abi( ELFOSABI_LINUX );
// writer.set_type( ET_EXEC );
// writer.set_machine( EM_ARM );
-
// Ensure that this is the correct elf type.
- if( reader.get_class() != ELFCLASS32 ||
+ if (reader.get_class() != ELFCLASS32 ||
reader.get_encoding() != ELFDATA2LSB ||
- reader.get_machine() != EM_ARM ||
- reader.get_type() != ET_EXEC
- )
+ reader.get_machine() != EM_ARM || reader.get_type() != ET_EXEC)
{
- printf( "Only 32-bit little-endian arm binaries are supported\n");
+ printf("Only 32-bit little-endian arm binaries are supported\n");
return 1;
}
// Determine number of output sections.
Elf_Half seg_num = reader.segments.size();
- for ( int i = 0; i < seg_num; ++i )
+ for (int i = 0; i < seg_num; ++i)
{
- const segment* pseg = reader.segments[i];
- for(int j = 0; j < pseg->get_sections_num(); j++)
+ const segment *pseg = reader.segments[i];
+ for (int j = 0; j < pseg->get_sections_num(); j++)
{
Elf_Half idx = pseg->get_section_index_at(j);
- section* psec = reader.sections[idx];
- if(psec->get_flags() & SHF_ALLOC)
+ section *psec = reader.sections[idx];
+ if (psec->get_flags() & SHF_ALLOC)
{
numSections++;
}
}
}
-
byteOffset = (sizeof(ape.header) + sizeof(APESection_t) * numSections);
// Print ELF file segments info
std::cout << "Number of segments: " << seg_num << std::endl;
numSections = 0;
- for ( int i = 0; i < seg_num; ++i )
+ for (int i = 0; i < seg_num; ++i)
{
- const segment* pseg = reader.segments[i];
- std::cout << " [" << i << "] 0x" << std::hex
- << pseg->get_flags()
- << "\tVirt: 0x"
- << pseg->get_virtual_address()
- << "\tFileSize: 0x"
- << pseg->get_file_size()
- << "\tSize: 0x"
- << pseg->get_memory_size()
- << "\tFlags: 0x"
- << pseg->get_flags()
- << std::endl;
-
- for(int j = 0; j < pseg->get_sections_num(); j++)
+ const segment *pseg = reader.segments[i];
+ std::cout << " [" << i << "] 0x" << std::hex << pseg->get_flags()
+ << "\tVirt: 0x" << pseg->get_virtual_address()
+ << "\tFileSize: 0x" << pseg->get_file_size() << "\tSize: 0x"
+ << pseg->get_memory_size() << "\tFlags: 0x"
+ << pseg->get_flags() << std::endl;
+
+ for (int j = 0; j < pseg->get_sections_num(); j++)
{
Elf_Half idx = pseg->get_section_index_at(j);
- section* psec = reader.sections[idx];
- if(psec->get_flags() & SHF_ALLOC)
+ section *psec = reader.sections[idx];
+ if (psec->get_flags() & SHF_ALLOC)
{
- std::cout << " [" << j << "] "
- << psec->get_name()
- << "\t"
- << psec->get_size()
- << "\tType: 0x"
- << psec->get_type()
- << "\tFlags: 0x"
- << psec->get_flags()
- << "\tAddr: 0x"
- << psec->get_address()
- << std::endl;
+ std::cout << " [" << j << "] " << psec->get_name() << "\t"
+ << psec->get_size() << "\tType: 0x"
+ << psec->get_type() << "\tFlags: 0x"
+ << psec->get_flags() << "\tAddr: 0x"
+ << psec->get_address() << std::endl;
APESection_t *section = &ape.header.section[numSections++];
section->flags = 0;
section->offset = byteOffset;
- const char* data = psec->get_data();
- if(data)
+ const char *data = psec->get_data();
+ if (data)
{
- uint32_t compressedSize = compress((uint8_t*)&ape.bytes[byteOffset], psec->get_size() * 2, // Output, compressed
- (const uint8_t*)data, psec->get_size()); // input, uncompressed
+ uint32_t compressedSize =
+ compress((uint8_t *)&ape.bytes[byteOffset],
+ psec->get_size() * 2, // Output, compressed
+ (const uint8_t *)data,
+ psec->get_size()); // input, uncompressed
// ROund up to nearest word.
compressedSize = ((compressedSize + 3) / 4) * 4;
section->compressedSize = compressedSize;
byteOffset += section->compressedSize;
- // memcpy(&ape.bytes[byteOffset], compressed, section->compressedSize);
- // byteOffset += section->compressedSize;
- section->crc = NVRam_crc((const uint8_t*)data, psec->get_size(), 0);
- section->flags |= APE_SECTION_FLAG_CHECKSUM_IS_CRC32 | APE_SECTION_FLAG_COMPRESSED;
+ // memcpy(&ape.bytes[byteOffset], compressed,
+ // section->compressedSize); byteOffset +=
+ // section->compressedSize;
+ section->crc =
+ NVRam_crc((const uint8_t *)data, psec->get_size(), 0);
+ section->flags |= APE_SECTION_FLAG_CHECKSUM_IS_CRC32 |
+ APE_SECTION_FLAG_COMPRESSED;
}
else
{
@@ -266,12 +251,11 @@ int main(int argc, char const *argv[])
section->decompressedSize = psec->get_size();
section->loadAddr = psec->get_address();
- if(psec->get_flags() & SHF_EXECINSTR)
+ if (psec->get_flags() & SHF_EXECINSTR)
{
section->flags |= APE_SECTION_FLAG_CODE;
}
}
-
}
}
@@ -281,17 +265,18 @@ int main(int argc, char const *argv[])
ape.header.version = get_symbol_value("VERSION", reader);
ape.header.entrypoint = get_symbol_value("__start", reader);
ape.header.unk1 = APE_HEADER_UNK1;
- ape.header.words = (sizeof(ape.header) + sizeof(APESection_t) * numSections) / 4;
+ ape.header.words =
+ (sizeof(ape.header) + sizeof(APESection_t) * numSections) / 4;
ape.header.unk2 = APE_HEADER_UNK2;
ape.header.sections = numSections;
ape.header.crc = 0;
///
- printf("Magic: 0x%08X\n", ape.header.magic);
+ printf("Magic: 0x%08X\n", ape.header.magic);
printf("UNK0: 0x%08X\n", ape.header.unk0);
char name[sizeof(ape.header.name) + 1] = {0};
- strncpy(name, (char*)ape.header.name, sizeof(ape.header.name));
+ strncpy(name, (char *)ape.header.name, sizeof(ape.header.name));
printf("Name: %s\n", name);
printf("Version: 0x%08X\n", ape.header.version);
printf("Start: 0x%08X\n", ape.header.entrypoint);
@@ -305,13 +290,10 @@ int main(int argc, char const *argv[])
// ...
-
-
calculated_crc = NVRam_crc(ape.bytes, (4 * ape.header.words), 0);
ape.header.crc = calculated_crc;
printf("Calculated CRC: 0x%08X\n", calculated_crc);
-
save_to_file(options["output"].c_str(), ape.bytes, byteOffset);
// fstream infile;
@@ -330,13 +312,12 @@ int main(int argc, char const *argv[])
// }
// else
// {
- // cerr << " Unable to open file '" << options["filename"] << "'" << endl;
- // exit(-1);
+ // cerr << " Unable to open file '" << options["filename"] << "'" <<
+ // endl; exit(-1);
// }
-
// elfio writer;
-
+
// // You can't proceed without this function call!
// writer.create( ELFCLASS32, ELFDATA2LSB );
// writer.set_os_abi( ELFOSABI_LINUX );
@@ -380,8 +361,8 @@ int main(int argc, char const *argv[])
// printf("CRC: 0x%08X\n", ape.header.crc);
// ape.header.crc = 0;
- // uint32_t calculated_crc = NVRam_crc(ape.bytes, (4 * ape.header.words), 0);
- // printf("Calculated CRC: 0x%08X\n", calculated_crc);
+ // uint32_t calculated_crc = NVRam_crc(ape.bytes, (4 * ape.header.words),
+ // 0); printf("Calculated CRC: 0x%08X\n", calculated_crc);
// for(int i = 0; i < ape.header.sections; i++)
// {
@@ -406,8 +387,8 @@ int main(int argc, char const *argv[])
// {
// printf(" crc32\n");
// }
- // printf(" %s\n", section->flags & APE_SECTION_FLAG_CODE ? "code" : "data");
- // if(section->flags & APE_SECTION_FLAG_UNK0)
+ // printf(" %s\n", section->flags & APE_SECTION_FLAG_CODE ? "code" :
+ // "data"); if(section->flags & APE_SECTION_FLAG_UNK0)
// {
// printf(" unknown\n");
// }
@@ -423,18 +404,20 @@ int main(int argc, char const *argv[])
// inBufferSize = section->compressedSize;
// outBufferPtr = (uint8_t *)malloc(section->decompressedSize);
// outBufferSize = section->decompressedSize;
- // out_length = decompress(outBufferPtr, outBufferSize, inBufferPtr, inBufferSize);
- // calculated_crc = NVRam_crc(outBufferPtr, outBufferSize, 0);
- // printf("out_length: 0x%08zX\n", out_length);
- // printf("out CRC: 0x%08X\n", calculated_crc);
+ // out_length = decompress(outBufferPtr, outBufferSize, inBufferPtr,
+ // inBufferSize); calculated_crc = NVRam_crc(outBufferPtr,
+ // outBufferSize, 0); printf("out_length: 0x%08zX\n",
+ // out_length); printf("out CRC: 0x%08X\n",
+ // calculated_crc);
// uint8_t* compOut = (uint8_t*)malloc(out_length * 2);
// int32_t compOutSize = out_length*2;
- // int32_t recomp = compress(compOut, compOutSize, outBufferPtr, out_length);
- // printf("recompressed length: 0x%08X\n", recomp);
+ // int32_t recomp = compress(compOut, compOutSize, outBufferPtr,
+ // out_length); printf("recompressed length: 0x%08X\n",
+ // recomp);
- // out_length = decompress(outBufferPtr, outBufferSize, compOut, recomp);
- // calculated_crc = NVRam_crc(outBufferPtr, outBufferSize, 0);
+ // out_length = decompress(outBufferPtr, outBufferSize, compOut,
+ // recomp); calculated_crc = NVRam_crc(outBufferPtr, outBufferSize, 0);
// printf("out_length: 0x%08zX\n", out_length);
// printf("try CRC: 0x%08X\n", calculated_crc);
@@ -454,7 +437,8 @@ int main(int argc, char const *argv[])
// bss_seg->set_align( 0x4 );
// // Add data section into data segment
- // bss_seg->add_section_index( bss_sec->get_index(), bss_sec->get_addr_align() );
+ // bss_seg->add_section_index( bss_sec->get_index(),
+ // bss_sec->get_addr_align() );
// }
// else if(!(section->flags & APE_SECTION_FLAG_CODE))
// {
@@ -466,7 +450,8 @@ int main(int argc, char const *argv[])
// data_seg->set_align( 0x4 );
// // Add data section into data segment
- // data_seg->add_section_index( data_sec->get_index(), data_sec->get_addr_align() );
+ // data_seg->add_section_index( data_sec->get_index(),
+ // data_sec->get_addr_align() );
// }
// else
// {
@@ -478,7 +463,8 @@ int main(int argc, char const *argv[])
// text_seg->set_align( 0x4 );
// // Add code section into program segment
- // text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() );
+ // text_seg->add_section_index( text_sec->get_index(),
+ // text_sec->get_addr_align() );
// }
// }
OpenPOWER on IntegriCloud