Ejemplo n.º 1
0
def use_cpfatfs():

    for flavor in bin_file_dests:
        fat_file_dest = os.path.join(bin_file_dests[flavor], 'NON-HLOS.bin')

        #if NON-HLOS.bin exists delete it, a new NON-HLOS.bin will be created
        #if NON-HLOS.bin already exists, fatgen.py doesn't create it
        #deleting this file so that it is created each time
        if os.path.exists(fat_file_dest):
            os.remove(fat_file_dest)
            lg.log("Existing " + fat_file_dest + " has been deleted.")
        if (fatgen_build):
            # now create NON-HLOS.bin of container size as specifief in partition.xml
            modem_partition_size = use_fatgen_toget_partitionsize()
            lg.log_exec([
                'python', fatgen_tool, '-f', '-s', modem_partition_size, '-n',
                fat_file_dest
            ],
                        verbose=0)
        else:
            # Copy fat.bin to our root directory.  Assume fat.bin is in same directory as cpfatfs.exe
            shutil.copy(cpfatfs_path + fat_file_src, fat_file_dest)

        os.chmod(
            fat_file_dest, stat.S_IREAD | stat.S_IWRITE | stat.S_IRGRP
            | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH)
        fat_dest_dir = 'image'
        for fat_file in mi.get_files(attr='fat_file', flavor=flavor):
            lg.log('update_common_info.py:' + 'cpfatfs' + ' ' + fat_file +
                   ' ' + fat_file_dest,
                   verbose=0)
            lg.log_exec([cpfatfs_tool, fat_file_dest, fat_dest_dir, fat_file],
                        verbose=0)
Ejemplo n.º 2
0
def use_fatgen_toget_partitionsize():
    if os.path.exists(fatgen_tool):
        lg.log('fatgen tool exists, using it to create new NON-HLOS.bin')
        #get modem partition size from partition.xml
        try:
            modem_partition_size = getModemPartitionSize()
            str_modem_partition_size = str(modem_partition_size)
            #print str_modem_partition_size

        except ModemPartitionSizeNotFoundException, ex:
            sys.exit('ModemPartitionSizeNotFoundException raised')
def create_gen_build_flavor_cmm():
    common_dir = os.path.dirname(os.path.dirname(__file__))
    destn_dir = join_paths(os.path.dirname(__file__), "../tools/cmm/gen")
    if not os.path.exists(destn_dir):
        os.makedirs(destn_dir)
    lg.log("update_common_info.py: Calling gen_cmm_data3 to create " +
           join_paths(destn_dir, "gen_buildflavor.cmm"))
    lg.log_exec([
        "python", "../tools/meta/gen_cmm_data3.py",
        os.path.dirname(common_dir),
        join_paths(destn_dir, "gen_buildflavor.cmm")
    ])
Ejemplo n.º 4
0
def initialize():
    if flavors:
        lg.log('flavors found')
        for flavor in flavors:
            path = os.path.join('./bin/', flavor)
            bin_file_dests[flavor] = path
            try:
                os.makedirs(path)
            except:
                # Ignore the exception that gets raised if the directory already exists.
                pass
    else:
        bin_file_dests[None] = ''
def workflow_delete(step_dict):
    for flavor in flavors:
        # Make a copy of step_dict for current flavor
        (step_dict_flavor, flavor_flag) = create_flavor_dict(step_dict, flavor)

        # Preprocess the standard items in the step
        preprocess_step(step_dict_flavor, flavor)

        # Once destination path is processed, try deleting it
        for key in step_dict_flavor:
            # Delete step should contain only keys of destinations to delete
            destn = clean_vars(step_dict_flavor[key])
            try:
                if os.path.isdir(destn):
                    shutil.rmtree(destn)
                    lg.log("update_common_info.py: Deleted the directory " +
                           destn)
                else:
                    os.remove(destn)
                    lg.log("update_common_info.py: Deleted the file " + destn)
            except:
                lg.log("update_common_info.py: Unable to delete " + destn)

        # Don't have to repeat if the step doesn't contain flavor info
        if (len(flavors) > 0) and (not flavor_flag):
            break
