2019-06-21 15:31:42 u010299133 阅读数 616

参考:

https://blog.csdn.net/qq_41248872/article/details/83575611


由于项目需要,需要获得linux系统中的当前的北京时间。但是通过localtime接口获取的时间和当前的北京时间无法对应上,比如现在是2019年,但是获取的时间是2016的,并且在系统启动后在命令行终端使用date查看的时间也是对应不上。

[root@arm-linux]#date
Thu Jan 21 08:50:46 UTC 2016

在此之前需要查看目录/dev/下面是否有rtc的设备节点

[root@arm-linux]#ls -al /dev/rtc*
crw-------    1 root     0         253,   0 Jan  1  1970 /dev/rtc0

第一步:

step1:从ubuntu系统中拷贝Shanghai文件到sdk中的etc目录下:

sudo cp /usr/share/zoneinfo/Asia/Shanghai common/root/etc/

step2:将文件名Shanghai改为localtime

sudo mv common/root/etc/Shanghai common/root/etc/localtime

从新编译sdk并烧写编译好的固件。

系统起来后发现时间还是没有变化,但是时区从UTC变为CST了:

date
Thu Jan 21 08:54:50 CST 2016

第二步:

在系统起来后,在终端通过如下方法可以修改当前的时间:

step1:写入系统时间
[root@arm-linux]#date -s "2019-6-21 15:19:45"
Fri Jun 21 15:19:45 UTC 2019

step2:写入硬件时钟

[root@arm-linux]#hwclock -w
[root@arm-linux]#

step3:查看硬件时间

[root@arm-linux]#hwclock
Fri Jun 21 15:21:08 2019  0.000000 seconds
[root@arm-linux]#

step4:查看系统时间

[root@arm-linux]#date
Fri Jun 21 15:20:09 UTC 2019
[root@arm-linux]#
[root@arm-linux]#

2016-02-01 00:00:00 ztguang 阅读数 3931
http://www.fx114.net/qa-59-85000.aspx



root@Ubuntu32:/home/zhangbin/android/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin# ls
arm-linux-androideabi-addr2line   arm-linux-androideabi-gprof
arm-linux-androideabi-ar          arm-linux-androideabi-ld
arm-linux-androideabi-as          arm-linux-androideabi-ld.bfd
arm-linux-androideabi-c++         arm-linux-androideabi-ld.gold
arm-linux-androideabi-c++filt     arm-linux-androideabi-ld.mcld
arm-linux-androideabi-cpp         arm-linux-androideabi-nm
arm-linux-androideabi-elfedit     arm-linux-androideabi-objcopy
arm-linux-androideabi-g++         arm-linux-androideabi-objdump
arm-linux-androideabi-gcc         arm-linux-androideabi-ranlib
arm-linux-androideabi-gcc-4.8     arm-linux-androideabi-readelf
arm-linux-androideabi-gcc-ar      arm-linux-androideabi-run
arm-linux-androideabi-gcc-nm      arm-linux-androideabi-size
arm-linux-androideabi-gcc-ranlib  arm-linux-androideabi-strings
arm-linux-androideabi-gcov        arm-linux-androideabi-strip
arm-linux-androideabi-gdb


root@Ubuntu32:/home/zhangbin/android/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin# ./arm-linux-androideabi-ld --help
Usage: ./arm-linux-androideabi-ld [options] file...
Options:
  --help                      Report usage information
  -v, --version               Report version information
  -V                          Report version and target information
  --add-needed                Not supported
  --no-add-needed             Do not copy DT_NEEDED tags from shared libraries
  --allow-multiple-definition Allow multiple definitions of symbols
  --no-allow-multiple-definition
                              Do not allow multiple definitions
  --allow-shlib-undefined     Allow unresolved references in shared libraries
  --no-allow-shlib-undefined  Do not allow unresolved references in shared libraries
  --as-needed                 Only set DT_NEEDED for shared libraries if used
  --no-as-needed              Always DT_NEEDED for shared libraries
  -assert [ignored]           Ignored
  -b [elf,binary], --format [elf,binary]
                              Set input format
  -Bdynamic                   -l searches for shared libraries
  -Bstatic                    -l does not search for shared libraries
  -dy                         alias for -Bdynamic
  -dn                         alias for -Bstatic
  -Bgroup                     Use group name lookup rules for shared library
  -Bsymbolic                  Bind defined symbols locally
  -Bsymbolic-functions        Bind defined function symbols locally
  --build-id [=STYLE]         Generate build ID note
  --check-sections            Check segment addresses for overlaps (default)
  --no-check-sections         Do not check segment addresses for overlaps
  --compress-debug-sections [none,zlib]
                              Compress .debug_* sections in the output file
  --copy-dt-needed-entries    Not supported
  --no-copy-dt-needed-entries Do not copy DT_NEEDED tags from shared libraries
  --cref                      Output cross reference table
  --no-cref                   Do not output cross reference table
  --ctors-in-init-array       Use DT_INIT_ARRAY for all constructors (default)
  --no-ctors-in-init-array    Handle constructors as directed by compiler
  -d, --define-common         Define common symbols
  --no-define-common          Do not define common symbols
  -dc                         Alias for -d
  -dp                         Alias for -d
  --debug [all,files,script,task][,...]
                              Turn on debugging
  --defsym SYMBOL=EXPRESSION  Define a symbol
  --demangle [=STYLE]         Demangle C++ symbols in log messages
  --no-demangle               Do not demangle C++ symbols in log messages
  --detect-odr-violations     Look for violations of the C++ One Definition Rule
  --no-detect-odr-violations  Do not look for violations of the C++ One Definition Rule
  -x, --discard-all           Delete all local symbols
  -X, --discard-locals        Delete all temporary local symbols
  --dynamic-list-data         Add data symbols to dynamic symbols
  --dynamic-list-cpp-new      Add C++ operator new/delete to dynamic symbols
  --dynamic-list-cpp-typeinfo Add C++ typeinfo to dynamic symbols
  --dynamic-list FILE         Read a list of dynamic symbols
  -e ADDRESS, --entry ADDRESS Set program start address
  --exclude-libs lib,lib ...  Exclude libraries from automatic export
  -E, --export-dynamic        Export all dynamic symbols
  --no-export-dynamic         Do not export all dynamic symbols (default)
  --export-dynamic-symbol SYMBOL
                              Export SYMBOL to dynamic symbol table
  -EB                         Link big-endian objects.
  -EL                         Link little-endian objects.
  --eh-frame-hdr              Create exception frame header
  --no-enum-size-warning      (ARM only) Do not warn about objects with incompatible enum sizes
  -f SHLIB, --auxiliary SHLIB Auxiliary filter for shared object symbol table
  -F SHLIB, --filter SHLIB    Filter for shared object symbol table
  --fatal-warnings            Treat warnings as errors
  --no-fatal-warnings         Do not treat warnings as errors
  -fini SYMBOL                Call SYMBOL at unload-time
  --fix-cortex-a8             (ARM only) Fix binaries for Cortex-A8 erratum.
  --no-fix-cortex-a8          (ARM only) Do not fix binaries for Cortex-A8 erratum.
  --fix-arm1176               (ARM only) Fix binaries for ARM1176 erratum.
  --no-fix-arm1176            (ARM only) Do not fix binaries for ARM1176 erratum.
  --merge-exidx-entries       (ARM only) Merge exidx entries in debuginfo.
  --no-merge-exidx-entries    (ARM only) Do not merge exidx entries in debuginfo.
  --fix-v4bx                  (ARM only) Rewrite BX rn as MOV pc, rn for ARMv4
  --fix-v4bx-interworking     (ARM only) Rewrite BX rn branch to ARMv4 interworking veneer
  -g                          Ignored
  --gdb-index                 Generate .gdb_index section
  --no-gdb-index              Do not generate .gdb_index section
  --gnu-unique                Enable STB_GNU_UNIQUE symbol binding (default)
  --no-gnu-unique             Disable STB_GNU_UNIQUE symbol binding
  -h FILENAME, -soname FILENAME
                              Set shared library name
  --hash-bucket-empty-fraction FRACTION
                              Min fraction of empty buckets in dynamic hash
  --hash-style [sysv,gnu,both]
                              Dynamic hash style
  -I PROGRAM, --dynamic-linker PROGRAM
                              Set dynamic linker path
  --incremental               Do an incremental link if possible; otherwise, do a full link and prepare output for incremental linking
  --no-incremental            Do a full link (default)
  --incremental-full          Do a full link and prepare output for incremental linking
  --incremental-update        Do an incremental link; exit if not possible
  --incremental-base FILE     Set base file for incremental linking (default is output file)
  --incremental-changed       Assume files changed
  --incremental-unchanged     Assume files didn't change
  --incremental-unknown       Use timestamps to check files (default)
  --incremental-startup-unchanged
                              Assume startup files unchanged (files preceding this option)
  --incremental-patch PERCENT Amount of extra space to allocate for patches
  -init SYMBOL                Call SYMBOL at load-time
  --just-symbols FILE         Read only symbol values from FILE
  --map-whole-files           Map whole files to memory (default on 64-bit hosts)
  --no-map-whole-files        Map relevant file parts to memory (default on 32-bit hosts)
  --keep-files-mapped         Keep files mapped across passes (default)
  --no-keep-files-mapped      Release mapped files after each pass
  --ld-generated-unwind-info  Generate unwind information for PLT (default)
  --no-ld-generated-unwind-info
                              Do not generate unwind information for PLT
  -l LIBNAME, --library LIBNAME
                              Search for library LIBNAME
  -L DIR, --library-path DIR  Add directory to search path
  --text-reorder              Enable text section reordering for GCC section names (default)
  --no-text-reorder           Disable text section reordering for GCC section names
  -nostdlib                    Only search directories specified on the command line.  仅仅搜寻命令行中指定的目录
  --rosegment                  Put read-only non-executable sections in their own segment
  -m EMULATION                Set GNU linker emulation; obsolete
  --mmap-output-file          Map the output file for writing (default).
  --no-mmap-output-file       Do not map the output file for writing.
  -M, --print-map             Write map file on standard output
  -Map MAPFILENAME            Write map file
  -n, --nmagic                Do not page align data
  -N, --omagic                Do not page align data, do not make text readonly
  --no-omagic                 Page align data, make text readonly
  --enable-new-dtags          Enable use of DT_RUNPATH and DT_FLAGS
  --disable-new-dtags         Disable use of DT_RUNPATH and DT_FLAGS
  --noinhibit-exec            Create an output file even if errors occur
  --no-undefined              Report undefined symbols (even with --shared)
  -o FILE, --output FILE      Set output file name
  -O LEVEL, -optimize LEVEL   Optimize output file size
  --oformat [binary]          Set output format
  -p                          (ARM only) Ignore for backward compatibility
  -pie                        Create a position independent executable
  --pic-executable            Create a position independent executable
  -no-pipeline-knowledge      (ARM only) Ignore for backward compatibility
  --plugin PLUGIN             Load a plugin library
  --plugin-opt OPTION         Pass an option to the plugin
  --posix-fallocate           Use posix_fallocate to reserve space in the output file (default).
  --no-posix-fallocate        Use fallocate or ftruncate to reserve space.
  --preread-archive-symbols   Preread archive symbols when multi-threaded
  --print-output-format       Print default output format
  --print-symbol-counts FILENAME
                              Print symbols defined and used for each input
  -Qy                         Ignored for SVR4 compatibility
  -q, --emit-relocs           Generate relocations in output
  -r, -relocatable            Generate relocatable output
  -i                          Synonym for -r
  --relax                     Relax branches on certain targets
  --retain-symbols-file FILE  keep only symbols listed in this file
  -R DIR                      Add DIR to runtime search path
  -rpath DIR                  Add DIR to runtime search path
  --rpath-link DIR            Add DIR to link time shared library search path  添加链接时要搜索的共享库的路径
  --section-ordering-file FILENAME
                              Layout sections in the order specified.
  --section-start SECTION=ADDRESS
                              Set address of section
  --sort-common [={ascending,descending}]
                              Sort common symbols by alignment
  --sort-section [none,name]  Sort sections by name.  '--no-text-reorder' will override '--sort-section=name' for .text
  --spare-dynamic-tags COUNT  Dynamic tag slots to reserve (default 5)
  -s, --strip-all             Strip all symbols
  -S, --strip-debug           Strip debugging information
  --strip-debug-non-line      Emit only debug line number information
  --strip-debug-gdb           Strip debug symbols that are unused by gdb (at least versions <= 7.4)
  --strip-lto-sections        Strip LTO intermediate code sections
  --stub-group-size SIZE      (ARM only) The maximum distance from instructions in a group of sections to their stubs.  Negative values mean stubs are always after the group. 1 means using default size.


  --no-keep-memory            Use less memory and more disk I/O (included only for compatibility with GNU ld)
  -G, -shared                 Generate shared library
  -Bshareable                 Generate shared library
  --split-stack-adjust-size SIZE
                              Stack size when -fsplit-stack function calls non-split
  -static                     Do not link against shared libraries
  --icf [none,all,safe]       Identical Code Folding. '--icf=safe' Folds ctors, dtors and functions whose pointers are definitely not taken.
  --icf-iterations COUNT      Number of iterations of ICF (default 2)
  --print-icf-sections        List folded identical sections on stderr
  --no-print-icf-sections     Do not list folded identical sections
  --keep-unique SYMBOL        Do not fold this symbol during ICF
  --gc-sections               Remove unused sections
  --no-gc-sections            Don't remove unused sections (default)
  --print-gc-sections         List removed unused sections on stderr
  --no-print-gc-sections      Do not list removed unused sections
  --stats                     Print resource usage statistics
  --sysroot DIR               Set target system root directory
  -t, --trace                 Print the name of each input file
  -T FILE, --script FILE      Read linker script
  --threads                   Run the linker multi-threaded
  --no-threads                Do not run the linker multi-threaded
  --thread-count COUNT        Number of threads to use
  --thread-count-initial COUNT
                              Number of threads to use in initial pass
  --thread-count-middle COUNT Number of threads to use in middle pass
  --thread-count-final COUNT  Number of threads to use in final pass
  -Tbss ADDRESS               Set the address of the bss segment
  -Tdata ADDRESS              Set the address of the data segment
  -Ttext ADDRESS              Set the address of the text segment
  -u SYMBOL, --undefined SYMBOL
                              Create undefined reference to SYMBOL
  --unresolved-symbols ignore-all,report-all,ignore-in-object-files,ignore-in-shared-libs
                              How to handle unresolved symbols
  --verbose                   Synonym for --debug=files
  --version-script FILE       Read version script
  --warn-common               Warn about duplicate common symbols
  --no-warn-common            Do not warn about duplicate common symbols (default)
  --warn-constructors         Ignored
  --no-warn-constructors      Ignored
  --warn-execstack            Warn if the stack is executable
  --no-warn-execstack         Do not warn if the stack is executable (default)
  --no-warn-mismatch          Don't warn about mismatched input files
  --warn-multiple-gp          Ignored
  --warn-search-mismatch      Warn when skipping an incompatible library
  --no-warn-search-mismatch   Don't warn when skipping an incompatible library
  --warn-shared-textrel       Warn if text segment is not shareable
  --no-warn-shared-textrel    Do not warn if text segment is not shareable (default)
  --warn-unresolved-symbols   Report unresolved symbols as warnings
  --error-unresolved-symbols  Report unresolved symbols as errors
  --no-wchar-size-warning     (ARM only) Do not warn about objects with incompatible wchar_t sizes
  --whole-archive             Include all archive contents
  --no-whole-archive          Include only needed archive contents
  --wrap SYMBOL               Use wrapper functions for SYMBOL
  -y SYMBOL, --trace-symbol SYMBOL
                              Trace references to symbol
  --undefined-version         Allow unused version in script (default)
  --no-undefined-version      Do not allow unused version in script
  -Y PATH                     Default search path for Solaris compatibility
  -(, --start-group           Start a library search group
  -), --end-group             End a library search group
  --start-lib                 Start a library
  --end-lib                   End a library 
  -z combreloc                Sort dynamic relocs
  -z nocombreloc              Do not sort dynamic relocs
  -z common-page-size=SIZE    Set common page size to SIZE
  -z defs                     Report undefined symbols (even with --shared)
  -z execstack                Mark output as requiring executable stack
  -z initfirst                Mark DSO to be initialized first at runtime
  -z interpose                Mark object to interpose all DSOs but executable
  -z lazy                     Mark object for lazy runtime binding (default)
  -z loadfltr                 Mark object requiring immediate process
  -z max-page-size=SIZE       Set maximum page size to SIZE
  -z muldefs                  Allow multiple definitions of symbols
  -z nocopyreloc              Do not create copy relocs
  -z nodefaultlib             Mark object not to use default search paths
  -z nodelete                 Mark DSO non-deletable at runtime
  -z nodlopen                 Mark DSO not available to dlopen
  -z nodump                   Mark DSO not available to dldump
  -z noexecstack              Mark output as not requiring executable stack
  -z now                      Mark object for immediate function binding
  -z origin                   Mark DSO to indicate that needs immediate $ORIGIN processing at runtime
  -z relro                    Where possible mark variables read-only after relocation
  -z norelro                  Don't mark variables read-only after relocation
  -z text                     Do not permit relocations in read-only segments
  -z notext                   Permit relocations in read-only segments (default)
  -z textoff                  Permit relocations in read-only segments (default)
./arm-linux-androideabi-ld: supported targets: elf32-i386 elf32-i386-freebsd elf32-i386-nacl elf32-x86-64 elf32-x86-64-freebsd elf32-x86-64-nacl elf64-x86-64 elf64-x86-64-freebsd elf64-x86-64-nacl elf64-sparc elf32-sparc elf64-powerpcle elf64-powerpc elf32-powerpcle elf32-powerpc elf32-bigarm elf32-bigarm-nacl elf32-littlearm elf32-littlearm-nacl
./arm-linux-androideabi-ld: supported emulations: elf_i386 elf_i386_nacl elf32_x86_64 elf32_x86_64_nacl elf_x86_64 elf_x86_64_nacl elf64_sparc elf32_sparc elf64lppc elf64ppc elf32lppc elf32ppc armelfb armelfb_nacl armelf armelf_nacl
Report bugs to <http://source.android.com/source/report-bugs.html>

root@Ubuntu32:/home/zhangbin/android/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin#

arm-linux-androideabi-ld options
--help                      Report usage information
  -v, --version               Report version information
  -V                          Report version and target information
  --add-needed                Not supported
  --no-add-needed             Do not copy DT_NEEDED tags from shared libraries
  --allow-multiple-definition Allow multiple definitions of symbols
  --no-allow-multiple-definition
                              Do not allow multiple definitions
  --allow-shlib-undefined     Allow unresolved references in shared libraries
  --no-allow-shlib-undefined  Do not allow unresolved references in shared libraries
  --as-needed                 Only set DT_NEEDED for shared libraries if used
  --no-as-needed              Always DT_NEEDED for shared libraries
  -assert [ignored]           Ignored
  -b [elf,binary], --format [elf,binary]
                              Set input format
  -Bdynamic                   -l searches for shared libraries  用-l来搜索共享库
  -Bstatic                    -l does not search for shared libraries
  -Bsymbolic                  Bind defined symbols locally
  -Bsymbolic-functions        Bind defined function symbols locally
  --build-id [=STYLE]         Generate build ID note
  --check-sections            Check segment addresses for overlaps (default)
  --no-check-sections         Do not check segment addresses for overlaps
  --compress-debug-sections [none,zlib]
                              Compress .debug_* sections in the output file
  --copy-dt-needed-entries    Not supported
  --no-copy-dt-needed-entries Do not copy DT_NEEDED tags from shared libraries
  --cref                      Output cross reference table
  --no-cref                   Do not output cross reference table
  -d, --define-common         Define common symbols
  --no-define-common          Do not define common symbols
  -dc                         Alias for -d
  -dp                         Alias for -d
  --debug [all,files,script,task][,...]
                              Turn on debugging
  --defsym SYMBOL=EXPRESSION  Define a symbol
  --demangle [=STYLE]         Demangle C++ symbols in log messages
  --no-demangle               Do not demangle C++ symbols in log messages
  --detect-odr-violations     Look for violations of the C++ One Definition Rule
  --no-detect-odr-violations  Do not look for violations of the C++ One Definition Rule
  -x, --discard-all           Delete all local symbols
  -X, --discard-locals        Delete all temporary local symbols
  --dynamic-list-data         Add data symbols to dynamic symbols
  --dynamic-list-cpp-new      Add C++ operator new/delete to dynamic symbols
  --dynamic-list-cpp-typeinfo Add C++ typeinfo to dynamic symbols
  --dynamic-list FILE         Read a list of dynamic symbols
  -e ADDRESS, --entry ADDRESS Set program start address
  --exclude-libs lib,lib ...  Exclude libraries from automatic export
  -E, --export-dynamic        Export all dynamic symbols
  --no-export-dynamic         Do not export all dynamic symbols (default)
  -EB                         Link big-endian objects.
  --eh-frame-hdr              Create exception frame header
  -EL                         Link little-endian objects.
  --no-enum-size-warning      (ARM only) Do not warn about objects with incompatible enum sizes
  --fatal-warnings            Treat warnings as errors
  --no-fatal-warnings         Do not treat warnings as errors
  -fini SYMBOL                Call SYMBOL at unload-time
  --fix-cortex-a8             (ARM only) Fix binaries for Cortex-A8 erratum.
  --no-fix-cortex-a8          (ARM only) Do not fix binaries for Cortex-A8 erratum.
  --merge-exidx-entries       (ARM only) Merge exidx entries in debuginfo.
  --no-merge-exidx-entries    (ARM only) Do not merge exidx entries in debuginfo.
  --fix-v4bx                  (ARM only) Rewrite BX rn as MOV pc, rn for ARMv4
  --fix-v4bx-interworking     (ARM only) Rewrite BX rn branch to ARMv4 interworking veneer
  -g                          Ignored
  -h FILENAME, -soname FILENAME
                              Set shared library name
  -i                          Ignored
  --hash-bucket-empty-fraction FRACTION
                              Min fraction of empty buckets in dynamic hash
  --hash-style [sysv,gnu,both]
                              Dynamic hash style
  -I PROGRAM, --dynamic-linker PROGRAM
                              Set dynamic linker path
  --incremental               Do an incremental link if possible; otherwise, do a full link and prepare output for incremental linking
  --no-incremental            Do a full link (default)
  --incremental-full          Do a full link and prepare output for incremental linking
  --incremental-update        Do an incremental link; exit if not possible
  --incremental-base FILE     Set base file for incremental linking (default is output file)
  --incremental-changed       Assume files changed
  --incremental-unchanged     Assume files didn't change
  --incremental-unknown       Use timestamps to check files (default)
  --incremental-startup-unchanged
                              Assume startup files unchanged (files preceding this option)
  --incremental-patch PERCENT Amount of extra space to allocate for patches
  -init SYMBOL                Call SYMBOL at load-time
  --just-symbols FILE         Read only symbol values from FILE
  --map-whole-files           Map whole files to memory (default on 64-bit hosts)
  --no-map-whole-files        Map relevant file parts to memory (default on 32-bit hosts)
  --keep-files-mapped         Keep files mapped across passes (default)
  --no-keep-files-mapped      Release mapped files after each pass
  -l LIBNAME, --library LIBNAME
                              Search for library LIBNAME
  -L DIR, --library-path DIR  Add directory to search path
  -nostdlib                    Only search directories specified on the command line.
  --rosegment                  Put read-only non-executable sections in their own segment
  -m EMULATION                Set GNU linker emulation; obsolete
  -M, --print-map             Write map file on standard output
  -Map MAPFILENAME            Write map file
  -n, --nmagic                Do not page align data
  -N, --omagic                Do not page align data, do not make text readonly
  --no-omagic                 Page align data, make text readonly
  --enable-new-dtags          Enable use of DT_RUNPATH and DT_FLAGS
  --disable-new-dtags         Disable use of DT_RUNPATH and DT_FLAGS
  --noinhibit-exec            Create an output file even if errors occur
  --no-undefined              Report undefined symbols (even with --shared)
  -o FILE, --output FILE      Set output file name
  -O LEVEL, -optimize LEVEL   Optimize output file size
  --oformat [binary]          Set output format
  -p                          (ARM only) Ignore for backward compatibility
  -pie                        Create a position independent executable
  --pic-executable            Create a position independent executable
  -no-pipeline-knowledge      (ARM only) Ignore for backward compatibility
  --preread-archive-symbols   Preread archive symbols when multi-threaded
  --print-symbol-counts FILENAME
                              Print symbols defined and used for each input
  -Qy                         Ignored for SVR4 compatibility
  -q, --emit-relocs           Generate relocations in output
  -r, -relocatable            Generate relocatable output
  --relax                     Relax branches on certain targets
  --retain-symbols-file FILE  keep only symbols listed in this file
  -R DIR                      Add DIR to runtime search path
  -rpath DIR                  Add DIR to runtime search path
  --rpath-link DIR            Add DIR to link time shared library search path
  --section-ordering-file FILENAME
                              Layout sections in the order specified.
  --section-start SECTION=ADDRESS
                              Set address of section
  --sort-common [={ascending,descending}]
                              Sort common symbols by alignment
  --spare-dynamic-tags COUNT  Dynamic tag slots to reserve (default 5)
  -s, --strip-all             Strip all symbols
  -S, --strip-debug           Strip debugging information
  --strip-debug-non-line      Emit only debug line number information
  --strip-debug-gdb           Strip debug symbols that are unused by gdb (at least versions <= 6.7)
  --strip-lto-sections        Strip LTO intermediate code sections
  --stub-group-size SIZE      (ARM only) The maximum distance from instructions in a group of sections to their stubs.  Negative values mean stubs are always after the group. 1 means using default size.


  --no-keep-memory            Use less memory and more disk I/O (included only for compatibility with GNU ld)
  -G, -shared                 Generate shared library
  -Bshareable                 Generate shared library
  --split-stack-adjust-size SIZE
                              Stack size when -fsplit-stack function calls non-split
  -static                     Do not link against shared libraries
  --icf [none,all,safe]       Identical Code Folding. '--icf=safe' Folds ctors, dtors and functions whose pointers are definitely not taken.
  --icf-iterations COUNT      Number of iterations of ICF (default 2)
  --print-icf-sections        List folded identical sections on stderr
  --no-print-icf-sections     Do not list folded identical sections
  --keep-unique SYMBOL        Do not fold this symbol during ICF
  --gc-sections               Remove unused sections
  --no-gc-sections            Don't remove unused sections (default)
  --print-gc-sections         List removed unused sections on stderr
  --no-print-gc-sections      Do not list removed unused sections
  --stats                     Print resource usage statistics
  --sysroot DIR               Set target system root directory
  -t, --trace                 Print the name of each input file
  -T FILE, --script FILE      Read linker script
  --threads                   Run the linker multi-threaded
  --no-threads                Do not run the linker multi-threaded
  --thread-count COUNT        Number of threads to use
  --thread-count-initial COUNT
                              Number of threads to use in initial pass
  --thread-count-middle COUNT Number of threads to use in middle pass
  --thread-count-final COUNT  Number of threads to use in final pass
  -Tbss ADDRESS               Set the address of the bss segment
  -Tdata ADDRESS              Set the address of the data segment
  -Ttext ADDRESS              Set the address of the text segment
  -u SYMBOL, --undefined SYMBOL
                              Create undefined reference to SYMBOL
  --verbose                   Synonym for --debug=files
  --version-script FILE       Read version script
  --warn-common               Warn about duplicate common symbols
  --no-warn-common            Do not warn about duplicate common symbols (default)
  --warn-constructors         Ignored
  --no-warn-constructors      Ignored
  --warn-execstack            Warn if the stack is executable
  --no-warn-execstack         Do not warn if the stack is executable (default)
  --no-warn-mismatch          Don't warn about mismatched input files
  --warn-multiple-gp          Ignored
  --warn-search-mismatch      Warn when skipping an incompatible library
  --no-warn-search-mismatch   Don't warn when skipping an incompatible library
  --warn-shared-textrel       Warn if text segment is not shareable
  --no-warn-shared-textrel    Do not warn if text segment is not shareable (default)
  --warn-unresolved-symbols   Report unresolved symbols as warnings
  --error-unresolved-symbols  Report unresolved symbols as errors
  --no-wchar-size-warning     (ARM only) Do not warn about objects with incompatible wchar_t sizes
  --whole-archive             Include all archive contents
  --no-whole-archive          Include only needed archive contents
  --wrap SYMBOL               Use wrapper functions for SYMBOL
  -y SYMBOL, --trace-symbol SYMBOL
                              Trace references to symbol
  --undefined-version         Allow unused version in script (default)
  --no-undefined-version      Do not allow unused version in script
  -Y PATH                     Default search path for Solaris compatibility
  -(, --start-group           Start a library search group
  -), --end-group             End a library search group
  --start-lib                 Start a library
  --end-lib                   End a library 
  -z combreloc                Sort dynamic relocs
  -z nocombreloc              Do not sort dynamic relocs
  -z common-page-size=SIZE    Set common page size to SIZE
  -z defs                     Report undefined symbols (even with --shared)
  -z execstack                Mark output as requiring executable stack
  -z initfirst                Mark DSO to be initialized first at runtime
  -z interpose                Mark object to interpose all DSOs but executable
  -z lazy                     Mark object for lazy runtime binding (default)
  -z loadfltr                 Mark object requiring immediate process
  -z max-page-size=SIZE       Set maximum page size to SIZE
  -z muldefs                  Allow multiple definitions of symbols
  -z nocopyreloc              Do not create copy relocs
  -z nodefaultlib             Mark object not to use default search paths
  -z nodelete                 Mark DSO non-deletable at runtime
  -z nodlopen                 Mark DSO not available to dlopen
  -z nodump                   Mark DSO not available to dldump
  -z noexecstack              Mark output as not requiring executable stack
  -z now                      Mark object for immediate function binding
  -z origin                   Mark DSO to indicate that needs immediate $ORIGIN processing at runtime
  -z relro                    Where possible mark variables read-only after relocation
  -z norelro                  Don't mark variables read-only after relocation
  -z text                     Do not permit relocations in read-only segments
  -z textoff                  Permit relocations in read-only segments (default)



<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(174) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
2015-10-09 10:21:40 zxywwb 阅读数 11492

最近在做基于Arm板linux嵌入式系统的RS485串口读写通讯首先参考 http://bbs.chinaunix.net/thread-3650543-1-1.html上的文章,该文章写道,读的时候有问题,本想在该文后面做些补充,但没权限发表,只好另起炉灶,在这里接着写了

之前楼主的代码我进行了实际的调试,我将串口换成 /dev/ttySAC0(对于串口1)读基本上没问题,也是比较经典的解决方案,应该是基于IBM deveplopworks社区的代码吧,具体也没考究,不过收的时候的确有些问题,我当时的现象是能部分收取,就是不全,多方尝试和查找网文,觉得问题应该集中在sleep时间上,应该是稍长了,可以用没有sleep的while进行read,实测接收正常,另外也还有另外两种方法接收的--信号和select,推荐select,在此把我解决问题用到的网文链接提供给诸位读者,希望能节省大家调试的时间:

[url]http://blog.csdn.net/bg2bkk/article/details/8668576[/url]  ( Linux系统串口接收数据编程 )
[url]http://blog.csdn.net/bg2bkk/article/details/8623867[/url]  (Linux串口编程 )
[url]http://www.ibm.com/developerworks/cn/linux/l-serials/index.html[/url] (Linux 下串口编程入门)
[url]http://zwkufo.blog.163.com/blog/static/258825120092171154284/[/url] (使用tcgetattr函数与tcsetattr函数控制终端)

读过如上的诸篇文章后,大家估计就会比较熟练了


转其中最有价值的一篇,大家看后就会写了:


Linux系统串口接收数据编程

http://blog.csdn.net/bg2bkk/article/details/8668576

         之前基于IBM deveplopworks社区的代码,做了串口初始化和发送的程序,今天在此基础上添加了读取串口数据的程序。首先是最简单的循环读取程序,第二个是通过软中断方式,使用信号signal机制读取串口,这里需要注意的是硬件中断是设备驱动层级的,而读写串口是用户级行为,只能通过信号机制模拟中断,信号机制的发生和处理其实于硬件中断无异,第三个是通过select系统调用,在没有数据时阻塞进程,串口有数据需要读时唤醒进程。第二个和第三个例子都能用来后台读取数据,值得学习。

代码一:循环读取数据

  1. #include<stdio.h>  
  2. #include<stdlib.h>  
  3. #include<unistd.h>  
  4. #include<sys/types.h>  
  5. #include<sys/stat.h>  
  6. #include<fcntl.h>  
  7. #include<termios.h>  
  8. #include<errno.h>  
  9.   
  10. #define FALSE -1  
  11. #define TRUE 0  
  12.   
  13. int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300,B38400, B19200, B9600, B4800, B2400, B1200, B300, };  
  14. int name_arr[] = {38400,  19200,  9600,  4800,  2400,  1200,  300, 38400, 19200,  9600, 4800, 2400, 1200,  300, };  
  15. void set_speed(int fd, int speed){  
  16.   int   i;   
  17.   int   status;   
  18.   struct termios   Opt;  
  19.   tcgetattr(fd, &Opt);   
  20.   for ( i= 0;  i < sizeof(speed_arr) / sizeof(int);  i++) {   
  21.     if  (speed == name_arr[i]) {       
  22.       tcflush(fd, TCIOFLUSH);       
  23.       cfsetispeed(&Opt, speed_arr[i]);    
  24.       cfsetospeed(&Opt, speed_arr[i]);     
  25.       status = tcsetattr(fd, TCSANOW, &Opt);    
  26.       if  (status != 0) {          
  27.         perror("tcsetattr fd1");    
  28.         return;       
  29.       }      
  30.       tcflush(fd,TCIOFLUSH);     
  31.     }    
  32.   }  
  33. }  
  34.   
  35. int set_Parity(int fd,int databits,int stopbits,int parity)  
  36. {   
  37.     struct termios options;   
  38.     if  ( tcgetattr( fd,&options)  !=  0) {   
  39.         perror("SetupSerial 1");       
  40.         return(FALSE);    
  41.     }  
  42.     options.c_cflag &= ~CSIZE;   
  43.     switch (databits)   
  44.     {     
  45.     case 7:       
  46.         options.c_cflag |= CS7;   
  47.         break;  
  48.     case 8:       
  49.         options.c_cflag |= CS8;  
  50.         break;     
  51.     default:      
  52.         fprintf(stderr,"Unsupported data size\n"); return (FALSE);    
  53.     }  
  54.     switch (parity)   
  55.     {     
  56.         case 'n':  
  57.         case 'N':      
  58.             options.c_cflag &= ~PARENB;   /* Clear parity enable */  
  59.             options.c_iflag &= ~INPCK;     /* Enable parity checking */   
  60.             break;    
  61.         case 'o':     
  62.         case 'O':       
  63.             options.c_cflag |= (PARODD | PARENB);   
  64.             options.c_iflag |= INPCK;             /* Disnable parity checking */   
  65.             break;    
  66.         case 'e':    
  67.         case 'E':     
  68.             options.c_cflag |= PARENB;     /* Enable parity */      
  69.             options.c_cflag &= ~PARODD;      
  70.             options.c_iflag |= INPCK;       /* Disnable parity checking */  
  71.             break;  
  72.         case 'S':   
  73.         case 's':  /*as no parity*/     
  74.             options.c_cflag &= ~PARENB;  
  75.             options.c_cflag &= ~CSTOPB;break;    
  76.         default:     
  77.             fprintf(stderr,"Unsupported parity\n");      
  78.             return (FALSE);    
  79.         }    
  80.       
  81.     switch (stopbits)  
  82.     {     
  83.         case 1:      
  84.             options.c_cflag &= ~CSTOPB;    
  85.             break;    
  86.         case 2:      
  87.             options.c_cflag |= CSTOPB;    
  88.            break;  
  89.         default:      
  90.              fprintf(stderr,"Unsupported stop bits\n");    
  91.              return (FALSE);   
  92.     }   
  93.     /* Set input parity option */   
  94.     if (parity != 'n')     
  95.         options.c_iflag |= INPCK;   
  96.     tcflush(fd,TCIFLUSH);  
  97.     options.c_cc[VTIME] = 150;   
  98.     options.c_cc[VMIN] = 0; /* Update the options and do it NOW */  
  99.     if (tcsetattr(fd,TCSANOW,&options) != 0)     
  100.     {   
  101.         perror("SetupSerial 3");     
  102.         return (FALSE);    
  103.     }   
  104.     return (TRUE);    
  105. }  
  106.   
  107. int main()  
  108. {  
  109.     printf("This program updates last time at %s   %s\n",__TIME__,__DATE__);  
  110.     printf("STDIO COM1\n");  
  111.     int fd;  
  112.     fd = open("/dev/ttyS0",O_RDWR);  
  113.     if(fd == -1)  
  114.     {  
  115.         perror("serialport error\n");  
  116.     }  
  117.     else  
  118.     {  
  119.         printf("open ");  
  120.         printf("%s",ttyname(fd));  
  121.         printf(" succesfully\n");  
  122.     }  
  123.   
  124.     set_speed(fd,115200);  
  125.     if (set_Parity(fd,8,1,'N') == FALSE)  {  
  126.         printf("Set Parity Error\n");  
  127.         exit (0);  
  128.     }  
  129.     char buf[] = "fe55aa07bc010203040506073d";  
  130.     write(fd,&buf,26);  
  131.     char buff[512];   
  132.     int nread;    
  133.     while(1)  
  134.     {  
  135.         if((nread = read(fd, buff, 512))>0)  
  136.         {  
  137.             printf("\nLen: %d\n",nread);  
  138.             buff[nread+1] = '\0';  
  139.             printf("%s",buff);  
  140.         }  
  141.     }  
  142.     close(fd);  
  143.     return 0;  
  144. }  

