Ejemplo n.º 1
0
    def validate_args(self, opt):
        res = 0

        ver_validator = re.compile('[\d]+\.[\d]+\-[\w]+')

        if not os.path.exists(self._codewarrior_path):
            print ("ERROR: could not find code warrior path. This is controlled by environmental\r\n"
                   " variable WHISTLE_CODEWARRIOR. To set this up follow these instructions: \r\n"
                   "  1. Go to Start Menu -> Right Click on My Computer -> Click Properties\r\n"
                   "  2. Click 'Advanced system settings' on the left\r\n"
                   "  3. Click 'Environment Variables' button\r\n"
                   "  4. Click 'New' button\r\n"
                   "  5. Enter variable name of 'WHISTLE_CODEWARRIOR' and variable value\r\n"
                   "     of your path for code warrior\r\n")
            print ("  supplied path: " + self._ecd_path)
            res = -1

        if not os.path.exists(self._ecd_path):
            print ("ERROR: could not find ECD.exe")
            print ("  supplied path: " + self._ecd_path)
            res = -1

        if opt.odir is None:
            print ("ERROR: must supply output directory (--odir).")
            res = -1

        out_dir = os.path.abspath(opt.odir)
        if out_dir is None or not os.path.exists(out_dir):
            print ("ERROR: problem with accessing output directory.")
            print (" dir: " + opt.odir)
            res = -1
        self._out_dir = out_dir

        if opt.boot1 or opt.boot2 or opt.app:
            if opt.d_usb and opt.d_uart:
                print("ERROR: cannot specify both debug UART and debug USB options, choose one.")
                res = -1

            if not opt.d_usb and not opt.d_uart:
                print("ERROR: must specify either --d_usb or --d_uart.")
                res = -1

        if opt.app:
            ver_match = ver_validator.match(opt.app)
            if ver_match is None or ver_match.group() is None:
                print("ERROR: must specify app version when building App in format of <major ver>.<minor ver>-tag "
                      "(#.#-string)")
                res = -1

        if opt.app:
            try:
                x = BinaryImageTLV.parse_version_string(opt.app)
            except:
                print("ERROR: app version does not meet input patter (x.y-tag)")
                res = -1

        if opt.boot1:
            ver_match = ver_validator.match(opt.boot1)
            if ver_match.group() is None:
                print("ERROR: must specify app version when building Boot1 in format of <major ver>.<minor ver>-tag "
                      "(#.#-string)")
                res = -1

        if opt.boot1:
            try:
                x = BinaryImageTLV.parse_version_string(opt.boot1)
            except:
                print("ERROR: boot1 version does not meet input patter (x.y-tag)")
                res = -1

        if opt.boot2:
            ver_match = ver_validator.match(opt.boot2)
            if ver_match.group() is None:
                print("ERROR: must specify app version when building Boot2 in format of <major ver>.<minor ver>-tag "
                      "(#.#-string)")
                res = -1

        if opt.boot2:
            try:
                x = BinaryImageTLV.parse_version_string(opt.boot2)
            except:
                print("ERROR: boot2 version does not meet input patter (x.y-tag)")
                res = -1

        return res
Ejemplo n.º 2
0
    def run(self, argv):
        parser = OptionParser()
        self.setupOptions(parser)
        (opt, args) = parser.parse_args(argv)

        if os.path.exists(ECLIPSE_LOCAL_METADATA):
            # Freescale mentioned this is necessary to avoid random JAVA errors.
            print "Cleaning CW env file: ", ECLIPSE_LOCAL_METADATA
            shutil.rmtree(ECLIPSE_LOCAL_METADATA)

        self._ecd_path = self._codewarrior_path + _ECD_REL_PATH

        if self.validate_args(opt) == -1:
            print ("Builder: RUN ERROR: failed to validate arguements.\r\n")
            return -1

        if opt.nodep is not None:
            self._process_dependencies = not opt.nodep

        if opt.d_uart:
            config = CONFIG_D_UART
        elif opt.d_usb:
            config = CONFIG_D_USB
        else:
            config = None

# Build projects
        if opt.app:
            if self.build(APP_BUILD_ITEM, config, opt.app, skipbuild=opt.skipbuild) != 0:
                print("\r\nBUILDER: ERROR out because of app build issue.\r\n")
                return -1

        if opt.boot1:
            if self.build(BOOT1_BUILD_ITEM, config, opt.boot1, skipbuild=opt.skipbuild) != 0:
                print("\r\nBUILDER: ERROR out because of boot1 build issue.\r\n")
                return -1

        if opt.boot2:
            if self.build(BOOT2_BUILD_ITEM, config, opt.boot2, skipbuild=opt.skipbuild) != 0:
                print("\r\nBUILDER: ERROR out because of boot2 build issue.\r\n")
                return -1

