diff --git a/CMakeLists.txt b/CMakeLists.txt index ce4e4e24b44f0c1b5b487f4cf8ffb2a1b0545e5d..e355f4177b7158e22f2fcbcc3c30f3b7e4be661e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ ENDFOREACH(src) #this would be text->.h add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/patch.S DEPENDS ${p_source_files} - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gen_patch.py ${ROM_OFFSET} ${CMAKE_CURRENT_SOURCE_DIR}/src/patch.S ${p_source_files} + COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/gen_patch.py ${ROM_OFFSET} ${CMAKE_CURRENT_SOURCE_DIR}/src/patch.S ${p_source_files} ) set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/patch.S) add_custom_target( generate_patch DEPENDS ${p_source_files} ) @@ -25,12 +25,12 @@ add_custom_target( generate_patch DEPENDS ${p_source_files} ) set(SRC_LIST ${c_source_files} ${s_source_files} ${CMAKE_CURRENT_SOURCE_DIR}/src/patch.S) add_executable(game ${SRC_LIST}) add_dependencies( game generate_patch ) -target_link_libraries(game c nosys gcc g m) +target_link_libraries(game c gcc g m) #custom command to use objcopy to create .bin files out of ELF files function(apply_patch INPUT) add_custom_command(TARGET ${INPUT} POST_BUILD - COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/app_patch.py ${CROSS_COMPILE} ${INPUT} ${GAME_MAP} ${CMAKE_CURRENT_SOURCE_DIR}/${ROM_INPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${ROM_OUTPUT} + COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/app_patch.py ${CROSS_COMPILE} ${INPUT} ${GAME_MAP} ${CMAKE_CURRENT_SOURCE_DIR}/${ROM_INPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${ROM_OUTPUT} COMMENT "Generating Final ROM") set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${ROM_OUTPUT}) endfunction(apply_patch) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..bce2d74a8ccb469d16e79dddf25c8494d141a899 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM ubuntu:18.04 + +MAINTAINER @XingXing + +RUN echo Asia/Chongqing > /etc/timezone && \ + echo tzdata tzdata/Areas select Asia | debconf-set-selections && \ + echo tzdata tzdata/Zones/Asia select Chongqing | debconf-set-selections + +ADD sources.list /etc/apt/ + +RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + gcc \ + gcc-m68k-linux-gnu \ + gcc-arm-linux-gnueabi \ + git \ + cmake \ + make \ + python3 \ + zip + +RUN groupadd -g 1000 dockerbot && useradd -g 1000 -u 1000 -m dockerbot +USER dockerbot + + diff --git a/app_patch.py b/app_patch.py index 42af0fd69fd27d9c5c459a9b3e19e514e1cd3354..fd57738f34a17c360247ec7429f6eeacb4ebad93 100644 --- a/app_patch.py +++ b/app_patch.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding:utf-8 -*- # (c) 2016 XingXing(HappyASR#gmail.com) @@ -6,44 +6,57 @@ import os import re import sys -def patch_file(crosstools,fileelf,filemap,fileori,fileout): - print 'processing', fileout - map_list = [] - for c in open(filemap,'r').readlines(): - if c.startswith('.rom'): - c=c.strip(' ').strip('\n') - c=re.split('\s*',c) - rom_base = int(c[1],16) - if '__patch_end_' in c or '__patch_start_' in c: - c=c.strip(' ').strip('\n') - c=re.split('\s*',c) - map_list.append( (int(c[0],16)-rom_base,c[1]) ) - #print c - map_list.sort() - #print map_list - dat_ori = open(fileori,'rb').read() - len_ori = len(dat_ori) - #dat_pat = open(filerom,'rb').read()+open(fileram,'rb').read() - os.system( "%sobjcopy.exe -Obinary -j.rom %s rom.bin" % (crosstools,fileelf)) - os.system( "%sobjcopy.exe -Obinary -j.ram %s ram.bin" % (crosstools,fileelf)) - dat_pat = open("rom.bin",'rb').read()+open("ram.bin",'rb').read() - os.remove("rom.bin") - os.remove("ram.bin") - for i in range(len(map_list)/2): - pat_start = map_list[2*i][0] - pat_end = map_list[2*i+1][0] - if(pat_end!=pat_start): - #print "%x-%x" % (pat_start,pat_end) - dat_ori = dat_ori[:pat_start]+dat_pat[pat_start:pat_end]+dat_ori[pat_end:] - dat_ori = dat_ori[:map_list[-1][0]]+dat_pat[map_list[-1][0]:]+dat_ori[len(dat_pat):] - len_now = len(dat_ori) - dat_ori += '\xFF'*(len_ori-len_now) - open(fileout,'wb').write(dat_ori) - print "Saved OK." - -if __name__=='__main__': - if len(sys.argv)>5: - patch_file(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5]) - else: - print "%s " % sys.argv[0] - sys.exit(1) \ No newline at end of file + +def parse_map(filemap): + map_list = [] + map_dat = open(filemap).read() + #.rom 0x0000000000100000 0x38a130 + r = re.findall(r"\n.rom\s+0x(\w+)", map_dat) + rom_base = int(r[0], 16) + # 0x0000000000100000 __patch_end_0x55c18 + r = re.findall(r"\n\s+0x(\w+)\s+(__patch_\S+_\S+)", map_dat) + for c in r: + map_list.append((int(c[0], 16) - rom_base, c[1])) + map_list.sort() + return map_list + +def patch_dat(dat_ori, dat_pat, pat_start, pat_end): + dat = dat_ori[:pat_start] + dat += dat_pat[pat_start:pat_end] + dat += dat_ori[pat_end:] + return dat + + +def patch_file(crosstools, fileelf, filemap, fileori, fileout): + print('processing', fileout) + map_list = parse_map(filemap) + + dat_ori = open(fileori, 'rb').read() + len_ori = len(dat_ori) + #dat_pat = open(filerom,'rb').read()+open(fileram,'rb').read() + os.system("%sobjcopy -Obinary -j.rom %s rom.bin" % (crosstools, fileelf)) + os.system("%sobjcopy -Obinary -j.ram %s ram.bin" % (crosstools, fileelf)) + dat_pat = open("rom.bin", 'rb').read() + open("ram.bin", 'rb').read() + os.remove("rom.bin") + os.remove("ram.bin") + for i in range(len(map_list) // 2): + pat_start = map_list[2 * i][0] + pat_end = map_list[2 * i + 1][0] + if (pat_end != pat_start): + dat_ori = patch_dat(dat_ori, dat_pat, pat_start, pat_end) + + c_addr = map_list[-1][0] + dat_ori = dat_ori[:c_addr] + dat_pat[c_addr:] + dat_ori[len(dat_pat):] + len_now = len(dat_ori) + dat_ori += b'\xFF' * (len_ori - len_now) + open(fileout, 'wb').write(dat_ori) + print("Saved OK.") + + +if __name__ == '__main__': + if len(sys.argv) > 5: + patch_file(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], + sys.argv[5]) + else: + print("%s " % sys.argv[0]) + sys.exit(1) diff --git a/gen_patch.py b/gen_patch.py index 2e657a47541ec552f6795f7b41216bf6bc2f6955..dabd737819c23f6bf3e59b9b7d1dcdd2d8c74f97 100644 --- a/gen_patch.py +++ b/gen_patch.py @@ -1,61 +1,70 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding:utf-8 -*- # (c) 2016 XingXing(HappyASR#gmail.com) -TOKEN_PATCH = 'XXPATCH' import os import re import sys +TOKEN_PATCH = 'XXPATCH' + + #return (org,file,line,str) def process_asm(filename): - resp = [] - print 'processing', filename - dat = open(filename).read() - dat = re.sub('//[ \t]*'+TOKEN_PATCH, '//$$PATCH', dat) - dat = dat.split(TOKEN_PATCH) - resp.append( (0,filename,0,dat[0]) ) - linecount = dat[0].count('\n') - for c in dat[1:]: - c = c.strip(' ').strip('\t') - org_str = c.split('(')[1].strip() - org_str = re.compile(r'[), ]').split(org_str)[0] - if org_str[:2]=='0x': - org_val = int(org_str,16)&0xfffffff - else: - org_val = int(org_str)&0xfffffff - resp.append( (org_val,filename,linecount,'\t'+TOKEN_PATCH+c) ) - linecount += c.count('\n') - return resp - -def gen_patch(addr_code,outfile,inpdir): - print "outfile=%s" % outfile - basepathlen = len(outfile)-len('src/patch.S') - patch_all = [] - for f in inpdir: - patch_all.extend( process_asm(f) ) - - patch_all.sort() - f = open(outfile,'w+') - f.write(''' + resp = [] + print('processing', filename) + dat = open(filename, encoding='UTF-8').read() + dat = re.sub('//[ \t]*' + TOKEN_PATCH, '//$$PATCH', dat) + dat = dat.split(TOKEN_PATCH) + resp.append((0, filename, 0, dat[0])) + linecount = dat[0].count('\n') + for c in dat[1:]: + c = c.strip(' ').strip('\t') + org_str = c.split('(')[1].strip() + org_str = re.compile(r'[), ]').split(org_str)[0] + if org_str[:2] == '0x': + org_val = int(org_str, 16) & 0xfffffff + else: + org_val = int(org_str) & 0xfffffff + resp.append((org_val, filename, linecount, '\t' + TOKEN_PATCH + c)) + linecount += c.count('\n') + return resp + + +def gen_patch(addr_code, outfile, inpdir): + print("outfile=%s" % outfile) + basepathlen = len(outfile) - len('src/patch.S') + patch_all = [] + for f in inpdir: + patch_all.extend(process_asm(f)) + + patch_all.sort() + f = open(outfile, 'w+', encoding='UTF-8') + f.write(''' #include "xxpacth_include.h" .section .patch,"ax" XXEXPORT_START(dumpy) ''') - for c in patch_all: - #print c - f.write('.file "%s"\n' % c[1][basepathlen:].replace('\\','\\\\')) - f.write('.line %d\n' % c[2]) - f.write(c[3]+'\n') - - f.write('.file __FILE__\n') - f.write('.line __LINE__\n') - f.write('XXEXPORT_END(dumpy)\n') - f.write('.org %s\n' % addr_code) - f.write('XXEXPORT_START(ccode)\n') - f.close() - -if __name__=='__main__': - gen_patch(sys.argv[1],sys.argv[2],sys.argv[3:]) + for c in patch_all: + #print c + f.write('.file "%s"\n' % c[1][basepathlen:].replace('\\', '\\\\')) + f.write('.line %d\n' % c[2]) + f.write(c[3] + '\n') + + f.write('''.file __FILE__ +.line __LINE__ +XXEXPORT_END(dumpy) +.org %s +XXEXPORT_START(ccode) +''' % addr_code) + f.close() + + +if __name__ == '__main__': + if (len(sys.argv) > 3): + gen_patch(sys.argv[1], sys.argv[2], sys.argv[3:]) + else: + print("%s " % sys.argv[0]) + sys.exit(1) diff --git a/pgm.cmake b/pgm.cmake index b61fe10acbf511569f3b0da63bc0f0d3af7ffe68..407179b9cd90cf841b938c0d2795db40c5a35407 100644 --- a/pgm.cmake +++ b/pgm.cmake @@ -13,23 +13,12 @@ set( CMAKE_SYSTEM_PROCESSOR ARMV5 ) # set( TC_PATH "" ) # The toolchain prefix for all toolchain executables -set( CROSS_COMPILE m68k-elf- ) +set( CROSS_COMPILE m68k-linux-gnu- ) -set( CMAKE_C_COMPILER ${TC_PATH}${CROSS_COMPILE}gcc.exe ) -set( CMAKE_CXX_COMPILER ${TC_PATH}${CROSS_COMPILE}g++.exe ) -set( CMAKE_ASM_COMPILER ${TC_PATH}${CROSS_COMPILE}gcc.exe ) - -# specify the cross compiler. We force the compiler so that CMake doesn't -# attempt to build a simple test program as this will fail without us using -# the -nostartfiles option on the command line -CMAKE_FORCE_C_COMPILER( ${CMAKE_C_COMPILER} GNU ) -CMAKE_FORCE_CXX_COMPILER( ${CMAKE_CXX_COMPILER} GNU ) - -# We must set the OBJCOPY setting into cache so that it's available to the -# whole project. Otherwise, this does not get set into the CACHE and therefore -# the build doesn't know what the OBJCOPY filepath is -set( CMAKE_OBJCOPY ${TC_PATH}${CROSS_COMPILE}objcopy.exe - CACHE FILEPATH "The toolchain objcopy command " FORCE ) +set( CMAKE_C_COMPILER ${TC_PATH}${CROSS_COMPILE}gcc ) +set( CMAKE_CXX_COMPILER ${TC_PATH}${CROSS_COMPILE}g++ ) +set( CMAKE_ASM_COMPILER ${TC_PATH}${CROSS_COMPILE}gcc ) +set( CMAKE_OBJCOPY ${TC_PATH}${CROSS_COMPILE}objcopy ) set( GAME_MAP "./game.map") set( ROM_OFFSET "0x380000") diff --git a/sources.list b/sources.list new file mode 100644 index 0000000000000000000000000000000000000000..5ec66c2c58b6992044f8bdb8aa5117760eab7622 --- /dev/null +++ b/sources.list @@ -0,0 +1,48 @@ +# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to +# newer versions of the distribution. +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted + +## Major bug fix updates produced after the final release of the +## distribution. +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted + +## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +## team. Also, please note that software in universe WILL NOT receive any +## review or updates from the Ubuntu security team. +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic universe +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic universe +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-updates universe +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-updates universe + +## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +## team, and may not be under a free licence. Please satisfy yourself as to +## your rights to use the software. Also, please note that software in +## multiverse WILL NOT receive any review or updates from the Ubuntu +## security team. +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic multiverse +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic multiverse +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-updates multiverse +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-updates multiverse + +## N.B. software from this repository may not have been tested as +## extensively as that contained in the main release, although it includes +## newer versions of some applications which may provide useful features. +## Also, please note that software in backports WILL NOT receive any review +## or updates from the Ubuntu security team. +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse + +## Uncomment the following two lines to add software from Canonical's +## 'partner' repository. +## This software is not part of Ubuntu, but is offered by Canonical and the +## respective vendors as a service to Ubuntu users. +# deb http://archive.canonical.com/ubuntu bionic partner +# deb-src http://archive.canonical.com/ubuntu bionic partner + +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-security universe +# deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-security universe +deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-security multiverse