コード例 #1
0
def get_dd_sha256(MODULE_DD_BIN):
    sha256 = None
    digest = mpgen_shell.dsystemf('openssl dgst -c -sha256 %s', MODULE_DD_BIN)
    ll = digest.split('=')
    if (len(ll) == 2):
        sha256 = ll[1].strip(' \n\r')
    return sha256
コード例 #2
0
    def get_kernel(self, vmlinux):
        if (OBJCOPY is None):
            print("ERROR: objcopy not defined\n")
            sys.exit(1)
        if (OBJDUMP is None):
            print("ERROR: objdump not defined\n")
            sys.exit(1)
        if (outdated(KERNEL_IMAGE, vmlinux)):
            print("OBJCOPY\n")
            mpgen_shell.dsystemf("%s %s %s", OBJCOPY, vmlinux, KERNEL_IMAGE)
            # mv(kernel_path, ".");
        if (outdated(SYMBOLS_FILENAME, KERNEL_IMAGE)):
            print("SYMBOLS\n")
            mpgen_shell.dsystemf('%s -t %s > %s', OBJDUMP, KERNEL_IMAGE,
                                 SYMBOLS_FILENAME)
        if (outdated(HEADERS_FILENAME, KERNEL_IMAGE)):
            print("SECTIONS\n")
            mpgen_shell.dsystemf("%s -h %s > %s", OBJDUMP, KERNEL_IMAGE,
                                 HEADERS_FILENAME)

        # mpgen_shell.dsystemf('%s --dwarf %s > %s', OBJDUMP, KERNEL_IMAGE, DWARF_FILENAME);

        self.symbol_tbl = mpgen_symbols.symbol_table()
        self.symbol_tbl.read_symbol_table(self.get_symbols_filename())

        self.section_tbl = mpgen_sections.Section_Table()
        self.section_tbl.read_section_table(self.get_sections_filename())
        return
コード例 #3
0
 def get_section_sha256(self, section_name):
     MODULE_DD_BIN = self.dd_section(section_name)
     sha256 = get_dd_sha256(MODULE_DD_BIN)
     mpgen_shell.dsystemf('rm %s', MODULE_DD_BIN)
     return sha256
コード例 #4
0
def get_dd_sha1(MODULE_DD_BIN):
    sha1 = mpgen_shell.dsystemf('openssl dgst -c -sha1 %s', MODULE_DD_BIN)
    return sha1