# Parse C-array and create binary file
        if opt.basepatch:
            in_patch_c = self._corona_base_path + BT_PATCH_DEF_LOCATION + "\\" + BT_BASE_PATCH_FILE
            out_patch_bin = self._out_dir + "\\" + os.path.basename(in_patch_c).rstrip('.c') + "-" + opt.basepatch + ".bin"
            bt_patch_out_file = self.patch_binary_parser(in_patch_c, out_patch_bin)
            print("Parsing BASEPATCH patch C-array and creating bin file.")
            print("        BASEPATCH: " + bt_patch_out_file)
        
        if opt.blepatch:
            in_patch_c = self._corona_base_path + BT_PATCH_DEF_LOCATION + "\\" + BT_LOW_ENERGY_PATCH_FILE
            out_patch_bin = self._out_dir + "\\" + os.path.basename(in_patch_c).rstrip('.c') + "-" + opt.blepatch + ".bin"
            ble_patch_out_file = self.patch_binary_parser(in_patch_c, out_patch_bin)
            print("Parsing LOWENERGY patch C-array and creating bin file.")
            print("        LOWENERGY: " + ble_patch_out_file)

# Convert S19 build outputs to BIN files
        if opt.genpkg or opt.genbin:
            for pkg in self._build_output:
                wbin = WhistleBinary()
                bin_file_path = self._out_dir + "\\" + pkg + "_" + self._build_output[pkg][VERSION] + "_" + config + ".bin"
                wbin.setxmap(self._build_output[pkg][GEN_XMAP_FILE_LOC])
                wbin.sets19file(self._build_output[pkg][GEN_S19_FILE_LOC])
                wbin.setbinfile(bin_file_path)
                [major, minor, tag] = BinaryImageTLV.parse_version_string(self._build_output[pkg][VERSION])
                wbin.set_image_version(major, minor, tag)
                res = wbin.burn()

                # Check for presence of output file to confirm success.
                if not os.path.exists(bin_file_path):
                    print "** Error: Output File: '", bin_file_path, "' could not be found!"
                    return -1

                self._build_output[pkg].update({GEN_BIN_FILE_LOC : bin_file_path})

        if opt.genpkg:
            fwu_pkg_gen_args = ["fwu_pkg_gen.py"]
            pkg_file_path = ""
            if opt.title:
                fwu_pkg_gen_args += ["-t", opt.pkg_title]
                pkg_file_path += opt.title + "_"
            if opt.boot1:
                fwu_pkg_gen_args += ["--boot1-img",
                                     self._build_output[BOOT1_BUILD_ITEM[TITLE]][GEN_BIN_FILE_LOC]]
                fwu_pkg_gen_args += ["--boot1-ver", opt.boot1]
                pkg_file_path += "BOOT1_" + opt.boot1 + "_"
            if opt.boot2:
                fwu_pkg_gen_args += ["--boot2a-img",
                                     self._build_output[BOOT2A_BUILD_ITEM[TITLE]][GEN_BIN_FILE_LOC]]
                fwu_pkg_gen_args += ["--boot2a-ver", opt.boot2]
                fwu_pkg_gen_args += ["--boot2b-img",
                                     self._build_output[BOOT2B_BUILD_ITEM[TITLE]][GEN_BIN_FILE_LOC]]
                fwu_pkg_gen_args += ["--boot2b-ver", opt.boot2]
                pkg_file_path += "BOOT2_" + opt.boot2 + "_"
            if opt.app:
                fwu_pkg_gen_args += ["--app-img",
                                     self._build_output[APP_BUILD_ITEM[TITLE]][GEN_BIN_FILE_LOC]]
                fwu_pkg_gen_args += ["--app-ver", opt.app]
                pkg_file_path += "APP_" + opt.app + "_"
            if opt.pad:
                fwu_pkg_gen_args += ["--pad"]
                pkg_file_path += "PADDED_"
            if opt.basepatch:
                patch_bin_file = bt_patch_out_file
                fwu_pkg_gen_args += ["--basepatch-bin", patch_bin_file]
                pkg_file_path += "BASEPATCH_" + opt.basepatch + "_"
            if opt.blepatch:
                patch_bin_file = ble_patch_out_file
                fwu_pkg_gen_args += ["--blepatch-bin", patch_bin_file]
                pkg_file_path += "BLEPATCH_" + opt.blepatch + "_"

            if pkg_file_path[len(pkg_file_path)-1] == "_":
                pkg_file_path = pkg_file_path[0:len(pkg_file_path)-1]

            pkg_file_path = self._out_dir + "\\" + pkg_file_path + ("" if config is None else ("_" + config)) + ".pkg"
            fwu_pkg_gen_args += ["-o", pkg_file_path]

            print ("FWU PKG GEN ARGS:")
            print (fwu_pkg_gen_args)
            pkgGen = FwuPackageGenerator()
            res = pkgGen.run(fwu_pkg_gen_args)

        print ("\r\n\r\nCOMPLETE!\r\n")
        return res