def printparameter(): lines = getcurrentparameterdatalines().split('\n') for l in lines: if l[:8] == 'CMDLINE:': printcmdline( l) else: pprint( l )
def makeROMkits(): '''make ROM kits based on current templates This is a run once process ''' try: src = os.path.join(KitchenConfig.KitchenConfig.KitchenPath, 'ROMtemplates/') dst = 'ROMKits/' pprint('Copying from ' + src + ' to ' + dst) shutil.copytree(src, dst) pprint('Adding images to ROM Kits') pcfilesrc = os.path.join(KitchenConfig.KitchenConfig.KitchenPath, 'processcontrol/populateROMkits') copyfilesworker(pcfilesrc, '', 0, verbose=1) src = 'CWMROMKit.zip' tgt = os.path.join(dst, rominfo.rominfo.romname.strip() + '_' + src) src = os.path.join(dst, src) os.system('mv ' + src + ' ' + tgt) src = 'ROMKit.zip' tgt = os.path.join(dst, rominfo.rominfo.romname.strip() + '_' + src) src = os.path.join(dst, src) os.system('mv ' + src + ' ' + tgt) except Exception as e: logerror('rkmainmenu::makeROMkits ', e, 1)
def printparameter(): lines = getcurrentparameterdatalines().split('\n') for l in lines: if l[:8] == 'CMDLINE:': printcmdline(l) else: pprint(l)
def makeROMkits(): '''make ROM kits based on current templates This is a run once process ''' try: src = os.path.join(KitchenConfig.KitchenConfig.KitchenPath, 'ROMtemplates/') dst = 'ROMKits/' pprint ('Copying from ' + src + ' to ' + dst) shutil.copytree(src,dst) pprint ('Adding images to ROM Kits') pcfilesrc = os.path.join(KitchenConfig.KitchenConfig.KitchenPath,'processcontrol/populateROMkits') copyfilesworker(pcfilesrc,'',0,verbose = 1) src = 'CWMROMKit.zip' tgt = os.path.join(dst,rominfo.rominfo.romname.strip() + '_' + src) src = os.path.join(dst,src) os.system('mv ' + src + ' ' + tgt) src = 'ROMKit.zip' tgt = os.path.join(dst,rominfo.rominfo.romname.strip() + '_' + src) src = os.path.join(dst,src) os.system('mv ' + src + ' ' + tgt) except Exception as e: logerror('rkmainmenu::makeROMkits ',e,1)
def copyImages(): '''copy the unpacked image files to the working folder ''' try: pprint('Copy image and parameter files') #and copy to working, no wilcard support so use glob for file in glob.glob( os.path.join( KitchenConfig.KitchenConfig.SourceROMUnpackedLoc(), 'Image/*.img')): print file shutil.copy(file, 'working') shutil.copy( os.path.join(KitchenConfig.KitchenConfig.SourceROMUnpackedLoc(), 'parameter'), 'working') for file in glob.glob( os.path.join( KitchenConfig.KitchenConfig.SourceROMUnpackedLoc(), '*.bin')): print file shutil.copy(file, 'working') rominfo.rominfo.originalsystemsize = os.stat( 'working/system.img').st_size except Exception as e: logerror('rkmainmenu::copyImages ', e, 1)
def ResizeSystem(): import system try: syssizeH, syssizeI, syssizeM, syssizeG = getsizes(rominfo.rominfo.system.size) ## sysosetH, sysosetI, sysosetM, sysosetG = getsizes( rominfo.rominfo.system.offset) size = long(raw_input('Enter new system size bytes ' + str(syssizeI) + ' :')) if size != syssizeI: size, newuseroffsethex = sizetoparamsize(size,verbose = 1) pprint('Applying these changes will adjust the parameters and system.img files.') apply = raw_input('Apply these changes Y/N:') if apply in ('y','Y'): Resizemtdblock(hex(size/512)[:-1],'system') ## rominfo.rominfo.system.size = hex(size/512)[:-1] ## rominfo.rominfo.user.offset = newuseroffsethex ## rominfo.rominfo.applyparameterchanges() system.shrinksystem() else: print 'No Change' dummy = raw_input('press enter to continue') except Exception as e: logerror('parameter::ResizeSystem ',e,1)
def ResizeSystem(): import system try: syssizeH, syssizeI, syssizeM, syssizeG = getsizes( rominfo.rominfo.system.size) ## sysosetH, sysosetI, sysosetM, sysosetG = getsizes( rominfo.rominfo.system.offset) size = long( raw_input('Enter new system size bytes ' + str(syssizeI) + ' :')) if size != syssizeI: size, newuseroffsethex = sizetoparamsize(size, verbose=1) pprint( 'Applying these changes will adjust the parameters and system.img files.' ) apply = raw_input('Apply these changes Y/N:') if apply in ('y', 'Y'): Resizemtdblock(hex(size / 512)[:-1], 'system') ## rominfo.rominfo.system.size = hex(size/512)[:-1] ## rominfo.rominfo.user.offset = newuseroffsethex ## rominfo.rominfo.applyparameterchanges() system.shrinksystem() else: print 'No Change' dummy = raw_input('press enter to continue') except Exception as e: logerror('parameter::ResizeSystem ', e, 1)
def printcmdline(cmdline): pprint( 'CMDLINE:') parts = cmdline[8:].split(' ') indent = ' ' for p in parts: if p[:20] == 'mtdparts=rk29xxnand:': printmtdparts(p,indent) else: pprint( indent + p)
def printcmdline(cmdline): pprint('CMDLINE:') parts = cmdline[8:].split(' ') indent = ' ' for p in parts: if p[:20] == 'mtdparts=rk29xxnand:': printmtdparts(p, indent) else: pprint(indent + p)
def copyImages(): '''copy the unpacked image files to the working folder ''' try: pprint('Copy image and parameter files') #and copy to working, no wilcard support so use glob for file in glob.glob(os.path.join(KitchenConfig.KitchenConfig.SourceROMUnpackedLoc(),'Image/*.img')): print file shutil.copy(file,'working') shutil.copy( os.path.join(KitchenConfig.KitchenConfig.SourceROMUnpackedLoc(),'parameter') ,'working') except Exception as e: logerror('kitchen_utils::copyImages ',e,1)
def repairparams(): '''attempt to repair the parameters file ''' try: repaired = False ri = rominfo.rominfo for b,err in ri.errorblocks: if err == 'size': imgsize = os.stat(os.path.join('working', b + '.img')).st_size newpsize = sizeinparamhex(sizeinwholeblocks(imgsize,int('0x2000',16)*512)) Resizemtdblock(newpsize, b) repaired = True if repaired == True: pprint( 'Repairs have been made') except Exception as e: logerror('parameter::repairparams ',e,1)
def repairparams(): '''attempt to repair the parameters file ''' try: repaired = False ri = rominfo.rominfo for b, err in ri.errorblocks: if err == 'size': imgsize = os.stat(os.path.join('working', b + '.img')).st_size newpsize = sizeinparamhex( sizeinwholeblocks(imgsize, int('0x2000', 16) * 512)) Resizemtdblock(newpsize, b) repaired = True if repaired == True: pprint('Repairs have been made') except Exception as e: logerror('parameter::repairparams ', e, 1)
def getROMFile(): '''prompt for a rom image and move it into the sources folder ''' header(); filepath = raw_input('Please enter file name:'); pprint(' ') pprint('=') #remove any trailing whitespace or single quotes filepath = filepath.rstrip() filepath = filepath.strip("'") rominfo.rominfo.setROMimgFilename(os.path.basename(filepath)) CheckMakeFolders([KitchenConfig.KitchenConfig.SourceROMUnpackedLoc()]); try: shutil.move(filepath, KitchenConfig.KitchenConfig.SourceROMLoc() + '/') except IOError as e: logerror('rkmainmenu::getROMFile IOError',e,1) except NameError as e: logerror('rkmainmenu::getROMFile NameError',e,1)
def getROMFile(): '''prompt for a rom image and move it into the sources folder ''' header() filepath = raw_input('Please enter file name:') pprint(' ') pprint('=') #remove any trailing whitespace or single quotes filepath = filepath.rstrip() filepath = filepath.strip("'") rominfo.rominfo.setROMimgFilename(os.path.basename(filepath)) CheckMakeFolders([KitchenConfig.KitchenConfig.SourceROMUnpackedLoc()]) try: shutil.move(filepath, KitchenConfig.KitchenConfig.SourceROMLoc() + '/') except IOError as e: logerror('rkmainmenu::getROMFile IOError', e, 1) except NameError as e: logerror('rkmainmenu::getROMFile NameError', e, 1)
def editparameter_menu(): header(checkvalid = True) printparameter() pprint('=') pprint ('1 Resize system') #pprint ('2 Apply change') pprint ('m parameter menu') pprint ('=') choice = raw_input('Enter selection :') if choice in ('1'): ResizeSystem() ## elif choice in ('2'): ## applychanges() if choice not in ('m','M'): editparameter_menu()
def copyImages(): '''copy the unpacked image files to the working folder ''' try: pprint('Copy image and parameter files') #and copy to working, no wilcard support so use glob for file in glob.glob(os.path.join(KitchenConfig.KitchenConfig.SourceROMUnpackedLoc(),'Image/*.img')): print file shutil.copy(file,'working') shutil.copy( os.path.join(KitchenConfig.KitchenConfig.SourceROMUnpackedLoc(),'parameter') ,'working') for file in glob.glob(os.path.join(KitchenConfig.KitchenConfig.SourceROMUnpackedLoc(),'*.bin')): print file shutil.copy(file,'working') rominfo.rominfo.originalsystemsize = os.stat('working/system.img').st_size except Exception as e: logerror('rkmainmenu::copyImages ',e,1)
def editparameter_menu(): header(checkvalid=True) printparameter() pprint('=') pprint('1 Resize system') #pprint ('2 Apply change') pprint('m parameter menu') pprint('=') choice = raw_input('Enter selection :') if choice in ('1'): ResizeSystem() ## elif choice in ('2'): ## applychanges() if choice not in ('m', 'M'): editparameter_menu()
def custom_remove(targetpath): '''Custom remove (ROM specific)''' try: pprint('=') pprint('ROM specific file removal: ' + targetpath) pprint('=') rfile = raw_input('Enter the path of your ROM specific removal file').strip().strip("'").strip('"') removefiles(rfile,targetpath); except Exception as e: logerror('kitchen_utils::custom_remove ',e,1)
def custom_deploy(deploypath): '''Custom deploy (ROM specific)''' try: pprint('=') pprint('ROM specific file deploy: ' + deploypath) pprint('=') dfile = raw_input('Enter the path of your ROM specific deploy file: ').strip().strip("'").strip('"') deployfiles(dfile,deploypath,1) except Exception as e: logerror('kitchen_utils::custom_deploy ',e,1)
def kernel_menu(): ''' stand alone menu''' try: ri = rominfo.rominfo if ri.kernelImageSize <> '': getkerneldata() my_menu = dict([ ('aa', 'Get Kernel image info'), ('bb', 'Brand Kernel'), ('t=', '='), ('vm', 'main menu'), ('z=', '=') ]) else: my_menu = dict([ ('aa', 'Get Kernel image info'), ('t=', '='), ('vm', 'main menu'), ('z=', '=') ]) choice = mymenu(my_menu,'Enter selection :') if choice in ('a'): getkerneldata() elif choice in ('b'): if w > 0: brandkernel(); elif choice in ('m','M'): pprint('=') pprint('Exiting') pprint('=') if choice not in ('m', 'M'): kernel_menu() except Exception as e: logerror('kernel::kernelmenu ' ,e,1)
def finalise_boot_recovery(image): '''pack up boot.img or recovery''' try: loc = image.find('.') folder = image[:loc] pprint('=') pprint('Finalising ' + image) print 'folder= ' + folder pprint('=') #check_make_folder('working/' + folder) touch_and_zip_boot_recovery(folder,image) print 'os.rename ' , print os.path.join('working', image),os.path.join('working', image + '.old') os.rename(os.path.join('working', image),os.path.join('working', image + '.old')) print 'renamed' #logging.debug('rkcrc -k working/custom' + image + '.gz ' + image) #os.system('rkcrc -k working/custom' + image + '.gz working/' + image) rkcrc('-k', 'working/custom' + image + '.gz', 'working/' + image) pprint('=') pprint(image + ' finalised') pprint('=') except Exception as e: logerror('kitchen_utils::finalise_boot_recovery ',e,1)
def mvcpfilesworker(movefilename,sourceroot,op,asroot,verbose=0): try: serr='' path = os.path.expanduser(movefilename) with open(path,'r') as f: for line in f: cl = line.strip(); if cl[:1] <> '#' and len(cl) > 0: args = cl.split(',') source = os.path.join(sourceroot, args[0].strip()) dest = os.path.join(sourceroot, args[1].strip()) if len(args) > 2: destpath = args[2].strip() else: destpath = '' pth,fn =os.path.split(source) fn= os.path.join(destpath,fn) logging.debug('kitchen_utils::mvcpfilesworker source' + source) logging.debug('kitchen_utils::mvcpfilesworker dest' + dest) iszip = 0 lendest = len(dest) if lendest > 3: if dest[lendest-3:] == 'zip': iszip = 1 logging.debug('kitchen_utils::mvcpfilesworker iszip' + str(iszip)) try: #if os.path.exists(source): if len(glob.glob(source)) > 0: if iszip == 1: logging.debug('kitchen_utils::mvcpfilesworker ' + dest) zf = zipfile.ZipFile(file=dest,mode='a',compression=zipfile.ZIP_DEFLATED) #zf.printdir() for file in glob.glob(source): if verbose ==1: pprint( 'Zipping {} size {:,} kb'.format(file,os.stat(file).st_size/1024)) zf.write(file,fn) zf.close() else: if verbose ==1: pprint( 'Processing {} size {:,} kb'.format(source,os.stat(source).st_size/1024)) logging.info('kitchen_utils::mvcpfilesworker ') logging.info([dest]) CheckMakeFoldersRoot([dest]) moves = op + ' ' + source + ' ' + dest if asroot==1: moves = 'sudo ' + moves logging.debug('kitchen_utils::mvcpfilesworker moves :' + moves) os.system(moves) else: logging.debug('kitchen_utils::mvcpfilesworker source does not exist Source= ' + source) except IOError as e: logerror('kitchen_utils::mvcpfilesworker inner ',e,1) serr = serr + 'could not move ' + sourceroot.strip() + args[0].strip() + '\n' if serr <> '': print serr choice=raw_input('Press enter to continue') except Exception as e: logerror('kitchen_utils::mvcpfilesworker ',e,1)
def cleanroot(): '''clean and root system.img 900supersport 1.1 * debloat * root, xml permissions market fix and busybox by deploy files (global) * branding by deploy files (Local) * addition of busybox synbolic links * build.prop update for language and region ''' kc = KitchenConfig.KitchenConfig try: header() pprint('=') pprint('system.img') pprint('=') pprint('De-bloat') pprint('=') mountsystem() removefiles(os.path.join(kc.KitchenPath, 'processcontrol/debloat'), 'working/mntsystem/') growsystem() mountsystem() pprint('=') pprint('= rooting the Cube now') pprint('=') pprint('= add Busybox for init.d') pprint('=') movefiles(os.path.join(kc.KitchenPath, 'processcontrol/movepreinstall')) deployfiles(os.path.join(kc.KitchenPath, 'processcontrol/deploy'), 'working/mntsystem', 0) makebusyboxlinks( os.path.join(kc.KitchenPath, 'processcontrol/makelinks')) CheckMakeFoldersRoot(['working/mntsystem/etc/init.d']) pprint('=') pprint('make english') pprint('=') os.system('sudo cp working/mntsystem/build.prop working/removed') apply_sed( os.path.join(kc.KitchenPath, 'processcontrol/buildprop_makeenglish'), 'working/mntsystem/build.prop', 0) extendBuildprop(0) if resizerequired == -1: shrinksystem() mountsystem() #open nautilus for review os.system('sudo ' + kc.browser + ' working/mntsystem/') finalisesystem() checkfsimage('working/system.img') #boot stuff unpackboot() initrc_mount_system_rw(0) addinitd_support(0) addpreinstall(1) brand_boot(1) finalise_boot() except Exception as e: logerror('rkmainmenu::cleanroot ', e, 1)
def promptLocalDeploy(): '''Promt the user to add any prepared files to the localdeploy folder ''' try: pprint('=') pprint(' ') pprint(' ') pprint('Now put any local resources in localdeploy') pprint(' ') pprint(' ') pprint('=') time.sleep(5) except Exception as e: logerror('kitchen_utils::promptLocalDeploy ',e,1)
def rkmainmenu(): '''Main menu for interaction with user This is a version 1 menu this needs to inspect the state of the current working ROM and offer options as appropriate''' try: main_menu = dict([ ('a1', 'Pick up img and create locations'), ('b2', 'Clean, brand and root system and boot images'), ('c3', 'Make ROM kits'), ('d4', 'Clean workspace (removes working files)'), #('f5', 'Wipe workspace, and unpacked'), ('g=', '='), ('hb', 'boot menu'), ('ir', 'recovery menu'), ('js', 'system menu'), ('kk', 'kernel menu'), ('lp', 'parameter menu'), ('mf', 'flash menu'), #('ng', 'graphics'), ('p=', '='), ('qw', 'broWse'), ('t=', '='), ('yx', 'eXit'), ('z=', '=') ]) choice = mymenu(main_menu, 'Enter selection :', checkvalid=True) if choice in ('1'): setworkingROM() elif choice in ('2'): cleanroot() elif choice in ('3'): makeROMkits() elif choice in ('4'): cleanworkspace() #elif choice in ('5'): # wipeworkspace() elif choice in ('b', 'B'): bootmenu() elif choice in ('s', 'S'): systemmenu() elif choice in ('r', 'R'): recoverymenu() elif choice in ('p', 'P'): parameter_menu() elif choice in ('f', 'F'): flash_menu() elif choice in ('r', 'R'): repairparams() elif choice in ('k', 'K'): kernel_menu() elif choice in ('W', 'w'): browse('') elif choice in ('x', 'X'): pprint('=') pprint('Exiting') pprint('=') if choice not in ('x', 'X'): rkmainmenu() except Exception as e: logerror('rkmainmenu::menu ', e, 1)
def promptLocalDeploy(): '''Promt the user to add any prepared files to the localdeploy folder ''' try: pprint('=') pprint(' ') pprint(' ') pprint('Now put any local resources in localdeploy') pprint(' ') pprint(' ') pprint('=') time.sleep(5) except Exception as e: logerror('kitchen_utils::promptLocalDeploy ', e, 1)
def rkmainmenu(): '''Main menu for interaction with user This is a version 1 menu this needs to inspect the state of the current working ROM and offer options as appropriate''' try: main_menu = dict([ ('a1', 'Pick up img and create locations'), ('b2', 'Clean, brand and root system and boot images'), ('c3', 'Make ROM kits'), ('d4', 'Clean workspace (removes working files)'), #('f5', 'Wipe workspace, and unpacked'), ('g=', '='), ('hb', 'boot menu'), ('ir', 'recovery menu'), ('js', 'system menu'), ('kk', 'kernel menu'), ('lp', 'parameter menu'), ('mf', 'flash menu'), #('ng', 'graphics'), ('p=', '='), ('qw', 'broWse'), ('t=', '='), ('yx', 'eXit'), ('z=', '=') ]) choice = mymenu( main_menu ,'Enter selection :' ,checkvalid = True) if choice in ('1'): setworkingROM() elif choice in ('2'): cleanroot() elif choice in ('3'): makeROMkits() elif choice in ('4'): cleanworkspace() #elif choice in ('5'): # wipeworkspace() elif choice in ('b','B'): bootmenu() elif choice in ('s','S'): systemmenu() elif choice in ('r','R'): recoverymenu() elif choice in ('p','P'): parameter_menu() elif choice in ('f','F'): flash_menu() elif choice in ('r','R'): repairparams() elif choice in ('k','K'): kernel_menu() elif choice in ('W','w'): browse('') elif choice in ('x','X'): pprint('=') pprint('Exiting') pprint('=') if choice not in ('x', 'X'): rkmainmenu() except Exception as e: logerror('rkmainmenu::menu ',e,1)
def mvcpfilesworker(movefilename,sourceroot,op,asroot,verbose=0): try: serr='' path = os.path.expanduser(movefilename) with open(path,'r') as f: for line in f: cl = line.strip(); if cl[:1] <> '#' and len(cl) > 0: args = cl.split(',') source = os.path.join(sourceroot, args[0].strip()) dest = os.path.join(sourceroot, args[1].strip()) if len(args) > 2: destpath = args[2].strip() else: destpath = '' pth,fn =os.path.split(source) fn= os.path.join(destpath,fn) logging.debug('kitchen_utils::mvcpfilesworker source' + source) logging.debug('kitchen_utils::mvcpfilesworker dest' + dest) iszip = 0 lendest = len(dest) if lendest > 3: if dest[lendest-3:] == 'zip': iszip = 1 logging.debug('kitchen_utils::mvcpfilesworker iszip' + str(iszip)) try: #if os.path.exists(source): if len(glob.glob(source)) > 0: if iszip == 1: logging.debug('kitchen_utils::mvcpfilesworker ' + dest) zf = zipfile.ZipFile(file=dest,mode='a',compression=zipfile.ZIP_DEFLATED) for file in glob.glob(source): #now set fn based on the glob'd filename and the destination pth,fn =os.path.split(file) fn= os.path.join(destpath,fn) logging.debug('kitchen_utils::mvcpfilesworker Zipping {} size {:,} kb'.format(file,os.stat(file).st_size/1024)) #zf.printdir() for file in glob.glob(source): if verbose ==1: pprint( 'Zipping {} size {:,} kb'.format(file,os.stat(file).st_size/1024)) zf.write(file,fn) zf.close() else: if verbose ==1: pprint( 'Processing {} size {:,} kb'.format(source,os.stat(source).st_size/1024)) logging.info('kitchen_utils::mvcpfilesworker ') logging.info([dest]) CheckMakeFoldersRoot([dest]) moves = op + ' ' + source + ' ' + dest if asroot==1: moves = 'sudo ' + moves logging.debug('kitchen_utils::mvcpfilesworker moves :' + moves) os.system(moves) else: logging.debug('kitchen_utils::mvcpfilesworker source does not exist Source= ' + source) except IOError as e: logerror('kitchen_utils::mvcpfilesworker inner ',e,1) serr = serr + 'could not move ' + sourceroot.strip() + args[0].strip() + '\n' if serr <> '': print serr choice=raw_input('Press enter to continue') except Exception as e: logerror('kitchen_utils::mvcpfilesworker ',e,1)
def printmtdparts(mtdparts,indent): pprint( indent + mtdparts[:20]) indent = indent + ' ' parts = mtdparts[20:].split(',') for p in parts: pprint( indent + p)
def sizetoparamsize(sizebytes, verbose=0): syssizeH, syssizeI, syssizeM, syssizeG = getsizes( rominfo.rominfo.system.size) sysosetH, sysosetI, sysosetM, sysosetG = getsizes( rominfo.rominfo.system.offset) if sizebytes != syssizeI: if verbose == 1: pprint('=') pprint('Resizing') sizebytes = sizeinwholeblocks(sizebytes, 4096) newuseroffsethex = sizeinparamhex(sizebytes + sysosetI) parth, partl = newuseroffsethex[:-3], newuseroffsethex[-3:] if partl != '000': parth = hex(long(parth, 16) + 1)[:-1] newuseroffsethex = parth + '000' sizebytes = (long(newuseroffsethex, 16) - long(sysosetH, 16)) * 512 if verbose == 1: pprint('Recalculating User offset') pprint('User offset required ' + newuseroffsethex) pprint('Recalculating size of system to fill space') pprint('New system size = ' + str(sizebytes) + ' ' + hex(sizebytes / 512)[:-1]) pprint('=') return sizebytes, newuseroffsethex
def printmtdparts(mtdparts, indent): pprint(indent + mtdparts[:20]) indent = indent + ' ' parts = mtdparts[20:].split(',') for p in parts: pprint(indent + p)
def brandkernel(): '''brand and sign kernel ''' global cluto # clut offset global pl # palette length global datao # data offset global w # kernel data image width global h # kernel data image height global ds # kernel data image size try: print print pprint('=') pprint('... Branding Kernel ') pprint('... opening working/kerneltmp.img for read') with open('working/kernel.img', 'r') as fr: skipbytes=0 sig=fr.read(4) pprint('... Checking for signature') if sig == 'KRNL': skipbytes=8 pprint('... signature found') fr.seek(skipbytes) #skip first 8 bytes to remove signing pprint('... opening working/kerneltmp.img for write') #open a file to build our branded kernel into with open('working/kerneltmp.img', 'w') as fw: pprint( '... read write the kernel up to clut ') pprint( '... adjust for the signature as required ') fw.write(fr.read(cluto-skipbytes)) pprint( '... open the clut for read and write to kerneltmp ') with open('localdeploy/logo_clut') as ft: #iterate the clut for c in iter(lambda: ft.read(1),""): #write into our output fw.write(c) #skip this byte from the source fr.read(1) pprint( '... read write through to the logo_data') fw.write(fr.read(datao-fr.tell())) pprint ('... open the image data for read and write to kerneltmp ') with open('localdeploy/logo_data') as ft: #iterate the data for c in iter(lambda: ft.read(1),""): #write it to our output fw.write(c) #skip corresponding byte from source fr.read(1) pprint( '... Write remainder of kernel') #iterate and write the remainder ofthe source for c in iter(lambda: fr.read(1),""): fw.write(c) pprint( '... sign the kernel and move branded kernels to working/brand') os.rename('working/kernel.img','working/brand/kernel.img.orig') rkcrc('-k', 'working/kerneltmp.img', 'working/kernel.img') #rename the temp file os.rename('working/kerneltmp.img','working/brand/unsignedkernel.img') except Exception as e: logerror('kernel::brandkernel ',e,1)
def sizetoparamsize(sizebytes,verbose = 0): syssizeH, syssizeI, syssizeM, syssizeG = getsizes(rominfo.rominfo.system.size) sysosetH, sysosetI, sysosetM, sysosetG = getsizes(rominfo.rominfo.system.offset) if sizebytes != syssizeI: if verbose == 1: pprint('=') pprint('Resizing') sizebytes = sizeinwholeblocks(sizebytes,4096) newuseroffsethex = sizeinparamhex(sizebytes + sysosetI) parth, partl = newuseroffsethex[:-3], newuseroffsethex[-3:] if partl != '000': parth = hex(long(parth,16)+1)[:-1] newuseroffsethex = parth + '000' sizebytes = (long(newuseroffsethex,16) - long(sysosetH,16))*512 if verbose == 1: pprint('Recalculating User offset') pprint('User offset required ' + newuseroffsethex) pprint('Recalculating size of system to fill space') pprint('New system size = ' + str(sizebytes) + ' ' + hex(sizebytes/512)[:-1]) pprint('=') return sizebytes, newuseroffsethex
def cleanroot(): '''clean and root system.img 900supersport 1.1 * debloat * root, xml permissions market fix and busybox by deploy files (global) * branding by deploy files (Local) * addition of busybox synbolic links * build.prop update for language and region ''' kc = KitchenConfig.KitchenConfig try: header(); pprint('=') pprint('system.img') pprint('=') pprint('De-bloat') pprint('=') mountsystem() removefiles(os.path.join(kc.KitchenPath, 'processcontrol/debloat'),'working/mntsystem/') growsystem() mountsystem() pprint('=') pprint('= rooting the Cube now') pprint('=') pprint('= add Busybox for init.d') pprint('=') movefiles(os.path.join(kc.KitchenPath, 'processcontrol/movepreinstall')) deployfiles(os.path.join(kc.KitchenPath, 'processcontrol/deploy'),'working/mntsystem',0) makebusyboxlinks(os.path.join(kc.KitchenPath, 'processcontrol/makelinks')) CheckMakeFoldersRoot(['working/mntsystem/etc/init.d']) pprint('=') pprint('make english') pprint('=') os.system('sudo cp working/mntsystem/build.prop working/removed') apply_sed(os.path.join(kc.KitchenPath, 'processcontrol/buildprop_makeenglish') ,'working/mntsystem/build.prop' ,0) extendBuildprop(0) if resizerequired == -1: shrinksystem() mountsystem() #open nautilus for review os.system('sudo ' + kc.browser + ' working/mntsystem/') finalisesystem() checkfsimage('working/system.img') #boot stuff unpackboot() initrc_mount_system_rw(0) addinitd_support(0) addpreinstall(1) brand_boot(1) finalise_boot() except Exception as e: logerror('rkmainmenu::cleanroot ' ,e,1)
def printkerneldata(): '''print kernel data ''' try: pprint( '=') pprint( 'ppllogo_RKlogo_clut offset:{0:x}'.format(cluto)) pprint( 'Palette length: {0:d}'.format(pl)) pprint( '=') pprint( 'logo_RKlogo_data offset: {0:x}'.format(datao)) pprint( 'resolution: {0:d}'.format(w) +':{0:d}'.format(h)) pprint( 'data size:{0:d}'.format(ds)) pprint( '=') except Exception as e: logerror('kernel::printkerneldata ',e,1)