您的位置:首页 > 其它

【知识分享】嵌入式应用程序开发,Windows环境一键编译下载

2016-11-21 21:29 399 查看
【版权声明: 本文为博主原创作品,请尊重劳动果实,请保留原文链接,谢谢】

http://www.cnblogs.com/Recan/p/6087083.html

------------------------------------------------------------------------------------------------------------------

本文以POS嵌入式linux程序开发为例,讲解了如下在Windows开发环境(Source Insight)下实现,POS程序一键编译下载。

以下是详细教程:

------------------------------------------------------------------------------------------------------------------

                嵌入式应用开发一键编译下载

众所周知,嵌入式应用的开发与通用PC应用开发有些不太一样,主要是因为嵌入式应用它运行的环境是有特殊性的,它的运行环境并不是普通的PC环境,而是一个资源相对匮乏的嵌入式系统,往往又不具备编译程序的能力,所以在它的开发流程上,通常我们采用的方法是交叉编译,即在宿主机(PC端主机)编码、编译,然后通过各种方式将应用程序下载到嵌入式系统中运行验证。有关嵌入式开发,交叉编译的方法,这里不在阐述,可自行了解。

本文重点介绍的是,如何在交叉编译的基础上,实现windows下编码,之后一键完成程序编译、下载到嵌入式系统的方法。

看到这里的客官,可能觉得不可思议,一键编译下载?怎么可能?不相信的吃瓜群众,且听我细细道来。

【注:不带WIFI或以太网模块的POS机,或非调试版本镜像的POS机,请点击右上角叉叉】

-----------------------------------------------华丽丽的分界线----------------------------------------------------

一、开发环境介绍

本人的开发环境如下:

Windows主机:Win7专业版,64位操作系统

Linux主机:(宿主机)Red Hat Enterprise Linux6,安装在VMware Workstation 7.0

linux内核:[root@localhost ~]# uname -a

Linux localhost.localdomain 2.6.32-71.el6.i686 #1 SMP Wed Sep 1 01:26:34 EDT 2010 i686 i686 i386 GNU/Linux

嵌入式系统:搭载ARM11处理器的定制linux系统,内核:Linux newpostech 2.6.32.65-bcm5892-secure #2 PREEMPT Mon May 25 10:53:57 CST 2015 armv6l GNU/Linux

Windows下代码编译IDE:Source Insgith 3.5 英文版

POS终端:NEW8210,带GPRS+WIFI+以太网通讯能力

其他辅助工具:

putty.exe,版本 Release 0.67

plink.exe,版本 Release 0.67

pfstp.exe,版本 Release 0.67

二、网络环境介绍

由于整一篇文章介绍的方法,都依赖于SSH协议的应用,自然而然,网络环境是必不可少的。

主要有3个方面的网络环境,Windows系统的网络、Linux宿主机的网络、嵌入式系统(POS终端)的网络,三者的网络情况至少满足:Windows系统与嵌入式系统网络互通,Windows系统与Linux宿主机网络互通。三者关系拓扑图如下所示:

