def main(self, get_kcc_version): self.verify_bundle_name() # Read in the existing build info for the release logging.info("Loading release build info...") ktools_path = os.path.join( get_kcc_version.kcc_version().get_kcc_path(self.os_type), "bin") rel_binfo = download_build_info.build_info(self.build_dir, self.build_name, ktools_path, self.kcs_output_dir) logging.info("DONE") # Get the build id from Kymera ELF self.build_id = rel_binfo.get_build_id() chip = chip_info.chip_info(rel_binfo.get_chipname()) if chip.is_supported() == False: raise Exception("Chip NOT supported: " + str(chip.get_string())) try: os.chdir(self.kcsmaker_path) mod = imp.load_source("mod", self.bdl_file) except IOError: logging.error("Can't find file " + str(self.bdl_file)) raise try: if len(mod.KDCs) > 0: logging.info("Building KCS " + str(self.bundle_name)) else: logging.error("Error. No KDCs to be built") exit() except IOError: logging.error("Error. KDCs variable NOT found in " + str(self.bdl_file)) raise if self.linkscript_path == "": self.linkscript_path = os.path.join( self.kcsmaker_path, "templates", chip.get_linkscript_template_name()) logging.info("DOWNLOAD_CONFIG = %s" % self.download_config) logging.info("RELEASE_FLAG = %s" % self.release_flag) logging.info("CAPABILITIES_PATH = %s" % self.capabilities_path) logging.info("KYMERA_SRC_PATH = %s" % self.kymera_src_path) logging.info("BUNDLE_NAME = %s" % self.bundle_name) logging.info("BUILD_DIR = %s" % self.build_dir) logging.info("PATCH_DIR = %s" % self.patch_dir) logging.info("BUILD_NAME = %s" % self.build_name) logging.info("BUILD_ROOT = %s" % self.build_root) logging.info("BUILD_ID = %s" % self.build_id) logging.info("KCS_OUTPUT_DIR = %s" % self.kcs_output_dir) logging.info("KCSMAKER_PATH = %s" % self.kcsmaker_path) logging.info("LINKSCRIPT_PATH = %s" % self.linkscript_path) logging.info("LABEL_NAME = %s" % self.label_name) kcsFileRoot = os.path.join(self.kcs_output_dir, "download", "debugbin", self.bundle_name) kcsFileT = kcsFileRoot + ".kcs" kcsFileB = kcsFileRoot + ".dkcs" kcsFileD = kcsFileRoot + ".kcs_DRAM" makeKCS = make_kcs.make_kcs(chip, self.build_id) logging.info("Generating KCS file " + kcsFileT + " ...") # Create output file if it doesn't exist if not os.path.exists(self.kcs_output_dir): os.makedirs(self.kcs_output_dir) # Check if we are building on the same bundle. If not then force a clean build if (os.path.exists(os.path.join(self.kcs_output_dir, "last_bundle.txt"))): last_bundle_file = open( os.path.join(self.kcs_output_dir, "last_bundle.txt"), "r") prev_bundle = last_bundle_file.readline() if prev_bundle != self.bundle_name: self.clean_build = True logging.info( "Previous build detected: {prev_build}, now building: {cur_build}. \ Forcing clean build".format(prev_build=prev_bundle, cur_build=self.bundle_name)) last_bundle_file.close() else: self.clean_build = True if self.clean_build == None: self.clean_build = self.release_flag kdc_count = 1 for kdc_name in mod.KDCs.keys(): logging.info("Generating KDC " + kdc_name) logging.info("Building " + str(mod.KDCs[kdc_name]) + " capabilities ...") cap_list = [] for cap_tuple in mod.KDCs[kdc_name]: cap_list.append( capability.Capability(cap_tuple[0], cap_tuple[1], cap_tuple[2], cap_tuple[3], self.capabilities_path)) # Build the elf and object files for each capability # Create a Build_Controller object to control the process if self.clean_build: # If Make sure the KDC file is created with an empty output directory for dir_or_file in os.listdir(self.kcs_output_dir): dir_or_file_abs = os.path.join(self.kcs_output_dir, dir_or_file) if os.path.isdir(dir_or_file_abs): # Don't delete this temp directory used to store kmap files if dir_or_file != "kmap_tmp": shutil.rmtree(dir_or_file_abs) else: # It's a file, remove it os.remove(dir_or_file_abs) # Write current bundle into a file last_bundle_file = open( os.path.join(self.kcs_output_dir, "last_bundle.txt"), "w") last_bundle_file.write(self.bundle_name) last_bundle_file.close() if self.make_jobs is None: self.make_jobs = True build = build_controller.Build_Controller( self.build_root, self.build_dir, self.kcs_output_dir, self.kcsmaker_path, self.download_config, rel_binfo.get_elf_name(), self.extra_include, self.build_name, self.kymera_src_path, self.os_type, self.patch_dir) build.build(rel_binfo, cap_list, kdc_name, self.linkscript_path, self.make_path, self.clean_build, self.make_jobs) logging.info( str(mod.KDCs[kdc_name]) + " capabilities successfully built.") # Copy kmap file to temp folder (it will get deleted on next KDC build) if not os.path.exists(os.path.join(self.kcs_output_dir, "kmap_tmp")): os.makedirs(os.path.join(self.kcs_output_dir, "kmap_tmp")) shutil.copy( os.path.join(self.kcs_output_dir, "download", "debugbin", kdc_name + ".kmap"), os.path.join(self.kcs_output_dir, "kmap_tmp", kdc_name + "(KDC).kmap")) objDumpPath = os.path.join( get_kcc_version.kcc_version().get_kcc_path(self.os_type), "bin", "kobjdump") oFiles = self.get_obj_files(chip, get_kcc_version) logging.info("oFiles" + str(oFiles)) self.check_lib_release_files(oFiles) dnldElfFile = os.path.join(self.kcs_output_dir, "download", "debugbin", kdc_name + ".elf") mapOutFile = os.path.join(self.kcs_output_dir, "download", "debugbin", "map_out.txt") makeKDC = make_kdc.make_kdc(dnldElfFile, rel_binfo.get_elf_name(), chip, objDumpPath, oFiles, cap_list, self.os_type, mapOutFile) kdc = makeKDC.generateKDC(kdc_count, rel_binfo.get_rom_kalaccess()) print(("Sizes for KDC {}:".format(dnldElfFile))) kdc.print_memory_usage() makeKCS.addKDC(kdc) kdc_count = kdc_count + 1 # Copy kmap files to the output folder where the KCS files are files = glob.iglob( os.path.join(self.kcs_output_dir, "kmap_tmp", "*.kmap")) for file in files: if os.path.isfile(file): debugbin_dir = os.path.join(self.kcs_output_dir, "download", "debugbin") if self.clean_build: shutil.move(file, debugbin_dir) else: shutil.copy(file, debugbin_dir) if self.clean_build: os.rmdir(os.path.join(self.kcs_output_dir, "kmap_tmp")) kcs = makeKCS.generateKCS() kcs.dumpToTextFile(kcsFileT) kcs.dumpToBinaryFile(kcsFileB) kcs.dumpToDRAMFile(kcsFileD) if self.release_flag: import release this_rel = release.release(self.release_flag, self.kcsmaker_path, self.build_id, self.bundle_name, self.download_config, self.user) release.get_lock() # Generate new release ID this_rel.generate_new_version_id() self.version_build_id = this_rel.get_version_id() logging.info("New BUILD ID: " + str(this_rel.get_version_id())) if self.kymera_src_id == "": self.kymera_src_id = self.get_base_build_id_from_kymera_src_path( ) this_rel.create_log() label = this_rel.label() this_rel.write_log("Label for released code " + str(label)) this_rel.write_log("Base Build ID\t" + str(self.kymera_src_id)) this_rel.end_log() this_rel.archive_KCS( this_rel.obtain_product_name(self.download_config)) release.release_lock() else: # Copy binaries to a common folder so they don't get erased when a new build is triggered if not os.path.exists( os.path.join(self.kymera_src_path, "output_bundles", self.download_config, self.bundle_name)): os.makedirs( os.path.join(self.kymera_src_path, "output_bundles", self.download_config, self.bundle_name)) file_ext_list = [".dkcs", ".kcs", ".elf", ".kmap", ".lst", ".sym"] for file_ext in file_ext_list: shutil.copy( os.path.join(self.kcs_output_dir, "download", "debugbin", self.bundle_name + file_ext), os.path.join(self.kymera_src_path, "output_bundles", self.download_config, self.bundle_name, self.bundle_name + file_ext)) print("Bundle built successfully and available at: " + "{0}".format( os.path.join(self.kymera_src_path, "output_bundles", self.download_config, self.bundle_name, self.bundle_name + ".dkcs")))
# Don't delete this temp directory used to store kmap files if dir_or_file != "kmap_tmp": shutil.rmtree(dir_or_file_abs) else: # It's a file, remove it os.remove(dir_or_file_abs) # Write current bundle into a file last_bundle_file = open(os.path.join(KCS_OUTPUT_DIR,"last_bundle.txt"),"w") last_bundle_file.write(BUNDLE_NAME) last_bundle_file.close() if MAKE_JOBS is None: MAKE_JOBS = True build = build_controller.Build_Controller(BUILD_ROOT, BUILD_DIR, KCS_OUTPUT_DIR, KCSMAKER_PATH, DOWNLOAD_CONFIG, rel_binfo.get_elf_name(), EXTRA_INCLUDE, BUILD_NAME, KYMERA_SRC_PATH, OS_TYPE) build.build(rel_binfo, cap_list, kdc_name, LINKSCRIPT_PATH, MAKE_PATH, clean_build, MAKE_JOBS) logging.info(str(mod.KDCs[kdc_name]) + " capabilities successfully built.") # Copy kmap file to temp folder (it will get deleted on next KDC build) if not os.path.exists(os.path.join(KCS_OUTPUT_DIR,"kmap_tmp")): os.makedirs(os.path.join(KCS_OUTPUT_DIR,"kmap_tmp")) shutil.copy(os.path.join(KCS_OUTPUT_DIR, "download", "debugbin", kdc_name + ".kmap"),os.path.join(KCS_OUTPUT_DIR,"kmap_tmp", kdc_name + "(KDC).kmap")) os.chdir(KCSMAKER_PATH) objDumpPath = os.path.join(get_kcc_version.kcc_version().get_kcc_path(OS_TYPE), "bin", "kobjdump") oFiles = get_obj_files() logging.info("oFiles" + str(oFiles)) dnldElfFile = os.path.join(KCS_OUTPUT_DIR, "download", "debugbin", kdc_name + ".elf") mapOutFile = os.path.join(KCS_OUTPUT_DIR, "download", "debugbin", "map_out.txt") makeKDC = make_kdc.make_kdc(dnldElfFile, rel_binfo.get_elf_name(), chip, objDumpPath, oFiles, cap_list, OS_TYPE, mapOutFile) kdc = makeKDC.generateKDC(kdc_count,rel_binfo.get_rom_kalaccess()) print(("Sizes for KDC {}:".format(dnldElfFile)))