📄 romimage.cpp
字号:
FATAL(write_bin(hole_list, copy_list, module_list, file_list, memory_list, reserve_list, kernel, config, mem_itr));
// final pass stuff
if(!config.autosize){
static char *debug_nocomp = (debug_nocomp = getenv("ri_debug_info")) ? strstr(debug_nocomp, "nocomp") : NULL;
// compact bin
if(!debug_nocomp)
FATAL(compact_bin(config.output_file));
}
}
}
}while(config.autosize--);
// process the chain file
if(config.xipchain){
if(config.output_file.rfind("\\") != string::npos)
config.output_file = config.output_file.substr(0, config.output_file.rfind("\\"));
config.output_file += "\\chain.bin";
FATAL(write_chain(config, memory_list));
FATAL(cat_bins(config.output_file));
FATAL(compact_bin(config.output_file));
}
if(config.bSRE ||
kernel->memory_iterator()->type() == ROM8_TYPE ||
kernel->memory_iterator()->type() == ROM16_TYPE ||
kernel->memory_iterator()->type() == ROMx8_TYPE)
FATAL(write_sre(config.output_file, kernel->memory_iterator()->type(), config.rom_info.offset, kernel->entry_rva() + kernel->memory_iterator()->address(), launch));
// write the rom file
if(config.rom_info.start ||
config.rom_info.size ||
config.rom_info.width){
if(// config.rom_info.start && // not sure if start is allowed to be zero sometimes or not. Could work.
config.rom_info.size &&
config.rom_info.width)
FATAL(write_rom(config.output_file, config.rom_info));
else
fprintf(stderr, "Warning: ROMSIZE = %08x and ROMWIDTH = %d, both must be set to generate a ROM\n", config.rom_info.size, config.rom_info.width);
}
// post build warnings about private bits in the image
for(mod_itr = module_list.begin(); mod_itr != module_list.end(); mod_itr++)
if(mod_itr->warn_private_bits())
cerr << "Warning: Module " << mod_itr->name() << " contains updated private code\n";
cout << "Done!\n";
return 0;
}
/*****************************************************************************/
bool process_args(char *argv[], int argc, string &bib_file, string &output_file, bool &launch){
bib_file = getenv("_winceroot") ? getenv("_winceroot") : "\\wince";
bib_file += "\\release\\ram.bib";
for(int i = 0; i < argc; i++){
if(strnicmp(argv[i], "-o", 3) == 0)
output_file = argv[i] + 3;
else if(strnicmp(argv[i], "-g", 3) == 0)
launch = true;
else if(strnicmp(argv[i], "/?", 3) == 0 || argc == 1){
printf("Usage: romimage [options] filename.bib\n\n"
"Valid options are:\n"
" -o output file - defaults to kernelname.bin\n"
" -g - auto launch (only used when generating an sre file)\n"
" /? - this usage statement\n\n"
"Romimage also checks various environment variables\n"
" To suppress various output:\n"
" ri_suppress_info = all,move,module,file,memory,hole,e32,o32,symbol\n\n"
" To comma delimit some of the output lists for easier parsing:\n"
" ri_comma_delimit = 1\n\n");
return false;
}
else if(argv[i][0] != '-')
bib_file = argv[i];
}
char *suppress = (suppress = getenv("ri_suppress_info")) ? strstr(suppress, "all") : NULL;
if(suppress)
_putenv("ri_suppress_info=all,move,module,file,memory,hole,e32,o32,symbol");
return true;
}
/*****************************************************************************/
/*
this is what happens when people want weird features
*/
bool comp_mem_itr(const MemoryList::iterator &mem1, const MemoryList::iterator &mem2){
return mem1->origional_address.address() < mem2->origional_address.address();
}
/*****************************************************************************/
/*
theory here is that we go through all the memory sections on the first pass
and make the ram start and size cover them all (no gaps allowed here).
on the second pass ...
*/
bool pass_state(Config &config, ModuleList &module_list, FileList &file_list, MemoryList &memory_list, MemoryList &reserve_list, ModuleList::iterator &kernel){
static int pass = 0;
static char *debug_show = (debug_show = getenv("ri_debug_info")) ? strstr(debug_show, "allpasses") : NULL;
if(!debug_show)
last_pass = !config.autosize; // is this the last pass. Last pass happens when autosize is 0
if(!config.autosize && !pass)
return true;
printf("\nPass %d...\n\n", ++pass);
MemoryList::iterator mem_itr, mem_itr2, ram_section;
DWORD start = 0xffffffff;
DWORD size = 0;
DWORD dll_code_start = 0;
DWORD dll_code_end = 0;
DWORD dll_data_start = 0;
DWORD dll_data_end = 0;
// autosize stuff
//*********************************************//
// multixip part
if(config.xipchain){
if(config.autosize){
if(config.rom_autosize){
// rom autosize
for(mem_itr = memory_list.begin(); mem_itr != memory_list.end(); mem_itr++){
if(mem_itr->type() == RAM_TYPE)
ram_section = mem_itr;
if(mem_itr->type() == RAMIMAGE_TYPE || mem_itr->type() == NANDIMAGE_TYPE || (mem_itr->type() == RAM_TYPE && config.ram_autosize)){
start = min(start, mem_itr->address());
size += mem_itr->length();
}
}
// automoving the fixupvar for the chain location to the end of everything
if(config.chainvar.size()){
DWORD newchain = start + size;
for(mem_itr = memory_list.begin(); mem_itr != memory_list.end(); mem_itr++){
if(mem_itr->type() == FIXUPVAR_TYPE && mem_itr->name() == config.chainvar){
mem_itr->Address::set(mem_itr->address(), newchain);
break;
}
}
// moving the reserved region
for(mem_itr = reserve_list.begin(); mem_itr != reserve_list.end(); mem_itr++){
if(mem_itr->address() == config.xipchain){
mem_itr->Address::set(newchain, mem_itr->length());
break;
}
}
// move pointer to the end
config.xipchain = newchain;
}
for(mem_itr = memory_list.begin(); mem_itr != memory_list.end(); mem_itr++){
if(mem_itr->type() == RAMIMAGE_TYPE || mem_itr->type() == NANDIMAGE_TYPE || (mem_itr->type() == RAM_TYPE && config.ram_autosize)){
mem_itr->Address::set(start, size);
}
}
}
}
else{
bool setchain = true; // to prevent this from happening every ramimage section through
MemoryList::iterator last;
vector<MemoryList::iterator>::iterator last_itr;
vector<MemoryList::iterator>::iterator mem_itr_itr;
vector<MemoryList::iterator> temp_list;
/* we need to do the rom positioning by address but we can't sort the list directly because
we'll break the iterator links in the modules list. So we'll create a list of iterators
to the memory list. Sort that the way we want it. Then we can process on that for this
step and we don't need to restore the origional list at all.
*/
for(mem_itr = memory_list.begin(); mem_itr != memory_list.end(); mem_itr++)
temp_list.push_back(mem_itr);
sort(temp_list.begin(), temp_list.end(), comp_mem_itr);
// rom positioning
for(last_itr = temp_list.end(), mem_itr_itr = temp_list.begin(); mem_itr_itr != temp_list.end(); mem_itr_itr++){
if((*mem_itr_itr)->type() == RAM_TYPE)
ram_section = *mem_itr_itr;
if((*mem_itr_itr)->type() == RAMIMAGE_TYPE){
if(config.rom_autosize){
if(last_itr != temp_list.end()){
if(setchain && config.chainvar.size()){
DWORD newchain = (*last_itr)->address_end();
// automoving the fixupvar for the chain location to the end of everything
for(mem_itr2 = memory_list.begin(); mem_itr2 != memory_list.end(); mem_itr2++){
if(mem_itr2->type() == FIXUPVAR_TYPE && mem_itr2->name() == config.chainvar){
mem_itr2->Address::set(mem_itr2->address(), newchain);
fprintf(stderr, "Warning: Changed fixupvar %s to point to new chain location %08x\n", mem_itr2->name().c_str(), newchain);
break;
}
}
// moving the reserved region
for(mem_itr2 = reserve_list.begin(); mem_itr2 != reserve_list.end(); mem_itr2++){
if(mem_itr2->address() == config.xipchain){
mem_itr2->Address::set(newchain, mem_itr2->length());
fprintf(stderr, "Warning: Moved Chain file start to %08x\n", newchain);
break;
}
}
if(mem_itr2 == reserve_list.end()){
fprintf(stderr, "Error: Chain address specified in XIPSCHAIN but no matching reserve section found.\n");
return false;
}
start = align_64k((*last_itr)->address_end() + mem_itr2->length());
// move pointer to the end
config.xipchain = newchain;
setchain = false;
}
else
start = align_64k((*last_itr)->address_end());
}
else
start = (*mem_itr_itr)->address();
size = (*mem_itr_itr)->m_romhdr.physlast - (*mem_itr_itr)->m_romhdr.physfirst + (*mem_itr_itr)->rom_gap;
(*mem_itr_itr)->Address::set(start, size);
if(debug_show){
printf("Region %s (%08x - %08x)\n", (*mem_itr_itr)->name().c_str(), (*mem_itr_itr)->address(), (*mem_itr_itr)->address_end());
}
}
last_itr = mem_itr_itr;
}
}
// sort by bib order (origional order) done automaticaly because we never changed it. hahaha
// ram positioning
if(config.ram_autosize){
start = align_64k(start + size);
if(start > ram_section->address())
ram_section->Address::set(start, ram_section->address_end() - start);
else
ram_section->Address::set(start, ram_section->address_end());
if(debug_show){
printf("Ram (%08x - %08x)\n", ram_section->address(), ram_section->address_end());
}
}
// nandimage allocations
for(last = memory_list.end(), mem_itr = memory_list.begin(); mem_itr != memory_list.end(); mem_itr++){
if(mem_itr->type() == NANDIMAGE_TYPE){
if(config.rom_autosize){
if(last != memory_list.end())
start = align_64k(last->address_end());
else
start = align_64k(start + size);
size = mem_itr->m_romhdr.physlast - mem_itr->m_romhdr.physfirst + mem_itr->rom_gap;
mem_itr->Address::set(start, size);
if(debug_show){
printf("Region %s (%08x - %08x)\n", mem_itr->name().c_str(), mem_itr->address(), mem_itr->address_end());
}
}
last = mem_itr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -