def METHOD_NAME(ifwi_file, ifwi_out_file, cfg_dir, key_file, script_dir, tool_dir, platform_id):
    if len (dlt_files) == 0:
        raise Exception("Please run the generated CfgDataStitch.py script instead of the original one in source tree !")
    fv_dir = get_script_dir()
    if not os.path.exists(fv_dir + '/ImgStitch.txt'):
        fv_dir = ''
    if ifwi_out_file == '':
        ifwi_out_file = os.path.join ('Output', os.path.basename(ifwi_file))
    out_dir = os.path.dirname(ifwi_out_file)
    if out_dir == '':
        out_dir = '.'
    if tool_dir == '':
        if fv_dir:
            tool_dir = os.path.realpath(os.path.join(fv_dir, '../../../../BaseTools/Bin/Win32'))
        else:
            tool_dir = get_script_dir()
    if script_dir == '':
        if fv_dir:
            script_dir = os.path.realpath(os.path.join(fv_dir, '../../../../BootloaderCorePkg/Tools'))
        else:
            script_dir = get_script_dir()
    if key_file == '':
        raise Exception("Key file is not specified!!")
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    if cfg_dir == "":
        dlt_dir = out_dir
        cfg_dir = '.'
    else:
        dlt_dir = cfg_dir
    cfg_ext = 'yaml'
    # CfgDataDef needs to be under cfgdata_dir
    if not os.path.exists(os.path.join(cfg_dir ,'CfgDataDef.' + cfg_ext)):
        raise Exception("No CfgDataDef.%s file found under directory '%s' !" % (cfg_ext, cfg_dir))
    # ensure all required files exist
    chk_files = [
            (script_dir, ['GenCfgData.py', 'CfgDataTool.py']),
            (cfg_dir, ['CfgDataDef.' + cfg_ext]),
        ]
    # Check for KEY_ID in key file string
    if not key_file.startswith('KEY_ID'):
         chk_files.extend([(os.path.dirname(key_file), [os.path.basename(key_file)])])
    result = check_file_exist (chk_files)
    if result:
        raise Exception("Cannot find file '%s' !" % result)
    chk_files = [
        (dlt_dir, [file[1] for file in dlt_files]),
        (out_dir, ['CfgDataInt.bin'])
    ]
    result = check_file_exist (chk_files)
    if result:
        # generate all required bins and dlts
        name_id = []
        for pid, dlt in dlt_files:
          name_id.append('%d:%s' % (pid, os.path.splitext(dlt)[0]))
        name_str = ','.join(name_id)
        run_cmd([sys.executable, os.path.join(script_dir, 'CfgDataTool.py'), 'export',
                '-i', ifwi_file, '-t', tool_dir, '-o', out_dir, '-n', name_str])
        for pid, dlt_name in dlt_files:
          bin_name = os.path.splitext(dlt_name)[0] + '.bin'
          dlt_path = os.path.join(dlt_dir, dlt_name)
          bin_path = os.path.join(out_dir, bin_name)
          run_cmd([sys.executable, os.path.join(script_dir, 'GenCfgData.py'), 'GENDLT',
                 os.path.join(cfg_dir, 'CfgDataDef.%s;%s' % (cfg_ext, bin_path)), dlt_path])
    # generate indivisual CFGDATA for each board
    bin_files = []
    for pid, dlt in dlt_files:
        bin_file = os.path.splitext(dlt)[0] + '.bin'
        bin_file = os.path.join(out_dir, bin_file)
        run_cmd([sys.executable, os.path.join(script_dir, 'GenCfgData.py'), 'GENBIN',
                 os.path.join(cfg_dir, 'CfgDataDef.%s;') % cfg_ext + os.path.join(
                     dlt_dir, dlt), bin_file])
        bin_files.append(bin_file)
    # merge the CFGDATA
    cmd_list = [sys.executable, os.path.join(script_dir, 'CfgDataTool.py'), 'merge',
                '-o', os.path.join(out_dir, 'CfgDataExt.bin')]
    if platform_id:
        cmd_list.extend(['-p', platform_id])
    cmd_list.append(os.path.join(out_dir, 'CfgDataInt.bin*'))
    cmd_list.extend(bin_files)
    run_cmd(cmd_list)
    # sign the CFGDATA
    cmd_list = [sys.executable, os.path.join(script_dir, 'CfgDataTool.py'), 'sign',
                '-o', os.path.join(out_dir, 'CfgData.bin')]
    cmd_list.extend(['-k', key_file,
                     os.path.join(out_dir, 'CfgDataExt.bin')])
    run_cmd(cmd_list)
    # replace the CFGDATA in IFWI
    cmd_list = [sys.executable, os.path.join(script_dir, 'CfgDataTool.py'), 'replace',
                '-i', ifwi_file, os.path.join(out_dir, 'CfgData.bin')]
    cmd_list.extend(['-o', os.path.join(out_dir, os.path.basename(ifwi_out_file))])
    run_cmd(cmd_list)
    # clean intermediate files
    for each in ['CfgDataExt.bin', 'CfgData.bin', 'Stage1b.fd', 'Stage1b.lz', 'CfgData.bin.hash', 'CfgData.bin.hash.tmp']:
        bin_files.append (os.path.join(out_dir, each))
    for file in bin_files:
        if os.path.exists(file):
            os.remove(file)