def workflow_copy(step_dict):
    # Execution step should specify the tool name to run
    if not ('destn_dir' in step_dict or 'src_files' in step_dict):
        lg.log(
            "update_common_info.py: Invalid copy step! Source Files or Destination not specified"
        )
    else:
        for flavor in flavors:
            # Make a copy of step_dict for current flavor
            (step_dict_flavor,
             flavor_flag) = create_flavor_dict(step_dict, flavor)

            # Preprocess the standard items in the step
            preprocess_step(step_dict_flavor, flavor)

            lg.log(
                "update_common_info: --------------------------------------------------"
            )
            lg.log("update_common_info:  Starting copy")

            if ('src_files' in step_dict_flavor.keys()):
                src_files = step_dict_flavor['src_files']
                destn_dir = step_dict_flavor['destn_dir']
                # Copy each file in the list
                for src_file in src_files:
                    # For wildcards
                    for file in glob(src_file):
                        lg.log("Copying " + file + " to " + destn_dir)
                        shutil.copy(file, destn_dir)
                lg.log(
                    "update_common_info: --------------------------------------------------\n"
                )

            # Don't have to repeat if the step doesn't contain flavor info
            if (len(flavors) > 0) and (not flavor_flag):
                break
Ejemplo n.º 7
0
if not options.non_hlos and not options.hlos and FIT_tool is None:
    options.non_hlos = True
    options.hlos = True

#---------------------------------------------------------#
# Get bearings                                            #
#---------------------------------------------------------#

on_linux = sys.platform.startswith("linux")

#---------------------------------------------------------#
# Print some diagnostic info                              #
#---------------------------------------------------------#
lg = lg.Logger('update_common')
lg.log("update_common_info:Platform is:" + sys.platform, verbose=0)
lg.log("update_common_info:Python Version is:" + sys.version, verbose=0)
lg.log("update_common_info:Current directory is:" + os.getcwd(), verbose=0)

#---------------------------------------------------------#
# Load the Meta-Info file                                 #
#---------------------------------------------------------#
lg.log("update_common_info:Loading the Meta-Info file", verbose=0)
mi = ml.meta_info(logger=lg)

#---------------------------------------------------------#
# Get flavor information                                  #
#---------------------------------------------------------#
flavors = mi.get_product_flavors()

#---------------------------------------------------------#
Ejemplo n.º 8
0
    temp_file = sys.argv[2]
else:
    print "Error: Invalid number of parameters."
    print __doc__
    sys.exit()

dst_path = os.path.dirname(temp_file)
if dst_path != "" and not os.path.isdir(dst_path):  # '' implies current directory, and is allowed
    print "Can't find destination directory:", dst_path
    print __doc__
    sys.exit(1)
logfile = os.path.join(dst_path, "gen_cmm_data")

lg = lg.Logger(logfile, save_old_log_file=False)

lg.log("Platform is:" + sys.platform)
lg.log("Python Version is:" + sys.version)
lg.log("Current directory is:" + os.getcwd())
lg.log("Args are:" + str(sys.argv))

cmm_script_header = ""
cmm_tag_template = """GLOBAL &%s
&%s="%s"
"""
cmm_script_trailer = """ENDDO"""
exception = False
sys.path.append(os.path.dirname(__file__))
import meta_lib as ml

if not targ_root.endswith("/") and not targ_root.endswith("\\"):
    targ_root += "/"
Ejemplo n.º 9
0
    print __doc__
    sys.exit(1)
logfile = os.path.join(dst_path, 'gen_cmm_data2')

#delete EXCEPTION_gen_cmm_data2.txt and SUCCESS_gen_cmm_data2.txt, if they exists
exception_file_path = os.path.join(dst_path, 'EXCEPTION_gen_cmm_data2.txt')
if os.path.exists(exception_file_path):
    os.remove(exception_file_path)

success_file_path = os.path.join(dst_path, 'SUCCESS.txt')
if os.path.exists(success_file_path):
    os.remove(success_file_path)

lg = lg.Logger(logfile, save_old_log_file=False)