コード例 #5
0
ファイル: mpgen.py プロジェクト: mxpro2003/qcs605_root
    def main():
        parser = argparse.ArgumentParser(
            description="MPGEN tool\n",
            formatter_class=argparse.RawDescriptionHelpFormatter)
        parser_group = parser.add_mutually_exclusive_group(required=True)
        parser_group.add_argument('--vmlinux',
                                  type=str,
                                  help='path to vmlinux',
                                  metavar='<in_file>')
        parser_group.add_argument('--header',
                                  type=str,
                                  help='generates MP header to a given file',
                                  metavar='<out_file>')
        parser.add_argument(
            '--dts_payload',
            type=bool,
            help=
            'generates MP DTS pay load .C file that contains dts_payload symbol',
            metavar='')
        parser.add_argument(
            '--dts',
            type=bool,
            help='generates MP DTS file. This includes dts pay load generation',
            metavar='')
        parser.add_argument('--config',
                            type=str,
                            help='path to kernel .config file',
                            default='')
        parser.add_argument('--binpath',
                            type=str,
                            help='path to cross compiler bin directory',
                            default='')
        parser.add_argument('--objcopy',
                            type=str,
                            help='file name of the `objcopy` utility',
                            default='aarch64-linux-androidkernel-objcopy')
        parser.add_argument('--objdump',
                            type=str,
                            help='file name of the `objdump` utility',
                            default='aarch64-linux-androidkernel-objdump')
        parser.add_argument('--dd',
                            type=str,
                            help='file name of the `dd` utility',
                            default='dd')
        parser.add_argument('--cc',
                            type=str,
                            help='compiler command line',
                            default='')

        args, unparsed = parser.parse_known_args()

        if (unparsed): raise Exception("Unknown arguments: %s" % unparsed)

        # Set ARGUMENTS
        mpgen_kernel.OBJCOPY = os.path.join(args.binpath, args.objcopy)
        mpgen_kernel.OBJDUMP = os.path.join(args.binpath, args.objdump)
        mpgen_shell.DD = args.dd

        print("\n\n")
        print("======================================")
        print("            %s version %s         " %
              (const.NAME, const.VERSION))
        print("======================================")

        # Generate MP header file
        if args.header:
            data = mpgen_cgen.generate_rtic_mp_header()
            with open(args.header, 'wb') as f:
                f.write(data)
                raise GreatSuccess

        # Generate MP object (C)
        vmlinux = args.vmlinux

        # create a kernel python object
        print("KERNEL")
        kernel = mpgen_kernel.Kernel()

        # objcopy the kernel if it is out of date
        print("VMLINUX")
        kernel.get_kernel(vmlinux)

        config = mpgen_kconfig.Kconfig(args.config)

        print("CATALOG")
        catalog = mpgen_catalog.get_catalog(config)

        print("POPULATE")
        mpdb = mpgen_populate.get_mpdb(catalog, kernel, config)

        if args.dts_payload or args.dts:
            # generate dts payload
            with open("rtic_dts_payload.c", "w") as f_cfile:
                c_content = mpgen_cgen.generate_rtic_dts(kernel, mpdb)
                print("writing DTS C file ...\n")
                f_cfile.write(c_content)

            if args.dts:
                # compile to object
                # mpgen_shell.dsystemf("cat rtic_dts.c  %s %s %s", OBJCOPY, vmlinux, KERNEL_IMAGE)
                print "building DTS pay load"
                mpgen_shell.dsystemf(
                    "%s -c rtic_dts_payload.c -o rtic_dts_payload.o" %
                    (args.cc))

                # cat $C_F | /pkg/asw/compilers/gnu/linaro-toolchain/.4.9-2014.06-02_linux-x86/bin/aarch64-linux-gnu-gcc -c -o alex_dummy_dtb.o -x c - && \
                # objcopy -j .rodata -O binary -I elf64-little alex_dummy_dtb.o alex_dummy_dtb.rodata

                # extract dts_payload binary content (assume we have only one structure in .const section, therefore get this section)
                # mpgen_shell.dsystemf("%s -j .const -O binary -I elf64-little alex_dummy_dtb.o alex_dummy_dtb.rodata" % (args.objcopy))
                # mpgen_shell.dsystemf("/usr/local/bin/gobjcopy -I elf64-little -j .const -O binary rtic_dts_payload.o rtic_dts_payload.const")
                mpgen_shell.dsystemf(
                    "%s -j .rodata -O binary rtic_dts_payload.o rtic_dts_payload.const"
                    % (args.objcopy))

                # convert binary blob to hex characters
                with open('rtic_dts_payload.const', 'rb') as f:
                    pyaload_bin = f.read()
                    payload_hex = binascii.hexlify(pyaload_bin)
                    payload_hex = " ".join([
                        a + b
                        for a, b in zip(payload_hex[::2], payload_hex[1::2])
                    ])

                    # generate dts file
                    with open("rtic_mp.dts", "w") as f:
                        content = mpgen_dtsgen.generate_rtic_mp_dts(
                            payload_hex)
                        f.write(content)
                        # print ">>>>>", content

        else:  # 'cfile'
            with open("rtic_mp.c", "w") as f_cfile:
                # cfile = mpgen_cfile.Cfile(kernel, mpdb)
                c_content = mpgen_cgen.generate_rtic_mp(kernel, mpdb)
                print("WRITE C\n")
                f_cfile.write(c_content)

        # For now generate xml by default
        with open("rtic_mp.xml", "w") as f:
            content = mpgen_xml.generate_rtic_mp_xml(kernel, mpdb)
            print("WRITE XML\n")
            f.write(content)
            f.close()

        print("======================================")
        print("            MPGEN PROTO RUN COMPLETE")
        print("======================================")

        # todo: add proper exit code
        # sys.exit(0)  # explicit exit is required for the frozen file
        raise GreatSuccess