代码清单二:通过signal机制读取数据

  1. #include<stdio.h>  
  2. #include<stdlib.h>  
  3. #include<unistd.h>  
  4. #include<sys/types.h>  
  5. #include<sys/stat.h>  
  6. #include<sys/signal.h>  
  7. #include<fcntl.h>  
  8. #include<termios.h>  
  9. #include<errno.h>  
  10.   
  11. #define FALSE -1  
  12. #define TRUE 0  
  13. #define flag 1  
  14. #define noflag 0  
  15.   
  16. int wait_flag = noflag;  
  17. int STOP = 0;  
  18. int res;  
  19.   
  20. int speed_arr[] =  
  21.   { B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400, B19200, B9600,  
  22. B4800, B2400, B1200, B300, };  
  23. int name_arr[] =  
  24.   { 38400, 19200, 9600, 4800, 2400, 1200, 300, 38400, 19200, 9600, 4800, 2400,  
  25. 1200, 300, };  
  26. void  
  27. set_speed (int fd, int speed)  
  28. {  
  29.   int i;  
  30.   int status;  
  31.   struct termios Opt;  
  32.   tcgetattr (fd, &Opt);  
  33.   for (i = 0; i < sizeof (speed_arr) / sizeof (int); i++)  
  34.     {  
  35.       if (speed == name_arr[i])  
  36.     {  
  37.       tcflush (fd, TCIOFLUSH);  
  38.       cfsetispeed (&Opt, speed_arr[i]);  
  39.       cfsetospeed (&Opt, speed_arr[i]);  
  40.       status = tcsetattr (fd, TCSANOW, &Opt);  
  41.       if (status != 0)  
  42.         {  
  43.           perror ("tcsetattr fd1");  
  44.           return;  
  45.         }  
  46.       tcflush (fd, TCIOFLUSH);  
  47.     }  
  48.     }  
  49. }  
  50.   
  51. int  
  52. set_Parity (int fd, int databits, int stopbits, int parity)  
  53. {  
  54.   struct termios options;  
  55.   if (tcgetattr (fd, &options) != 0)  
  56.     {  
  57.       perror ("SetupSerial 1");  
  58.       return (FALSE);  
  59.     }  
  60.   options.c_cflag &= ~CSIZE;  
  61.   switch (databits)  
  62.     {  
  63.     case 7:  
  64.       options.c_cflag |= CS7;  
  65.       break;  
  66.     case 8:  
  67.       options.c_cflag |= CS8;  
  68.       break;  
  69.     default:  
  70.       fprintf (stderr, "Unsupported data size\n");  
  71.       return (FALSE);  
  72.     }  
  73.   switch (parity)  
  74.     {  
  75.     case 'n':  
  76.     case 'N':  
  77.       options.c_cflag &= ~PARENB;   /* Clear parity enable */  
  78.       options.c_iflag &= ~INPCK;    /* Enable parity checking */  
  79.       break;  
  80.     case 'o':  
  81.     case 'O':  
  82.       options.c_cflag |= (PARODD | PARENB);  
  83.       options.c_iflag |= INPCK; /* Disnable parity checking */  
  84.       break;  
  85.     case 'e':  
  86.     case 'E':  
  87.       options.c_cflag |= PARENB;    /* Enable parity */  
  88.       options.c_cflag &= ~PARODD;  
  89.       options.c_iflag |= INPCK; /* Disnable parity checking */  
  90.       break;  
  91.     case 'S':  
  92.     case 's':           /*as no parity */  
  93.       options.c_cflag &= ~PARENB;  
  94.       options.c_cflag &= ~CSTOPB;  
  95.       break;  
  96.     default:  
  97.       fprintf (stderr, "Unsupported parity\n");  
  98.       return (FALSE);  
  99.     }  
  100.   
  101.   switch (stopbits)  
  102.     {  
  103.     case 1:  
  104.       options.c_cflag &= ~CSTOPB;  
  105.       break;  
  106.     case 2:  
  107.       options.c_cflag |= CSTOPB;  
  108.       break;  
  109.     default:  
  110.       fprintf (stderr, "Unsupported stop bits\n");  
  111.       return (FALSE);  
  112.     }  
  113.   /* Set input parity option */  
  114.   if (parity != 'n')  
  115.     options.c_iflag |= INPCK;  
  116.   tcflush (fd, TCIFLUSH);  
  117.   options.c_cc[VTIME] = 150;  
  118.   options.c_cc[VMIN] = 0;   /* Update the options and do it NOW */  
  119.   if (tcsetattr (fd, TCSANOW, &options) != 0)  
  120.     {  
  121.       perror ("SetupSerial 3");  
  122.       return (FALSE);  
  123.     }  
  124.   return (TRUE);  
  125. }  
  126.   
  127. void  
  128. signal_handler_IO (int status)  
  129. {  
  130.   printf ("received SIGIO signale.\n");  
  131.   wait_flag = noflag;  
  132. }  
  133.   
  134. int  
  135. main ()  
  136. {  
  137.   printf ("This program updates last time at %s   %s\n", __TIME__, __DATE__);  
  138.   printf ("STDIO COM1\n");  
  139.   int fd;  
  140.   struct sigaction saio;  
  141.   fd = open ("/dev/ttyUSB0", O_RDWR);  
  142.   if (fd == -1)  
  143.     {  
  144.       perror ("serialport error\n");  
  145.     }  
  146.   else  
  147.     {  
  148.       printf ("open ");  
  149.       printf ("%s", ttyname (fd));  
  150.       printf (" succesfully\n");  
  151.     }  
  152.   
  153.   saio.sa_handler = signal_handler_IO;  
  154.   sigemptyset (&saio.sa_mask);  
  155.   saio.sa_flags = 0;  
  156.   saio.sa_restorer = NULL;  
  157.   sigaction (SIGIO, &saio, NULL);  
  158.   
  159.   //allow the process to receive SIGIO  
  160.   fcntl (fd, F_SETOWN, getpid ());  
  161.   //make the file descriptor asynchronous  
  162.   fcntl (fd, F_SETFL, FASYNC);  
  163.   
  164.   set_speed (fd, 115200);  
  165.   if (set_Parity (fd, 8, 1, 'N') == FALSE)  
  166.     {  
  167.       printf ("Set Parity Error\n");  
  168.       exit (0);  
  169.     }  
  170.   
  171.   char buf[255];  
  172. while (STOP == 0)  
  173.     {  
  174.       usleep (100000);  
  175.       /* after receving SIGIO ,wait_flag = FALSE,input is availabe and can be read */  
  176.       if (wait_flag == 0)  
  177.     {  
  178.       memset (buf, 0, sizeof(buf));  
  179.       res = read (fd, buf, 255);  
  180.       printf ("nread=%d,%s\n", res, buf);  
  181. //    if (res ==1)  
  182. //      STOP = 1;       /*stop loop if only a CR was input */  
  183.       wait_flag = flag; /*wait for new input */  
  184.     }  
  185.     }  
  186.   
  187.   
  188.   close (fd);  
  189.   return 0;  
  190. }  


代码三:通过select系统调用进行io多路切换,实现异步读取串口数据

  1. #include<stdio.h>  
  2. #include<stdlib.h>  
  3. #include<unistd.h>  
  4. #include<sys/types.h>  
  5. #include<sys/stat.h>  
  6. #include<sys/signal.h>  
  7. #include<fcntl.h>  
  8. #include<termios.h>  
  9. #include<errno.h>  
  10.   
  11. #define FALSE -1  
  12. #define TRUE 0  
  13. #define flag 1  
  14. #define noflag 0  
  15.   
  16. int wait_flag = noflag;  
  17. int STOP = 0;  
  18. int res;  
  19.   
  20. int speed_arr[] =  
  21.   { B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400, B19200, B9600,  
  22. B4800, B2400, B1200, B300, };  
  23. int name_arr[] =  
  24.   { 384001920096004800240012003003840019200960048002400,  
  25. 1200300, };  
  26. void  
  27. set_speed (int fd, int speed)  
  28. {  
  29.   int i;  
  30.   int status;  
  31.   struct termios Opt;  
  32.   tcgetattr (fd, &Opt);  
  33.   for (i = 0; i < sizeof (speed_arr) / sizeof (int); i++)  
  34.     {  
  35.       if (speed == name_arr[i])  
  36.     {  
  37.       tcflush (fd, TCIOFLUSH);  
  38.       cfsetispeed (&Opt, speed_arr[i]);  
  39.       cfsetospeed (&Opt, speed_arr[i]);  
  40.       status = tcsetattr (fd, TCSANOW, &Opt);  
  41.       if (status != 0)  
  42.         {  
  43.           perror ("tcsetattr fd1");  
  44.           return;  
  45.         }  
  46.       tcflush (fd, TCIOFLUSH);  
  47.     }  
  48.     }  
  49. }  
  50.   
  51. int  
  52. set_Parity (int fd, int databits, int stopbits, int parity)  
  53. {  
  54.   struct termios options;  
  55.   if (tcgetattr (fd, &options) != 0)  
  56.     {  
  57.       perror ("SetupSerial 1");  
  58.       return (FALSE);  
  59.     }  
  60.   options.c_cflag &= ~CSIZE;  
  61.   switch (databits)  
  62.     {  
  63.     case 7:  
  64.       options.c_cflag |= CS7;  
  65.       break;  
  66.     case 8:  
  67.       options.c_cflag |= CS8;  
  68.       break;  
  69.     default:  
  70.       fprintf (stderr, "Unsupported data size\n");  
  71.       return (FALSE);  
  72.     }  
  73.   switch (parity)  
  74.     {  
  75.     case 'n':  
  76.     case 'N':  
  77.       options.c_cflag &= ~PARENB;   /* Clear parity enable */  
  78.       options.c_iflag &= ~INPCK;    /* Enable parity checking */  
  79.       break;  
  80.     case 'o':  
  81.     case 'O':  
  82.       options.c_cflag |= (PARODD | PARENB);  
  83.       options.c_iflag |= INPCK; /* Disnable parity checking */  
  84.       break;  
  85.     case 'e':  
  86.     case 'E':  
  87.       options.c_cflag |= PARENB;    /* Enable parity */  
  88.       options.c_cflag &= ~PARODD;  
  89.       options.c_iflag |= INPCK; /* Disnable parity checking */  
  90.       break;  
  91.     case 'S':  
  92.     case 's':           /*as no parity */  
  93.       options.c_cflag &= ~PARENB;  
  94.       options.c_cflag &= ~CSTOPB;  
  95.       break;  
  96.     default:  
  97.       fprintf (stderr, "Unsupported parity\n");  
  98.       return (FALSE);  
  99.     }  
  100.   
  101.   switch (stopbits)  
  102.     {  
  103.     case 1:  
  104.       options.c_cflag &= ~CSTOPB;  
  105.       break;  
  106.     case 2:  
  107.       options.c_cflag |= CSTOPB;  
  108.       break;  
  109.     default:  
  110.       fprintf (stderr, "Unsupported stop bits\n");  
  111.       return (FALSE);  
  112.     }  
  113.   /* Set input parity option */  
  114.   if (parity != 'n')  
  115.     options.c_iflag |= INPCK;  
  116.   tcflush (fd, TCIFLUSH);  
  117.   options.c_cc[VTIME] = 150;  
  118.   options.c_cc[VMIN] = 0;   /* Update the options and do it NOW */  
  119.   if (tcsetattr (fd, TCSANOW, &options) != 0)  
  120.     {  
  121.       perror ("SetupSerial 3");  
  122.       return (FALSE);  
  123.     }  
  124.   return (TRUE);  
  125. }  
  126.   
  127. void  
  128. signal_handler_IO (int status)  
  129. {  
  130.   printf ("received SIGIO signale.\n");  
  131.   wait_flag = noflag;  
  132. }  
  133.   
  134. int  
  135. main ()  
  136. {  
  137.   printf ("This program updates last time at %s   %s\n", __TIME__, __DATE__);  
  138.   printf ("STDIO COM1\n");  
  139.   int fd;  
  140.   fd = open ("/dev/ttyUSB0", O_RDWR);  
  141.   if (fd == -1)  
  142.     {  
  143.       perror ("serialport error\n");  
  144.     }  
  145.   else  
  146.     {  
  147.       printf ("open ");  
  148.       printf ("%s", ttyname (fd));  
  149.       printf (" succesfully\n");  
  150.     }  
  151.   
  152.   set_speed (fd, 115200);  
  153.   if (set_Parity (fd, 81'N') == FALSE)  
  154.     {  
  155.       printf ("Set Parity Error\n");  
  156.       exit (0);  
  157.     }  
  158.   
  159.   char buf[255];  
  160.   fd_set rd;  
  161.   int nread = 0;  
  162.   while(1)  
  163.   {  
  164.     FD_ZERO(&rd);  
  165.     FD_SET(fd, &rd);  
  166.     while(FD_ISSET(fd, &rd))  
  167.     {  
  168.         if(select(fd+1, &rd, NULL,NULL,NULL) < 0)  
  169.         {  
  170.             perror("select error\n");  
  171.         }  
  172.         else  
  173.         {  
  174.             while((nread = read(fd, buf, sizeof(buf))) > 0)  
  175.             {  
  176.                 printf("nread = %d,%s\n",nread, buf);  
  177.                 printf("test\n");  
  178.                 memset(buf, 0 , sizeof(buf));  
  179.             }  
  180.         }  
  181.     }  
  182.   }  
  183.   close (fd);  
  184.   return 0;  


2016-02-01 00:00:00 ztguang 阅读数 0
http://blog.chinaunix.net/uid-20417436-id-3023950.html

一 过程控制选项:
    在编程的过程中。很少人会去在意编译的全部过程,分几个阶段?其实编译只是生成可执行文件众多步骤之一。对于一个c/cpp文件第一步是预处理,第二步是编译,第三步是汇编,第四步是链接。

1.(预处理)arm-linux-cpp 预处理程序 将*.c处理然后可以得到*.i(此举可用arm-linux-gcc -E)

2. (编译)/home/zylinux/home_work/install_tools/arm_gcc/usr/local/arm/4.3.2 /bin/../libexec/gcc/arm-none-linux-gnueabi/4.3.2/cc1 将*.i 编译成 *.s(此举可用arm-linux-gcc -S)

3.(汇编)arm-linux-as 将*.s 汇编成 *.o/home/zylinux/home_work/install_tools/arm_gcc/usr/local/arm/4.3.2/bin/../libexec/gcc/arm-none-linux-gnueabi/4.3.2/cc1 (此举可用arm-linux-gcc -c)

4.(链接)arm-linux-ld 将*.o 链接成ELF程序

    如果想看到全部过程,可以在编译的时候加上-v选项即可。
二 警告选项:
    -Wall 打开所有需要注意的警告信息。
    
三 调试选项:
    -g 这个地方稍微注意下,只有在编译的时候选了这个选项,调试的时候才能用gdb。

四 优化选项:
    -O 这个就是-O1。
    -O2。
    -O3。
五 链接选项:
    一个程序,往往是会包含启动代码(crtl.o,crti.o,crtend.o,crtn.o),以及一些标准库(-lgcc,-lgcc_eh,lc-lgcc,-lgcc_eh)。如果不需要这两个部分可以使用以下选项
    -nostartfiles(一般内核和bootloader编译的时候需要加上此类选项。)
    -nostdlib(一般内核和bootloader编译的时候需要加上此类选项。)

    -static (在链接的时候如果加上此选项,程序为静态链接,程序将会很大)
    -shared (在制作库的时候需要加上此项)
六 比较繁琐的链接选项(-Xlinker option)
    一般在arm-linux-gcc 中需要把选项参数传递给连接器的时候,需要使用两次-Xlinker,一次传选项,一次传参数,或者使用-Wl,如果有选项则后面用逗号。
    -Xlinker option(-Xlinker -rpath -Xlinker )    gcc -Xlinker -Ttext -Xlinker 0x000 hello.c
    -Wl,option(-Wl,-rpath, )                gcc -Wl,-Ttext,0x000 hello.c
    -u symbol 这个选项使得连接器取消这个符号在此文件中定义,从而链接库模块取得奇定义。

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(33) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
评论热议
2015-12-03 15:49:35 MingLLu 阅读数 4328
@author : mingliang.lu
@date   : 201512315:48:32
@e-mail : <mingllu@163.com>

默认的搜索路径是通过在ubuntu-12.04的shell窗口输入如下命令显示:

echo 'main(){}'|arm-linux-gcc -E -v - 

比如说我的路径显示则如下:

Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /scratch/julian/lite-respin/linux/src/gcc-4.3/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --enable-shared --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2008q3-72' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/julian/lite-respin/linux/obj/host-libs-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/julian/lite-respin/linux/obj/host-libs-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/julian/lite-respin/linux/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) 
COLLECT_GCC_OPTIONS='-march=armv4t' '-E' '-v'
 /usr/local/arm-4.3.2/4.3.2/bin/../libexec/gcc/arm-none-linux-gnueabi/4.3.2/cc1 -E -quiet -v -imultilib armv4t -iprefix /usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/ -isysroot /usr/local/arm-4.3.2/4.3.2/bin/../arm-none-linux-gnueabi/libc - -march=armv4t
ignoring nonexistent directory "/usr/local/arm-4.3.2/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/local/include"
ignoring duplicate directory "/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/../../lib/gcc/arm-none-linux-gnueabi/4.3.2/include"
ignoring duplicate directory "/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/../../lib/gcc/arm-none-linux-gnueabi/4.3.2/include-fixed"
ignoring duplicate directory "/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/../../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/include
 /usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/include-fixed
 /usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/include
 /usr/local/arm-4.3.2/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
main(){}
COMPILER_PATH=/usr/local/arm-4.3.2/4.3.2/bin/../libexec/gcc/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm-4.3.2/4.3.2/bin/../libexec/gcc/:/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/
LIBRARY_PATH=/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/armv4t/:/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/:/usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/:/usr/local/arm-4.3.2/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/:/usr/local/arm-4.3.2/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/
COLLECT_GCC_OPTIONS='-march=armv4t' '-E' '-v'

其中的下面这一段就代表着arm-linux-gcc在编译文件时所搜索的头文件路径:

#include "..." search starts here:
#include <...> search starts here:
 /usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/include
 /usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/include-fixed
 /usr/local/arm-4.3.2/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/include
 /usr/local/arm-4.3.2/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include

arm-linux-gcc 编译

阅读数 0