lg.log("Platform is:" + sys.platform)
lg.log("Python Version is:" + sys.version)
lg.log("Current directory is:" + os.getcwd())
lg.log("Args are:" + str(sys.argv))

cmm_script_header = ''
cmm_tag_template = '''GLOBAL &%s
&%s="%s"
'''
cmm_script_trailer = '''ENDDO'''
exception = False
sys.path.append(os.path.dirname(__file__))
import meta_lib as ml

mi = ml.meta_info(logger=lg)
Ejemplo n.º 10
0
 if not (options.attr or options.container or options.flav or options.fatgen
         or options.fatadd or options.partsize):
     print "Error: Invalid Syntax."
     print __doc__
     sys.exit(1)
 # Initialize log file
 logfile = 'fat_creation'
 fcname = os.path.splitext(os.path.basename(options.container))[0]
 if len(fcname) > 0:
     logfile += '_' + fcname.lower()
 lg = lg.Logger(logfile)
 mi = ml.meta_info(logger=lg)
 on_linux = sys.platform.startswith("linux")
 # Create fat container
 #---------------------
 lg.log("fat_creation.py: Specified container location:")
 lg.log("                 " + options.container)
 # fatgen can't take float partition size, consider only int part
 lg.log("fat_creation.py: Specified partition size: " + options.partsize)
 options.partsize = options.partsize.split('.')[0]
 lg.log(
     "fat_creation.py: Float partition can't be used for fat creation, hence truncating it. New partition size : "
     + options.partsize)
 if os.path.exists(options.container):  # check and delete existing file
     lg.log("                 Deleting existing file")
     os.remove(options.container)
 if not os.path.exists(options.fatgen):  # check for fatgen tool
     lg.log("                 fatgen tool not found in")
     lg.log("                    " + options.fatgen)
     sys.exit(1)
 lg.log("                 Using fatgen from " + options.fatgen)
Ejemplo n.º 11
0
                      help="sectorsize")
    (options, args) = parser.parse_args()

    mi = ml.meta_info(logger=lg)
    on_linux = sys.platform.startswith("linux")
    lg = lg.Logger('fat_creation')

    if not (options.attr or options.container or options.flav or options.fatgen
            or options.fatadd or options.partsize):
        print "Error: Invalid Syntax."
        print __doc__
        sys.exit(1)

    # Create fat container
    #---------------------
    lg.log("fat_creation.py: Specified container location:")
    lg.log("                 " + options.container)
    lg.log("fat_creation.py: Specified partition size: " + options.partsize)
    if os.path.exists(options.container):  # check and delete existing file
        lg.log("                 Deleting existing file")
        os.remove(options.container)
    if not os.path.exists(options.fatgen):  # check for fatgen tool
        lg.log("                 fatgen tool not found in")
        lg.log("                    " + options.fatgen)
        sys.exit(1)
    lg.log("                 Using fatgen from " + options.fatgen)
    # execute fatgen
    fatgen_cmd = [
        'python', options.fatgen, '-f', '-s', options.partsize, '-n',
        options.container
    ]
Ejemplo n.º 12
0
   print __doc__
   sys.exit(1)
logfile = os.path.join(dst_path,'gen_cmm_data2')

#delete EXCEPTION_gen_cmm_data2.txt and SUCCESS_gen_cmm_data2.txt, if they exists
exception_file_path = os.path.join( dst_path,'EXCEPTION_gen_cmm_data2.txt' )
if os.path.exists( exception_file_path ):
   os.remove( exception_file_path )

success_file_path = os.path.join( dst_path,'SUCCESS.txt' )
if os.path.exists( success_file_path ):
   os.remove( success_file_path )

lg = lg.Logger(logfile, save_old_log_file=False)

lg.log("Platform is:" + sys.platform)
lg.log("Python Version is:" + sys.version)
lg.log("Current directory is:" + os.getcwd())
lg.log("Args are:" + str(sys.argv))

cmm_script_header = ''
cmm_tag_template = '''GLOBAL &%s
&%s="%s"
'''
cmm_script_trailer = '''ENDDO'''
exception = False
sys.path.append(os.path.dirname(__file__))
import meta_lib as ml

mi = ml.meta_info(logger=lg)
Ejemplo n.º 13
0
    else:
        print >> sys.stderr, "Failed locating contents.xml"
        sys.exit(0)

import meta_lib as ml
import meta_log as lg

# Create log and meta interface
lg = lg.Logger(log_to_stdout=options.debug_msg, save_old_log_file=False)
mi = ml.meta_info(file_pfn=os.path.join(os.path.dirname(sys.argv[0]),
                                        contents_xml_rel_path),
                  logger=lg,
                  fb_nearest=options.fb_nearest)

if options.debug_msg:
    lg.log("meta_cli : meta_info object created with " + contents_xml_rel_path)

if len(sys.argv[1:]) < 1:
    parser.error("invalid usage. \nFor help , please try: \nmeta_cli.py -h")

if options.print_doc:
    input_string.remove('--doc')
if options.print_dir:
    input_string.remove('--dir')
    print_dir(ml, mi)
    sys.exit(0)

if options.fb_nearest:
    input_string.remove('--fb_nearest')
if options.debug_msg:
    input_string.remove('--dbg')
def workflow_exec(step_dict):
    # Execution step should specify the tool name to run
    if not ('tool_name' in step_dict or 'params' in step_dict):
        lg.log(
            "update_common_info.py: Invalid exec step! Tool name or command not specified"
        )
    else:
        for flavor in flavors:
            # Make a copy of step_dict for current flavor
            (step_dict_flavor,
             flavor_flag) = create_flavor_dict(step_dict, flavor)

            # Preprocess the standard items in the step
            preprocess_step(step_dict_flavor, flavor)

            # After preprocess check if the tool is available and execute
            if step_dict_flavor['tool_name']:
                lg.log(
                    "update_common_info: --------------------------------------------------"
                )
                lg.log("update_common_info:  Calling " +
                       step_dict_flavor['tool_name'].split('/')[-1] + " " +
                       (flavor or ""))

                # Check if the step has file_vars or files and loop accordingly
                if ('src_file_vars' in step_dict_flavor.keys()) and (len(
                        step_dict_flavor['src_file_vars']) > 0):
                    src_file_vars = step_dict_flavor['src_file_vars']
                    for key in src_file_vars.keys():
                        step_dict_flavor['src_file_var'] = key
                        for file in src_file_vars[key]:
                            step_dict_flavor['src_file'] = file
                            params = evaluate_params(step_dict_flavor)
                            lg.log(
                                "update_common_info: --------------------------------------------------\n"
                            )
                            lg.log_exec(params)
                elif ('src_files' in step_dict_flavor.keys()) and (len(
                        step_dict_flavor['src_files']) > 0):
                    src_files = step_dict_flavor['src_files']
                    for src_file in src_files:
                        step_dict_flavor['src_file'] = src_file
                        params = evaluate_params(step_dict_flavor)
                        lg.log(
                            "update_common_info: --------------------------------------------------\n"
                        )
                        lg.log_exec(params)
                else:
                    params = evaluate_params(step_dict_flavor)
                    lg.log(
                        "update_common_info: --------------------------------------------------\n"
                    )
                    lg.log_exec(params)

                if ('start_dir' in step_dict_flavor.keys()):
                    # cd'd to exec_dir in preprocessing, so revert back
                    os.chdir(step_dict_flavor['start_dir'])
                    del step_dict_flavor['start_dir']

            # Don't have to repeat if the step doesn't contain flavor info
            if (len(flavors) > 0) and (not flavor_flag):
                break