1 ::This is a bat file which for logining on linux-host by putty in cmd-line with ssh2 protocol.
2 ::When windows host login on linux-host, it will excute some cmds list in -m ***.sh.
3 ::In this, it will be a make cmd for make out excuteable files in pos.
4
5 ::::::::::::::::::::::::::::: help ::::::::::::::::::::::::::::::::::::::::::::::::::::
6 ::Tips for configuration
7 ::There are only some params need to be configured. Here the list :
8 ::pro_app_name, configure for your make-app name
9 ::pro_path, configure for your make-app source project path in compile-linux host
10 ::host_upload_path, configure for your own share upload path in in compile-linux host
11 ::local_upload_path, configure your own share upload path in youe local windows host
12 ::usually, host_upload_path = local_upload_path, through VMware-shared filesystem
13 ::plink_host_ip, your compile-linux host ip address
14 ::plink_user, user for login compile-linux host
15 ::plink_pwd, passwd for user who login compile-linux host
16 ::plink_exe, plink.exe locate path in local windows host
17 ::pscp_ip,  your pos-linux host ip address
18 ::pscp_user, user for login pos-linux host
19 ::pscp_pwd, passwd for user who login pos-linux host
20 ::pscp_remote_path, the pro_app_name locate path in pos-linux host
21 ::psftp_exe, psftp.exe locate path in local windows host
22 ::Other params can be always the same
23 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
24
25 ::Here is the begin of the BAT process
26 @echo off
27
28 ::set new windows run in max-windows=size :: "%~nx0" is its own app
29 ::echo "%1"
30 if "%1" == "max" goto top
31 start "tmp window" /max "%~nx0" max
32 ::echo "%~nx0"
33 ::pause
34 exit
35 :top
36
37 ::start /max
38 ::set cmd windows size (cols * lines)
39 mode con cols=100 lines=3000
40 ::set disp font in cmd window to utf-8 format
41 chcp 65001
42
43 ::The tile for every project
44 ::title      POS程序---》编译---》下载
45
46 ::Some configretion for bat excute  ::No space in the two side of "="
47 ::Set again for every project
48 ::The path is in your linux-compile-host
49 set pro_app_name=YsChnBank
50 set pro_path=/share/ys_tms/
51 set host_upload_path=/share/test_upload/upload/
52 set local_upload_path=D:\VMwareShare\test_upload\upload\
53 set make_cmd=make
54 set cp_app_2_upload=cp ./Release/%pro_app_name% %host_upload_path%
55 set ok_tips=echo -e \"%pro_app_name% project is compiled ok !!!!\"
56 set err_tips=echo -e \"%pro_app_name% project is compiled error, getting key input ...\"; getkey
57 set input_cmd_list=cd %pro_path%;%make_cmd%;if [ $? = 0 ];then %cp_app_2_upload%; %ok_tips% ;else %err_tips%; fi
58
59 ::Usually set one time is ok
60 ::The ip for your linux-compile-host will be changed in sometimes.
61 set plink_host_ip=192.168.1.80
62 set plink_user=root
63 set plink_pwd=mypasswd
64 ::Set your own path
65 set plink_exe=D:\my_putty\plink.exe
66
67 @echo on
68 ::use plink.exe (the cmd mode for putty) :: unsupported -load %putty_config%
69 ::-m .sh_param input mode
70 ::set putty_param_file=D:\my_putty\make.sh
71 ::%plink_exe%  -ssh -pw %ssh_user_pwd% %ssh_user%@%ssh_host_ip% -m %putty_param_file%
72 ::echo "%plink_exe%"  -ssh -pw %plink_pwd% %plink_user%@%plink_host_ip% %input_cmd_list% > 1234.txt
73 ::all only cmd input mode
74 "%plink_exe%"  -ssh -pw %plink_pwd% %plink_user%@%plink_host_ip% %input_cmd_list%
75
76 @echo off
77 ::Check cmd excute ok ?
78 ::if %ERRORLEVEL% EQU 0 (echo success) else (echo fail)
79
80 @echo Begin to download %pro_app_name% to remote-linux-host ...
81
82 @echo off
83 ::Some configretion for upload app to pos-linux-host
84 set pscp_ip=192.168.2.61
85 set pscp_user=user0
86 set pscp_pwd=yourpasswd
87 ::config the app located path
88 set pscp_remote_path=/home/%pscp_user%/YsChnBank/
89 set pscp_exe=D:\my_putty\pscp.exe
90 set psftp_exe=D:\my_putty\psftp.exe
91
92 @echo on
93 ::Call pscp.exe. It only upload one file in one time !
94 ::"%pscp_exe%" -pw %pscp_pwd% "%local_upload_path%%pro_app_name%"  %pscp_user%@%pscp_ip%:%pscp_remote_path%
95
96 ::create tmp batch_file for psftp
97 @echo off
98 set tmp_cmd=tmp.cmd
99 echo cd %pscp_remote_path% > %tmp_cmd%
100 echo del %pscp_remote_path%%pro_app_name% >> %tmp_cmd%
101 echo !@echo before upload, time %time% >> %tmp_cmd%
102 echo put %local_upload_path%%pro_app_name% >> %tmp_cmd%
103 echo !@echo before upload, time %time% >> %tmp_cmd%
104 ::echo put %local_upload_path%FinalData_cn.rar >> %tmp_cmd%
105 echo !@echo after  upload, time %time% >> %tmp_cmd%
106 echo chmod a+x %pscp_remote_path%%pro_app_name% >> %tmp_cmd%
107 ::echo echo "uploading files ..." > %tmp_cmd%
108 ::echo cd /home/user0/ >> %tmp_cmd%
109 ::echo rmdir /home/user0/test123/ >> %tmp_cmd%
110 ::echo del /home/user0/test.test >> %tmp_cmd%
111 echo close >> %tmp_cmd%
112 ::set the tmp cmd file hidden
113 ::@attrib +s +r +a +h %tmp_cmd%
114
115 ::call psftp.exe for upload some files together
116 ::Can't disp the download percentage what has been done.
117 @echo on
118 @echo cur time %time%
119 ::echo "%psftp_exe%" -pw %pscp_pwd%  %pscp_user%@%pscp_ip% -b %tmp_cmd% > 123456.txt
120 "%psftp_exe%" -pw %pscp_pwd%  %pscp_user%@%pscp_ip% -b %tmp_cmd%
121 ::"%psftp_exe%" -pw %pscp_pwd%  %pscp_user%@%pscp_ip% -b "D:\my_putty\tmp.cmd"
122 @echo cur time %time%
123
124 ::clear tmp cmd file
125 @attrib -s -r -a -h %tmp_cmd%
126 @del %tmp_cmd%
127
128 @pause
129 exit


Windows下批处理文件demo
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: