From 9e297aa436704ec5c1e7d162f5e6d836f2b15d6e Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Mon, 13 Jan 2025 18:38:58 +0800 Subject: [PATCH] =?UTF-8?q?mfgtool=20ah=20=E5=8F=AF=E4=BB=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8ninja=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .gn | 10 +++++ build/BUILD.gn | 21 ++++++++++ build/BUILDCONFIG.gn | 41 +++++++++++++++++++ build/config.gn | 17 ++++++++ build/toolchain/BUILD.gn | 88 ++++++++++++++++++++++++++++++++++++++++ mfgtool/BUILD.gn | 11 +++++ mfgtool/ah/BUILD.gn | 13 ++++++ pib/src/iot_oem.c | 2 +- 9 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 .gn create mode 100644 build/BUILD.gn create mode 100755 build/BUILDCONFIG.gn create mode 100644 build/config.gn create mode 100755 build/toolchain/BUILD.gn create mode 100644 mfgtool/BUILD.gn create mode 100644 mfgtool/ah/BUILD.gn diff --git a/.gitignore b/.gitignore index 410ec42..4721cdf 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ mfgtool/ah/ah mfgtool/lzma/elzma mfgtool/oem_tool/oem_tool mfgtool/*.o +out/ diff --git a/.gn b/.gn new file mode 100644 index 0000000..d5211bf --- /dev/null +++ b/.gn @@ -0,0 +1,10 @@ + + + + +buildconfig = "//build/BUILDCONFIG.gn" + +root = "//mfgtool" + +script_executable = "/usr/bin/env" + diff --git a/build/BUILD.gn b/build/BUILD.gn new file mode 100644 index 0000000..cc3f948 --- /dev/null +++ b/build/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +config("compiler_defaults") { + if (current_os == "linux") { + cflags = [ + "-fPIC", + "-pthread", + ] + } +} + +config("executable_ldconfig") { + if (!is_mac) { + ldflags = [ + "-Wl,-rpath=\$ORIGIN/", + "-Wl,-rpath-link=", + ] + } +} diff --git a/build/BUILDCONFIG.gn b/build/BUILDCONFIG.gn new file mode 100755 index 0000000..619fa97 --- /dev/null +++ b/build/BUILDCONFIG.gn @@ -0,0 +1,41 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +if (target_os == "") { + target_os = host_os +} +if (target_cpu == "") { + target_cpu = host_cpu +} +if (current_cpu == "") { + current_cpu = target_cpu +} +if (current_os == "") { + current_os = target_os +} + +is_linux = host_os == "linux" && current_os == "linux" && target_os == "linux" +is_mac = host_os == "mac" && current_os == "mac" && target_os == "mac" + +# All binary targets will get this list of configs by default. +_shared_binary_target_configs = [ "//build:compiler_defaults" ] + +# Apply that default list to the binary target types. +set_defaults("executable") { + configs = _shared_binary_target_configs + + # Executables get this additional configuration. + configs += [ "//build:executable_ldconfig" ] +} +set_defaults("static_library") { + configs = _shared_binary_target_configs +} +set_defaults("shared_library") { + configs = _shared_binary_target_configs +} +set_defaults("source_set") { + configs = _shared_binary_target_configs +} + +set_default_toolchain("//build/toolchain:gcc") diff --git a/build/config.gn b/build/config.gn new file mode 100644 index 0000000..ae243ad --- /dev/null +++ b/build/config.gn @@ -0,0 +1,17 @@ + + +if (target_cpu == ""){ + target_cpu = "x64" +} +if (target_os == ""){ + target_os = "linux" +} +if (current_cpu == ""){ + current_cpu = target_cpu +} +if (current_os == ""){ + current_os = target_os +} + +set_default_toolchain(":gcc") + diff --git a/build/toolchain/BUILD.gn b/build/toolchain/BUILD.gn new file mode 100755 index 0000000..c04ee1e --- /dev/null +++ b/build/toolchain/BUILD.gn @@ -0,0 +1,88 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +toolchain("gcc") { + tool("cc") { + depfile = "{{output}}.d" + command = "gcc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CC {{output}}" + outputs = + [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] + } + + tool("cxx") { + depfile = "{{output}}.d" + command = "g++ -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CXX {{output}}" + outputs = + [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] + } + + tool("alink") { + command = "rm -f {{output}} && ar rcs {{output}} {{inputs}}" + description = "AR {{target_output_name}}{{output_extension}}" + + outputs = + [ "{{target_out_dir}}/{{target_output_name}}{{output_extension}}" ] + default_output_extension = ".a" + output_prefix = "lib" + } + + tool("solink") { + soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". + sofile = "{{output_dir}}/$soname" + rspfile = soname + ".rsp" + if (is_mac) { + os_specific_option = "-install_name @executable_path/$sofile" + rspfile_content = "{{inputs}} {{solibs}} {{libs}}" + } else { + os_specific_option = "-Wl,-soname=$soname" + rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" + } + + command = "g++ -shared {{ldflags}} -o $sofile $os_specific_option @$rspfile" + + description = "SOLINK $soname" + + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + default_output_extension = ".so" + + # Use this for {{output_dir}} expansions unless a target manually overrides + # it (in which case {{output_dir}} will be what the target specifies). + default_output_dir = "{{root_out_dir}}" + + outputs = [ sofile ] + link_output = sofile + depend_output = sofile + output_prefix = "lib" + } + + tool("link") { + outfile = "{{target_output_name}}{{output_extension}}" + rspfile = "$outfile.rsp" + if (is_mac) { + command = "g++ {{ldflags}} -o $outfile @$rspfile {{solibs}} {{libs}}" + } else { + command = "g++ {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" + } + description = "LINK $outfile" + default_output_dir = "{{root_out_dir}}" + rspfile_content = "{{inputs}}" + outputs = [ outfile ] + } + + tool("stamp") { + command = "touch {{output}}" + description = "STAMP {{output}}" + } + + tool("copy") { + command = "cp -af {{source}} {{output}}" + description = "COPY {{source}} {{output}}" + } +} diff --git a/mfgtool/BUILD.gn b/mfgtool/BUILD.gn new file mode 100644 index 0000000..574774d --- /dev/null +++ b/mfgtool/BUILD.gn @@ -0,0 +1,11 @@ +group("mfgtools") { + deps = [ + # This will expand to the name "//tutorial:tutorial" which is the full name + # of our new target. Run "gn help labels" for more. + # "//ah:aha", + "ah:aha" + ] +} + + + diff --git a/mfgtool/ah/BUILD.gn b/mfgtool/ah/BUILD.gn new file mode 100644 index 0000000..7805a53 --- /dev/null +++ b/mfgtool/ah/BUILD.gn @@ -0,0 +1,13 @@ +executable("aha") { + sources = [ + "add_header_v1.c", + "../ram/src/crc.c", + "../ram/src/sha256.c" + ] + + include_dirs = [ + "../ram/inc", + "../../inc", + "../../inc/utils" + ] +} \ No newline at end of file diff --git a/pib/src/iot_oem.c b/pib/src/iot_oem.c index d138403..d182938 100644 --- a/pib/src/iot_oem.c +++ b/pib/src/iot_oem.c @@ -122,7 +122,7 @@ uint32_t iot_oem_read_mtd_ext(uint8_t *buff,uint32_t buff_size) uint8_t fw_prtition = PART_NUM_FW1; char str_buff[10]={0}; imgHdr hdr={0}; - imgHdr run_fw_hdr; + imgHdr run_fw_hdr={0}; const uint8_t *data; const char *oem_ext_magic_str = IOT_OEM_EXT_MAGIC_STR; int oem_ext_magic_str_len = strlen(oem_ext_magic_str);