def preprocess_step(step_dict_flavor, flavor):
    # If step is "exec" process the tool name to get path
    if ('tool_name' in step_dict_flavor):
        tool_name = step_dict['tool_name']
        tool_build = mi.get_tool_build(tool_name, 'workflow')
        if tool_build:
            # If valid build exists, get the full path to tool
            tool_pfn = join_paths(mi.get_build_path(tool_build),
                                  mi.get_tool_path(tool_name, 'workflow'),
                                  tool_name)
            step_dict_flavor['tool_name'] = tool_pfn
        else:
            step_dict_flavor['tool_name'] = None
            # The tool for this exec step is not present. Need not proceed...
            return

    # If destination directory is specified, create if not found
    if ('destn_dir' in step_dict_flavor):
        destn_dir = clean_vars(step_dict_flavor['destn_dir'])
        if not os.path.exists(destn_dir):
            lg.log("update_common_info.py: Creating directory " + destn_dir)
            os.makedirs(destn_dir)
        # After evaluating map it back to the dictionary
        step_dict_flavor['destn_dir'] = destn_dir

    # If execution directory is specified, create and cd to it
    if ('exec_dir' in step_dict_flavor):
        exec_dir = clean_vars(step_dict_flavor['exec_dir'])
        if not os.path.exists(exec_dir):
            os.makedirs(exec_dir)
        # Save the current path and change to exec_dir
        start_dir = os.getcwd()
        step_dict_flavor['start_dir'] = start_dir
        os.chdir(exec_dir)
        step_dict_flavor['exec_dir'] = exec_dir
        lg.log("Changed working directory to " + step_dict_flavor['exec_dir'])

    # If root directory is specified, get the root of that build
    if ('root_dir' in step_dict_flavor):
        if ('$[build' in step_dict_flavor['root_dir']):
            build = clean_vars(step_dict_flavor['root_dir'])
            root_dir = mi.get_build_path(build)
            step_dict_flavor['root_dir'] = root_dir

    # Get list of source files based on the given key
    src_files = []
    if ('src_files' in step_dict_flavor):
        src_files = step_dict_flavor['src_files']
        if '$' in src_files:
            # If source_files is listed as var:value pair, use get_files and filter with provided attr
            # This will return a list of files filtered with flavor and attribute
            attr = clean_vars(src_files)
            src_files = mi.get_files(attr=attr, flavor=flavor)
        else:
            # Treat is just as a file or a directory path and make it a list
            src_files = [clean_vars(src_files)]
        step_dict_flavor['src_files'] = src_files
    src_file_vars = []
    if ('src_file_vars' in step_dict_flavor):
        # If source is listed as file_vars, use get_file_vars
        # This will return a dictionary with var:[file] pairs
        attr = clean_vars(step_dict_flavor['src_file_vars'])
        src_file_vars = mi.get_file_vars(attr, flavor=flavor)
        step_dict_flavor['src_file_vars'] = src_file_vars
def use_fat_add():
    for flavor in bin_file_dests:
        fat_file_dest = os.path.join(bin_file_dests[flavor], 'NON-HLOS.bin')

        #if NON-HLOS.bin exists delete it, a new NON-HLOS.bin will be created
        #if NON-HLOS.bin already exists, fatgen.py doesn't create it
        #deleting this file so that it is created each time
        if os.path.exists(fat_file_dest):
            os.remove(fat_file_dest)
            lg.log("Existing " + fat_file_dest + " has been deleted.")
        if (fatgen_build):
            # Create NON-HLOS.bin of container size as specified in partition.xml
            modem_partition_size = use_fatgen_toget_partitionsize()
            lg.log_exec([
                'python', fatgen_tool, '-f', '-s', modem_partition_size, '-n',
                fat_file_dest
            ],
                        verbose=0)
        else:
            # Copy fat.bin to our root directory.  Assume fat.bin is in same directory as cpfatfs.exe
            shutil.copy(fatadd_path + fat_file_src, fat_file_dest)

        os.chmod(
            fat_file_dest, stat.S_IREAD | stat.S_IWRITE | stat.S_IRGRP
            | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH)

        # Add each "fat_file" from contents.xml
        fatFiles = mi.get_files(attr='fat_file', flavor=flavor)
        # Create sub directories in NON-HLOS.bin for each "sub_dir" from contents.xml
        subDirFiles = mi.get_files(attr='sub_dir', flavor=flavor, abs=False)
        subDirFatFiles = {}
        if len(subDirFiles) > 0:
            for relfile in subDirFiles:
                for absfile in fatFiles:
                    tempabsfile = absfile
                    if on_linux == False:
                        tempabsfile = absfile.replace('/', '\\')
                    if tempabsfile.find(relfile) != -1:
                        subDirFatFiles[absfile] = os.path.dirname(relfile)

        for fat_file in fatFiles:
            fat_dest_dir = 'image'
            print fat_file
            if fat_file in subDirFatFiles:
                fat_dest_dir = os.path.join(fat_dest_dir,
                                            subDirFatFiles[fat_file])
            lg.log('update_common_info.py:' + 'fatadd' + ' ' + fat_file + ' ' +
                   fat_file_dest,
                   verbose=0)
            lg.log_exec([
                'python', fatadd_tool, '-n', fat_file_dest, '-f' + fat_file,
                '-d' + fat_dest_dir
            ],
                        verbose=0)

        # Add ver_info.txt
        fat_dest_dir = 'verinfo'
        bid_file = os.path.join(os.path.dirname(__file__), 'Ver_Info.txt')
        if os.path.exists(bid_file):
            lg.log('update_common_info.py:' + 'fatadd' + ' ' + bid_file + ' ' +
                   fat_file_dest,
                   verbose=0)
            lg.log_exec([
                'python', fatadd_tool, '-n', fat_file_dest, '-f' + bid_file,
                '-d' + fat_dest_dir
            ],
                        verbose=0)
    options.non_hlos = True
    options.hlos = True
workflow_filter_list = []
if options.wflow_filter:
    workflow_filter_list = options.wflow_filter.strip().split(',')

#---------------------------------------------------------#
# Get bearings                                            #
#---------------------------------------------------------#
on_linux = sys.platform.startswith("linux")

#---------------------------------------------------------#
# Initialize logger and print some diagnostic info        #
#---------------------------------------------------------#
lg = lg.Logger('update_common')
lg.log("update_common_info:Platform is:" + sys.platform, verbose=0)
lg.log("update_common_info:Python Version is:" + sys.version, verbose=0)
lg.log("update_common_info:Current directory is:" + os.getcwd(), verbose=0)

#---------------------------------------------------------#
# Load the Meta-Info file                                 #
#---------------------------------------------------------#
lg.log("update_common_info:Loading the Meta-Info file", verbose=0)
import meta_lib as ml
mi = ml.meta_info(logger=lg)

#---------------------------------------------------------#
# Get flavor information                                  #
#---------------------------------------------------------#
flavors = mi.get_product_flavors()
# Returns empty list [] if no flavors found
Ejemplo n.º 18
0
else:
    print "Error: Invalid number of parameters."
    print __doc__
    sys.exit()

dst_path = os.path.dirname(temp_file)
if (dst_path != '' and  # '' implies current directory, and is allowed
        not os.path.isdir(dst_path)):
    print "Can't find destination directory:", dst_path
    print __doc__
    sys.exit(1)
logfile = os.path.join(dst_path, 'gen_cmm_data')

lg = lg.Logger(logfile, save_old_log_file=False)

lg.log("Platform is:" + sys.platform)
lg.log("Python Version is:" + sys.version)
lg.log("Current directory is:" + os.getcwd())
lg.log("Args are:" + str(sys.argv))

cmm_script_header = ''
cmm_tag_template = '''GLOBAL &%s
&%s="%s"
'''
cmm_script_trailer = '''ENDDO'''
exception = False
sys.path.append(os.path.dirname(__file__))
import meta_lib as ml

if not targ_root.endswith('/') and not targ_root.endswith('\\'):
    targ_root += '/'
import os
import subprocess
import pprint
from ctypes import *
import struct
from optparse import OptionParser

sys.path.append('../tools/meta')
import meta_lib as ml
import meta_log as lg

logfilename = os.path.join("gen_bootloader_image")
print logfilename

lg = lg.Logger(logfilename)
lg.log("Current working directory" + os.getcwd())

# Log the OS environment
lg.log("OS Environment:")
for var in os.environ:
    lg.log("   " + var + ' = ' + os.environ[var])

mi = ml.meta_info(logger=lg)

var_list = {}
var_list_1 = mi.get_file_vars(attr="bootloader_image")
for dict in [var_list_1]:
    for k, v in dict.iteritems():
        var_list.setdefault(k, list())
        var_list[k] += v