├── .gitignore ├── COPYING ├── MAINTAINER ├── README ├── configs ├── sample-3630.cfg ├── sample.cfg └── udev │ └── 51-omap.rules ├── docs ├── c1_s1_main.dox ├── c2_s1_caveat.dox ├── c3_s1_apps.dox ├── c3_s2_app_pserial.dox ├── c3_s3_app_pusb.dox ├── c3_s4_app_ukermit.dox ├── c3_s5_app_ucmd.dox ├── c3_s6_app_gpsign.dox ├── c4_s1_compile.dox ├── c5_s1_library.dox └── doxyfile ├── include ├── common.h ├── compare.h ├── f_status.h ├── file.h ├── rev.h ├── serial.h └── tagger.h ├── lib ├── f_status.c ├── file_posix.c ├── file_win32.c ├── lcfg │ ├── README │ ├── lcfg_static.c │ └── lcfg_static.h ├── serial_posix.c └── serial_win32.c ├── makefile └── src ├── asm ├── sty-omap3.S └── sty-omap3.bin ├── gpsign.c ├── pserial.c ├── pusb.c ├── sysrq.c ├── tagger.c ├── ucmd.c └── ukermit.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore libraries 2 | *.a 3 | *.o 4 | # Ignore swap files 5 | .*.swp 6 | # Ignore documentation 7 | docs/html/* 8 | docs/latex/* 9 | # Ignore generated exes 10 | *.exe 11 | pusb 12 | pserial 13 | ukermit 14 | ucmd 15 | gpsign 16 | tagger 17 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | ======================================================================= 2 | 3 | GNU GENERAL PUBLIC LICENSE 4 | Version 2, June 1991 5 | 6 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 7 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | 11 | Preamble 12 | 13 | The licenses for most software are designed to take away your 14 | freedom to share and change it. By contrast, the GNU General Public 15 | License is intended to guarantee your freedom to share and change free 16 | software--to make sure the software is free for all its users. This 17 | General Public License applies to most of the Free Software 18 | Foundation's software and to any other program whose authors commit to 19 | using it. (Some other Free Software Foundation software is covered by 20 | the GNU Library General Public License instead.) You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not 24 | price. Our General Public Licenses are designed to make sure that you 25 | have the freedom to distribute copies of free software (and charge for 26 | this service if you wish), that you receive source code or can get it 27 | if you want it, that you can change the software or use pieces of it 28 | in new free programs; and that you know you can do these things. 29 | 30 | To protect your rights, we need to make restrictions that forbid 31 | anyone to deny you these rights or to ask you to surrender the rights. 32 | These restrictions translate to certain responsibilities for you if you 33 | distribute copies of the software, or if you modify it. 34 | 35 | For example, if you distribute copies of such a program, whether 36 | gratis or for a fee, you must give the recipients all the rights that 37 | you have. You must make sure that they, too, receive or can get the 38 | source code. And you must show them these terms so they know their 39 | rights. 40 | 41 | We protect your rights with two steps: (1) copyright the software, and 42 | (2) offer you this license which gives you legal permission to copy, 43 | distribute and/or modify the software. 44 | 45 | Also, for each author's protection and ours, we want to make certain 46 | that everyone understands that there is no warranty for this free 47 | software. If the software is modified by someone else and passed on, we 48 | want its recipients to know that what they have is not the original, so 49 | that any problems introduced by others will not reflect on the original 50 | authors' reputations. 51 | 52 | Finally, any free program is threatened constantly by software 53 | patents. We wish to avoid the danger that redistributors of a free 54 | program will individually obtain patent licenses, in effect making the 55 | program proprietary. To prevent this, we have made it clear that any 56 | patent must be licensed for everyone's free use or not licensed at all. 57 | 58 | The precise terms and conditions for copying, distribution and 59 | modification follow. 60 | 61 | GNU GENERAL PUBLIC LICENSE 62 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 63 | 64 | 0. This License applies to any program or other work which contains 65 | a notice placed by the copyright holder saying it may be distributed 66 | under the terms of this General Public License. The "Program", below, 67 | refers to any such program or work, and a "work based on the Program" 68 | means either the Program or any derivative work under copyright law: 69 | that is to say, a work containing the Program or a portion of it, 70 | either verbatim or with modifications and/or translated into another 71 | language. (Hereinafter, translation is included without limitation in 72 | the term "modification".) Each licensee is addressed as "you". 73 | 74 | Activities other than copying, distribution and modification are not 75 | covered by this License; they are outside its scope. The act of 76 | running the Program is not restricted, and the output from the Program 77 | is covered only if its contents constitute a work based on the 78 | Program (independent of having been made by running the Program). 79 | Whether that is true depends on what the Program does. 80 | 81 | 1. You may copy and distribute verbatim copies of the Program's 82 | source code as you receive it, in any medium, provided that you 83 | conspicuously and appropriately publish on each copy an appropriate 84 | copyright notice and disclaimer of warranty; keep intact all the 85 | notices that refer to this License and to the absence of any warranty; 86 | and give any other recipients of the Program a copy of this License 87 | along with the Program. 88 | 89 | You may charge a fee for the physical act of transferring a copy, and 90 | you may at your option offer warranty protection in exchange for a fee. 91 | 92 | 2. You may modify your copy or copies of the Program or any portion 93 | of it, thus forming a work based on the Program, and copy and 94 | distribute such modifications or work under the terms of Section 1 95 | above, provided that you also meet all of these conditions: 96 | 97 | a) You must cause the modified files to carry prominent notices 98 | stating that you changed the files and the date of any change. 99 | 100 | b) You must cause any work that you distribute or publish, that in 101 | whole or in part contains or is derived from the Program or any 102 | part thereof, to be licensed as a whole at no charge to all third 103 | parties under the terms of this License. 104 | 105 | c) If the modified program normally reads commands interactively 106 | when run, you must cause it, when started running for such 107 | interactive use in the most ordinary way, to print or display an 108 | announcement including an appropriate copyright notice and a 109 | notice that there is no warranty (or else, saying that you provide 110 | a warranty) and that users may redistribute the program under 111 | these conditions, and telling the user how to view a copy of this 112 | License. (Exception: if the Program itself is interactive but 113 | does not normally print such an announcement, your work based on 114 | the Program is not required to print an announcement.) 115 | 116 | These requirements apply to the modified work as a whole. If 117 | identifiable sections of that work are not derived from the Program, 118 | and can be reasonably considered independent and separate works in 119 | themselves, then this License, and its terms, do not apply to those 120 | sections when you distribute them as separate works. But when you 121 | distribute the same sections as part of a whole which is a work based 122 | on the Program, the distribution of the whole must be on the terms of 123 | this License, whose permissions for other licensees extend to the 124 | entire whole, and thus to each and every part regardless of who wrote it. 125 | 126 | Thus, it is not the intent of this section to claim rights or contest 127 | your rights to work written entirely by you; rather, the intent is to 128 | exercise the right to control the distribution of derivative or 129 | collective works based on the Program. 130 | 131 | In addition, mere aggregation of another work not based on the Program 132 | with the Program (or with a work based on the Program) on a volume of 133 | a storage or distribution medium does not bring the other work under 134 | the scope of this License. 135 | 136 | 3. You may copy and distribute the Program (or a work based on it, 137 | under Section 2) in object code or executable form under the terms of 138 | Sections 1 and 2 above provided that you also do one of the following: 139 | 140 | a) Accompany it with the complete corresponding machine-readable 141 | source code, which must be distributed under the terms of Sections 142 | 1 and 2 above on a medium customarily used for software interchange; or, 143 | 144 | b) Accompany it with a written offer, valid for at least three 145 | years, to give any third party, for a charge no more than your 146 | cost of physically performing source distribution, a complete 147 | machine-readable copy of the corresponding source code, to be 148 | distributed under the terms of Sections 1 and 2 above on a medium 149 | customarily used for software interchange; or, 150 | 151 | c) Accompany it with the information you received as to the offer 152 | to distribute corresponding source code. (This alternative is 153 | allowed only for noncommercial distribution and only if you 154 | received the program in object code or executable form with such 155 | an offer, in accord with Subsection b above.) 156 | 157 | The source code for a work means the preferred form of the work for 158 | making modifications to it. For an executable work, complete source 159 | code means all the source code for all modules it contains, plus any 160 | associated interface definition files, plus the scripts used to 161 | control compilation and installation of the executable. However, as a 162 | special exception, the source code distributed need not include 163 | anything that is normally distributed (in either source or binary 164 | form) with the major components (compiler, kernel, and so on) of the 165 | operating system on which the executable runs, unless that component 166 | itself accompanies the executable. 167 | 168 | If distribution of executable or object code is made by offering 169 | access to copy from a designated place, then offering equivalent 170 | access to copy the source code from the same place counts as 171 | distribution of the source code, even though third parties are not 172 | compelled to copy the source along with the object code. 173 | 174 | 4. You may not copy, modify, sublicense, or distribute the Program 175 | except as expressly provided under this License. Any attempt 176 | otherwise to copy, modify, sublicense or distribute the Program is 177 | void, and will automatically terminate your rights under this License. 178 | However, parties who have received copies, or rights, from you under 179 | this License will not have their licenses terminated so long as such 180 | parties remain in full compliance. 181 | 182 | 5. You are not required to accept this License, since you have not 183 | signed it. However, nothing else grants you permission to modify or 184 | distribute the Program or its derivative works. These actions are 185 | prohibited by law if you do not accept this License. Therefore, by 186 | modifying or distributing the Program (or any work based on the 187 | Program), you indicate your acceptance of this License to do so, and 188 | all its terms and conditions for copying, distributing or modifying 189 | the Program or works based on it. 190 | 191 | 6. Each time you redistribute the Program (or any work based on the 192 | Program), the recipient automatically receives a license from the 193 | original licensor to copy, distribute or modify the Program subject to 194 | these terms and conditions. You may not impose any further 195 | restrictions on the recipients' exercise of the rights granted herein. 196 | You are not responsible for enforcing compliance by third parties to 197 | this License. 198 | 199 | 7. If, as a consequence of a court judgment or allegation of patent 200 | infringement or for any other reason (not limited to patent issues), 201 | conditions are imposed on you (whether by court order, agreement or 202 | otherwise) that contradict the conditions of this License, they do not 203 | excuse you from the conditions of this License. If you cannot 204 | distribute so as to satisfy simultaneously your obligations under this 205 | License and any other pertinent obligations, then as a consequence you 206 | may not distribute the Program at all. For example, if a patent 207 | license would not permit royalty-free redistribution of the Program by 208 | all those who receive copies directly or indirectly through you, then 209 | the only way you could satisfy both it and this License would be to 210 | refrain entirely from distribution of the Program. 211 | 212 | If any portion of this section is held invalid or unenforceable under 213 | any particular circumstance, the balance of the section is intended to 214 | apply and the section as a whole is intended to apply in other 215 | circumstances. 216 | 217 | It is not the purpose of this section to induce you to infringe any 218 | patents or other property right claims or to contest validity of any 219 | such claims; this section has the sole purpose of protecting the 220 | integrity of the free software distribution system, which is 221 | implemented by public license practices. Many people have made 222 | generous contributions to the wide range of software distributed 223 | through that system in reliance on consistent application of that 224 | system; it is up to the author/donor to decide if he or she is willing 225 | to distribute software through any other system and a licensee cannot 226 | impose that choice. 227 | 228 | This section is intended to make thoroughly clear what is believed to 229 | be a consequence of the rest of this License. 230 | 231 | 8. If the distribution and/or use of the Program is restricted in 232 | certain countries either by patents or by copyrighted interfaces, the 233 | original copyright holder who places the Program under this License 234 | may add an explicit geographical distribution limitation excluding 235 | those countries, so that distribution is permitted only in or among 236 | countries not thus excluded. In such case, this License incorporates 237 | the limitation as if written in the body of this License. 238 | 239 | 9. The Free Software Foundation may publish revised and/or new versions 240 | of the General Public License from time to time. Such new versions will 241 | be similar in spirit to the present version, but may differ in detail to 242 | address new problems or concerns. 243 | 244 | Each version is given a distinguishing version number. If the Program 245 | specifies a version number of this License which applies to it and "any 246 | later version", you have the option of following the terms and conditions 247 | either of that version or of any later version published by the Free 248 | Software Foundation. If the Program does not specify a version number of 249 | this License, you may choose any version ever published by the Free Software 250 | Foundation. 251 | 252 | 10. If you wish to incorporate parts of the Program into other free 253 | programs whose distribution conditions are different, write to the author 254 | to ask for permission. For software which is copyrighted by the Free 255 | Software Foundation, write to the Free Software Foundation; we sometimes 256 | make exceptions for this. Our decision will be guided by the two goals 257 | of preserving the free status of all derivatives of our free software and 258 | of promoting the sharing and reuse of software generally. 259 | 260 | NO WARRANTY 261 | 262 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 263 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 264 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 265 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 266 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 267 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 268 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 269 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 270 | REPAIR OR CORRECTION. 271 | 272 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 273 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 274 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 275 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 276 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 277 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 278 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 279 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 280 | POSSIBILITY OF SUCH DAMAGES. 281 | 282 | END OF TERMS AND CONDITIONS 283 | -------------------------------------------------------------------------------- /MAINTAINER: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # # 3 | # Regular Maintainers for OMAP U-Boot Utilities: # 4 | # # 5 | # Note: lists sorted by Maintainer Name # 6 | ######################################################################### 7 | 8 | Nishanth Menon 9 | 10 | pusb pserial ukermit ucmd gpsign 11 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | +----------------------------------------------------------------------------+ 2 | | Welcome to Utils for U-Boot Utilities for OMAP! | 3 | +----------------------------------------------------------------------------+ 4 | 5 | ======== 6 | Dated 27 Aug 2008 - Nishanth Menon 7 | ======== 8 | +----------------------------------------------------------------------------+ 9 | Table of Contents: 10 | ================= 11 | 0) CAVEATS 12 | 1) COMPILATION Environment 13 | 2) COMPILING the code 14 | 3) pserial help 15 | 4) ukermit help 16 | 5) ucmd help 17 | 6) pusb help 18 | 7) gpsign help 19 | 8) Generic Example of usage 20 | 9) Files and Directories 21 | 10) Credits 22 | +----------------------------------------------------------------------------+ 23 | 24 | IMPORTANT NOTE: This document is meant for folks who dont have generated 25 | documentation and need to see how it all works. However, this doc does get 26 | outdated pretty fast.. so take this as a generic directions. 27 | if you would like the latest. do a 'make docs' and look at 28 | documentation in docs/html/index.html file 29 | 30 | 0) CAVEATS 31 | ========== 32 | Before using any tools, I would love to know it's limitations, hence the 33 | section 0 ;). some of the known caveats at the time of writing are: 34 | a) pusb does not yet work on windows. This is still a work in progress 35 | b) ukermit is cranky when used with large packets - it is disabled at the moment 36 | c) pserial can be used with most usb->rs232 adapters, however CH431 based 37 | adapters are not support due to the fact that the linux kernel driver for 38 | the CH341 does not support even parity. 39 | 40 | 1) COMPILATION Environment: 41 | =========================== 42 | To get documentation run 'make docs'. You need doxygen and graphviz in your path 43 | for this to work. Documentation generation has been tried in linux only. 44 | 45 | Linux: 46 | ------ 47 | A) Get the Environment: 48 | ---------------------- 49 | Based on which ever distribution you have, you would need gcc, make, 50 | binutils, libc 51 | 52 | You could run "apt-get install gcc" or "yum install gcc" based on debian or 53 | redhat distribution 54 | 55 | NOTE: to make documentation, you'd need doxygen, graphviz, dot, latex, 56 | pdflatex, makeindex and related packages 57 | 58 | Windows: 59 | ------- 60 | A)Get the Environment: 61 | ---------------------- 62 | NOTE: based on the speed of your internet connection and machine speed, these 63 | steps could take quite a while.. So dont blame me ;). I have just tried these 64 | on a 32 bit Windows XP machine, so no guarentees on 64 bit or Windows 65 | Vista,2000,95 and whatever is around.. 66 | 67 | I) Compiler: http://www.mingw.org/ 68 | i) Download automated installer from: 69 | http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=240780 70 | ii) Select gcc from options provided to 71 | Example: C:\MinGW 72 | = C:\MingW 73 | II) Get compilation environment: http://gnuwin32.sourceforge.net/ 74 | you can install individual packages from 75 | http://gnuwin32.sourceforge.net/packages.html OR go for the entire package by 76 | doing the following steps: 77 | i) Run the getGNUWin32 application to download and install from: 78 | http://sourceforge.net/project/showfiles.php?group_id=163416&package_id=184724 79 | ii) Select the location to install the applications to 80 | Example: c:\gnuWinTemp 81 | iii) Click on windows start->run "cmd" 82 | iv) cd to C:\gnuWinTemp\GetGnuWin32\ 83 | v) If you have a net proxy to set, this would be the time to do it. e.g. for 84 | http proxy(proxy.com) running on port 80, run: 85 | set http_proxy=http://proxy.com:80 86 | Note: NO QUOTES. Dont try 'set http_proxy="http://proxy.com:80"'. 87 | Things are a bit brain dead and takes '"' as part of the variable. 88 | vi) Setup the mirrors: 89 | Example: set GNUWIN32_MIRROR="voxel umn unc" 90 | (Yes with the '"'s) 91 | Note: if you want to see the available mirrors run 'notepad readme.txt' 92 | vii) Run the command "download" -> This will take a while all the apps are 93 | pulled down, but, what the heck, you get all the apps :). 94 | Note: if you do not desire to install all, read the readme.txt on how to 95 | select the packages you'd need to install 96 | viii) Run the command "install" -> This again could take a while 97 | ix) now open a windows explorer window (windows key+e) and move the directory 98 | to . Example: 99 | C:\gnuWinTemp\GetGnuWin32\gnuwin32 to c:\gnuwin32 100 | directory c:\gnuWinTemp can now be deleted (if you would like to save some 101 | disk space) 102 | = c:\gnuwin32 103 | III) setup the environment variables 104 | i) Right click on system and select "System Properties" 105 | ii) Click on "Advanced" Tab 106 | iii) Click on the "Environment Variable" button 107 | iv) Add \bin and \bin to the Path 108 | variable (it is in System variable). 109 | Example: c:\gnuwin32\bin;C:\MinGW\bin 110 | 111 | B) Additional params for building code for Windows 112 | -------------------------------------------------- 113 | You can choose where the make,gcc are taken in windows compilation: 114 | i) Using variables to compile 115 | Example: 116 | set COMPILER_PREFIX=C:\MingW\bin\ 117 | set APP_PREFIX=C:\gnuwin32\bin\ 118 | make 119 | 120 | ii) Edit the Makefile and change the COMPILER_PREFIX and APP_PREFIX variables 121 | to point to where the files are present. 122 | 123 | To Compile code open a new command prompt by running "cmd" from start->run 124 | cd to the code and do a make 125 | 126 | 2) COMPILING the code: 127 | ====================== 128 | * 'make docs' will generate the documentation. 129 | * 'make' will compile all binaries except pusb 130 | * 'make usb' will generate pusb as there is a dependency on libusb and OS 131 | compiled on. 132 | * 'make clean' and 'make distclean' will cleanup all temporary files as required. 133 | 134 | By default, code builds in quiet mode, by setting variable V=1 during compile, 135 | you can get detailed build steps: 136 | Example: make V=1 137 | 138 | NOTE: make docs requires graphviz, doxygen packages 139 | 140 | 3) pserial help 141 | =============== 142 | This Application helps download a second file as response to ASIC ID over 143 | serial port 144 | 145 | Syntax: 146 | ------ 147 | ./pserial -p portName -f fileToDownload 148 | 149 | Where: 150 | ----- 151 | portName - RS232 device being used. Example: Linux: /dev/ttyS0, Windows: 152 | COM1,COM2 etc. 153 | fileToDownload - file to be downloaded as response to asic id 154 | 155 | Usage Example: 156 | ------------- 157 | Linux: ./pserial -p /dev/ttyS0 -f ~/tmp/u-boot.bin 158 | Windows: pserial -p COM1 -f z:\tmp\u-boot.bin 159 | 160 | 4) ukermit help 161 | =============== 162 | This Application helps download a fileusing U-Boot's kermit protocol over 163 | serial port 164 | 165 | Syntax: 166 | ------ 167 | ./ukermit -p portName -f fileToDownload [-d delay_time] 168 | 169 | Where: 170 | ----- 171 | portName - RS232 device being used. Example: Linux: /dev/ttyS0, Windows: 172 | COM1,COM2 etc. 173 | fileToDownload - file to be downloaded 174 | delay_time - delay in ms b/w each packet transmission and ack 175 | 176 | Usage Example: 177 | ------------- 178 | Linux: ./ukermit -p /dev/ttyS0 -f ~/tmp/u-boot.bin 179 | Windows: ukermit -p COM1 -f z:\tmp\u-boot.bin 180 | 181 | 5) ucmd help 182 | ============ 183 | This sends a command and expects a provided matching response from target 184 | 185 | Syntax: 186 | ------ 187 | ./ucmd -p portName -c "command to send" -e "Expect String" 188 | 189 | Where: 190 | ----- 191 | portName - RS232 device being used. Example: Linux: /dev/ttyS0, Windows: 192 | COM1,COM2 etc. 193 | command to send - Command to send to uboot 194 | Expect string - String to expect from target - on match the 195 | application returns 196 | 197 | Usage Example: 198 | ------------- 199 | Linux: ./ucmd -p /dev/ttyS0 -c "help" -e "U-Boot>" 200 | Windows: ucmd -p COM1 -c "help" -e "U-Boot>" 201 | 202 | 6) pusb help 203 | ============ 204 | This Application helps download a second file as response to ASIC ID over USB 205 | 206 | Syntax: 207 | ------ 208 | ./pusb [-v] [-V] [-d device_ID] -f input_file 209 | Where: 210 | ----- 211 | -v : (optional) verbose messages 212 | -V : (optional) verbose messages + usblib debug messages 213 | -q : (optional) Ultra quiet - no outputs other than error 214 | -d device_ID: (optional) USB Device id (Uses default of 0xD009) 215 | -f input_file: input file to be transmitted to target 216 | NOTE: it is required to run this program in sudo mode to get access at times 217 | 218 | Usage Example: 219 | Linux: sudo ./pusb -f u-boot.bin 220 | 221 | 7) gpsign help 222 | ============== 223 | App description: 224 | --------------- 225 | generates a formatted image which may be used for 226 | nand, onenand or mmc boot on a OMAP GP device. 227 | This can also add a configuration header which 228 | allows for preconfiguration of various clock,ram 229 | GPMC or MMC settings prior to the image starting. 230 | 231 | Syntax: 232 | ------- 233 | ./gpsign [-c config file] [-l loadaddr] [-f input_file] [-?] 234 | Where: 235 | ------ 236 | -c config_file: CH configuration file[Default none] 237 | -l loadaddress: load address for result img[Default 0x40208800] 238 | -f input_file: input binary to sign[Default x-load.bin] 239 | -? : provide extended help including a sample config file 240 | ------ 241 | 242 | Usage Example: 243 | All OS: gpsign 244 | 245 | 8) Generic Example of usage 246 | =========================== 247 | The following example is using U-Boot-V2. But it is not restricted to just 248 | that! My notes in [NOTE:] comments below 249 | 250 | $ ./pserial -p /dev/ttyS1 -f ../u-serial.bin 251 | [NOTE: this will wait for ASIC ID -> So I switch on/reset the board after 252 | this] 253 | Waiting For Device ASIC ID: Press Ctrl+C to stop 254 | ASIC ID Detected. 255 | Sending 2ndFile: 256 | Downloading file: 100.000% completed(35108/35108 bytes) 257 | File download completed. 258 | 259 | $ ./ucmd -p /dev/ttyS1 -c "loadb -f /dev/ram0" -e 'bps...' 260 | [NOTE: run the loadb command to load to memory.. loadb command ends with bps.. 261 | to show it is waiting for a file to be send from host] 262 | Output: 263 | loadb -f /dev/ram0 264 | ## Ready for binary (kermit) download to 0x00000000 offset on /dev/ram0 device 265 | at 115200 bps... 266 | Match Found. Operation completed! 267 | 268 | $ ./ukermit -p /dev/ttyS1 -f ../u-serial.bin 269 | [NOTE: use ukermit to download the file to the target] 270 | Downloading file: 100.000% completed(35108/35108 bytes) 271 | File Download completed 272 | 273 | $ ./ucmd -p /dev/ttyS1 -c "go 0x80000000" -e "X-load 343x>" 274 | [NOTE: we just execute the file which was downloaded] 275 | Output: 276 | go 0x80000000 277 | ## Starting application at 0x80.0.0-rc5-git (Aug 21 2008 - 11:22:15) 278 | 279 | Board: Texas Instrument's SDP343x 280 | Malloc space: 0x87bfff10 -> 0x87ffff10 (size 4 MB) 281 | Stack space : 0x87bf7f10 -> 0x87bfff10 (size 32 kB) 282 | running /env/bin/init... 283 | not found 284 | X-load 343x> 285 | Match Found. Operation completed! 286 | 287 | [NOTE: you could embedd these in script files to automate commonly used 288 | operations such as flashing an image etc.. and ease up things a lot more] 289 | 290 | 9) Files and Directories 291 | ======================== 292 | . (Source Root. All final executables are generated here) 293 | |-- COPYING (Copy Right file ->READ THIS) 294 | |-- README (This file) 295 | |-- configs (Sample configuration files for boards) 296 | | |-- sample-3630.cfg - sample omap3630 file (example zoom3) 297 | | `-- sample.cfg 298 | |-- docs (documentation Directory) 299 | | |-- c1_s1_main.dox 300 | | |-- c2_s1_caveat.dox 301 | | |-- c3_s1_apps.dox 302 | | |-- c3_s2_app_pserial.dox 303 | | |-- c3_s3_app_pusb.dox 304 | | |-- c3_s4_app_ukermit.dox 305 | | |-- c3_s5_app_ucmd.dox 306 | | |-- c4_s1_compile.dox 307 | | |-- c5_s1_library.dox 308 | | `-- doxyfile 309 | < `--html/index.html -> This is root html file when we generate docs> 310 | < `--html/index.hhc -> This is root hhc project file for generating chm> 311 | < `--latex/refman.pdf -> This is the final pdf when we generate docs> 312 | |-- include (common headers for libraries) 313 | | |-- file.h 314 | | |-- f_status.h 315 | | |-- rev.h 316 | | `-- serial.h 317 | |-- lib (libraries used by apps) 318 | | |-- file_posix.c (Linux/Mac OS/posix compilant file ops) 319 | | |-- file_win32.c (Windows file ops) 320 | | |-- f_status.c (show off status of operations) 321 | | |-- lcfg (liblcfg library for configuration file handling) 322 | | | |-- README 323 | | | |-- lcfg_static.c 324 | | | `-- lcfg_static.h 325 | | |-- serial_posix.c (Linux/Mac OS/posix Serial port ops) 326 | | `-- serial_win32.c (Windows Serial port ops) 327 | |-- makefile (make file for build) 328 | `-- src (app source directory) 329 | |-- gpserial.c (gpserial source) 330 | |-- pserial.c (pserial source) 331 | |-- ucmd.c (ucmd source) 332 | |-- pusb.c (pusb source) 333 | `-- ukermit.c (ukermit source) 334 | 335 | 6 directories, 33 files 336 | 337 | 338 | 10) Credits 339 | ======================== 340 | At the start of writing this code, there was no git, no svn, just zip files, 341 | so a couple of honorable mentions at this time: 342 | Dirk Behme - general directions and initial usb discussion as here: 343 | http://groups.google.com/group/beagleboard/browse_thread/thread/ae2c601ebe104a4 344 | pusb is a scratch write but in general uses the same concepts 345 | 346 | Rob Clark - Mac OS support, tons of cleanups in serial code, and in general a 347 | willing experimenter with new ideas :) 348 | 349 | Paul Baecher for writing liblcfg: http://liblcfg.carnivore.it/ - I recommend it 350 | to anyone looking for a quiet simple config file handling parser 351 | -------------------------------------------------------------------------------- /configs/sample-3630.cfg: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Sample configuration file for gpsign (e.g. zoom3) 4 | * 5 | * (C) Copyright 2009 6 | * Texas Instruments, 7 | * Sukumar Ghorai 8 | * 9 | * This program is free software; you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License as published by the 11 | * Free Software Foundation version 2. 12 | * 13 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 14 | * whether express or implied; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 | * MA 02111-1307 USA 22 | */ 23 | /* Default image load address when using this config file */ 24 | loadaddr = "0x82000000" 25 | 26 | /* 27 | * The following section is a MUST HAVE 28 | * provides the settings of the clocks etc. 29 | */ 30 | platform_chsettings = { 31 | section_key = "0xC0C0C0C1" 32 | valid = "0x1" 33 | version = "0x1" 34 | flags = "0x050001FD" 35 | /*General clock settings */ 36 | GEN_PRM_CLKSRC_CTRL = "0x40" 37 | GEN_PRM_CLKSEL = "0x3" 38 | GEN_CM_CLKSEL1_EMU = "0x2" 39 | /* Clock Configuration */ 40 | CLK_CM_CLKSEL_CORE = "0x130A" 41 | CLK_CM_CLKSEL_WKUP = "0x15" 42 | /* DPLL3 (Core) Settings */ 43 | DPLL3_CM_CLKEN_PLL = "0x00370007" 44 | DPLL3_CM_AUTOIDLE_PLL = "0x0" 45 | DPLL3_CM_CLKSEL1_PLL = "0x08C80C00" 46 | /* DPLL4 (Peripheral) Settings */ 47 | DPLL4_CM_CLKEN_PLL = "0x00000011" 48 | DPLL4_CM_AUTOIDLE_PLL = "0x00000000" 49 | DPLL4_CM_CLKSEL2_PLL = "0x0441B00C" 50 | DPLL4_CM_CLKSEL3_PLL = "0x00000009" 51 | /* DPLL1(MPU) Settings */ 52 | DPLL1_CM_CLKEN_PLL_MPU = "0x00000037" 53 | DPLL1_CM_AUTOIDLE_PLL_MPU = "0x0" 54 | DPLL1_CM_CLKSEL1_PLL_MPU = "0x00112C0C" 55 | DPLL1_CM_CLKSEL2_PLL_MPU = "0x1" 56 | DPLL1_CM_CLKSTCTRL_MPU = "0x0" 57 | } 58 | 59 | /* SDRAM configuration section - optional */ 60 | platform_chram = { 61 | section_key = "0xC0C0C0C2" 62 | valid = "0x1" 63 | SDRC_SYSCONFIG_LSB = "0x0000" 64 | SDRC_CS_CFG_LSB = "0x0002" 65 | SDRC_SHARING_LSB = "0x0100" 66 | SDRC_DLLA_CTRL = "0x0000000A" 67 | SDRC_POWER = "0x00000085" 68 | /* I use CS0 and CS1 */ 69 | flags = "0x3" 70 | /* CS0 */ 71 | mem_type_cs0 = "0x3" 72 | SDRC_MCFG_0 = "0x03588099" 73 | SDRC_MR_0_LSB = "0x00000032" 74 | SDRC_ACTIM_CTRLA_0 = "0xA2E1B4C6" 75 | SDRC_ACTIM_CTRLB_0 = "0x0002131C" 76 | SDRC_RFRCTRL_0 = "0x0005E601" 77 | /* CS1 */ 78 | mem_type_cs1 = "0x3" 79 | SDRC_MCFG_1 = "0x03588099" 80 | SDRC_MR_1_LSB = "0x00000032" 81 | SDRC_ACTIM_CTRLA_1 = "0xA2E1B4C6" 82 | SDRC_ACTIM_CTRLB_1 = "0x0002131C" 83 | SDRC_RFRCTRL_1 = "0x0005E601" 84 | } 85 | 86 | /* 87 | * Similar structures for platform_chflash and platform_chmmcsd 88 | * can optionally exist 89 | */ 90 | board= { 91 | mach_id = "0x000009A1" 92 | board_rev = "0x10" 93 | bootargs = 94 | "console=ttyS0,115200n8 noinitrd ip=dhcp root=/dev/nfs rw nfsroot=128.247.75.1:/home/fs/rootfs,nolock,wsize=1024,rsize=1024" 95 | ram0 = { 96 | start = "0x80000000" 97 | size = "0x10000000" 98 | } 99 | ram1 = { 100 | start = "0x90000000" 101 | size = "0x10000000" 102 | } 103 | sty_file="src/asm/sty-omap3.bin" 104 | } 105 | -------------------------------------------------------------------------------- /configs/sample.cfg: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Sample configuration file for gpsign 4 | * 5 | * (C) Copyright 2009 6 | * Texas Instruments, 7 | * Nishanth Menon 8 | * 9 | * This program is free software; you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License as published by the 11 | * Free Software Foundation version 2. 12 | * 13 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 14 | * whether express or implied; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 | * MA 02111-1307 USA 22 | */ 23 | /* Default image load address when using this config file */ 24 | loadaddr = "0x81000000" 25 | 26 | /* 27 | * The following section is a MUST HAVE 28 | * provides the settings of the clocks etc. 29 | */ 30 | platform_chsettings = { 31 | section_key = "0xC0C0C0C1" 32 | valid = "0x1" 33 | version = "0x1" 34 | flags = "0x050001FD" 35 | /*General clock settings */ 36 | GEN_PRM_CLKSRC_CTRL = "0x40" 37 | GEN_PRM_CLKSEL = "0x3" 38 | GEN_CM_CLKSEL1_EMU = "0x2030A50" 39 | /* Clock Configuration */ 40 | CLK_CM_CLKSEL_CORE = "0x40A" 41 | CLK_CM_CLKSEL_WKUP = "0x14" 42 | /* DPLL3 (Core) Settings */ 43 | DPLL3_CM_CLKEN_PLL = "0x770077" 44 | DPLL3_CM_AUTOIDLE_PLL = "0x0" 45 | DPLL3_CM_CLKSEL1_PLL = "0x8A60C00" 46 | /* DPLL4 (Peripheral) Settings */ 47 | DPLL4_CM_CLKEN_PLL = "0x770077" 48 | DPLL4_CM_AUTOIDLE_PLL = "0xD80C" 49 | DPLL4_CM_CLKSEL2_PLL = "0x0" 50 | DPLL4_CM_CLKSEL3_PLL = "0x9" 51 | /* DPLL1(MPU) Settings */ 52 | DPLL1_CM_CLKEN_PLL_MPU = "0x77" 53 | DPLL1_CM_AUTOIDLE_PLL_MPU = "0x0" 54 | DPLL1_CM_CLKSEL1_PLL_MPU = "0x10FA0C" 55 | DPLL1_CM_CLKSEL2_PLL_MPU = "0x1" 56 | DPLL1_CM_CLKSTCTRL_MPU = "0x0" 57 | } 58 | 59 | /* SDRAM configuration section - optional */ 60 | platform_chram = { 61 | section_key = "0xC0C0C0C2" 62 | valid = "0x1" 63 | SDRC_SYSCONFIG_LSB = "0x0" 64 | SDRC_CS_CFG_LSB = "0x1" 65 | SDRC_SHARING_LSB = "0x100" 66 | SDRC_DLLA_CTRL = "0xA" 67 | SDRC_POWER = "0x81" 68 | /* I use CS0 and CS1 */ 69 | flags = "0x3" 70 | /* CS0 */ 71 | mem_type_cs0 = "0x3" 72 | SDRC_MCFG_0 = "0x02D04011" 73 | SDRC_MR_0_LSB = "0x00000032" 74 | SDRC_ACTIM_CTRLA_0 = "0xBA9DC4C6" 75 | SDRC_ACTIM_CTRLB_0 = "0x00012522" 76 | SDRC_RFRCTRL_0 = "0x0004E201" 77 | /* CS1 */ 78 | mem_type_cs1 = "0x3" 79 | SDRC_MCFG_1 = "0x02D04011" 80 | SDRC_MR_1_LSB = "0x00000032" 81 | SDRC_ACTIM_CTRLA_1 = "0xBA9DC4C6" 82 | SDRC_ACTIM_CTRLB_1 = "0x00012522" 83 | SDRC_RFRCTRL_1 = "0x0004E201" 84 | } 85 | 86 | /* 87 | * Similar structures for platform_chflash and platform_chmmcsd 88 | * can optionally exist 89 | */ 90 | /* 91 | * board configuration SDP3430 - for kernel ATAG 92 | */ 93 | board = { 94 | mach_id = "0x00000472" 95 | board_rev = "0x20" 96 | bootargs = 97 | "console=ttyS0,115200n8 noinitrd ip=dhcp root=/dev/nfs rw nfsroot=128.247.75.1:/home/fs/rootfs,nolock,wsize=1024,rsize=1024 mem=128M" 98 | ram0 = { 99 | start = "0x80000000" 100 | size = "0x08000000" 101 | } 102 | ram1 = { 103 | start = "0xA0000000" 104 | size = "0x00000000" 105 | } 106 | sty_file="src/asm/sty-omap3.bin" 107 | } 108 | -------------------------------------------------------------------------------- /configs/udev/51-omap.rules: -------------------------------------------------------------------------------- 1 | # Placed into the public domain 2010 by Dan Fandrich 2 | # 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation version 2. 6 | # 7 | # This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 8 | # whether express or implied; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | # General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU General Public License 13 | # along with this program; if not, write to the Free Software 14 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 15 | # MA 02111-1307 USA 16 | # 17 | # udev rule that makes a T.I. OMAP USB boot device world writable 18 | # Place into /etc/udev/rules.d/ (or wherever appropriate for your system) to 19 | # allow OMAP devices to be writable by all users with local login access. 20 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0451", MODE="0666" 21 | -------------------------------------------------------------------------------- /docs/c1_s1_main.dox: -------------------------------------------------------------------------------- 1 | /** @mainpage OMAP U-Boot Utils 2 | 3 | @section uboot_utils_intro Introduction 4 | This is a bunch of utilities meant to work with U-Boot 5 | [http://www.denx.de/wiki/UBoot] 6 | 7 | @section uboot_utils_motivation Motivation: 8 | Traditionally U-Boot has worked with terminal applications such as 9 | minicom/hyperterminal etc. However, 10 | @li These applications dont work out fine when we think of automating these 11 | as part of scripts or the like. 12 | @li Many corporations use a mixture of Operating Systems at work. Common 13 | applications functioning similarly accross host Operating Systems are sadly 14 | lacking. 15 | 16 | This bunch of utilities we hope to bridge these gaps. We can create wrappers 17 | on top of these utilities, allowing us to potentially have automated 18 | command execution driven from the host. 19 | 20 | @section uboot_utils_details Details 21 | @li @subpage ub_compiliation 22 | @li @subpage ub_caveats 23 | @li @subpage ub_library 24 | @li @subpage ub_apps 25 | 26 | @section license U-Boot Utils' License 27 | 28 | @verbatim 29 | This program is free software; you can redistribute it and/or modify it 30 | under the terms of the GNU General Public License as published by the 31 | Free Software Foundation version 2. 32 | 33 | This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 34 | whether express or implied; without even the implied warranty of 35 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 36 | General Public License for more details. 37 | 38 | You should have received a copy of the GNU General Public License 39 | along with this program; if not, write to the Free Software 40 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, 41 | MA 02111-1307 USA 42 | @endverbatim 43 | 44 | */ 45 | 46 | -------------------------------------------------------------------------------- /docs/c2_s1_caveat.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_caveats Known Caveats 3 | The following lists the known issues with omap U-Boot utils 4 | @li pusb does not yet work on windows. This is still a work in progress 5 | @li ukermit is cranky when used with large packets - it is disabled at the moment 6 | */ 7 | -------------------------------------------------------------------------------- /docs/c3_s1_apps.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_apps Applications in U-Boot Utilities 3 | U-Boot utilities provide the following apps: 4 | @li @subpage ub_pserial - OMAP specific utility which downloads a file in 5 | response to ASIC ID over serial port. 6 | @li @subpage ub_pusb - OMAP specific utility which downloads a file in 7 | response to ASIC ID over USB connection. 8 | @li @subpage ub_ucmd - Send a command to U-Boot and wait till a specific match appears. 9 | @li @subpage ub_ukermit - Download a file from host without using kermit to U-Boot. 10 | @li @subpage ub_gpsign - Sign a image for booting with additional parameters. 11 | */ 12 | -------------------------------------------------------------------------------- /docs/c3_s2_app_pserial.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_pserial pserial 3 | 4 | This Application helps download a second file as response to ASIC ID over 5 | serial port 6 | 7 | @section section Syntax: 8 | @code 9 | pserial -p portName -f fileToDownload 10 | @endcode 11 | 12 | Where: 13 | @li portName - RS232 device being used. Example: Linux: /dev/ttyS0, Windows: 14 | COM1,COM2 etc. 15 | @li fileToDownload - file to be downloaded as response to asic id 16 | 17 | @section example Usage Example: 18 | @code 19 | Linux: ./pserial -p /dev/ttyS0 -f ~/tmp/u-boot.bin 20 | @endcode 21 | @code 22 | Windows: pserial.exe -p COM1 -f z:\tmp\u-boot.bin 23 | @endcode 24 | 25 | @section file Files: 26 | @li @ref src/pserial.c 27 | */ 28 | -------------------------------------------------------------------------------- /docs/c3_s3_app_pusb.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_pusb pusb 3 | 4 | This Application helps download a second file as response to ASIC ID over 5 | USB 6 | 7 | @section section Syntax: 8 | @code 9 | pusb [-v] [-V] [-d device_ID] -f input_file 10 | @endcode 11 | 12 | Where: 13 | @li -v : (optional) verbose messages 14 | @li -V : (optional) verbose messages + usblib debug messages 15 | @li -q : (optional) Ultra quiet - no outputs other than error 16 | @li -d device_ID: (optional) USB Device id (Uses default of 0xD009) 17 | @li -f input_file: input file to be transmitted to target 18 | 19 | @warning Use sudo to get access to set_configuration 20 | 21 | @section example Usage Example: 22 | @code 23 | Linux: sudo ./pusb -d 0xd009 -f ~/tmp/u-boot.bin 24 | @endcode 25 | 26 | For *ix users: 27 | Note pusb uses LibUSB. This is dependent on usbfs being present in the system. 28 | See http://www.linuxquestions.org/linux/answers/Programming/Developing_Linux_Device_Drivers_using_Libusb_API 29 | for further information 30 | 31 | @section file Files: 32 | @li @ref src/pusb.c 33 | */ 34 | -------------------------------------------------------------------------------- /docs/c3_s4_app_ukermit.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_ukermit ukermit 3 | 4 | This Application helps download a fileusing U-Boot's kermit protocol over 5 | serial port 6 | 7 | @section section Syntax: 8 | @code 9 | ./ukermit -p portName -f fileToDownload [-d delay_time] 10 | @endcode 11 | 12 | Where: 13 | @li portName - RS232 device being used. Example: Linux: /dev/ttyS0, Windows: 14 | COM1,COM2 etc. 15 | @li fileToDownload - file to be downloaded 16 | @li delay_time - delay time in ms for ack reciept (optional) - usually used when 17 | u-boot has something to do between packets -such as write to nand/nor etc.. 18 | which takes extra time and standard serial communication apps might fail 19 | 20 | @section example Usage Example: 21 | @code 22 | Linux: ./ukermit -p /dev/ttyS0 -f ~/tmp/u-boot.bin 23 | @endcode 24 | @code 25 | Windows: ukermit.exe -p COM1 -f z:\tmp\u-boot.bin 26 | @endcode 27 | 28 | @section file Files: 29 | @li @ref src/ukermit.c 30 | 31 | */ 32 | -------------------------------------------------------------------------------- /docs/c3_s5_app_ucmd.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_ucmd ucmd 3 | 4 | This sends a command and expects a provided matching response from target 5 | 6 | @section section Syntax: 7 | @code 8 | ucmd -p portName -c "command to send" -e "Expect String" 9 | @endcode 10 | 11 | Where: 12 | @li portName - RS232 device being used. Example: Linux: /dev/ttyS0, Windows: 13 | COM1,COM2 etc. 14 | @li command to send - Command to send to uboot 15 | @li Expect string - String to expect from target - on match the application returns 16 | 17 | @section example Usage Example: 18 | @code 19 | Linux: ./ucmd -p /dev/ttyS0 -c "help" -e "U-Boot>" 20 | @endcode 21 | @code 22 | Windows: ucmd.exe -p COM1 -c "help" -e "U-Boot>" 23 | @endcode 24 | 25 | @section file Files: 26 | @li @ref src/ucmd.c 27 | */ 28 | -------------------------------------------------------------------------------- /docs/c3_s6_app_gpsign.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_gpsign gpsign 3 | 4 | This application generates a formatted image which may be used for 5 | nand, onenand or mmc boot on a OMAP GP device. 6 | This can also add a configuration header which 7 | allows for preconfiguration of various clock,ram 8 | GPMC or MMC settings prior to the image starting. 9 | 10 | @section section Syntax: 11 | @code 12 | gpsign [-c config file] [-l loadaddr] [-f input_file] [-?] 13 | @endcode 14 | 15 | Where: 16 | @li -c config_file : CH configuration file[Default none] 17 | @li -l loadaddress : load address for result img[Default 0x40208800] -overrides 18 | default and values in configuration file 19 | @li -f input_file : input binary to sign[Default x-load.bin] 20 | @li -? : provide extended help including a sample config file 21 | 22 | 23 | @section example Usage Example: 24 | @code 25 | gpsign 26 | Uses x-loader.bin, loadaddress 0x40208800 and signs without Configuration 27 | Header 28 | 29 | gpsign -l 0x80000000 30 | Uses x-loader.bin and signs without Configuration Header for loadaddress 31 | 0x80000000 32 | 33 | gpsign -c sample.cfg -l 0x80000000 34 | Uses x-loader.bin, uses sample.cfg and loadaddress 0x80000000 35 | (ignores value in configuration file) 36 | 37 | gpsign -c sample.cfg -f u-boot.bin 38 | Uses u-boot.bin and uses sample.cfg for configuration 39 | 40 | @endcode 41 | 42 | @warning Please refer to OMAP3430 TRM for further details on the fields 43 | 44 | Example Configuration file (full option list with gpsign -?) 45 | @code 46 | load_addr = "0x80000000" 47 | platform_chsettings = { 48 | section_key = "0xC0C0C0C1" 49 | valid = "0x1" 50 | version = "0x1" 51 | flags = "0x050001FD" 52 | /*General clock settings */ 53 | GEN_PRM_CLKSRC_CTRL = "0x40" 54 | GEN_PRM_CLKSEL = "0x3" 55 | GEN_CM_CLKSEL1_EMU = "0x2030A50" 56 | /* Clock Configuration */ 57 | CLK_CM_CLKSEL_CORE = "0x40A" 58 | CLK_CM_CLKSEL_WKUP = "0x14" 59 | /* DPLL3 (Core) Settings */ 60 | DPLL3_CM_CLKEN_PLL = "0x770077" 61 | DPLL3_CM_AUTOIDLE_PLL = "0x0" 62 | DPLL3_CM_CLKSEL1_PLL = "0x8A60C00" 63 | /* DPLL4 (Peripheral) Settings */ 64 | DPLL4_CM_CLKEN_PLL = "0x770077" 65 | DPLL4_CM_AUTOIDLE_PLL = "0xD80C" 66 | DPLL4_CM_CLKSEL2_PLL = "0x0" 67 | DPLL4_CM_CLKSEL3_PLL = "0x9" 68 | /* DPLL1(MPU) Settings */ 69 | DPLL1_CM_CLKEN_PLL_MPU = "0x77" 70 | DPLL1_CM_AUTOIDLE_PLL_MPU = "0x0" 71 | DPLL1_CM_CLKSEL1_PLL_MPU = "0x10FA0C" 72 | DPLL1_CM_CLKSEL2_PLL_MPU = "0x1" 73 | DPLL1_CM_CLKSTCTRL_MPU = "0x0" 74 | } 75 | 76 | platform_chram = { 77 | section_key = "0xC0C0C0C2" 78 | valid = "0x1" 79 | SDRC_SYSCONFIG_LSB = "0x0" 80 | SDRC_CS_CFG_LSB = "0x1" 81 | SDRC_SHARING_LSB = "0x100" 82 | SDRC_DLLA_CTRL = "0xA" 83 | SDRC_POWER = "0x81" 84 | /* I use CS0 and CS1 */ 85 | flags = "0x3" 86 | /* CS0 */ 87 | mem_type_cs0 = "0x3" 88 | SDRC_MCFG_0 = "0x02D04011" 89 | SDRC_MR_0_LSB = "0x00000032" 90 | SDRC_ACTIM_CTRLA_0 = "0xBA9DC4C6" 91 | SDRC_ACTIM_CTRLB_0 = "0x00012522" 92 | SDRC_RFRCTRL_0 = "0x0004E201" 93 | /* CS1 */ 94 | mem_type_cs1 = "0x3" 95 | SDRC_MCFG_1 = "0x02D04011" 96 | SDRC_MR_1_LSB = "0x00000032" 97 | SDRC_ACTIM_CTRLA_1 = "0xBA9DC4C6" 98 | SDRC_ACTIM_CTRLB_1 = "0x00012522" 99 | SDRC_RFRCTRL_1 = "0x0004E201" 100 | } 101 | @endcode 102 | @warning This uses http://liblcfg.carnivore.it/ (libcfg)for parsing 103 | configuration files 104 | @code 105 | Copyright (c) 2007--2009 Paul Baecher 106 | This program is free software; you can redistribute it and/or modify 107 | it under the terms of the GNU General Public License as published by 108 | the Free Software Foundation; either version 2 of the License, or 109 | (at your option) any later version. 110 | @endcode 111 | 112 | @section file Files: 113 | @li @ref src/gpsign.c 114 | */ 115 | -------------------------------------------------------------------------------- /docs/c4_s1_compile.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_compiliation Compiling the Code 3 | Table Of Contents 4 | 5 | @li @ref a 6 | @li @ref a_1 7 | @li @ref a_2 8 | @li @ref a_2_1 9 | @li @ref a_2_2 10 | @li @ref b 11 | 12 | @section a A) Getting ready to compile code 13 | 14 | @subsection a_1 A.1) Linux 15 | This section explains the compilation environment needs of linux 16 | 17 | Based on which ever distribution you have, you would need gcc, make, 18 | binutils, libc, system utils such as find, sed, uname, grep, tr etc. For 19 | documentation, you'd need doxygen and graphviz, latex, pdflatex, makeindex. 20 | For pusb, you will need libusb(and known to work only on Linux at the moment) 21 | 22 | You could run "apt-get install gcc" or "yum install gcc" based on debian or 23 | redhat distributions. 24 | 25 | 26 | @subsection a_2 A.2) Windows 27 | 28 | @subsubsection a_2_1 A.2.1) Get the Environment: 29 | NOTE: based on the speed of your internet connection and machine speed, these 30 | steps could take quite a while.. So dont blame me ;). I have just tried these 31 | on a 32 bit Windows XP machine, so no guarentees on 64 bit or Windows 32 | Vista,2000,95 and whatever is around.. 33 | 34 | @li MingW Compiler: http://www.mingw.org/ 35 | @verbatim 36 | i) Download automated installer from: 37 | http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=240780 38 | ii) Select gcc from options provided to 39 | Example: C:\MinGW 40 | = C:\MingW 41 | @endverbatim 42 | @li Get compilation environment:GnuWin32 http://gnuwin32.sourceforge.net/ 43 | you can install individual packages from 44 | http://gnuwin32.sourceforge.net/packages.html OR go for the entire package by 45 | getting getGnuWin32 from 46 | http://sourceforge.net/project/showfiles.php?group_id=163416&package_id=184724 47 | . Follow the steps provided below: 48 | @verbatim 49 | i) Run the getGNUWin32 application to download and install GNUwin32 apps 50 | ii) Select the location to install the applications to 51 | Example: c:\gnuWinTemp 52 | iii) Click on windows start->run "cmd" 53 | iv) cd to C:\gnuWinTemp\GetGnuWin32\ 54 | v) If you have a net proxy to set, this would be the time to do it. e.g. for 55 | http proxy(proxy.com) running on port 80, run: 56 | set http_proxy=http://proxy.com:80 57 | Note: NO QUOTES. Dont try 'set http_proxy="http://proxy.com:80"'. 58 | Things are a bit brain dead and takes '"' as part of the variable. 59 | vi) Setup the mirrors: 60 | Example: set GNUWIN32_MIRROR="voxel umn unc" 61 | (Yes with the '"'s) 62 | Note: if you want to see the available mirrors run 'notepad readme.txt' 63 | vii) Run the command "download" -> This will take a while all the apps are 64 | pulled down, but, what the heck, you get all the apps :). 65 | Note: if you do not desire to install all, read the readme.txt on how to 66 | select the packages you'd need to install 67 | viii) Run the command "install" -> This again could take a while 68 | ix) now open a windows explorer window (windows key+e) and move the directory 69 | to . Example: 70 | C:\gnuWinTemp\GetGnuWin32\gnuwin32 to c:\gnuwin32 71 | directory c:\gnuWinTemp can now be deleted (if you would like to save some 72 | disk space) 73 | = c:\gnuwin32 74 | @endverbatim 75 | @li Setup the environment variables 76 | @verbatim 77 | i) Right click on system and select "System Properties" 78 | ii) Click on "Advanced" Tab 79 | iii) Click on the "Environment Variable" button 80 | iv) Add \bin and \bin to the Path 81 | variable (it is in System variable). 82 | Example: c:\gnuwin32\bin;C:\MinGW\bin 83 | @endverbatim 84 | 85 | @subsubsection a_2_2 A.2.2) Additional params for building code for Windows 86 | You can choose where the make,gcc are taken in windows compilation: 87 | @verbatim 88 | i) Using variables to compile 89 | Example: 90 | set COMPILER_PREFIX=C:\MingW\bin\ 91 | set APP_PREFIX=C:\gnuwin32\bin\ 92 | make 93 | 94 | ii) Edit the Makefile and change the COMPILER_PREFIX and APP_PREFIX variables 95 | to point to where the files are present. 96 | @endverbatim 97 | To Compile code open a new command prompt by running "cmd" from start->run 98 | cd to the code and do a make 99 | 100 | 101 | @section b B) Compiling the code: 102 | make can be invoked in the following manner: 103 | @li Build binaries: 104 | @code make@endcode will compile all binaries except pusb. 105 | @code make usb@endcode will compile pusb.(currently only for linux) 106 | @li Build documentation 107 | @code make docs @endcode will generate html documentation 108 | @li Clean up the build 109 | @code make clean @endcode will clean out all build object files + executables 110 | @code make distclean @endcode will do what clean does + find and destroy all temporary files and any generated documentation. 111 | 112 | By default, code builds in quiet mode, by setting variable V=1 during 113 | compile, you can get detailed build steps. Example: 114 | @code 115 | make V=1 116 | @endcode 117 | */ 118 | -------------------------------------------------------------------------------- /docs/c5_s1_library.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page ub_library OS dependent Libraries 3 | 4 | In general accessing OS specific system devices such as file and serial port tends to be a pain. Hence, 5 | there we define a set of APIs which are OS independent . APIs and defines can be found here: 6 | @li @ref include/serial.h - provide for OS independent APIs for applications to access serial port 7 | @li @ref include/file.h - provide OS independent APIs for accessing file 8 | @li lib/lcfg/lcfg_static.h - liblcfg library from Paul Baecher's http://liblcfg.carnivore.it/ 9 | generated with the mksinglefile.sh - rev 0.2.0 10 | 11 | The corresponding OS dependent implementation is done in lib/serial_[OS].c lib/file_[OS].c 12 | */ 13 | -------------------------------------------------------------------------------- /include/common.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief stuff that belong no where, common header for all files 4 | * 5 | * FileName: include/rev.h 6 | * 7 | */ 8 | /* 9 | * (C) Copyright 2009 10 | * Texas Instruments, 11 | * Nishanth Menon 12 | * 13 | * This program is free software; you can redistribute it and/or modify it 14 | * under the terms of the GNU General Public License as published by the 15 | * Free Software Foundation version 2. 16 | * 17 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 18 | * whether express or implied; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program; if not, write to the Free Software 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 25 | * MA 02111-1307 USA 26 | */ 27 | #ifndef __LIB_COMMON_H 28 | #define __LIB_COMMON_H 29 | 30 | #ifndef DISABLE_COLOR 31 | /* Colored prints enabled by default */ 32 | #ifndef __WIN32__ 33 | 34 | #define _COLOR_(m) "\x1b[" # m 35 | #define RED _COLOR_(1;31m) 36 | #define GREEN _COLOR_(1;32m) 37 | #define BLUE _COLOR_(1;34m) 38 | #define RESET _COLOR_(0m) 39 | 40 | #define COLOR_PRINT(COLOR,ARGS...)\ 41 | {\ 42 | printf(COLOR ARGS);\ 43 | printf(RESET);\ 44 | } 45 | 46 | #else 47 | #include 48 | #include 49 | 50 | #define RED FOREGROUND_RED 51 | #define GREEN FOREGROUND_GREEN 52 | #define BLUE FOREGROUND_BLUE 53 | #define COLOR_PRINT(COLOR,ARGS...)\ 54 | {\ 55 | HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);\ 56 | CONSOLE_SCREEN_BUFFER_INFO pConsoleScreenBufferInfo;\ 57 | GetConsoleScreenBufferInfo(hStdout,&pConsoleScreenBufferInfo);\ 58 | SetConsoleTextAttribute(hStdout, COLOR | FOREGROUND_INTENSITY);\ 59 | printf(ARGS);\ 60 | SetConsoleTextAttribute(hStdout, pConsoleScreenBufferInfo.wAttributes);\ 61 | } 62 | #endif /* __WIN32__ */ 63 | 64 | #define APP_ERROR(ARGS...) {COLOR_PRINT(RED,ARGS)} 65 | 66 | #else /* #ifndef DISABLE_COLOR */ 67 | 68 | #define COLOR_PRINT(COLOR,ARGS...) printf(ARGS); 69 | #define APP_ERROR(ARGS...) {fprintf(stderr,ARGS);} 70 | 71 | #endif /* #ifndef DISABLE_COLOR */ 72 | 73 | #endif /* __LIB_COMMON_H */ 74 | -------------------------------------------------------------------------------- /include/compare.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPARE__ 2 | #define __COMPARE__ 3 | 4 | #define TYPE_U8 1 5 | #define TYPE_U16 2 6 | #define TYPE_U32 3 7 | #define TYPE_S 4 8 | 9 | struct compare_map { 10 | char *name; 11 | void *variable; 12 | int type; 13 | }; 14 | static struct compare_map *variable_map_g; 15 | static int size_var_map; 16 | /** 17 | * @brief compare_eventhandler - this is the parser logic 18 | * 19 | * This provides a hook for the lcfg library to call when a 20 | * match is found for a specific keypair 21 | * 22 | * @param key key string 23 | * @param data data buffer 24 | * @param len length of the data buffer 25 | * @param user_data any specifics 26 | * 27 | * @return error if it did not match our dictionary or a data overflow, 28 | * else success 29 | */ 30 | static enum lcfg_status compare_eventhandler(const char *key, void *data, size_t len, void *user_data) 31 | { 32 | int i; 33 | struct compare_map *c = NULL; 34 | const char *str = (const char *)data; 35 | int ret = 0; 36 | unsigned int val = 1, max_val; 37 | for (i = 0; i < size_var_map; i++) { 38 | c = &variable_map_g[i]; 39 | if (!strcmp(c->name, key)) { 40 | val = 0; 41 | break; 42 | } 43 | } 44 | 45 | if (val) { 46 | APP_ERROR("Skipping unused '%s' in config file\n", key) 47 | return lcfg_status_ok; 48 | } 49 | switch (c->type) { 50 | case TYPE_S: 51 | strcpy((char *)c->variable, (char *)data); 52 | break; 53 | case TYPE_U32: 54 | case TYPE_U16: 55 | case TYPE_U8: 56 | ret = sscanf(str, "%x", &val); 57 | if (!ret) { 58 | APP_ERROR("scanf failed for key %s and data %s\n", key, 59 | str) 60 | return lcfg_status_ok; 61 | } 62 | max_val = 0xFFFFFFFF; 63 | if (c->type == TYPE_U32) 64 | *((unsigned int *)c->variable) = val; 65 | else if (c->type == TYPE_U16) { 66 | max_val = 0xFFFF; 67 | *((unsigned short *)c->variable) = (unsigned short)val; 68 | } else if (c->type == TYPE_U8) { 69 | max_val = 0xFF; 70 | *((unsigned char *)c->variable) = (unsigned char)val; 71 | } else { 72 | APP_ERROR("%s:%s():%d:Key %s type %d unhandled->" 73 | "please email developer with this message\n", 74 | __FILE__, __FUNCTION__, __LINE__, c->name, 75 | c->type) 76 | } 77 | if (val > max_val) { 78 | APP_ERROR("Config File error: in key %s, value 0x%08X " 79 | "is greater than maximum allowed value 0x%08X" 80 | "\n", c->name, val, max_val) 81 | return lcfg_status_error; 82 | } 83 | 84 | break; 85 | default: 86 | APP_ERROR("Unknown type??\n") 87 | return lcfg_status_error; 88 | 89 | } 90 | return lcfg_status_ok; 91 | } 92 | #endif /* __COMPARE__ */ 93 | -------------------------------------------------------------------------------- /include/f_status.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief header for lib for showing file transfer status 4 | * 5 | * FileName: include/f_status.h 6 | * 7 | * File transfer status apis 8 | * 9 | */ 10 | /* 11 | * (C) Copyright 2008 12 | * Texas Instruments, 13 | * Nishanth Menon 14 | * 15 | * This program is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation version 2. 18 | * 19 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 20 | * whether express or implied; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 27 | * MA 02111-1307 USA 28 | */ 29 | #ifndef __LIB_INCLUDE_F_STATUS 30 | #define __LIB_INCLUDE_F_STATUS 31 | 32 | #define SPECIAL_PRINT 1 33 | #define NORMAL_PRINT 0 34 | /** 35 | * @brief f_status_init initialize the status structures 36 | * 37 | * @param total_size - total size of the file 38 | * @param special - display special display -> for apps interfacing with ui stuff 39 | */ 40 | void f_status_init(signed long total_size, unsigned char special); 41 | 42 | /** 43 | * @brief f_status_show show current status -> to be called by apps when they desire to display 44 | * 45 | * @param cur_size - current size 46 | * 47 | * @return 0 - ok ,1 - not ok.. size was too large 48 | */ 49 | int f_status_show(signed long cur_size); 50 | #endif /* __LIB_INCLUDE_F_STATUS */ 51 | -------------------------------------------------------------------------------- /include/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Header for Generic I/O definition. 4 | * 5 | * FileName: include/file.h 6 | * 7 | * The OS specific implementation should implement these APIs. 8 | * 9 | */ 10 | /* 11 | * (C) Copyright 2008 12 | * Texas Instruments, 13 | * Nishanth Menon 14 | * 15 | * This program is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation version 2. 18 | * 19 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 20 | * whether express or implied; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 27 | * MA 02111-1307 USA 28 | */ 29 | #ifndef __FILE__H_ 30 | #define __FILE__H_ 31 | /** File Operation failed */ 32 | #define FILE_ERROR -1 33 | /** File Operation OK */ 34 | #define FILE_OK 0 35 | 36 | signed long f_size(const char *f_name); 37 | signed char f_open(const char *f_name); 38 | signed char f_close(void); 39 | signed int f_read(unsigned char *buffer, unsigned int read_size); 40 | int f_seek(long offset); 41 | 42 | #endif /* __FILE__H_ */ 43 | -------------------------------------------------------------------------------- /include/rev.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Nothing other than storing a common rev information 4 | * 5 | * FileName: include/rev.h 6 | * 7 | */ 8 | /* 9 | * (C) Copyright 2008-2009 10 | * Texas Instruments, 11 | * Nishanth Menon 12 | * 13 | * This program is free software; you can redistribute it and/or modify it 14 | * under the terms of the GNU General Public License as published by the 15 | * Free Software Foundation version 2. 16 | * 17 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 18 | * whether express or implied; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program; if not, write to the Free Software 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 25 | * MA 02111-1307 USA 26 | */ 27 | #ifndef __LIB_REV_H 28 | #define __LIB_REV_H 29 | #define OMAP_UBOOT_UTILS_REVISION "\nRev: OMAP U-boot Utils v0.2.1\n" 30 | #define OMAP_UBOOT_UTILS_LICENSE \ 31 | "\nCopyright (C) 2008-2009 Texas Instruments, \n"\ 32 | "This is free software; see the source for copying conditions.\n"\ 33 | "There is NO warranty; not even for MERCHANTABILITY or FITNESS\n"\ 34 | "FOR A PARTICULAR PURPOSE.\n" 35 | 36 | #include 37 | #define REVPRINT() COLOR_PRINT(BLUE, OMAP_UBOOT_UTILS_REVISION) 38 | #define LIC_PRINT() COLOR_PRINT(GREEN, OMAP_UBOOT_UTILS_LICENSE) 39 | 40 | #endif /* __LIB_REV_H */ 41 | -------------------------------------------------------------------------------- /include/serial.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Generic header for OS independent APIs to access serial port 4 | * 5 | * FileName: include/serial.h 6 | * 7 | * These APIs should be implemented by OS specific code 8 | * 9 | */ 10 | /* 11 | * (C) Copyright 2008 12 | * Texas Instruments, 13 | * Nishanth Menon 14 | * 15 | * This program is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation version 2. 18 | * 19 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 20 | * whether express or implied; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 27 | * MA 02111-1307 USA 28 | */ 29 | #ifndef _SERIAL_H 30 | #define _SERIAL_H 31 | 32 | signed char s_open(char *port); 33 | signed char s_configure(unsigned long baud_rate, unsigned char parity, 34 | unsigned char stop_bits, unsigned char data); 35 | signed char s_close(void); 36 | signed int s_read_remaining(void); 37 | signed int s_read(unsigned char *p_buffer, unsigned long size); 38 | signed int s_write(unsigned char *p_buffer, unsigned long size); 39 | signed int s_getc(void); 40 | signed int s_putc(char x); 41 | signed int s_flush(unsigned int *rx_left, unsigned int *tx_left); 42 | signed int s_break(int sec_stay, int sec_post); 43 | 44 | #define SERIAL_OK 0 45 | #define SERIAL_FAILED -1 46 | #define SERIAL_TIMEDOUT -2 47 | 48 | #define NOPARITY 0 49 | #define ODDPARITY 1 50 | #define EVENPARITY 2 51 | 52 | #define ONE_STOP_BIT 0 53 | #define ONEPFIVE_STOP_BIT 1 54 | #define TWO_STOP_BIT 2 55 | 56 | #endif /* _SERIAL_H */ 57 | -------------------------------------------------------------------------------- /include/tagger.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tagging utility for zImage files 4 | * 5 | * FileName: include/tagger.h 6 | * 7 | * ATAG information and related header info 8 | */ 9 | /* 10 | * tagger: 11 | * (C) Copyright 2010 12 | * Texas Instruments, 13 | * 14 | * Nishanth Menon 15 | * Original code from: u-boot/include/asm-arm/setup.h 16 | * linux/include/asm/setup.h 17 | * 18 | * Copyright (C) 1997-1999 Russell King 19 | * 20 | * This program is free software; you can redistribute it and/or modify 21 | * it under the terms of the GNU General Public License version 2 as 22 | * published by the Free Software Foundation. 23 | * 24 | * Structure passed to kernel to tell it about the 25 | * hardware it's running on. See linux/Documentation/arm/Setup 26 | * for more info. 27 | */ 28 | #ifndef __TAGGER_H__ 29 | #define __TAGGER_H__ 30 | 31 | #ifndef __ASSEMBLER__ 32 | 33 | typedef unsigned char u8; 34 | typedef unsigned short u16; 35 | typedef unsigned int u32; 36 | 37 | /* The list ends with an ATAG_NONE node. */ 38 | #define ATAG_NONE 0x00000000 39 | struct tag_header { 40 | u32 size; 41 | u32 tag; 42 | } __attribute__ ((__packed__)); 43 | 44 | /* The list must start with an ATAG_CORE node */ 45 | #define ATAG_CORE 0x54410001 46 | struct tag_core { 47 | u32 flags; /* bit 0 = read-only */ 48 | u32 pagesize; 49 | u32 rootdev; 50 | } __attribute__ ((__packed__)); 51 | 52 | /* it is allowed to have multiple ATAG_MEM nodes */ 53 | #define ATAG_MEM 0x54410002 54 | struct tag_mem32 { 55 | u32 size; 56 | u32 start; /* physical start address */ 57 | } __attribute__ ((__packed__)); 58 | 59 | /* VGA text type displays */ 60 | #define ATAG_VIDEOTEXT 0x54410003 61 | struct tag_videotext { 62 | u8 x; 63 | u8 y; 64 | u16 video_page; 65 | u8 video_mode; 66 | u8 video_cols; 67 | u16 video_ega_bx; 68 | u8 video_lines; 69 | u8 video_isvga; 70 | u16 video_points; 71 | } __attribute__ ((__packed__)); 72 | 73 | /* describes how the ramdisk will be used in kernel */ 74 | #define ATAG_RAMDISK 0x54410004 75 | struct tag_ramdisk { 76 | u32 flags; /* bit 0 = load, bit 1 = prompt */ 77 | u32 size; /* decompressed ramdisk size in _kilo_ bytes */ 78 | u32 start; /* starting block of floppy-based RAM disk image */ 79 | } __attribute__ ((__packed__)); 80 | 81 | /* describes where the compressed ramdisk image lives (virtual address) */ 82 | /* 83 | * this one accidentally used virtual addresses - as such, 84 | * its depreciated. 85 | */ 86 | #define ATAG_INITRD 0x54410005 87 | 88 | /* describes where the compressed ramdisk image lives (physical address) */ 89 | #define ATAG_INITRD2 0x54420005 90 | struct tag_initrd { 91 | u32 start; /* physical start address */ 92 | u32 size; /* size of compressed ramdisk image in bytes */ 93 | } __attribute__ ((__packed__)); 94 | 95 | /* board serial number. "64 bits should be enough for everybody" */ 96 | #define ATAG_SERIAL 0x54410006 97 | struct tag_serialnr { 98 | u32 low; 99 | u32 high; 100 | } __attribute__ ((__packed__)); 101 | 102 | /* board revision */ 103 | #define ATAG_REVISION 0x54410007 104 | struct tag_revision { 105 | u32 rev; 106 | } __attribute__ ((__packed__)); 107 | 108 | /* initial values for vesafb-type framebuffers. see struct screen_info 109 | * in include/linux/tty.h 110 | */ 111 | #define ATAG_VIDEOLFB 0x54410008 112 | struct tag_videolfb { 113 | u16 lfb_width; 114 | u16 lfb_height; 115 | u16 lfb_depth; 116 | u16 lfb_linelength; 117 | u32 lfb_base; 118 | u32 lfb_size; 119 | u8 red_size; 120 | u8 red_pos; 121 | u8 green_size; 122 | u8 green_pos; 123 | u8 blue_size; 124 | u8 blue_pos; 125 | u8 rsvd_size; 126 | u8 rsvd_pos; 127 | } __attribute__ ((__packed__)); 128 | 129 | /* command line: \0 terminated string */ 130 | #define ATAG_CMDLINE 0x54410009 131 | struct tag_cmdline { 132 | char cmdline[1]; /* this is the minimum size */ 133 | } __attribute__ ((__packed__)); 134 | struct tag { 135 | struct tag_header hdr; 136 | union { 137 | struct tag_core core; 138 | struct tag_mem32 mem; 139 | struct tag_videotext videotext; 140 | struct tag_ramdisk ramdisk; 141 | struct tag_initrd initrd; 142 | struct tag_serialnr serialnr; 143 | struct tag_revision revision; 144 | struct tag_videolfb videolfb; 145 | struct tag_cmdline cmdline; 146 | } u; 147 | } __attribute__ ((__packed__)); 148 | 149 | #define tag_next(t) ((struct tag *)((u32 *)(t) + (t)->hdr.size)) 150 | #define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type)) >> 2) 151 | 152 | #define CONFIG_NR_DRAM_BANKS 2 153 | struct board { 154 | u32 mach_id; 155 | u32 board_rev; 156 | char bootargs[1024]; 157 | char sty_file[1024]; 158 | /* Ram */ 159 | struct { 160 | u32 start; 161 | u32 size; /* 0 means no existo */ 162 | } ram[CONFIG_NR_DRAM_BANKS]; 163 | /* Framebuffer? */ 164 | struct { 165 | u32 base; 166 | u32 size; /* 0 means does not exist */ 167 | } fb; 168 | /* Serial */ 169 | struct { /* both 0 means does not exist */ 170 | u32 high; 171 | u32 low; 172 | } serial; 173 | }; 174 | 175 | #endif /* !__ASSEMBLER__ */ 176 | 177 | /* Magic code to be used in sty-xxx.S will be replaced by tagger */ 178 | #define MAGIC_MACHID 0xDEADBEEF 179 | #define MAGIC_INTERIMSIZE 0xCAFEBEEF 180 | 181 | #endif /* __TAGGER_H__ */ 182 | -------------------------------------------------------------------------------- /lib/f_status.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief lib for showing file transfer status 4 | * 5 | * FileName: lib/f_status.c 6 | * 7 | * File transfer status apis 8 | * 9 | */ 10 | /* 11 | * (C) Copyright 2008 12 | * Texas Instruments, 13 | * Nishanth Menon 14 | * 15 | * This program is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation version 2. 18 | * 19 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 20 | * whether express or implied; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 27 | * MA 02111-1307 USA 28 | */ 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | #define BACK_SPACE_CHAR '\b' 38 | /* max buffer size */ 39 | #define PRINT_SIZE 100 40 | 41 | /* Store my old buffer */ 42 | static char print_buff[PRINT_SIZE]; 43 | /* backspace characters */ 44 | static char back_buff[PRINT_SIZE]; 45 | /* total size of the file */ 46 | static signed long tsize; 47 | /* Special prints of the order of percent/cur/total size */ 48 | static unsigned char s_special; 49 | 50 | /** 51 | * @brief f_status_init initialize the status structures 52 | * 53 | * @param total_size - total size of the file 54 | * @param special - display s_special display -> for 55 | * apps interfacing with ui stuff 56 | */ 57 | void f_status_init(signed long total_size, unsigned char special) 58 | { 59 | tsize = total_size; 60 | memset(back_buff, BACK_SPACE_CHAR, sizeof(back_buff)); 61 | print_buff[0] = '\0'; 62 | s_special = special; 63 | } 64 | 65 | /** 66 | * @brief f_status_show show current status -> to be called by apps when they 67 | * desire to display 68 | * 69 | * @param cur_size - current size 70 | * 71 | * @return 0 - ok ,1 - not ok.. size was too large 72 | */ 73 | int f_status_show(signed long cur_size) 74 | { 75 | int off; 76 | float percent; 77 | if (cur_size > tsize) { 78 | return -1; 79 | } 80 | percent = cur_size; 81 | percent /= tsize; 82 | percent *= 100; 83 | if (s_special) { 84 | printf("%.03f/%ld/%ld", percent, cur_size, tsize); 85 | return 0; 86 | } 87 | /* get length of old buffer */ 88 | off = strlen(print_buff); 89 | /* should i print backspaces? */ 90 | if (off) { 91 | back_buff[off] = '\0'; 92 | printf("%s", back_buff); 93 | /* restore backspace */ 94 | back_buff[off] = BACK_SPACE_CHAR; 95 | } 96 | sprintf(print_buff, 97 | "Downloading file: %.03f%% completed (%ld/%ld bytes)", percent, 98 | cur_size, tsize); 99 | printf("%s", print_buff); 100 | fflush(stdout); 101 | return 0; 102 | } 103 | -------------------------------------------------------------------------------- /lib/file_posix.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief file io implementation for Linux and POSIX compliant OSes 4 | * 5 | * FileName: lib/file_linux.c 6 | * 7 | */ 8 | /* 9 | * (C) Copyright 2008 10 | * Texas Instruments, 11 | * Nishanth Menon 12 | * 13 | * This program is free software; you can redistribute it and/or modify it 14 | * under the terms of the GNU General Public License as published by the 15 | * Free Software Foundation version 2. 16 | * 17 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 18 | * whether express or implied; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program; if not, write to the Free Software 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 25 | * MA 02111-1307 USA 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "file.h" 34 | #include 35 | 36 | /************* CONSTS ***************/ 37 | #define F_ERROR(ARGS...) APP_ERROR(ARGS);perror("File:Error") 38 | 39 | #ifdef DEBUG 40 | #define F_INFO(ARGS...) fprintf(stdout,ARGS) 41 | #else 42 | #define F_INFO(ARGS...) 43 | #endif 44 | 45 | /************* VARS ***************/ 46 | static FILE *file; 47 | 48 | /**************** EXPOSED FUNCTIONS ****************/ 49 | 50 | /** 51 | * @brief f_size - returns the size of the file 52 | * 53 | * @param f_name - name of the file including path 54 | * 55 | * @return success/fail 56 | */ 57 | signed long f_size(const char *f_name) 58 | { 59 | struct stat f_stat; 60 | if (stat(f_name, &f_stat)) { 61 | F_ERROR("Could not stat %s\n", f_name); 62 | return FILE_ERROR; 63 | } 64 | F_INFO("File size is %d\n", (unsigned int)f_stat.st_size); 65 | return f_stat.st_size; 66 | } 67 | 68 | /** 69 | * @brief f_open - open the file 70 | * 71 | * @param f_name file name 72 | * 73 | * @return success/fail 74 | */ 75 | signed char f_open(const char *f_name) 76 | { 77 | if (file != NULL) { 78 | F_ERROR("file %s already open\n", f_name); 79 | return FILE_ERROR; 80 | } 81 | file = fopen(f_name, "r"); 82 | if (file == NULL) { 83 | F_ERROR("could not open file %s\n", f_name); 84 | return FILE_ERROR; 85 | } 86 | F_INFO("file %s opened\n", (char *)f_name); 87 | return FILE_OK; 88 | } 89 | 90 | /** 91 | * @brief f_close - close the file 92 | * 93 | * @return pass/fail 94 | */ 95 | signed char f_close(void) 96 | { 97 | if (file == NULL) { 98 | F_ERROR("file is not open\n"); 99 | return FILE_ERROR; 100 | } 101 | if (fclose(file)) { 102 | F_ERROR("could not close file!\n"); 103 | file = NULL; 104 | return FILE_ERROR; 105 | } 106 | file = NULL; 107 | F_INFO("file closed\n"); 108 | return FILE_OK; 109 | } 110 | 111 | /** 112 | * @brief f_read - read from file 113 | * 114 | * @param buffer buffer 115 | * @param read_size size to read 116 | * 117 | * @return num bytes read 118 | */ 119 | signed int f_read(unsigned char *buffer, unsigned int read_size) 120 | { 121 | int ret; 122 | if (file == NULL) { 123 | F_ERROR("file is not open\n"); 124 | return FILE_ERROR; 125 | } 126 | ret = fread(buffer, 1, read_size, file); 127 | F_INFO("read operation returned %d\n", ret); 128 | return ret; 129 | } 130 | 131 | /** 132 | * @brief f_seek - seek to location in file 133 | * 134 | * @param offset in file 135 | * 136 | * @return status 137 | */ 138 | int f_seek(long offset) 139 | { 140 | int ret; 141 | if (file == NULL) { 142 | F_ERROR("file is not open\n"); 143 | return FILE_ERROR; 144 | } 145 | ret = fseek(file, offset, SEEK_SET); 146 | F_INFO("seek operation returned %d\n", ret); 147 | return ret; 148 | } 149 | -------------------------------------------------------------------------------- /lib/file_win32.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Windows API based implementation of include/file.h 4 | * 5 | * FileName: lib/file_win32.c 6 | * 7 | * Support File operations using Win32 APIs. Compiled with MingW 8 | * 9 | */ 10 | /* 11 | * (C) Copyright 2008 12 | * Texas Instruments, 13 | * Nishanth Menon 14 | * 15 | * This program is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation version 2. 18 | * 19 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 20 | * whether express or implied; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 27 | * MA 02111-1307 USA 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include "file.h" 34 | #include 35 | 36 | /***** TYPES(WINDOWS SPECIFIC) *******/ 37 | #ifndef FALSE 38 | #define FALSE 0 39 | #endif 40 | #ifndef TRUE 41 | #define TRUE 1 42 | #endif 43 | #ifndef NULL 44 | #define NULL ((void *)0) 45 | #endif 46 | 47 | /************* CONSTS ***************/ 48 | #define F_ERROR(ARGS...) APP_ERROR(ARGS) 49 | #define F_INFO(ARGS...) 50 | //#define F_INFO(ARGS...) fprintf(stdout,ARGS) 51 | 52 | /************* VARS ***************/ 53 | static HANDLE Fhandle = INVALID_HANDLE_VALUE; 54 | 55 | /**************** EXPOSED FUNCTIONS ****************/ 56 | 57 | /** 58 | * @brief f_size - returns the size of the file 59 | * 60 | * @param f_name - name of the file including path 61 | * 62 | * @return success/fail 63 | */ 64 | signed long f_size(const char *f_name) 65 | { 66 | HANDLE MF; 67 | if (Fhandle != INVALID_HANDLE_VALUE) { 68 | F_ERROR("File already opend\n"); 69 | return FILE_ERROR; 70 | } 71 | MF = CreateFile(f_name, GENERIC_READ, FILE_SHARE_READ, NULL, 72 | OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); 73 | if (MF != INVALID_HANDLE_VALUE) { 74 | DWORD High, Low; 75 | Low = GetFileSize(MF, &High); 76 | if ((High == 0) && (Low != 0xFFFFFFFF)) { 77 | F_INFO("%s: Size : High = %X, Low = %X\n", f_name, 78 | (unsigned int)High, (unsigned int)Low); 79 | CloseHandle(MF); 80 | return Low; 81 | } 82 | F_INFO("%s High %d Low %d - cannot handle\n", f_name, 83 | (unsigned int)High, (unsigned int)Low); 84 | CloseHandle(MF); 85 | } else { 86 | F_ERROR("%s: Could not open file: Error=%i\n", f_name, 87 | (int)GetLastError()); 88 | 89 | } 90 | return FILE_ERROR; 91 | } 92 | 93 | /** 94 | * @brief f_open - open the file 95 | * 96 | * @param f_name file name 97 | * 98 | * @return success/fail 99 | */ 100 | signed char f_open(const char *f_name) 101 | { 102 | if (Fhandle != INVALID_HANDLE_VALUE) { 103 | F_ERROR("File already opend\n"); 104 | return FILE_ERROR; 105 | } 106 | Fhandle = CreateFile(f_name, GENERIC_READ, FILE_SHARE_READ, NULL, 107 | OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); 108 | if (Fhandle != INVALID_HANDLE_VALUE) { 109 | F_INFO("%s: opened fine\n", f_name); 110 | return FILE_OK; 111 | } else { 112 | F_ERROR("%s: Could not open file: Error=%i\n", f_name, 113 | (int)GetLastError()); 114 | } 115 | return FILE_ERROR; 116 | } 117 | 118 | /** 119 | * @brief f_close - close the file 120 | * 121 | * @return pass/fail 122 | */ 123 | signed char f_close(void) 124 | { 125 | if (Fhandle == INVALID_HANDLE_VALUE) { 126 | F_ERROR("File not opened to close!\n"); 127 | return FILE_ERROR; 128 | } 129 | CloseHandle(Fhandle); 130 | F_INFO("File closed fine\n"); 131 | Fhandle = INVALID_HANDLE_VALUE; 132 | return FILE_OK; 133 | } 134 | 135 | /** 136 | * @brief f_read - read from file 137 | * 138 | * @param buffer buffer 139 | * @param read_size size to read 140 | * 141 | * @return pass/fail 142 | */ 143 | signed int f_read(unsigned char *buffer, unsigned int read_size) 144 | { 145 | unsigned long actual_read = 0, total_read = 0, to_read = read_size; 146 | if (Fhandle == INVALID_HANDLE_VALUE) { 147 | F_ERROR("File not opened to read!\n"); 148 | return FILE_ERROR; 149 | } 150 | while (total_read < read_size) { 151 | BOOL err = 152 | ReadFile(Fhandle, buffer, to_read, &actual_read, NULL); 153 | if (err != TRUE) { 154 | F_ERROR("Read operation failed! error = %i,to_read=%d\n" 155 | "read_size=%d,total_read=%d\n", 156 | (int)GetLastError(), (unsigned int)to_read, 157 | (unsigned int)read_size, 158 | (unsigned int)total_read); 159 | return FILE_ERROR; 160 | } 161 | if (actual_read == 0) { 162 | F_ERROR("Should not have read just 0 bytes!!!\n"); 163 | break; 164 | } 165 | to_read -= actual_read; 166 | total_read += actual_read; 167 | buffer += actual_read; 168 | F_INFO("Read %d, rem %d total_read %d!\n", 169 | (unsigned int)actual_read, (unsigned int)to_read, 170 | (unsigned int)total_read); 171 | 172 | } 173 | F_INFO("All read!\n"); 174 | 175 | return total_read; 176 | } 177 | -------------------------------------------------------------------------------- /lib/lcfg/README: -------------------------------------------------------------------------------- 1 | liblcfg - lightweight configuration file library 2 | Website: http://liblcfg.carnivore.it/ 3 | This uses the static version of the code. 4 | 5 | the files lcfg_static.c lcfg_static.h were generated using mksinglefile.sh 6 | 7 | Copyright (c) 2007--2009 Paul Baecher 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License along 20 | with this program; if not, write to the Free Software Foundation, Inc., 21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | 23 | $Id: lcfg.c 1446 2009-01-15 22:44:36Z dp $ 24 | -------------------------------------------------------------------------------- /lib/lcfg/lcfg_static.h: -------------------------------------------------------------------------------- 1 | /* 2 | * liblcfg - lightweight configuration file library 3 | * Copyright (c) 2007--2009 Paul Baecher 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * $Id: lcfg.h 1446 2009-01-15 22:44:36Z dp $ 20 | * 21 | */ 22 | 23 | #ifndef LCFG_H 24 | #define LCFG_H 25 | 26 | #include 27 | 28 | struct lcfg; 29 | 30 | enum lcfg_status { lcfg_status_ok, lcfg_status_error }; 31 | 32 | typedef enum lcfg_status (*lcfg_visitor_function)(const char *key, void *data, size_t size, void *user_data); 33 | 34 | 35 | /* open a new config file */ 36 | struct lcfg * lcfg_new(const char *filename); 37 | 38 | /* parse config into memory */ 39 | enum lcfg_status lcfg_parse(struct lcfg *); 40 | 41 | /* visit all configuration elements */ 42 | enum lcfg_status lcfg_accept(struct lcfg *, lcfg_visitor_function, void *); 43 | 44 | /* access a value by path */ 45 | enum lcfg_status lcfg_value_get(struct lcfg *, const char *, void **, size_t *); 46 | 47 | /* return the last error message */ 48 | const char * lcfg_error_get(struct lcfg *); 49 | 50 | /* set error */ 51 | void lcfg_error_set(struct lcfg *, const char *fmt, ...); 52 | 53 | /* destroy lcfg context */ 54 | void lcfg_delete(struct lcfg *); 55 | 56 | 57 | #endif 58 | /* 59 | * liblcfg - lightweight configuration file library 60 | * Copyright (c) 2007--2009 Paul Baecher 61 | * 62 | * This program is free software; you can redistribute it and/or modify 63 | * it under the terms of the GNU General Public License as published by 64 | * the Free Software Foundation; either version 2 of the License, or 65 | * (at your option) any later version. 66 | * 67 | * This program is distributed in the hope that it will be useful, 68 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 69 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 70 | * GNU General Public License for more details. 71 | * 72 | * You should have received a copy of the GNU General Public License along 73 | * with this program; if not, write to the Free Software Foundation, Inc., 74 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 75 | * 76 | * $Id$ 77 | * 78 | */ 79 | 80 | #ifndef LCFGX_TREE_H 81 | #define LCFGX_TREE_H 82 | 83 | 84 | enum lcfgx_type 85 | { 86 | lcfgx_string, 87 | lcfgx_list, 88 | lcfgx_map, 89 | }; 90 | 91 | struct lcfgx_tree_node 92 | { 93 | enum lcfgx_type type; 94 | char *key; /* NULL for root node */ 95 | 96 | union 97 | { 98 | struct 99 | { 100 | void *data; 101 | size_t len; 102 | } string; 103 | struct lcfgx_tree_node *elements; /* in case of list or map type */ 104 | } value; 105 | 106 | struct lcfgx_tree_node *next; 107 | }; 108 | 109 | struct lcfgx_tree_node *lcfgx_tree_new(struct lcfg *); 110 | 111 | void lcfgx_tree_delete(struct lcfgx_tree_node *); 112 | 113 | 114 | #endif 115 | 116 | -------------------------------------------------------------------------------- /lib/serial_posix.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Serial port operations wrapper for Linux/posix compliant OSs 4 | * 5 | * FileName: lib/serial_linux.c 6 | * 7 | * This implements the APIs in include/serial.h for linux and posix 8 | * compliant OSes. The code here is heavily indebted to: 9 | * @li http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html#AEN129 10 | * @li http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html 11 | * 12 | */ 13 | /* 14 | * (C) Copyright 2008 15 | * Texas Instruments, 16 | * Nishanth Menon 17 | * 18 | * This program is free software; you can redistribute it and/or modify it 19 | * under the terms of the GNU General Public License as published by the 20 | * Free Software Foundation version 2. 21 | * 22 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 23 | * whether express or implied; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program; if not, write to the Free Software 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 30 | * MA 02111-1307 USA 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | 47 | /************* CONSTS ***************/ 48 | #define S_ERROR(ARGS...) APP_ERROR(ARGS); perror("Serial: System Error") 49 | #ifdef DEBUG 50 | #define S_INFO(FORMAT,ARGS...) printf ("%s[%d]:" FORMAT "\n",\ 51 | __FUNCTION__,__LINE__,ARGS) 52 | #else 53 | #define S_INFO(ARGS...) 54 | #endif 55 | 56 | /* Setup delay time */ 57 | #define VTIME_SET 5 58 | 59 | /************* VARS ***************/ 60 | static unsigned char port[30]; 61 | static int fd; 62 | static struct termios oldtio, newtio; 63 | 64 | /**************** EXPOSED FUNCTIONS ****************/ 65 | /** 66 | * @brief s_open - open a serial port 67 | * 68 | * @param t_port -port number 69 | * 70 | * @return success/fail 71 | */ 72 | signed char s_open(char *t_port) 73 | { 74 | int x; 75 | char cmd[200]; 76 | if (fd) { 77 | S_ERROR("Port is already open\n"); 78 | return SERIAL_FAILED; 79 | } 80 | /* Check if serial port is used by other process */ 81 | 82 | /* NOTE: it is a bad idea to use lsof, but the alternative 83 | * is to write large amount of code.. 84 | */ 85 | sprintf(cmd, "lsof |grep %s 2>&1 >/dev/null", t_port); 86 | x = system(cmd); 87 | if (x == 0) { 88 | S_ERROR("device %s being used already?\n", t_port); 89 | sprintf(cmd, "lsof |grep %s", t_port); 90 | x = system(cmd); 91 | return SERIAL_FAILED; 92 | } 93 | fd = open(t_port, O_RDWR | O_NOCTTY); 94 | if (fd < 0) { 95 | S_ERROR("failed to open %s\n", t_port); 96 | perror(t_port); 97 | return SERIAL_FAILED; 98 | } 99 | strncpy((char *)port, t_port, 30); 100 | S_INFO("Serial port %s opend fine\n", port); 101 | return SERIAL_OK; 102 | } 103 | 104 | /** 105 | * @brief s_configure - configure the serial port 106 | * 107 | * @param s_baud_rate -baudrate 108 | * @param s_parity -parity 109 | * @param s_stop_bits -num stop bits 110 | * @param s_data_bits -data bits 111 | * 112 | * @return -success/failure 113 | */ 114 | signed char s_configure(unsigned long s_baud_rate, unsigned char s_parity, 115 | unsigned char s_stop_bits, unsigned char s_data_bits) 116 | { 117 | int ret; 118 | 119 | if (!fd) { 120 | S_ERROR("terminal is not open!\n"); 121 | return SERIAL_FAILED; 122 | } 123 | /* save current port settings */ 124 | ret = tcgetattr(fd, &oldtio); 125 | if (ret < 0) { 126 | S_ERROR("failed to set get old attribs\n"); 127 | return SERIAL_FAILED; 128 | } 129 | 130 | /* get current settings, and modify as needed */ 131 | ret = tcgetattr(fd, &newtio); 132 | if (ret < 0) { 133 | S_ERROR("failed to get current attribs\n"); 134 | return SERIAL_FAILED; 135 | } 136 | 137 | switch (s_baud_rate) { 138 | case 57600: 139 | s_baud_rate = B57600; 140 | break; 141 | case 115200: 142 | s_baud_rate = B115200; 143 | break; 144 | /* Add other baudrates - see /usr/include/bits/termios.h */ 145 | default: 146 | S_ERROR("Unknown baudrate %d\n", (unsigned int)s_baud_rate); 147 | return SERIAL_FAILED; 148 | } 149 | cfsetospeed(&newtio, s_baud_rate); 150 | cfsetispeed(&newtio, s_baud_rate); 151 | 152 | newtio.c_cflag &= ~(CS5 | CS6 | CS7 | CS8); 153 | switch (s_data_bits) { 154 | case 5: 155 | newtio.c_cflag |= CS5; 156 | break; 157 | case 6: 158 | newtio.c_cflag |= CS6; 159 | break; 160 | case 7: 161 | newtio.c_cflag |= CS7; 162 | break; 163 | case 8: 164 | newtio.c_cflag |= CS8; 165 | break; 166 | default: 167 | S_ERROR("unknown data bit %d\n", s_data_bits); 168 | return SERIAL_FAILED; 169 | } 170 | 171 | switch (s_stop_bits) { 172 | case ONE_STOP_BIT: 173 | newtio.c_cflag &= ~CSTOPB; 174 | break; 175 | case TWO_STOP_BIT: 176 | newtio.c_cflag |= CSTOPB; 177 | break; 178 | default: 179 | S_ERROR("unknown stop bit %d\n", s_stop_bits); 180 | return SERIAL_FAILED; 181 | } 182 | 183 | newtio.c_cflag &= ~(PARENB | PARODD); 184 | newtio.c_iflag &= ~(IGNPAR); 185 | switch (s_parity) { 186 | case ODDPARITY: /* odd */ 187 | newtio.c_cflag |= PARENB | PARODD; 188 | newtio.c_iflag |= IGNPAR; 189 | break; 190 | case EVENPARITY: /* even */ 191 | newtio.c_cflag |= PARENB; 192 | newtio.c_iflag = 0; 193 | break; 194 | case NOPARITY: /* none */ 195 | break; 196 | default: 197 | S_ERROR("unknown parity %d", s_parity); 198 | return SERIAL_FAILED; 199 | } 200 | 201 | newtio.c_iflag |= IGNBRK; 202 | newtio.c_cflag |= CLOCAL | CREAD; 203 | 204 | S_INFO("c_cflag: 0x%08x\n", (unsigned int)(newtio.c_cflag)); 205 | 206 | newtio.c_oflag = 0; 207 | /* set input mode (non-canonical, no echo,...) */ 208 | newtio.c_lflag = 0; 209 | newtio.c_cc[VTIME] = VTIME_SET; 210 | newtio.c_cc[VMIN] = 1; 211 | #ifdef VSWTC 212 | newtio.c_cc[VSWTC] = 0; 213 | #endif 214 | ret = tcflush(fd, TCIFLUSH); 215 | if (ret < 0) { 216 | S_ERROR("failed to set flush buffers\n"); 217 | return SERIAL_FAILED; 218 | } 219 | ret = tcsetattr(fd, TCSANOW, &newtio); 220 | if (ret < 0) { 221 | S_INFO("tcsetattr -> %s (%d) fd=%d", strerror(errno), ret, fd); 222 | S_ERROR("failed to set new attribs\n"); 223 | return SERIAL_FAILED; 224 | } 225 | S_INFO("Serial port %s configured fine\n", port); 226 | return SERIAL_OK; 227 | } 228 | 229 | /** 230 | * @brief Flush the serial port data 231 | * 232 | * @param rx_bytes return bytes that remains(TBD) 233 | * @param tx_bytes the bytes that are to be send(TBD) 234 | * 235 | * @return error/fail 236 | */ 237 | signed int s_flush(unsigned int *rx_bytes, unsigned int *tx_bytes) 238 | { 239 | int ret; 240 | if (!fd) { 241 | S_ERROR("terminal is not open!\n"); 242 | return SERIAL_FAILED; 243 | } 244 | ret = tcflush(fd, TCIFLUSH); 245 | if (ret < 0) { 246 | S_ERROR("failed to flush buffers2\n"); 247 | return SERIAL_FAILED; 248 | } 249 | S_INFO("Serial port %s flushed fine\n", port); 250 | 251 | return SERIAL_OK; 252 | } 253 | 254 | /** 255 | * @brief s_close - close the serial port 256 | * 257 | * @return sucess/fail 258 | */ 259 | signed char s_close(void) 260 | { 261 | int ret = 0; 262 | if (!fd) { 263 | S_ERROR("terminal is not open!\n"); 264 | return SERIAL_FAILED; 265 | } 266 | /* 267 | * To prevent switching modes before the last vestiges 268 | * of the data bits have been send, sleep a second. 269 | * This seems to be especially true for usb2serial 270 | * convertors.. it does look as if the data is buffered 271 | * at the usb2serial device itself and closing/changing 272 | * attribs before the final data is pushed is going to 273 | * kill the last bits which need to be send 274 | */ 275 | sleep(1); 276 | /* restore the old port settings */ 277 | ret = tcsetattr(fd, TCSANOW, &oldtio); 278 | if (ret < 0) { 279 | S_ERROR("failed to rest old settings\n"); 280 | return SERIAL_FAILED; 281 | } 282 | ret = tcflush(fd, TCIFLUSH); 283 | if (ret < 0) { 284 | S_ERROR("failed to flush serial file handle\n"); 285 | } 286 | ret = close(fd); 287 | fd = 0; 288 | if (ret < 0) { 289 | S_ERROR("failed to close serial file handle\n"); 290 | return SERIAL_FAILED; 291 | } 292 | S_INFO("Serial closed %s fine\n", port); 293 | return SERIAL_OK; 294 | } 295 | 296 | /** 297 | * @brief s_read - serial port read 298 | * 299 | * @param p_buffer buffer 300 | * @param size buffer length 301 | * 302 | * @return bytes read if ok, else SERIAL_FAILED 303 | */ 304 | signed int s_read(unsigned char *p_buffer, unsigned long size) 305 | { 306 | int ret = 0; 307 | if (!fd) { 308 | S_ERROR("terminal is not open!\n"); 309 | return SERIAL_FAILED; 310 | } 311 | /* read entire chunk.. no giving up! */ 312 | newtio.c_cc[VMIN] = size; 313 | newtio.c_cc[VTIME] = VTIME_SET; 314 | ret = tcsetattr(fd, TCSANOW, &newtio); 315 | ret = read(fd, p_buffer, size); 316 | if (ret < 0) { 317 | S_ERROR("failed to read data\n"); 318 | return SERIAL_FAILED; 319 | } 320 | 321 | S_INFO("Serial read requested=%lu, read=%d\n", size, ret); 322 | return ret; 323 | } 324 | 325 | /** 326 | * @brief s_write - write to serial port 327 | * 328 | * @param p_buffer - buffer pointer 329 | * @param size -size of buffer 330 | * 331 | * @return bytes wrote if ok, else SERIAL_FAILED 332 | */ 333 | signed int s_write(unsigned char *p_buffer, unsigned long size) 334 | { 335 | int ret = 0, ret1; 336 | if (!fd) { 337 | S_ERROR("terminal is not open!\n"); 338 | return SERIAL_FAILED; 339 | } 340 | ret = write(fd, p_buffer, size); 341 | if (ret < 0) { 342 | S_ERROR("failed to write data\n"); 343 | return SERIAL_FAILED; 344 | } 345 | /* Wait till it is emptied */ 346 | ret1 = tcdrain(fd); 347 | if (ret1 < 0) { 348 | S_ERROR("failed in datai drain\n"); 349 | perror(NULL); 350 | return ret1; 351 | } 352 | S_INFO("Serial wrote Requested=%ld wrote=%d\n", size, ret); 353 | return ret; 354 | } 355 | 356 | /** 357 | * @brief s_read_remaining - get the remaining bytes (TBD) 358 | * 359 | * @return error or num bytes remaining 360 | */ 361 | signed int s_read_remaining(void) 362 | { 363 | if (!fd) { 364 | S_ERROR("terminal is not open!\n"); 365 | return SERIAL_FAILED; 366 | } 367 | /* Not implemented yet */ 368 | return (0); 369 | } 370 | 371 | /** 372 | * @brief s_getc - get a character from serial port 373 | * 374 | * @return character read or error 375 | */ 376 | signed int s_getc(void) 377 | { 378 | unsigned char x = 0; 379 | int ret = 0; 380 | ret = s_read(&x, 1); 381 | if (ret < 0) { 382 | S_ERROR("getc failed-%d\n", ret); 383 | return ret; 384 | } 385 | S_INFO("[%c]%x", x, x); 386 | return x; 387 | } 388 | 389 | /** 390 | * @brief s_putc - put a character into serial port 391 | * 392 | * @param x - character to write 393 | * 394 | * @return character written or error 395 | */ 396 | signed int s_putc(char x) 397 | { 398 | int ret = 0; 399 | S_INFO("[%c] 0x%02x", x, (unsigned char)x); 400 | ret = s_write((unsigned char *)&x, 1); 401 | if (ret < 0) { 402 | S_ERROR("putc failed-%d\n", ret); 403 | return ret; 404 | } 405 | return x; 406 | } 407 | 408 | /** 409 | * @brief s_break - Send a break event 410 | * 411 | * @param sec_stay: how long to keep the break condition? 412 | * @param sec_post: how long to wait after break? 413 | * 414 | * @return success/failure 415 | */ 416 | signed int s_break(int sec_stay, int sec_post) 417 | { 418 | int ret = 0, ret1; 419 | 420 | if (!fd) { 421 | S_ERROR("terminal is not open!\n"); 422 | return SERIAL_FAILED; 423 | } 424 | 425 | ret = ioctl(fd, TIOCSBRK); 426 | if (ret < 0) 427 | return ret; 428 | if (sec_stay) 429 | sleep(sec_stay); 430 | ret = ioctl(fd,TIOCCBRK); 431 | if (ret < 0) 432 | return ret; 433 | if (sec_post) 434 | sleep(sec_post); 435 | } 436 | 437 | -------------------------------------------------------------------------------- /lib/serial_win32.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Win32 based serial port operations. 4 | * 5 | * FileName: lib/serial_win32.c 6 | * 7 | * I am heavily indebted to MSDN for guiding me on this. 8 | * http://msdn.microsoft.com/ 9 | * 10 | */ 11 | /* 12 | * (C) Copyright 2008 13 | * Texas Instruments, 14 | * Nishanth Menon 15 | * 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU General Public License as published by the 18 | * Free Software Foundation version 2. 19 | * 20 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 21 | * whether express or implied; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program; if not, write to the Free Software 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 28 | * MA 02111-1307 USA 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include "serial.h" 35 | #include 36 | 37 | /***** TYPES(WINDOWS SPECIFIC) *******/ 38 | #ifndef FALSE 39 | #define FALSE 0 40 | #endif 41 | #ifndef TRUE 42 | #define TRUE 1 43 | #endif 44 | #ifndef NULL 45 | #define NULL ((void *)0) 46 | #endif 47 | 48 | /************* CONSTS ***************/ 49 | #define S_ERROR(ARGS...) APP_ERROR(ARGS) 50 | #define S_INFO(ARGS...) 51 | #ifdef DEBUG 52 | #define S_INFO(ARGS...) fprintf(stdout,ARGS) 53 | #define S_DEBUG(FORMAT,ARGS...) printf ("%s[%d]:" FORMAT "\n",\ 54 | __FUNCTION__,__LINE__,ARGS) 55 | #else 56 | #define S_DEBUG(ARGS...) 57 | #endif 58 | 59 | #define BUF_SIZE (8096*2) 60 | #define RX_HW_BUF_SIZE BUF_SIZE 61 | #define TX_HW_BUF_SIZE BUF_SIZE 62 | #define R_EVENT_MASK EV_RXCHAR 63 | #define T_EVENT_MASK EV_TXEMPTY 64 | 65 | /************* VARS ***************/ 66 | static unsigned char port[30]; 67 | static HANDLE h_serial; 68 | static OVERLAPPED read_overlapped; 69 | static OVERLAPPED write_overlapped; 70 | 71 | /**************** HELPERS ****************/ 72 | static signed int reset_comm_error(unsigned int *rx_bytes, 73 | unsigned int *tx_bytes); 74 | 75 | /**************** EXPOSED FUNCTIONS ****************/ 76 | /** 77 | * @brief s_open - open a serial port 78 | * 79 | * @param t_port -port number 80 | * 81 | * @return success/fail 82 | */ 83 | signed char s_open(char *t_port) 84 | { 85 | char com_port[20] = "\\\\.\\"; 86 | S_DEBUG("%s", t_port); 87 | if (strlen(port) >= 30) { 88 | S_ERROR("too large portname %s\n", t_port); 89 | return SERIAL_FAILED; 90 | } 91 | strcat(com_port, t_port); 92 | 93 | h_serial = 94 | CreateFile(com_port, GENERIC_READ | GENERIC_WRITE, 0, NULL, 95 | OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); 96 | if (h_serial == INVALID_HANDLE_VALUE) { 97 | S_ERROR("Could not open port %s %s\n", port, com_port); 98 | return SERIAL_FAILED; 99 | } 100 | strcpy(port, t_port); 101 | 102 | memset(&read_overlapped, 0, sizeof(read_overlapped)); 103 | read_overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 104 | 105 | memset(&write_overlapped, 0, sizeof(write_overlapped)); 106 | write_overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 107 | 108 | S_INFO("port %s opened fine!\n", port); 109 | return SERIAL_OK; 110 | } 111 | 112 | /** 113 | * @brief s_configure - configure the serial port 114 | * 115 | * @param s_baud_rate -baudrate 116 | * @param s_parity -parity 117 | * @param s_stop_bits -num stop bits 118 | * @param s_data_bits -data bits 119 | * 120 | * @return -success/failure 121 | */ 122 | signed char s_configure(unsigned long s_baud_rate, unsigned char s_parity, 123 | unsigned char s_stop_bits, unsigned char s_data_bits) 124 | { 125 | COMSTAT com_stat; 126 | DWORD errors; 127 | COMMTIMEOUTS timeouts; 128 | DCB dcb = { 129 | 0 130 | }; 131 | dcb.DCBlength = sizeof(DCB); 132 | 133 | S_DEBUG("%d %d %d %d", (unsigned int)s_baud_rate, s_parity, s_stop_bits, 134 | s_data_bits); 135 | /* Get current configuration of serial port. */ 136 | if (!GetCommState(h_serial, &dcb)) { 137 | S_ERROR("Could not get state of port %s\n", port); 138 | return SERIAL_FAILED; 139 | } 140 | 141 | /* Setup new params 142 | * See http://msdn.microsoft.com/en-us/library/aa363214(VS.85).aspx 143 | */ 144 | dcb.BaudRate = s_baud_rate; 145 | dcb.fBinary = TRUE; 146 | dcb.fParity = (s_parity == NOPARITY) ? FALSE : TRUE; 147 | dcb.fOutxCtsFlow = FALSE; 148 | dcb.fOutxDsrFlow = FALSE; 149 | dcb.fDtrControl = DTR_CONTROL_DISABLE; 150 | dcb.fDsrSensitivity = FALSE; 151 | dcb.fTXContinueOnXoff = FALSE; 152 | dcb.fOutX = FALSE; 153 | dcb.fInX = FALSE; 154 | dcb.fErrorChar = FALSE; 155 | dcb.fNull = FALSE; 156 | dcb.fRtsControl = RTS_CONTROL_DISABLE; 157 | dcb.fAbortOnError = FALSE; 158 | dcb.Parity = s_parity; 159 | dcb.ByteSize = s_data_bits; 160 | dcb.StopBits = s_stop_bits; 161 | if (!SetCommState(h_serial, &dcb)) { 162 | S_ERROR 163 | ("Could not set state of port %s baudrate=%d " 164 | "s_parity=%d stop=%d s_data_bits=%d\n", port, 165 | (unsigned int)s_baud_rate, s_parity, s_stop_bits, 166 | s_data_bits); 167 | return SERIAL_FAILED; 168 | } 169 | if (!SetupComm(h_serial, RX_HW_BUF_SIZE, TX_HW_BUF_SIZE)) { 170 | S_ERROR("Buffer setup failed on port %s\n", port); 171 | return SERIAL_FAILED; 172 | } 173 | 174 | /* Setup Timeout */ 175 | timeouts.ReadIntervalTimeout = MAXDWORD; 176 | timeouts.ReadTotalTimeoutMultiplier = 0; 177 | timeouts.ReadTotalTimeoutConstant = 0; 178 | timeouts.WriteTotalTimeoutMultiplier = 0; 179 | timeouts.WriteTotalTimeoutConstant = 0; 180 | if (!SetCommTimeouts(h_serial, &timeouts)) { 181 | S_ERROR("Timeout setting failed\n"); 182 | return SERIAL_FAILED; 183 | } 184 | ClearCommError(h_serial, &errors, &com_stat); 185 | PurgeComm(h_serial, 186 | PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | 187 | PURGE_RXCLEAR); 188 | 189 | S_INFO("Configured fine\n"); 190 | return SERIAL_OK; 191 | } 192 | 193 | signed int s_flush(unsigned int *rx_bytes, unsigned int *tx_bytes) 194 | { 195 | COMSTAT com_stat; 196 | unsigned long errors; 197 | S_DEBUG("%p %p\n", rx_bytes, tx_bytes); 198 | ClearCommError(h_serial, &errors, &com_stat); 199 | CancelIo(h_serial); 200 | PurgeComm(h_serial, 201 | PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | 202 | PURGE_RXCLEAR); 203 | if (rx_bytes) 204 | *rx_bytes = com_stat.cbInQue; 205 | if (tx_bytes) 206 | *tx_bytes = com_stat.cbOutQue; 207 | return 0; 208 | } 209 | 210 | /** 211 | * @brief s_close - close the serial port 212 | * 213 | * @return sucess/fail 214 | */ 215 | signed char s_close(void) 216 | { 217 | unsigned long ret; 218 | 219 | S_DEBUG("%s ", "enter"); 220 | if (h_serial != INVALID_HANDLE_VALUE) { 221 | SetCommMask(h_serial, R_EVENT_MASK | T_EVENT_MASK); 222 | CancelIo(h_serial); 223 | PurgeComm(h_serial, 224 | PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | 225 | PURGE_RXCLEAR); 226 | ret = CloseHandle(h_serial); 227 | if (ret == 0) { 228 | S_ERROR("Opps.. failed to close port %s\n", port); 229 | } 230 | h_serial = INVALID_HANDLE_VALUE; 231 | } 232 | if (read_overlapped.hEvent != NULL) 233 | CloseHandle(read_overlapped.hEvent); 234 | if (write_overlapped.hEvent != NULL) 235 | CloseHandle(write_overlapped.hEvent); 236 | S_INFO("Closed fine\n"); 237 | return SERIAL_OK; 238 | } 239 | 240 | /** 241 | * @brief s_read - serial port read 242 | * 243 | * @param p_buffer buffer 244 | * @param size buffer length 245 | * 246 | * @return success/fail 247 | */ 248 | signed int s_read(unsigned char *p_buffer, unsigned long size) 249 | { 250 | signed int ret = 0; 251 | signed int err = 0; 252 | unsigned long size_to_read = size; 253 | unsigned long tot_read = 0; 254 | /*unsigned long event_mask = R_EVENT_MASK; */ 255 | S_DEBUG("%p:%d", p_buffer, (unsigned int)size); 256 | 257 | if (h_serial == INVALID_HANDLE_VALUE) { 258 | S_ERROR("Not opened\n"); 259 | return SERIAL_FAILED; 260 | } 261 | if (size == 0) { 262 | S_INFO("0 byte read..ok\n"); 263 | return SERIAL_OK; 264 | } 265 | if (size >= RX_HW_BUF_SIZE) { 266 | S_ERROR("More than read buffer\n"); 267 | return SERIAL_FAILED; 268 | } 269 | /* Read mask is set already in transmit */ 270 | do { 271 | ret = ReadFile(h_serial, p_buffer, size_to_read, &size, 272 | &read_overlapped); 273 | if (size) { 274 | S_INFO("read %d bytes\n", size); 275 | size_to_read -= size; 276 | p_buffer += size; 277 | tot_read += size; 278 | } 279 | } while (size_to_read > 0); 280 | ret = tot_read; 281 | S_INFO("size = %d\n", (unsigned int)size); 282 | if (!size && (GetLastError() == ERROR_IO_PENDING)) { 283 | err = GetLastError(); 284 | S_ERROR("Read[%s]: Readfile error: %i\n", port, err); 285 | reset_comm_error(NULL, NULL); 286 | PurgeComm(h_serial, 287 | PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | 288 | PURGE_RXCLEAR); 289 | } 290 | 291 | S_INFO("**** Read[%s]Rem: %d Got: %d, Timeout:%d\n", port, 292 | (unsigned int)size_to_read, ret, timeout); 293 | S_DEBUG("%d", ret); 294 | return ret; 295 | } 296 | 297 | /** 298 | * @brief s_write - write to serial port 299 | * 300 | * @param p_buffer - buffer pointer 301 | * @param size -size of buffer 302 | * 303 | * @return success/failure 304 | */ 305 | signed int s_write(unsigned char *p_buffer, unsigned long size) 306 | { 307 | signed int ret = 0; 308 | signed int err = 0; 309 | unsigned long sizeToWrite = size; 310 | unsigned long tot_write = 0; 311 | unsigned long event_mask = T_EVENT_MASK; 312 | 313 | S_DEBUG("%p %d", p_buffer, (unsigned int)size); 314 | if (h_serial == INVALID_HANDLE_VALUE) { 315 | S_ERROR("Not opened\n"); 316 | return SERIAL_FAILED; 317 | } 318 | if (size == 0) { 319 | S_INFO("0 byte write..ok\n"); 320 | return SERIAL_OK; 321 | } 322 | if (size >= TX_HW_BUF_SIZE) { 323 | S_ERROR("More than normal buffer size\n"); 324 | return SERIAL_FAILED; 325 | } 326 | 327 | ResetEvent(write_overlapped.hEvent); 328 | 329 | SetCommMask(h_serial, T_EVENT_MASK); 330 | WaitCommEvent(h_serial, &event_mask, &write_overlapped); 331 | do { 332 | ret = WriteFile(h_serial, p_buffer, sizeToWrite, &size, 333 | &write_overlapped); 334 | if (!ret) 335 | WaitForSingleObject(write_overlapped.hEvent, INFINITE); 336 | S_INFO("write %d bytes\n", size); 337 | size = sizeToWrite; 338 | 339 | sizeToWrite -= size; 340 | p_buffer += size; 341 | tot_write += size; 342 | } while (sizeToWrite > 0); 343 | ret = tot_write; 344 | 345 | if (!size && (GetLastError() == ERROR_IO_PENDING)) { 346 | err = GetLastError(); 347 | S_ERROR("Write[%s]: Writefile error: %i\n", port, err); 348 | reset_comm_error(NULL, NULL); 349 | PurgeComm(h_serial, 350 | PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | 351 | PURGE_RXCLEAR); 352 | } 353 | SetCommMask(h_serial, R_EVENT_MASK); 354 | 355 | S_INFO("**** Write[%s]Rem: %d Got: %d, Timeout:%d\n", port, 356 | (unsigned int)sizeToWrite, ret, timeout); 357 | S_DEBUG("%d", ret); 358 | return ret; 359 | } 360 | 361 | /** 362 | * @brief s_read_remaining - read remaining bytes 363 | * 364 | * @return num bytes remaining OR error. 365 | */ 366 | signed int s_read_remaining(void) 367 | { 368 | unsigned int rx_bytes; 369 | unsigned int tx_bytes; 370 | signed int ret = 0; 371 | S_DEBUG("%s", "enter"); 372 | ret = reset_comm_error(&rx_bytes, &tx_bytes); 373 | S_DEBUG("%d %d", ret, rx_bytes); 374 | return (ret < 0) ? ret : rx_bytes; 375 | } 376 | 377 | /** 378 | * @brief s_getc - get a single character 379 | * 380 | * @return character read or error 381 | */ 382 | signed int s_getc(void) 383 | { 384 | char x = 0; 385 | int ret = 0; 386 | ret = s_read(&x, 1); 387 | if (ret < 0) { 388 | S_ERROR("getc failed-%d\n", ret); 389 | return ret; 390 | } 391 | S_DEBUG("[%c]%x", x, x); 392 | return x; 393 | } 394 | 395 | /** 396 | * @brief s_putc put a single character 397 | * 398 | * @param x -character to write to serial port 399 | * 400 | * @return -written character or error 401 | */ 402 | signed int s_putc(char x) 403 | { 404 | int ret = 0; 405 | S_DEBUG("[%c] 0x%02x", x, (unsigned char)x); 406 | ret = s_write(&x, 1); 407 | if (ret < 0) { 408 | S_ERROR("putc failed-%d\n", ret); 409 | return ret; 410 | } 411 | return x; 412 | } 413 | 414 | /** 415 | * @brief s_break - Send a break event 416 | * 417 | * @param sec_stay: how long to keep the break condition? 418 | * @param sec_post: how long to wait after break? 419 | * 420 | * @return success/failure 421 | */ 422 | signed int s_break(int sec_stay, int sec_post) 423 | { 424 | return SERIAL_FAILED; 425 | } 426 | 427 | /**************** HELPERS ****************/ 428 | 429 | /** 430 | * @brief reset_comm_error - Reset comport errors 431 | * 432 | * @param rx_bytes - read the bytes left 433 | * @param tx_bytes - read the bytes left 434 | * 435 | * @return success/failure 436 | */ 437 | static signed int reset_comm_error(unsigned int *rx_bytes, 438 | unsigned int *tx_bytes) 439 | { 440 | char errStr[20] = { 0 }; 441 | COMSTAT com_stat; 442 | unsigned long errors; 443 | ClearCommError(h_serial, &errors, &com_stat); 444 | /* If we see errors, then print the same */ 445 | if (errors & CE_DNS) 446 | strcat(errStr, "DNS "); 447 | if (errors & CE_IOE) 448 | strcat(errStr, "IOE "); 449 | if (errors & CE_OOP) 450 | strcat(errStr, "OOP "); 451 | if (errors & CE_PTO) 452 | strcat(errStr, "PTO "); 453 | if (errors & CE_MODE) 454 | strcat(errStr, "MODE "); 455 | if (errors & CE_BREAK) 456 | strcat(errStr, "BREAK "); 457 | if (errors & CE_FRAME) 458 | strcat(errStr, "FRAME "); 459 | if (errors & CE_RXOVER) 460 | strcat(errStr, "RXOVER "); 461 | if (errors & CE_TXFULL) 462 | strcat(errStr, "TXFULL "); 463 | if (errors & CE_OVERRUN) 464 | strcat(errStr, "OVERRUN "); 465 | if (errors & CE_RXPARITY) 466 | strcat(errStr, "RXPARITY "); 467 | S_ERROR 468 | ("Reset:Port[%s] error = 0x%X errorstring = %s " 469 | "RX_PEND=%d TX_PEND=%d.\n", 470 | port, (unsigned int)errors, errStr, 471 | (unsigned int)com_stat.cbInQue, (unsigned int)com_stat.cbOutQue); 472 | if (rx_bytes) 473 | *rx_bytes = com_stat.cbInQue; 474 | if (tx_bytes) 475 | *tx_bytes = com_stat.cbOutQue; 476 | return errors; 477 | } 478 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Make file for compiling host app 3 | # 4 | # (C) Copyright 2008-2010 5 | # Texas Instruments, 6 | # Nishanth Menon 7 | # 8 | # This program is free software; you can redistribute it and/or modify it 9 | # under the terms of the GNU General Public License as published by the 10 | # Free Software Foundation version 2. 11 | # 12 | # This program is distributed .as is. WITHOUT ANY WARRANTY of any kind, 13 | # whether express or implied; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program; if not, write to the Free Software 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, 20 | # MA 02111-1307 USA 21 | 22 | HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \ 23 | sed -e "s/\(cygwin\).*/cygwin/") 24 | srctree := $(if $(SRC),$(SRC),$(CURDIR)) 25 | 26 | ifeq ($(HOSTOS),windowsnt) 27 | WINDOWS=1 28 | endif 29 | 30 | ifeq ($(HOSTOS),windows32) 31 | WINDOWS=1 32 | endif 33 | 34 | # Windows Specific handling 35 | ifdef WINDOWS 36 | EXE_PREFIX=.exe 37 | #Installation System specific 38 | ifndef COMPILER_PREFIX 39 | COMPILER_PREFIX=C:\\MinGW\\bin\\ 40 | endif 41 | ifndef APP_PREFIX 42 | APP_PREFIX=C:\\GnuWin32\\bin\\ 43 | endif 44 | endif #windows 45 | 46 | # Selective Library 47 | ifdef WINDOWS 48 | LIB_FILES=lib/serial_win32.c lib/file_win32.c 49 | else 50 | LIB_FILES=lib/serial_posix.c lib/file_posix.c 51 | endif 52 | LIB_FILES+=lib/f_status.c lib/lcfg/lcfg_static.c 53 | 54 | #App source code 55 | PSERIAL_FILES=src/pserial.c 56 | SYSRQ_FILES=src/sysrq.c 57 | KERMIT_FILES=src/ukermit.c 58 | UCMD_FILES=src/ucmd.c 59 | PUSB_FILES=src/pusb.c 60 | GPSIGN_FILES=src/gpsign.c 61 | TAGGER_FILES=src/tagger.c 62 | 63 | # Add all SOC/platform specific sty files here 64 | STY_FILES=src/asm/sty-omap3.S 65 | 66 | DOCS=docs/html docs/latex 67 | 68 | # Final output files 69 | PSERIAL_EXE=pserial$(EXE_PREFIX) 70 | SYSRQ_EXE=sysrq$(EXE_PREFIX) 71 | KERMIT_EXE=ukermit$(EXE_PREFIX) 72 | UCMD_EXE=ucmd$(EXE_PREFIX) 73 | PUSB_EXE=pusb$(EXE_PREFIX) 74 | GPSIGN_EXE=gpsign$(EXE_PREFIX) 75 | TAGGER_EXE=tagger$(EXE_PREFIX) 76 | 77 | # Object Files 78 | PSERIAL_OBJ=$(PSERIAL_FILES:.c=.o) 79 | SYSRQ_OBJ=$(SYSRQ_FILES:.c=.o) 80 | KERMIT_OBJ=$(KERMIT_FILES:.c=.o) 81 | UCMD_OBJ=$(UCMD_FILES:.c=.o) 82 | PUSB_OBJ=$(PUSB_FILES:.c=.o) 83 | GPSIGN_OBJ=$(GPSIGN_FILES:.c=.o) 84 | TAGGER_OBJ=$(TAGGER_FILES:.c=.o) 85 | 86 | LIB_OBJ=$(LIB_FILES:.c=.o) 87 | STY_OBJS=$(STY_FILES:.S=.ao) 88 | STY_BINS=$(STY_FILES:.S=.bin) 89 | 90 | CLEANUPFILES=$(PSERIAL_OBJ) $(LIB_OBJ) $(PSERIAL_EXE) $(GWART_OBJ)\ 91 | $(KERMIT_EXE) $(KERMIT_OBJ) $(UCMD_OBJ) $(UCMD_EXE)\ 92 | $(PUSB_EXE) $(PUSB_OBJ) $(GPSIGN_EXE) $(GPSIGN_OBJ)\ 93 | $(TAGGER_EXE) $(TAGGER_OBJ) $(STY_OBJS) $(SYSRQ_OBJ) 94 | 95 | CC=$(COMPILER_PREFIX)gcc 96 | LD=$(COMPILER_PREFIX)gcc 97 | RM=$(APP_PREFIX)rm$(EXE_PREFIX) 98 | ECHO=$(APP_PREFIX)echo$(EXE_PREFIX) 99 | DOXYGEN=$(APP_PREFIX)doxygen$(EXE_PREFIX) 100 | 101 | CFLAGS=-Wall -O3 -Iinclude -Ilib/lcfg 102 | LDFLAGS= 103 | 104 | CFLAGS+=-fdata-sections -ffunction-sections 105 | ifeq ($(HOSTOS),darwin) 106 | LDFLAGS+=-Wl,-dead_strip 107 | else 108 | LDFLAGS+=-Wl,--gc-sections -Wl,--print-gc-sections -Wl,--no-print-gc-sections 109 | endif 110 | # should usually produce -lusb-1.0 111 | LDFLAGS_USB=`pkg-config libusb-1.0 --libs` 112 | 113 | CROSS_CC ?=$(CROSS_COMPILE)gcc 114 | CROSS_OBJDUMP ?=$(CROSS_COMPILE)objdump 115 | CROSS_OBJCOPY ?=$(CROSS_COMPILE)objcopy 116 | 117 | ifdef DISABLE_COLOR 118 | CFLAGS+=-DDISABLE_COLOR 119 | endif 120 | 121 | ifdef V 122 | VERBOSE = $(V) 123 | endif 124 | ifndef VERBOSE 125 | VERBOSE = 0 126 | endif 127 | 128 | %.ao: %.S 129 | @$(ECHO) "Cross Compiling: " $< 130 | $(if $(VERBOSE:1=),@)$(CROSS_CC) $(CFLAGS) -o $@ -c $< 131 | 132 | %.bin: %.ao %.S 133 | @$(ECHO) "Generating Crossbin: " $< 134 | $(if $(VERBOSE:1=),@)$(CROSS_OBJCOPY) -O binary $< $@ 135 | 136 | %.o: %.c 137 | @$(ECHO) "Compiling: " $< 138 | $(if $(VERBOSE:1=),@)$(CC) $(CFLAGS) -o $@ -c $< 139 | 140 | .PHONY : all 141 | 142 | all: $(PSERIAL_EXE) $(KERMIT_EXE) $(UCMD_EXE) $(GPSIGN_EXE) $(TAGGER_EXE) $(SYSRQ_EXE) 143 | 144 | usb: $(PUSB_EXE) 145 | 146 | sty: $(STY_BINS) 147 | @$(ECHO) "Completed all sty files" 148 | 149 | $(SYSRQ_EXE): $(SYSRQ_OBJ) $(LIB_OBJ) makefile 150 | @$(ECHO) "Generating: $@" 151 | $(if $(VERBOSE:1=),@)$(LD) $(SYSRQ_OBJ) $(LIB_OBJ) $(LDFLAGS) -o $@ 152 | @$(ECHO) 153 | 154 | $(PSERIAL_EXE): $(PSERIAL_OBJ) $(LIB_OBJ) makefile 155 | @$(ECHO) "Generating: $@" 156 | $(if $(VERBOSE:1=),@)$(LD) $(PSERIAL_OBJ) $(LIB_OBJ) $(LDFLAGS) -o $@ 157 | @$(ECHO) 158 | 159 | $(KERMIT_EXE): $(KERMIT_OBJ) $(LIB_OBJ) makefile 160 | @$(ECHO) "Generating: $@" 161 | $(if $(VERBOSE:1=),@)$(LD) $(KERMIT_OBJ) $(LIB_OBJ) $(LDFLAGS) -o $@ 162 | @$(ECHO) 163 | 164 | $(UCMD_EXE): $(UCMD_OBJ) $(LIB_OBJ) makefile 165 | @$(ECHO) "Generating: $@" 166 | $(if $(VERBOSE:1=),@)$(LD) $(UCMD_OBJ) $(LIB_OBJ) $(LDFLAGS) -o $@ 167 | @$(ECHO) 168 | 169 | $(GPSIGN_EXE): $(GPSIGN_OBJ) $(LIB_OBJ) makefile 170 | @$(ECHO) "Generating: $@" 171 | $(if $(VERBOSE:1=),@)$(LD) $(GPSIGN_OBJ) $(LIB_OBJ) $(LDFLAGS) -o $@ 172 | @$(ECHO) 173 | 174 | $(TAGGER_EXE): $(TAGGER_OBJ) $(LIB_OBJ) makefile 175 | @$(ECHO) "Generating: $@" 176 | $(if $(VERBOSE:1=),@)$(LD) $(TAGGER_OBJ) $(LIB_OBJ) $(LDFLAGS) -o $@ 177 | @$(ECHO) 178 | 179 | $(PUSB_EXE): $(PUSB_OBJ) $(LIB_OBJ) makefile 180 | @$(ECHO) "Generating: $@" 181 | $(if $(VERBOSE:1=),@)$(LD) $(PUSB_OBJ) $(LIB_OBJ) $(LDFLAGS) $(LDFLAGS_USB) -o $@ 182 | @$(ECHO) 183 | 184 | $(PUSB_OBJ): $(PUSB_FILES) 185 | @$(ECHO) "Compiling: " $< 186 | $(if $(VERBOSE:1=),@)$(CC) $(CFLAGS) `pkg-config libusb-1.0 --cflags` -o $@ -c $< 187 | 188 | 189 | .PHONY : docs 190 | docs: 191 | @$(ECHO) "Generating Documentation:" 192 | $(if $(VERBOSE:1=),@)-$(DOXYGEN) docs/doxyfile 193 | $(if $(VERBOSE:1=),@)-$(MAKE) -C docs/latex 194 | .PHONY : clean 195 | clean: 196 | @$(ECHO) "Cleaning:" 197 | $(if $(VERBOSE:1=),@)-$(RM) -$(if $(VERBOSE:1=),,v)f $(CLEANUPFILES) core 198 | 199 | .PHONY : distclean 200 | distclean: 201 | @$(ECHO) "Dist cleaning:" 202 | $(if $(VERBOSE:1=),@)-$(RM) -$(if $(VERBOSE:1=),,v)f $(CLEANUPFILES) 203 | $(if $(VERBOSE:1=),@)-$(RM) -r$(if $(VERBOSE:1=),,v)f $(DOCS) 204 | ifndef WINDOWS 205 | $(if $(VERBOSE:1=),@)find $(srctree) $(RCS_FIND_IGNORE) \ 206 | \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 207 | -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ 208 | -o -name '.*.rej' -o -size 0 -o -name "*.ao"\ 209 | -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \ 210 | -type f -print | xargs rm -$(if $(VERBOSE:1=),,v)f 211 | endif 212 | 213 | -------------------------------------------------------------------------------- /src/asm/sty-omap3.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Sty utility 4 | * 5 | * FileName: src/asm/sty-omap3.S 6 | * 7 | * sty is a small setup header for disabling watchdog, 8 | * setting up atag and starting off zImage 9 | * it sets up two magic numbers for the final app to fill 10 | * up 11 | */ 12 | /* 13 | * (C) Copyright 2010 14 | * Texas Instruments, 15 | * Nishanth Menon 16 | * 17 | * This program is free software; you can redistribute it and/or modify it 18 | * under the terms of the GNU General Public License as published by the 19 | * Free Software Foundation version 2. 20 | * 21 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 22 | * whether express or implied; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | * General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 29 | * MA 02111-1307 USA 30 | */ 31 | #include "tagger.h" 32 | 33 | /* This is where ATAG and related info will finally reside. Risky? */ 34 | #define INTERIM_DATA_ADDRESS 0x80000100 35 | 36 | /* OMAP3 Watchdog timer base and registers */ 37 | #define WDT_BASE 0x48314000 38 | #define WSPR 0x48 39 | #define WWPS 0x34 40 | 41 | #define CONTROL_PADCONF_UARTx_RX_VAL 0x00 42 | #define CONTROL_PADCONF_UARTx_TX_VAL 0x00 43 | #define CONTROL_PADCONF_MASK 0xFF 44 | 45 | #define UART_MODE 0x00 46 | /* Soft reset values */ 47 | #define LCR_VAL_EFR_SOFT_RESET 0xBF 48 | #define EFR_VAL_SOFT_RESET 0x10 49 | #define LCR_VAL_IER_MCR_SOFT_RESET 0x80 50 | #define IER_VAL_SOFT_RESET 0x00 51 | #define MCR_VAL_SOFT_RESET 0x00 52 | #define LCR_VAL_BREAKS_REMOVED 0x40 53 | #define RESET_MODE_VAL 0x07 54 | 55 | /* FIFO config values */ 56 | #define MCR_VAL_FIFO_CONFIG 0x40 57 | #define TLR_VAL_FIFO_CONFIG 0x00 58 | #define FCR_VAL_FIFO_CONFIG 0x05 59 | 60 | /* Baudrate, data and stop config */ 61 | #define LCR_VAL_DLL_ACCESS 0x80 62 | #define DATA_BITS 0x03 /* 8 data bits */ 63 | #define PARITY_BITS 0x00 /* None */ 64 | #define STOP_BITS 0x00 /* 1 stop bit */ 65 | #define DLL_VAL_BAUD 0x1A /* Value for baudrate of 115200 */ 66 | #define DHL_VAL_BAUD 0x00 67 | 68 | #define UART_REG_RHR 0x00 69 | #define UART_REG_THR 0x00 70 | #define UART_REG_DLL 0x00 71 | #define UART_REG_DLH 0x04 72 | #define UART_REG_IER 0x04 73 | #define UART_REG_EFR 0x08 74 | #define UART_REG_IIR 0x08 75 | #define UART_REG_FCR 0x08 76 | #define UART_REG_LCR 0x0C 77 | #define UART_REG_MCR 0x10 78 | #define UART_REG_XON1 0x10 79 | #define UART_REG_XON2 0x14 80 | #define UART_REG_LSR 0x14 81 | #define UART_REG_MSR 0x18 82 | #define UART_REG_TCR 0x18 83 | #define UART_REG_XOFF1 0x18 84 | #define UART_REG_SPR 0x1C 85 | #define UART_REG_TLR 0x1C 86 | #define UART_REG_XOFF2 0x1C 87 | #define UART_REG_MDR1 0x20 88 | #define UART_REG_MDR2 0x24 89 | #define UART_REG_SFLSR 0x28 90 | #define UART_REG_TXFLL 0x28 91 | #define UART_REG_TXFLH 0x2C 92 | #define UART_REG_RESUME 0x2C 93 | #define UART_REG_SFREGL 0x30 94 | #define UART_REG_RXFLL 0x30 95 | #define UART_REG_SFREGH 0x34 96 | #define UART_REG_RXFLH 0x34 97 | #define UART_REG_BLR 0x38 98 | #define UART_REG_ACREG 0x3C 99 | #define UART_DIV_1_6 0x3C 100 | #define UART_REG_SCR 0x40 101 | #define UART_REG_SSR 0x44 102 | #define UART_REG_EBLR 0x48 103 | 104 | sty_start: 105 | /* 106 | * set the cpu to SVC32 mode 107 | */ 108 | mrs r0, cpsr 109 | bic r0, r0, #0x1f 110 | orr r0, r0, #0xd3 111 | msr cpsr, r0 112 | 113 | /* Do some initial cleanups */ 114 | /* Disable watch dog timer */ 115 | ldr r0, WD_BASE 116 | ldr r1, WD_AAAA 117 | str r1, [r0, #WSPR] 118 | nop 119 | 120 | wdl1: 121 | ldr r2, [r0, #WWPS] 122 | cmp r2, #0 123 | bne wdl1 124 | 125 | ldr r1, WD_5555 126 | str r1, [r0, #WSPR] 127 | nop 128 | 129 | wdl2: 130 | ldr r2, [r0, #WWPS] 131 | cmp r2, #0 132 | bne wdl2 133 | /* 134 | * Invalidate L1 I/D 135 | */ 136 | mov r0, #0 /* set up for MCR */ 137 | mcr p15, 0, r0, c8, c7, 0 /* invalidate TLBs */ 138 | mcr p15, 0, r0, c7, c5, 1 /* invalidate icache */ 139 | 140 | /* Invalide L2 cache (gp device call point) 141 | * - warning, this may have issues on EMU/HS devices 142 | * this call can corrupt r0-r5 143 | */ 144 | mov r12, #0x1 /* set up to invalide L2 */ 145 | smi: .word 0xE1600070 /* Call SMI monitor */ 146 | 147 | /* 148 | * disable MMU stuff and caches 149 | */ 150 | mrc p15, 0, r0, c1, c0, 0 151 | bic r0, r0, #0x00002000 /* clear bits 13 (--V-) */ 152 | bic r0, r0, #0x00000007 /* clear bits 2:0 (-CAM) */ 153 | orr r0, r0, #0x00000002 /* set bit 1 (--A-) Align */ 154 | mcr p15, 0, r0, c1, c0, 0 155 | 156 | /* disable irq and fiq */ 157 | mov r0, #0xC0 158 | mrs r3, cpsr 159 | orr r2, r3, r0 160 | msr cpsr_c, r2 161 | 162 | 163 | /* 164 | * UART Configuration 165 | * XXX: Ideally, this should be handled by kernel, Not here!!! 166 | */ 167 | 168 | /* Enable the function clock for UART1 and UART2 */ 169 | ldr r0, CM_FCLKEN1_CORE 170 | ldr r1, [r0] 171 | ldr r2, CM_FCLKEN1_CORE_VAL 172 | orr r1, r1, r2 173 | str r1, [r0] 174 | ldr r0, CM_ICLKEN1_CORE 175 | ldr r1, [r0] 176 | ldr r2, CM_FCLKEN1_CORE_VAL 177 | orr r1, r1, r2 178 | str r1, [r0] 179 | 180 | /* Enable uart 3 */ 181 | ldr r0, CM_FCLKEN_PER 182 | ldr r1, [r0] 183 | ldr r2, CM_FCLKEN_PER_VAL 184 | orr r1, r1, r2 185 | str r1, [r0] 186 | ldr r0, CM_ICLKEN_PER 187 | ldr r1, [r0] 188 | orr r1, r1, r2 189 | str r1, [r0] 190 | 191 | /* MUX setup for UART Module */ 192 | ldr r0, CONTROL_PADCONF_UARTx_RX 193 | ldrb r1, [r0] 194 | bic r1, r1, #CONTROL_PADCONF_MASK 195 | mov r2, #CONTROL_PADCONF_UARTx_RX_VAL 196 | orr r1, r1,r2 197 | strb r1, [r0] 198 | 199 | ldr r0, CONTROL_PADCONF_UARTx_TX 200 | ldrb r1, [r0] 201 | bic r1, r1, #CONTROL_PADCONF_MASK 202 | mov r2, #CONTROL_PADCONF_UARTx_TX_VAL 203 | orr r1, r1,r2 204 | strb r1, [r0] 205 | 206 | /* UART config - 1 and 3 - hoping all boards live */ 207 | ldr r2, UART1_REG_BASE_ADDR 208 | bl uart_config 209 | ldr r2, UART3_REG_BASE_ADDR 210 | bl uart_config 211 | 212 | /* Finish off the rest of the configuration */ 213 | b start_linux 214 | 215 | uart_config: 216 | /* Saving the LR value for return purpose */ 217 | mov r0, lr 218 | /* UART soft reset */ 219 | mov r3, #LCR_VAL_EFR_SOFT_RESET 220 | /* To access the EFR, writing the cmd to LCR */ 221 | strb r3, [r2, #UART_REG_LCR] 222 | mov r3, #EFR_VAL_SOFT_RESET 223 | strb r3, [r2, #UART_REG_EFR] 224 | /* Load the contents of LCR into R4 */ 225 | ldrb r4, [r2, #UART_REG_LCR] 226 | bic r4, r4, #LCR_VAL_IER_MCR_SOFT_RESET 227 | strb r4, [r2, #UART_REG_LCR] 228 | mov r3, #IER_VAL_SOFT_RESET 229 | /* Disable the interrupts */ 230 | strb r3, [r2, #UART_REG_IER] 231 | 232 | mov r3, #MCR_VAL_SOFT_RESET 233 | /* Set force control signals inactive */ 234 | strb r3, [r2, #UART_REG_MCR] 235 | /* Getting the data from UART LCR register */ 236 | ldrb r4, [r2, #UART_REG_LCR] 237 | bic r4, r4, #LCR_VAL_BREAKS_REMOVED 238 | strb r4, [r2, #UART_REG_LCR] 239 | 240 | mov r3, #RESET_MODE_VAL 241 | /* Resetting the UART(by MDR1[2:0]=7) */ 242 | strb r3, [r2, #UART_REG_MDR1] 243 | 244 | /* UART FIFO config */ 245 | ldrb r3, [r2, #UART_REG_MCR] 246 | orr r3, r3, #MCR_VAL_FIFO_CONFIG 247 | strb r3, [r2, #UART_REG_MCR] 248 | 249 | mov r3, #TLR_VAL_FIFO_CONFIG 250 | strb r3, [r2, #UART_REG_TLR] 251 | 252 | mov r3, #FCR_VAL_FIFO_CONFIG 253 | strb r3, [r2, #UART_REG_FCR] 254 | 255 | /* Baud rate, data, stop config */ 256 | /* Enable the DLL & DLH access*/ 257 | mov r3, #LCR_VAL_DLL_ACCESS 258 | orr r3, r3, #DATA_BITS 259 | orr r3, r3, #PARITY_BITS 260 | orr r3, r3, #STOP_BITS 261 | strb r3, [r2, #UART_REG_LCR] 262 | 263 | mov r3, #DLL_VAL_BAUD 264 | strb r3, [r2, #UART_REG_DLL] 265 | mov r3, #DHL_VAL_BAUD 266 | strb r3, [r2, #UART_REG_DLH] 267 | 268 | ldrb r4, [r2, #UART_REG_LCR] 269 | /* Disable the DLL & DLH access*/ 270 | bic r4, r4, #LCR_VAL_DLL_ACCESS 271 | strb r4, [r2, #UART_REG_LCR] 272 | 273 | /* Set the UART MODE */ 274 | mov r3, #UART_MODE 275 | /* Enable uart with 16x baudrate mode */ 276 | strb r3, [r2, #UART_REG_MDR1] 277 | /* return */ 278 | mov pc, r0 279 | 280 | CM_FCLKEN1_CORE: .word 0x48004A00 281 | CM_FCLKEN1_CORE_VAL: .word 0x00006000 282 | CM_ICLKEN1_CORE: .word 0x48004A10 283 | CM_FCLKEN_PER: .word 0x48005000 284 | CM_ICLKEN_PER: .word 0x48005010 285 | CM_FCLKEN_PER_VAL: .word 0x00000800 286 | /* UART specific baseaddress */ 287 | UART3_REG_BASE_ADDR: .word 0x49020000 288 | UART1_REG_BASE_ADDR: .word 0x4806A000 289 | 290 | /* UART1 */ 291 | CONTROL_PADCONF_UARTx_RX: .word 0x48002182 292 | CONTROL_PADCONF_UARTx_TX: .word 0x4800217c 293 | 294 | /*********** end me config ****/ 295 | start_linux: 296 | /* atag is recommended in first 16Kb of memory- so relocate */ 297 | adr r0, sty_end 298 | ldr r1, interim_data_size 299 | ldr r3, interim_data_store 300 | add r0, r0, #4 301 | add r1, r1, #8 302 | copy_loop: 303 | ldr r4, [r0] 304 | str r4, [r3] 305 | sub r1, r1, #4 306 | add r0, r0, #4 307 | add r3, r3, #4 308 | cmp r1, #8 309 | bgt copy_loop 310 | 311 | 312 | /* 313 | * Ref: http://www.arm.linux.org.uk/developer/booting.php 314 | * before we jump to zImage, set 315 | * r0 = 0. 316 | * r1 = machine type number discovered in (3) above. 317 | * r2 = physical address of tagged list in system RAM. 318 | */ 319 | ldr r1, mach_id 320 | /* 321 | * image is organized as follows: 322 | * sty- this code 323 | * atag 324 | * (optional)device tree data and other future stuff we want added 325 | * zImage 326 | * 327 | * interim_data_size =atag_size + additiona data like device_tree 328 | * zImage location(or jump to location) = sty_end + interim_data_size 329 | * atag data_location = sty_end + 4 330 | */ 331 | adr r4, sty_end 332 | ldr r5, interim_data_size 333 | 334 | /* r3 stores the zImage address to jump to when we are ready */ 335 | add r3, r4, r5 336 | add r3, r3, #4 337 | 338 | /* atag is packed right behind this, so add a word */ 339 | ldr r2, interim_data_store 340 | 341 | /* set r0 to 0 */ 342 | mov r0, #0 343 | 344 | /* 345 | * we are all set.. now jump and start praying ;) 346 | * NOTE: we dont disable watchdog etc yet.. mebbe we should be doing 347 | * it.. but if the kernel does not bootup, it is better that the 348 | * watchdog kill us.. 349 | */ 350 | bx r3 351 | 352 | interim_data_store: .word INTERIM_DATA_ADDRESS 353 | WD_BASE: .word WDT_BASE 354 | WD_AAAA: .word 0xAAAA 355 | WD_5555: .word 0x5555 356 | 357 | mach_id: .word MAGIC_MACHID 358 | interim_data_size: .word MAGIC_INTERIMSIZE 359 | sty_end: .word 0x0 360 | -------------------------------------------------------------------------------- /src/asm/sty-omap3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nmenon/omap-u-boot-utils/2a9344ac45f6e4074793182dcaca7b0403dff389/src/asm/sty-omap3.bin -------------------------------------------------------------------------------- /src/gpsign.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Signing utility for omap3 4 | * 5 | * FileName: src/chsign.c 6 | * 7 | * Read the .bin file and write out the .bin.ift file. 8 | * The signed image is the original pre-pended with the size of the image 9 | * and the load address. If not entered on command line, file name is 10 | * assumed to be x-load.bin in current directory and load address is 11 | * 0x40200800. 12 | */ 13 | /* 14 | * (C) Copyright 2009 15 | * Texas Instruments, 16 | * Nishanth Menon 17 | * 18 | * This program is free software; you can redistribute it and/or modify it 19 | * under the terms of the GNU General Public License as published by the 20 | * Free Software Foundation version 2. 21 | * 22 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 23 | * whether express or implied; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program; if not, write to the Free Software 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 30 | * MA 02111-1307 USA 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #ifndef __APPLE__ 40 | #include 41 | #endif 42 | #include 43 | 44 | #include "lcfg_static.h" 45 | #include "rev.h" 46 | #include "compare.h" 47 | 48 | #define CONFIG_FILE_ARG "c" 49 | #define CONFIG_FILE_ARG_C 'c' 50 | #define IMAGE_FILE_ARG "f" 51 | #define IMAGE_FILE_ARG_C 'f' 52 | #define LOAD_ADDRESS_ARG "l" 53 | #define LOAD_ADDRESS_ARG_C 'l' 54 | #define PAGE_4K_ARG "4" 55 | #define PAGE_4K_ARG_C '4' 56 | 57 | /********************** CHSETTINGS STRUCTURES *****************************/ 58 | #define CH_SETTINGS "CHSETTINGS" 59 | #define CH_RAM "CHRAM" 60 | #define CH_FLASH "CHFLASH" 61 | #define CH_MMCSD "CHMMCSD" 62 | 63 | typedef unsigned char u8; 64 | typedef unsigned short u16; 65 | typedef unsigned int u32; 66 | /* Every TOC has the same structure */ 67 | #define OFFSET_TOC_START 0x0 68 | struct ch_toc_struct { 69 | u32 start; 70 | u32 size; 71 | u8 reserved[12]; 72 | u8 name[12]; 73 | } __attribute__ ((__packed__)); 74 | 75 | #define OFFSET_START_CHSETTINGS 0xA0 76 | struct ch_settings { 77 | #define CH_S_KEY 0xC0C0C0C1 78 | u32 section_key; 79 | #define CH_S_VALID 0x1 80 | u8 valid; /* 1 for valid, 0 for not valid */ 81 | #define CH_S_VERSION 0x1 82 | u8 version; 83 | u16 reserved; 84 | #define CH_S_APPLY_SETTING (0x1 << 0) 85 | #define CH_S_PERFORM_CLK_S (0x1 << 2) 86 | #define CH_S_LOCK_DPLL4 (0x1 << 3) 87 | #define CH_S_LOCK_DPLL1 (0x1 << 4) 88 | #define CH_S_LOCK_DPLL3 (0x1 << 5) 89 | #define CH_S_BYPASS_DPLL4 (0x1 << 6) 90 | #define CH_S_BYPASS_DPLL1 (0x1 << 7) 91 | #define CH_S_BYPASS_DPLL3 (0x1 << 8) 92 | #define CH_S_CLK_12P0MHZ (0x1 << 24) 93 | #define CH_S_CLK_13P0MHZ (0x2 << 24) 94 | #define CH_S_CLK_16P8MHZ (0x3 << 24) 95 | #define CH_S_CLK_19P2MHZ (0x4 << 24) 96 | #define CH_S_CLK_26P0MHZ (0x5 << 24) 97 | #define CH_S_CLK_38P4MHZ (0x6 << 24) 98 | u32 flags; 99 | /*General clock settings */ 100 | u32 GEN_PRM_CLKSRC_CTRL; 101 | u32 GEN_PRM_CLKSEL; 102 | u32 GEN_CM_CLKSEL1_EMU; 103 | /* Clock Configuration */ 104 | u32 CLK_CM_CLKSEL_CORE; 105 | u32 CLK_CM_CLKSEL_WKUP; 106 | u32 DPLL3_CM_CLKEN_PLL; 107 | u32 DPLL3_CM_AUTOIDLE_PLL; 108 | u32 DPLL3_CM_CLKSEL1_PLL; 109 | u32 DPLL4_CM_CLKEN_PLL; 110 | u32 DPLL4_CM_AUTOIDLE_PLL; 111 | u32 DPLL4_CM_CLKSEL2_PLL; 112 | u32 DPLL4_CM_CLKSEL3_PLL; 113 | u32 DPLL1_CM_CLKEN_PLL_MPU; 114 | u32 DPLL1_CM_AUTOIDLE_PLL_MPU; 115 | u32 DPLL1_CM_CLKSEL1_PLL_MPU; 116 | u32 DPLL1_CM_CLKSEL2_PLL_MPU; 117 | u32 DPLL1_CM_CLKSTCTRL_MPU; 118 | } __attribute__ ((__packed__)); 119 | 120 | #define OFFSET_START_CHRAM 0xF0 121 | struct ch_ram { 122 | #define CH_R_KEY 0xC0C0C0C2 123 | u32 section_key; /* 0x0 */ 124 | #define CH_R_VALID 0x1 125 | u8 valid; /* 0x4 */ 126 | u8 reserved0[3]; /* 0x5 */ 127 | u16 SDRC_SYSCONFIG_LSB; /* 0x8 */ 128 | u16 SDRC_CS_CFG_LSB; 129 | u16 SDRC_SHARING_LSB; 130 | u16 SDRC_ERR_TYPE_LSB; 131 | u32 SDRC_DLLA_CTRL; 132 | u32 reserved1; 133 | u32 SDRC_POWER; 134 | /* CS0 */ 135 | #define CH_R_TYPE_SDRAM 0 136 | #define CH_R_TYPE_LPSDR 1 137 | #define CH_R_TYPE_DDR 2 138 | #define CH_R_TYPE_MDDR 3 139 | #define CH_R_TYPE_UNKNOWN 4 140 | u16 mem_type_cs0; 141 | u16 reserved2; 142 | u32 SDRC_MCFG_0; 143 | u16 SDRC_MR_0_LSB; 144 | u16 SDRC_EMR1_0_LSB; 145 | u16 SDRC_EMR2_0_LSB; 146 | u16 SDRC_EMR3_0_LSB; 147 | u32 SDRC_ACTIM_CTRLA_0; 148 | u32 SDRC_ACTIM_CTRLB_0; 149 | u32 SDRC_RFRCTRL_0; 150 | /* CS1 */ 151 | u16 mem_type_cs1; 152 | u16 reserved3; 153 | u32 SDRC_MCFG_1; 154 | u16 SDRC_MR_1_LSB; 155 | u16 SDRC_EMR1_1_LSB; 156 | u16 SDRC_EMR2_1_LSB; 157 | u16 SDRC_EMR3_1_LSB; 158 | u32 SDRC_ACTIM_CTRLA_1; 159 | u32 SDRC_ACTIM_CTRLB_1; 160 | u32 SDRC_RFRCTRL_1; 161 | 162 | u32 reserved4; 163 | 164 | #define CH_R_FLAGS_CS0_CONFIGURED (0x1 << 0) 165 | #define CH_R_FLAGS_CS1_CONFIGURED (0x1 << 1) 166 | u16 flags; 167 | 168 | u16 reserved5; 169 | } __attribute__ ((__packed__)); 170 | 171 | #define OFFSET_START_CHFLASH 0x14C 172 | struct ch_flash { 173 | #define CH_F_KEY 0xC0C0C0C3 174 | u32 section_key; /* 0x0 */ 175 | #define CH_F_VALID 0x1 176 | u8 valid; /* 0x4 */ 177 | u8 reserved[3]; /* 0x5 */ 178 | u16 GPMC_SYSCONFIG_LSB; /* 0x8 */ 179 | u16 GPMC_IRQENABLE_LSB; /* 0xA */ 180 | u16 GPMC_TIMEOUT_CONTROL_LSB; /* 0xC */ 181 | u16 GPMC_CONFIG_LSB; /* 0xE */ 182 | u32 GPMC_CONFIG1_0; /* 0x10 */ 183 | u32 GPMC_CONFIG2_0; /* 0x14 */ 184 | u32 GPMC_CONFIG3_0; /* 0x18 */ 185 | u32 GPMC_CONFIG4_0; /* 0x1C */ 186 | u32 GPMC_CONFIG5_0; /* 0x20 */ 187 | u32 GPMC_CONFIG6_0; /* 0x24 */ 188 | u32 GPMC_CONFIG7_0; /* 0x28 */ 189 | u32 GPMC_PREFETCH_CONFIG1; /* 0x2C */ 190 | u16 GPMC_PREFETCH_CONFIG2_LSB; /* 0x30 */ 191 | u16 GPMC_PREFETCH_CONTROL_LSB; /* 0x32 */ 192 | u16 GPMC_ECC_CONFIG; /* 0x34 */ 193 | u16 GPMC_ECC_CONTROL; /* 0x36 */ 194 | u16 GPMC_ECC_SIZE_CONFIG_LSB; /* 0x38 */ 195 | #define CH_F_ENABLEA1_A0 1 196 | u16 enable_A1_A10; /* 0x3A */ 197 | } __attribute__ ((__packed__)); 198 | 199 | #define OFFSET_START_CHMMCSD 0x188 200 | struct ch_mmcsd { 201 | #define CH_M_KEY 0xC0C0C0C3 202 | u32 section_key; /* 0x0 */ 203 | #define CH_M_VALID 0x1 204 | u8 valid; /* 0x4 */ 205 | u8 reserved[3]; /* 0x5 */ 206 | u16 MMCHS_SYSCTRL_MSB; /* 0x8 */ 207 | #define CH_M_SYSCTRL_LSB_NOUPDATE 0xFFFF 208 | u16 MMCHS_SYSCTRL_LSB; /* 0xA */ 209 | #define CH_M_BUS_WIDTH_1BIT 1 210 | #define CH_M_BUS_WIDTH_4BIT 2 211 | #define CH_M_BUS_WIDTH_8BIT 4 212 | #define CH_M_BUS_WIDTH_NOUPDATE 0xFFFFFFFF 213 | u32 bus_width; /* 0xC */ 214 | } __attribute__ ((__packed__)); 215 | 216 | #define PAGE_PAD_SIZE 2048 217 | 218 | /********************** VARIABLES *****************************/ 219 | static u8 ch_buffer[512]; 220 | static struct ch_settings platform_chsettings; 221 | static struct ch_ram platform_chram; 222 | static struct ch_flash platform_chflash; 223 | static struct ch_mmcsd platform_chmmcsd; 224 | unsigned int loadaddr; 225 | static struct compare_map variable_map[] = { 226 | /* *INDENT-OFF* */ 227 | /* GENERAL SETTINGS */ 228 | {"loadaddr", &loadaddr, TYPE_U32}, 229 | 230 | /* CHSETTINGS VALUES */ 231 | {"platform_chsettings.section_key", &platform_chsettings.section_key, TYPE_U32}, 232 | {"platform_chsettings.valid", &platform_chsettings.valid, TYPE_U8}, 233 | {"platform_chsettings.version", &platform_chsettings.version, TYPE_U8}, 234 | {"platform_chsettings.flags", &platform_chsettings.flags, TYPE_U32}, 235 | {"platform_chsettings.GEN_PRM_CLKSRC_CTRL", &platform_chsettings.GEN_PRM_CLKSRC_CTRL, TYPE_U32}, 236 | {"platform_chsettings.GEN_PRM_CLKSEL", &platform_chsettings.GEN_PRM_CLKSEL, TYPE_U32}, 237 | {"platform_chsettings.GEN_CM_CLKSEL1_EMU", &platform_chsettings.GEN_CM_CLKSEL1_EMU, TYPE_U32}, 238 | {"platform_chsettings.CLK_CM_CLKSEL_CORE", &platform_chsettings.CLK_CM_CLKSEL_CORE, TYPE_U32}, 239 | {"platform_chsettings.CLK_CM_CLKSEL_WKUP", &platform_chsettings.CLK_CM_CLKSEL_WKUP, TYPE_U32}, 240 | {"platform_chsettings.DPLL3_CM_CLKEN_PLL", &platform_chsettings.DPLL3_CM_CLKEN_PLL, TYPE_U32}, 241 | {"platform_chsettings.DPLL3_CM_AUTOIDLE_PLL", &platform_chsettings.DPLL3_CM_AUTOIDLE_PLL, TYPE_U32}, 242 | {"platform_chsettings.DPLL3_CM_CLKSEL1_PLL", &platform_chsettings.DPLL3_CM_CLKSEL1_PLL, TYPE_U32}, 243 | {"platform_chsettings.DPLL4_CM_CLKEN_PLL", &platform_chsettings.DPLL4_CM_CLKEN_PLL, TYPE_U32}, 244 | {"platform_chsettings.DPLL4_CM_AUTOIDLE_PLL", &platform_chsettings.DPLL4_CM_AUTOIDLE_PLL, TYPE_U32}, 245 | {"platform_chsettings.DPLL4_CM_CLKSEL2_PLL", &platform_chsettings.DPLL4_CM_CLKSEL2_PLL, TYPE_U32}, 246 | {"platform_chsettings.DPLL4_CM_CLKSEL3_PLL", &platform_chsettings.DPLL4_CM_CLKSEL3_PLL, TYPE_U32}, 247 | {"platform_chsettings.DPLL1_CM_CLKEN_PLL_MPU", &platform_chsettings.DPLL1_CM_CLKEN_PLL_MPU, TYPE_U32}, 248 | {"platform_chsettings.DPLL1_CM_AUTOIDLE_PLL_MPU", &platform_chsettings.DPLL1_CM_AUTOIDLE_PLL_MPU, TYPE_U32}, 249 | {"platform_chsettings.DPLL1_CM_CLKSEL1_PLL_MPU", &platform_chsettings.DPLL1_CM_CLKSEL1_PLL_MPU, TYPE_U32}, 250 | {"platform_chsettings.DPLL1_CM_CLKSEL2_PLL_MPU", &platform_chsettings.DPLL1_CM_CLKSEL2_PLL_MPU, TYPE_U32}, 251 | {"platform_chsettings.DPLL1_CM_CLKSTCTRL_MPU", &platform_chsettings.DPLL1_CM_CLKSTCTRL_MPU, TYPE_U32}, 252 | 253 | /* CHRAM VALUES */ 254 | {"platform_chram.section_key", &platform_chram.section_key, TYPE_U32}, 255 | {"platform_chram.valid", &platform_chram.valid, TYPE_U8}, 256 | {"platform_chram.SDRC_SYSCONFIG_LSB", &platform_chram.SDRC_SYSCONFIG_LSB, TYPE_U16}, 257 | {"platform_chram.SDRC_CS_CFG_LSB", &platform_chram.SDRC_CS_CFG_LSB, TYPE_U16}, 258 | {"platform_chram.SDRC_SHARING_LSB", &platform_chram.SDRC_SHARING_LSB, TYPE_U16}, 259 | {"platform_chram.SDRC_ERR_TYPE_LSB", &platform_chram.SDRC_ERR_TYPE_LSB, TYPE_U16}, 260 | {"platform_chram.SDRC_DLLA_CTRL", &platform_chram.SDRC_DLLA_CTRL, TYPE_U32}, 261 | {"platform_chram.SDRC_POWER", &platform_chram.SDRC_POWER, TYPE_U32}, 262 | {"platform_chram.mem_type_cs0", &platform_chram.mem_type_cs0, TYPE_U16}, 263 | {"platform_chram.SDRC_MCFG_0", &platform_chram.SDRC_MCFG_0, TYPE_U32}, 264 | {"platform_chram.SDRC_MR_0_LSB", &platform_chram.SDRC_MR_0_LSB, TYPE_U16}, 265 | {"platform_chram.SDRC_EMR1_0_LSB", &platform_chram.SDRC_EMR1_0_LSB, TYPE_U16}, 266 | {"platform_chram.SDRC_EMR2_0_LSB", &platform_chram.SDRC_EMR2_0_LSB, TYPE_U16}, 267 | {"platform_chram.SDRC_EMR3_0_LSB", &platform_chram.SDRC_EMR3_0_LSB, TYPE_U16}, 268 | {"platform_chram.SDRC_ACTIM_CTRLA_0", &platform_chram.SDRC_ACTIM_CTRLA_0, TYPE_U32}, 269 | {"platform_chram.SDRC_ACTIM_CTRLB_0", &platform_chram.SDRC_ACTIM_CTRLB_0, TYPE_U32}, 270 | {"platform_chram.SDRC_RFRCTRL_0", &platform_chram.SDRC_RFRCTRL_0, TYPE_U32}, 271 | {"platform_chram.mem_type_cs1", &platform_chram.mem_type_cs1, TYPE_U16}, 272 | {"platform_chram.SDRC_MCFG_1", &platform_chram.SDRC_MCFG_1, TYPE_U32}, 273 | {"platform_chram.SDRC_MR_1_LSB", &platform_chram.SDRC_MR_1_LSB, TYPE_U16}, 274 | {"platform_chram.SDRC_EMR1_1_LSB", &platform_chram.SDRC_EMR1_1_LSB, TYPE_U16}, 275 | {"platform_chram.SDRC_EMR2_1_LSB", &platform_chram.SDRC_EMR2_1_LSB, TYPE_U16}, 276 | {"platform_chram.SDRC_EMR3_1_LSB", &platform_chram.SDRC_EMR3_1_LSB, TYPE_U16}, 277 | {"platform_chram.SDRC_ACTIM_CTRLA_1", &platform_chram.SDRC_ACTIM_CTRLA_1, TYPE_U32}, 278 | {"platform_chram.SDRC_ACTIM_CTRLB_1", &platform_chram.SDRC_ACTIM_CTRLB_1, TYPE_U32}, 279 | {"platform_chram.SDRC_RFRCTRL_1", &platform_chram.SDRC_RFRCTRL_1, TYPE_U32}, 280 | {"platform_chram.flags", &platform_chram.flags, TYPE_U32}, 281 | 282 | /* CHFLASH VALUES */ 283 | {"platform_chflash.section_key", &platform_chflash.section_key, TYPE_U32}, 284 | {"platform_chflash.valid", &platform_chflash.valid, TYPE_U8, }, 285 | {"platform_chflash.GPMC_SYSCONFIG_LSB", &platform_chflash.GPMC_SYSCONFIG_LSB, TYPE_U16}, 286 | {"platform_chflash.GPMC_IRQENABLE_LSB", &platform_chflash.GPMC_IRQENABLE_LSB, TYPE_U16}, 287 | {"platform_chflash.GPMC_TIMEOUT_CONTROL_LSB", &platform_chflash.GPMC_TIMEOUT_CONTROL_LSB, TYPE_U16}, 288 | {"platform_chflash.GPMC_CONFIG_LSB", &platform_chflash.GPMC_CONFIG_LSB, TYPE_U16}, 289 | {"platform_chflash.GPMC_CONFIG1_0", &platform_chflash.GPMC_CONFIG1_0, TYPE_U32}, 290 | {"platform_chflash.GPMC_CONFIG2_0", &platform_chflash.GPMC_CONFIG2_0, TYPE_U32}, 291 | {"platform_chflash.GPMC_CONFIG3_0", &platform_chflash.GPMC_CONFIG3_0, TYPE_U32}, 292 | {"platform_chflash.GPMC_CONFIG4_0", &platform_chflash.GPMC_CONFIG4_0, TYPE_U32}, 293 | {"platform_chflash.GPMC_CONFIG5_0", &platform_chflash.GPMC_CONFIG5_0, TYPE_U32}, 294 | {"platform_chflash.GPMC_CONFIG6_0", &platform_chflash.GPMC_CONFIG6_0, TYPE_U32}, 295 | {"platform_chflash.GPMC_CONFIG7_0", &platform_chflash.GPMC_CONFIG7_0, TYPE_U32}, 296 | {"platform_chflash.GPMC_PREFETCH_CONFIG1", &platform_chflash.GPMC_PREFETCH_CONFIG1, TYPE_U32}, 297 | {"platform_chflash.GPMC_PREFETCH_CONFIG2_LSB", &platform_chflash.GPMC_PREFETCH_CONFIG2_LSB, TYPE_U16}, 298 | {"platform_chflash.GPMC_PREFETCH_CONTROL_LSB", &platform_chflash.GPMC_PREFETCH_CONTROL_LSB, TYPE_U16}, 299 | {"platform_chflash.GPMC_ECC_CONFIG", &platform_chflash.GPMC_ECC_CONFIG, TYPE_U16}, 300 | {"platform_chflash.GPMC_ECC_CONTROL", &platform_chflash.GPMC_ECC_CONTROL, TYPE_U16}, 301 | {"platform_chflash.GPMC_ECC_SIZE_CONFIG_LSB", &platform_chflash.GPMC_ECC_SIZE_CONFIG_LSB, TYPE_U16}, 302 | {"platform_chflash.enable_A1_A10", &platform_chflash.enable_A1_A10, TYPE_U16}, 303 | 304 | /* CHMMC VALUES */ 305 | {"platform_chmmcsd.section_key", &platform_chmmcsd.section_key, TYPE_U32}, 306 | {"platform_chmmcsd.valid", &platform_chmmcsd.valid, TYPE_U8}, 307 | {"platform_chmmcsd.MMCHS_SYSCTRL_MSB", &platform_chmmcsd.MMCHS_SYSCTRL_MSB, TYPE_U16}, 308 | {"platform_chmmcsd.MMCHS_SYSCTRL_LSB", &platform_chmmcsd.MMCHS_SYSCTRL_LSB, TYPE_U16}, 309 | {"platform_chmmcsd.bus_width", &platform_chmmcsd.bus_width, TYPE_U32}, 310 | /* *INDENT-ON* */ 311 | 312 | }; 313 | 314 | /** 315 | * @brief fillup_ch - fill up the structures 316 | * 317 | * This will fill up the ch_buffer with the required 318 | * TOC etc.. this is the image formatting logic 319 | * 320 | * @return 0 if ch was required else returns 1 321 | */ 322 | static int fillup_ch(void) 323 | { 324 | int toc_idx = 0; 325 | struct ch_toc_struct toc; 326 | /* CHSETTINGS IS A MUST */ 327 | if (!platform_chsettings.valid) { 328 | return 1; 329 | } 330 | memset(ch_buffer, 0, sizeof(ch_buffer)); 331 | memset(&toc, 0, sizeof(toc)); 332 | toc.start = OFFSET_START_CHSETTINGS; 333 | toc.size = sizeof(platform_chsettings); 334 | strcpy((char *)toc.name, CH_SETTINGS); 335 | memcpy(ch_buffer + toc_idx, &toc, sizeof(toc)); 336 | memcpy(ch_buffer + toc.start, &platform_chsettings, 337 | sizeof(platform_chsettings)); 338 | toc_idx += sizeof(toc); 339 | if (platform_chram.valid) { 340 | memset(&toc, 0, sizeof(toc)); 341 | toc.start = OFFSET_START_CHRAM; 342 | toc.size = sizeof(platform_chram); 343 | strcpy((char *)toc.name, CH_RAM); 344 | memcpy(ch_buffer + toc_idx, &toc, sizeof(toc)); 345 | memcpy(ch_buffer + toc.start, &platform_chram, 346 | sizeof(platform_chram)); 347 | toc_idx += sizeof(toc); 348 | } 349 | if (platform_chflash.valid) { 350 | memset(&toc, 0, sizeof(toc)); 351 | toc.start = OFFSET_START_CHFLASH; 352 | toc.size = sizeof(platform_chflash); 353 | strcpy((char *)toc.name, CH_FLASH); 354 | memcpy(ch_buffer + toc_idx, &toc, sizeof(toc)); 355 | memcpy(ch_buffer + toc.start, &platform_chflash, 356 | sizeof(platform_chflash)); 357 | toc_idx += sizeof(toc); 358 | } 359 | if (platform_chmmcsd.valid) { 360 | memset(&toc, 0, sizeof(toc)); 361 | toc.start = OFFSET_START_CHMMCSD; 362 | toc.size = sizeof(platform_chmmcsd); 363 | strcpy((char *)toc.name, CH_MMCSD); 364 | memcpy(ch_buffer + toc_idx, &toc, sizeof(toc)); 365 | memcpy(ch_buffer + toc.start, &platform_chmmcsd, 366 | sizeof(platform_chflash)); 367 | toc_idx += sizeof(toc); 368 | } 369 | /* Fill up the TOC */ 370 | memset(&toc, 0xff, sizeof(toc)); 371 | memcpy(ch_buffer + toc_idx, &toc, sizeof(toc)); 372 | 373 | return 0; 374 | } 375 | 376 | /** 377 | * @brief usage - help info 378 | * 379 | * @param appname my name 380 | * @param extend extended help 381 | */ 382 | static void usage(char *appname, int extend) 383 | { 384 | int i; 385 | struct compare_map *c = NULL; 386 | printf("App description:\n" 387 | "---------------\n" 388 | "generates a formatted image which may be used for\n" 389 | "nand, onenand or mmc boot on a OMAP GP device.\n" 390 | "This can also add a configuration header which\n" 391 | "allows for preconfiguration of various clock,ram\n" 392 | "GPMC or MMC settings prior to the image starting.\n" 393 | "Syntax:\n" 394 | "%s [-" CONFIG_FILE_ARG " config file] [-" LOAD_ADDRESS_ARG 395 | " loadaddr] [-" PAGE_4K_ARG "] [-" IMAGE_FILE_ARG " input_file]" 396 | "[-?]\n" 397 | "Where:\n" 398 | "------\n" 399 | " -" CONFIG_FILE_ARG " config_file: CH configuration file " 400 | "[Default none]\n" 401 | " -" LOAD_ADDRESS_ARG " loadaddress: load address for result " 402 | "image [Default 0x40208800]\n" 403 | " -" PAGE_4K_ARG " 4096 bytes flash page size [Default 2048]\n" 404 | " -" IMAGE_FILE_ARG " input_file: input binary to sign " 405 | "[Default x-load.bin]\n" 406 | " -? : provide extended help including a sample config file\n" 407 | "------\n", appname); 408 | REVPRINT(); 409 | LIC_PRINT(); 410 | COLOR_PRINT(GREEN, OMAP_UBOOT_UTILS_LICENSE 411 | "\nThis uses http://liblcfg.carnivore.it/ (libcfg)for parsing " 412 | "configuration files\n" 413 | "Copyright (c) 2007--2009 Paul Baecher\n" 414 | "This program is free software; you can redistribute it and/or\n" 415 | "modify it under the terms of the GNU General Public License\n" 416 | "as published by the Free Software Foundation; either version\n" 417 | "2 of the License, or (at your option) any later version.\n"); 418 | if (extend) { 419 | char line[60]; 420 | memset(line, '-', sizeof(line)); 421 | line[sizeof(line) - 1] = 0; 422 | printf("\nExtended help\n" "---------------\n" 423 | "Configuration options used from config file:\n"); 424 | printf("+%s+\n| %-49s | %5s |\n+%s+\n", line, 425 | "Section.Variable_name", "size", line); 426 | for (i = 0; 427 | i < sizeof(variable_map) / sizeof(struct compare_map); 428 | i++) { 429 | c = &variable_map[i]; 430 | printf("| %-49s | %5s |\n", c->name, 431 | (c->type == TYPE_U32) ? "32bit" : (c->type == 432 | TYPE_U16) ? 433 | "16bit" : "8bit"); 434 | } 435 | printf("+%s+\n", line); 436 | COLOR_PRINT(RED, 437 | "Please refer to 3430 TRM for further details on " 438 | "the fields and bit locations\n"); 439 | printf("\nSample Cfg file:\n" "load_addr = \"0x80000000\"\n" 440 | "platform_chsettings = {\n" 441 | " section_key = \"0xC0C0C0C1\"\n" 442 | " valid = \"0x1\"\n" " version = \"0x1\"\n" 443 | " flags = \"0x050001FD\"\n" 444 | " /*General clock settings */\n" 445 | " GEN_PRM_CLKSRC_CTRL = \"0x40\"\n" 446 | " GEN_PRM_CLKSEL = \"0x3\"\n" 447 | " GEN_CM_CLKSEL1_EMU = \"0x2030A50\"\n" 448 | " /* Clock Configuration */\n" 449 | " CLK_CM_CLKSEL_CORE = \"0x40A\"\n" 450 | " CLK_CM_CLKSEL_WKUP = \"0x14\"\n" 451 | " /* DPLL3 (Core) Settings */\n" 452 | " DPLL3_CM_CLKEN_PLL = \"0x770077\"\n" 453 | " DPLL3_CM_AUTOIDLE_PLL = \"0x0\"\n" 454 | " DPLL3_CM_CLKSEL1_PLL = \"0x8A60C00\"\n" 455 | " /* DPLL4 (Peripheral) Settings */\n" 456 | " DPLL4_CM_CLKEN_PLL = \"0x770077\"\n" 457 | " DPLL4_CM_AUTOIDLE_PLL = \"0xD80C\"\n" 458 | " DPLL4_CM_CLKSEL2_PLL = \"0x0\"\n" 459 | " DPLL4_CM_CLKSEL3_PLL = \"0x9\"\n" 460 | " /* DPLL1(MPU) Settings */\n" 461 | " DPLL1_CM_CLKEN_PLL_MPU = \"0x77\"\n" 462 | " DPLL1_CM_AUTOIDLE_PLL_MPU = \"0x0\"\n" 463 | " DPLL1_CM_CLKSEL1_PLL_MPU = \"0x10FA0C\"\n" 464 | " DPLL1_CM_CLKSEL2_PLL_MPU = \"0x1\"\n" 465 | " DPLL1_CM_CLKSTCTRL_MPU = \"0x0\"\n" 466 | "}\n" 467 | "\n" 468 | "platform_chram = {\n" 469 | " section_key = \"0xC0C0C0C2\"\n" 470 | " valid = \"0x1\"\n" 471 | " SDRC_SYSCONFIG_LSB = \"0x0\"\n" 472 | " SDRC_CS_CFG_LSB = \"0x1\"\n" 473 | " SDRC_SHARING_LSB = \"0x100\"\n" 474 | " SDRC_DLLA_CTRL = \"0xA\"\n" 475 | " SDRC_POWER = \"0x81\"\n" 476 | " /* I use CS0 and CS1 */\n" 477 | " flags = \"0x3\"\n" 478 | " /* CS0 */\n" 479 | " mem_type_cs0 = \"0x3\"\n" 480 | " SDRC_MCFG_0 = \"0x02D04011\"\n" 481 | " SDRC_MR_0_LSB = \"0x00000032\"\n" 482 | " SDRC_ACTIM_CTRLA_0 = \"0xBA9DC4C6\"\n" 483 | " SDRC_ACTIM_CTRLB_0 = \"0x00012522\"\n" 484 | " SDRC_RFRCTRL_0 = \"0x0004E201\"\n" 485 | " /* CS1 */\n" 486 | " mem_type_cs1 = \"0x3\"\n" 487 | " SDRC_MCFG_1 = \"0x02D04011\"\n" 488 | " SDRC_MR_1_LSB = \"0x00000032\"\n" 489 | " SDRC_ACTIM_CTRLA_1 = \"0xBA9DC4C6\"\n" 490 | " SDRC_ACTIM_CTRLB_1 = \"0x00012522\"\n" 491 | " SDRC_RFRCTRL_1 = \"0x0004E201\"\n" "}\n"); 492 | 493 | } 494 | } 495 | 496 | /* main application */ 497 | int main(int argc, char *argv[]) 498 | { 499 | int i; 500 | char *ifname, ofname[FILENAME_MAX], *cfile, ch; 501 | FILE *ifile, *ofile; 502 | unsigned long len; 503 | struct stat sinfo; 504 | unsigned int cmd_loadaddr = 0xFFFFFFFF; 505 | int page_size_4k = 0; 506 | char *page_pad = NULL; 507 | int c; 508 | char *appname = argv[0]; 509 | 510 | /* Default to x-load.bin and 0x40200800 and no config file */ 511 | ifname = "x-load.bin"; 512 | cfile = NULL; 513 | loadaddr = 0x40208800; 514 | 515 | while ((c = 516 | getopt(argc, argv, 517 | CONFIG_FILE_ARG ":" IMAGE_FILE_ARG ":" LOAD_ADDRESS_ARG 518 | ":" PAGE_4K_ARG)) != -1) 519 | switch (c) { 520 | case CONFIG_FILE_ARG_C: 521 | cfile = optarg; 522 | break; 523 | case IMAGE_FILE_ARG_C: 524 | ifname = optarg; 525 | break; 526 | case LOAD_ADDRESS_ARG_C: 527 | sscanf(optarg, "%x", &cmd_loadaddr); 528 | break; 529 | case PAGE_4K_ARG_C: 530 | page_size_4k = 1; 531 | page_pad = malloc(PAGE_PAD_SIZE); 532 | if (!page_pad) { 533 | APP_ERROR("Out of memory\n"); 534 | exit(0); 535 | } 536 | memset(page_pad, 0xff, PAGE_PAD_SIZE); 537 | break; 538 | case '?': 539 | i = 0; 540 | if ((optopt == IMAGE_FILE_ARG_C) 541 | || (optopt == CONFIG_FILE_ARG_C) 542 | || (optopt == LOAD_ADDRESS_ARG_C)) { 543 | APP_ERROR("Option -%c requires an argument.\n", 544 | optopt); 545 | } else if (optopt == '?') { 546 | APP_ERROR("EXTENDED help\n") 547 | i = 1; 548 | } else if (isprint(optopt)) { 549 | APP_ERROR("Unknown option `-%c'.\n", optopt) 550 | } else { 551 | APP_ERROR("Unknown option character `\\x%x'.\n", 552 | optopt) 553 | } 554 | usage(appname, i); 555 | return 1; 556 | default: 557 | abort(); 558 | } 559 | /* 560 | * reset the struct params 561 | * This is completely uneccesary in most cases, but I like being 562 | * paranoid 563 | */ 564 | memset(&platform_chsettings, 0, sizeof(platform_chsettings)); 565 | memset(&platform_chram, 0, sizeof(platform_chram)); 566 | memset(&platform_chflash, 0, sizeof(platform_chflash)); 567 | memset(&platform_chmmcsd, 0, sizeof(platform_chmmcsd)); 568 | /* Parse the configuration header */ 569 | if (cfile != NULL) { 570 | /* parse Configuration file */ 571 | struct lcfg *c = lcfg_new(cfile); 572 | enum lcfg_status stat; 573 | if (!c) { 574 | APP_ERROR("Config file %s init failed\n", cfile) 575 | usage(appname, 0); 576 | return -2; 577 | } 578 | stat = lcfg_parse(c); 579 | if (stat == lcfg_status_ok) { 580 | variable_map_g= variable_map; 581 | size_var_map = sizeof(variable_map)/sizeof(struct compare_map); 582 | lcfg_accept(c, compare_eventhandler, 0); 583 | } else { 584 | APP_ERROR("Config file %s: %s\n", cfile, 585 | lcfg_error_get(c)) 586 | } 587 | lcfg_delete(c); 588 | if (stat != lcfg_status_ok) { 589 | usage(appname, 1); 590 | return -3; 591 | } 592 | } 593 | 594 | /* Over Ride configuration file values with values from 595 | * command line if provided 596 | */ 597 | if (cmd_loadaddr != 0xFFFFFFFF) 598 | loadaddr = cmd_loadaddr; 599 | 600 | /* Form the output file name. */ 601 | strcpy(ofname, ifname); 602 | strcat(ofname, ".ift"); 603 | 604 | /* Open the input file. */ 605 | ifile = fopen(ifname, "rb"); 606 | if (ifile == NULL) { 607 | APP_ERROR("Cannot open %s\n", ifname); 608 | usage(appname, 0); 609 | return -3; 610 | } 611 | /* Get file length. */ 612 | stat(ifname, &sinfo); 613 | len = sinfo.st_size; 614 | 615 | /* Open the output file and write it. */ 616 | ofile = fopen(ofname, "wb"); 617 | if (ofile == NULL) { 618 | APP_ERROR("Cannot open %s\n", ofname); 619 | fclose(ifile); 620 | exit(0); 621 | } 622 | /* Fill up Configuration header */ 623 | if (!fillup_ch()) 624 | fwrite(ch_buffer, 1, sizeof(ch_buffer), ofile); 625 | 626 | fwrite(&len, 1, 4, ofile); 627 | fwrite(&loadaddr, 1, 4, ofile); 628 | for (i = 0; i < len; i++) { 629 | int z = fread(&ch, 1, 1, ifile); 630 | if (!z) 631 | APP_ERROR("no data?\n"); 632 | if (page_size_4k) { 633 | /* Account for 8 bytes header */ 634 | if (i > 8 && !(((i + 8) % PAGE_PAD_SIZE))) 635 | fwrite(page_pad, PAGE_PAD_SIZE, 1, ofile); 636 | } 637 | fwrite(&ch, 1, 1, ofile); 638 | } 639 | 640 | fclose(ifile); 641 | fclose(ofile); 642 | return 0; 643 | } 644 | -------------------------------------------------------------------------------- /src/pserial.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Peripheral Boot downloader over UART 4 | * 5 | * FileName: src/pserial.c 6 | * 7 | * Application which uses Peripheral mode configuration to download 8 | * an image using the OMAP ROM Code protocol 9 | * 10 | */ 11 | /* 12 | * (C) Copyright 2008-2009 13 | * Texas Instruments, 14 | * Nishanth Menon 15 | * 16 | * This program is free software; you can redistribute it and/or modify it 17 | * under the terms of the GNU General Public License as published by the 18 | * Free Software Foundation version 2. 19 | * 20 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 21 | * whether express or implied; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program; if not, write to the Free Software 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 28 | * MA 02111-1307 USA 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "rev.h" 37 | #include "serial.h" 38 | #include "file.h" 39 | #include "f_status.h" 40 | 41 | #define ASIC_ID_SIZE 7 42 | #define ASIC_ID_OMAP4430 0x4430 43 | #define ASIC_ID_OMAP3430 0x3430 44 | #define ASIC_ID_OMAP3630 0x3630 45 | 46 | #define MAX_BUF 2048 47 | #define TOT_SIZE MAX_BUF 48 | #define PRINT_SIZE 100 49 | 50 | #define PORT_ARG "p" 51 | #define PORT_ARG_C 'p' 52 | #define SEC_ARG "f" 53 | #define SEC_ARG_C 'f' 54 | #define VERBOSE_ARG "v" 55 | #define VERBOSE_ARG_C 'v' 56 | 57 | /** 58 | * @brief send_file - send a file to the host 59 | * 60 | * @param f_name file to send 61 | * 62 | * @return fail/success 63 | */ 64 | static int send_file(char *f_name) 65 | { 66 | signed int size = 0; 67 | unsigned char buffer[TOT_SIZE] = { 0 }; 68 | unsigned int tot_read = 0, to_read; 69 | signed int cur_read; 70 | signed int ret; 71 | 72 | size = f_size(f_name); 73 | 74 | if (size < 0) { 75 | APP_ERROR("File Size Operation failed! File exists?\n") 76 | return size; 77 | } 78 | if (f_open(f_name) != FILE_OK) { 79 | APP_ERROR("File Open failed!File Exists & readable?\n") 80 | return -1; 81 | } 82 | f_status_init(size, NORMAL_PRINT); 83 | /* Send the size */ 84 | ret = s_write((unsigned char *)&size, sizeof(size)); 85 | if (ret != sizeof(size)) { 86 | APP_ERROR("Oops.. did not send size properly :(\n") 87 | return -1; 88 | } 89 | /* Send the file to target */ 90 | while (tot_read < size) { 91 | int cur_write; 92 | to_read = size - tot_read; 93 | to_read = (to_read > TOT_SIZE) ? TOT_SIZE : to_read; 94 | cur_read = f_read(buffer, to_read); 95 | if (cur_read < 0) { 96 | APP_ERROR("Oops.. read failed!\n") 97 | break; 98 | } 99 | cur_write = s_write(buffer, cur_read); 100 | if (cur_write != cur_read) { 101 | APP_ERROR("did not right data to serial port" 102 | " serial cur_write = %d, file cur_read= %d\n", 103 | cur_write, cur_read) 104 | } 105 | tot_read += cur_read; 106 | f_status_show(tot_read); 107 | #ifdef DEBUG 108 | { 109 | int i = 0; 110 | for (i = 0; i < cur_read; i++) { 111 | printf("[%04d]0x%02X ", i, buffer[i]); 112 | } 113 | } 114 | printf("\n"); 115 | #endif 116 | } 117 | 118 | if (f_close() != FILE_OK) { 119 | APP_ERROR("File Close failed\n") 120 | } 121 | return 0; 122 | } 123 | 124 | /** 125 | * @brief usage - help info 126 | * 127 | * @param appname my name 128 | */ 129 | static void usage(char *appname) 130 | { 131 | #ifdef __WIN32__ 132 | #define PORT_NAME "COM1" 133 | #define F_NAME "c:\\temp\\u-boot.bin" 134 | #else 135 | #define PORT_NAME "/dev/ttyS0" 136 | #define F_NAME "~/tmp/u-boot.bin" 137 | #endif 138 | printf("App description:\n" 139 | "---------------\n" 140 | "This Application helps download a second file as " 141 | "response to ASIC ID over serial port\n\n" 142 | "Syntax:\n" 143 | "------\n" 144 | "%s -" PORT_ARG " portName -" SEC_ARG " fileToDownload [-" 145 | VERBOSE_ARG "]\n\n" 146 | "Where:\n" "-----\n" 147 | "portName - RS232 device being used. Example: " PORT_NAME "\n" 148 | "fileToDownload - file to be downloaded as response to " 149 | "asic id\n" 150 | "-"VERBOSE_ARG " - print complete ASIC id dump(optional)\n" 151 | "\nUsage Example:\n" "-------------\n" 152 | "%s -" PORT_ARG " " PORT_NAME " -" SEC_ARG " " F_NAME "\n", 153 | appname, appname); 154 | REVPRINT(); 155 | LIC_PRINT(); 156 | 157 | } 158 | 159 | /** 160 | * @brief main application entry 161 | * 162 | * @param argc 163 | * @param *argv 164 | * 165 | * @return pass/fail 166 | */ 167 | int main(int argc, char **argv) 168 | { 169 | signed char ret = 0; 170 | unsigned char buff[MAX_BUF]; 171 | unsigned int download_command = 0xF0030002; 172 | char *port = NULL; 173 | char *second_file = NULL; 174 | char *appname = argv[0]; 175 | int c; 176 | int read_size = 0; 177 | unsigned int asic_id = 0; 178 | char verbose = 0; 179 | /* Option validation */ 180 | opterr = 0; 181 | 182 | while ((c = getopt(argc, argv, PORT_ARG ":" SEC_ARG ":" VERBOSE_ARG)) != 183 | -1) 184 | switch (c) { 185 | case VERBOSE_ARG_C: 186 | verbose = 1; 187 | break; 188 | case PORT_ARG_C: 189 | port = optarg; 190 | break; 191 | case SEC_ARG_C: 192 | second_file = optarg; 193 | break; 194 | case '?': 195 | if ((optopt == SEC_ARG_C) || (optopt == PORT_ARG_C)) { 196 | APP_ERROR("Option -%c requires an argument.\n", 197 | optopt) 198 | } else if (isprint(optopt)) { 199 | APP_ERROR("Unknown option `-%c'.\n", optopt) 200 | } else { 201 | APP_ERROR("Unknown option character `\\x%x'.\n", 202 | optopt) 203 | } 204 | usage(appname); 205 | return 1; 206 | default: 207 | abort(); 208 | } 209 | if ((port == NULL) || (second_file == NULL)) { 210 | APP_ERROR("Error: Not Enough Args\n") 211 | usage(appname); 212 | return -1; 213 | } 214 | 215 | /* Setup the port */ 216 | ret = s_open(port); 217 | if (ret != SERIAL_OK) { 218 | APP_ERROR("serial open failed\n") 219 | return ret; 220 | } 221 | ret = s_configure(115200, EVENPARITY, ONE_STOP_BIT, 8); 222 | if (ret != SERIAL_OK) { 223 | s_close(); 224 | APP_ERROR("serial configure failed\n") 225 | return ret; 226 | } 227 | 228 | /* Read ASIC ID */ 229 | printf("Waiting For Device ASIC ID: Press Ctrl+C to stop\n"); 230 | while (!ret) { 231 | ret = s_read(buff, 1); 232 | if (buff[0] != 0x04) 233 | ret = 0; 234 | } 235 | 236 | ret = 0; 237 | while (!ret) { 238 | ret = s_read(buff, ASIC_ID_SIZE); 239 | if ((ret != ASIC_ID_SIZE)) { 240 | APP_ERROR("Did not read asic ID ret = %d\n", ret) 241 | s_close(); 242 | return ret; 243 | } 244 | } 245 | if (verbose) { 246 | int i = 0; 247 | for (i = 0; i < ASIC_ID_SIZE; i++) 248 | printf("[%d] 0x%x[%c]\n", i, buff[i], buff[i]); 249 | } 250 | asic_id = (buff[3] << 8) + buff[4]; 251 | switch (asic_id) { 252 | case ASIC_ID_OMAP4430: 253 | printf("ASIC ID Detected: OMAP 4430 with ROM Version" 254 | " 0x%02x%02x\n", buff[5], buff[6]); 255 | read_size = 59; 256 | break; 257 | case ASIC_ID_OMAP3430: 258 | case ASIC_ID_OMAP3630: 259 | printf("ASIC ID Detected: OMAP %04x with ROM Version" 260 | " 0x%02x%02x\n", asic_id, buff[5], buff[6]); 261 | read_size = 50; 262 | break; 263 | default: 264 | printf("ASIC ID Detected: 0x%02x 0x%02x 0x%02x 0x%02x\n", 265 | buff[3], buff[4], buff[5], buff[6]); 266 | read_size = 50; 267 | break; 268 | } 269 | 270 | ret = 0; 271 | while (!ret) { 272 | ret = s_read(buff, read_size); 273 | if ((ret != read_size)) { 274 | APP_ERROR("Did not read asic ID ret = %d\n", ret) 275 | s_close(); 276 | return ret; 277 | } 278 | } 279 | 280 | if (verbose) { 281 | int i = 0; 282 | for (i = 0; i < read_size; i++) 283 | printf("[%d] 0x%x[%c]\n", i, buff[i], buff[i]); 284 | } 285 | 286 | /* Send the Download command */ 287 | printf("Sending 2ndFile:\n"); 288 | ret = 289 | s_write((unsigned char *)&download_command, 290 | sizeof(download_command)); 291 | if (ret != sizeof(download_command)) { 292 | APP_ERROR("oppps!! did not actually manage to send command\n") 293 | return -1; 294 | } 295 | if (send_file(second_file) != 0) { 296 | APP_ERROR("send file failed!\n") 297 | } 298 | 299 | ret = s_close(); 300 | if (ret != SERIAL_OK) { 301 | APP_ERROR("serial close failed\n") 302 | return ret; 303 | } 304 | printf("\nFile download completed.\n"); 305 | 306 | return ret; 307 | } 308 | -------------------------------------------------------------------------------- /src/pusb.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Peripheral Boot downloader over USB 4 | * 5 | * FileName: src/pserial.c 6 | * 7 | * OMAP USB peripheral booting helper using libusb example 8 | * USB module usage based on testlibusb.c 9 | * 10 | * Caveat: NOTE: Windows support is still a work in progress 11 | * 12 | */ 13 | /* 14 | * (C) Copyright 2008-2009 15 | * Texas Instruments, 16 | * Nishanth Menon 17 | * 18 | * This program is free software; you can redistribute it and/or modify it 19 | * under the terms of the GNU General Public License as published by the 20 | * Free Software Foundation version 2. 21 | * 22 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 23 | * whether express or implied; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program; if not, write to the Free Software 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 30 | * MA 02111-1307 USA 31 | */ 32 | #ifdef __WIN32__ 33 | #include /* for Sleep() in dos/mingw */ 34 | #else 35 | #include 36 | #include 37 | #endif 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include "rev.h" 48 | #include "file.h" 49 | #include "f_status.h" 50 | 51 | /* Texas Instruments */ 52 | #define SEARCH_VENDOR_DEFAULT 0x0451 53 | /* OMAP3430 */ 54 | #define SEARCH_PRODUCT_DEFAULT 0xD009 55 | /* bConfigurationValue: 1 */ 56 | #define CONFIG_INDEX_DEFAULT 0x1 57 | /* bInterfaceNumber: 0 */ 58 | #define INTERFACE_INDEX_DEFAULT 0x0 59 | #define DEVICE_IN_ENDPOINT 0x81 60 | #define DEVICE_OUT_ENDPOINT 0x1 61 | #define ASICID_SIZE_OMAP3 69 /* 1+7+4+23+23+11 */ 62 | #define ASICID_SIZE_OMAP4 81 /* 1+7+4+23+35+11 */ 63 | #define ASIC_ID_TIMEOUT 100 64 | #define COMMAND_SIZE 4 65 | #define GET_ASICID_COMMAND 0xF0030003 66 | #define DOWNLOAD_COMMAND 0xF0030002 67 | #define MAX_SIZE (64 * 1024) 68 | #define READ_BUFFER_SIZE 4096 69 | 70 | /* Print control */ 71 | #define V_PRINT(ARGS...) if (verbose >= 1) printf(ARGS) 72 | #define N_PRINT(ARGS...) if (verbose >= 0) printf(ARGS) 73 | 74 | static int verbose = 0; 75 | static int asicid_size = ASICID_SIZE_OMAP3; 76 | static unsigned int search_vendor = SEARCH_VENDOR_DEFAULT; 77 | static unsigned int search_product = SEARCH_PRODUCT_DEFAULT; 78 | static int config_idx = CONFIG_INDEX_DEFAULT; 79 | static libusb_device_handle *udev; 80 | static char *program_name; 81 | 82 | /** 83 | * @brief sleep for a definite time 84 | * 85 | * @param ms delay in ms 86 | * 87 | * @return none 88 | */ 89 | static void usb_sleep(unsigned int ms) 90 | { 91 | #ifndef __WIN32__ 92 | struct timespec poll_interval = { 93 | .tv_sec = 0, 94 | .tv_nsec = ms * 1000 * 1000, 95 | }; 96 | nanosleep(&poll_interval, NULL); 97 | #else 98 | Sleep(ms); 99 | #endif 100 | } 101 | 102 | /******* ACTUAL CONFIGURATION OF THE DEVICE ********************/ 103 | int configure_device(libusb_device_handle *udev) 104 | { 105 | int ret = 0; 106 | ret = libusb_set_configuration(udev, config_idx); 107 | if (ret != 0) { 108 | APP_ERROR("set configuration returned error :%d %s\n", ret, 109 | strerror(errno)); 110 | return ret; 111 | } 112 | return 0; 113 | } 114 | 115 | /* send commands to the boot rom; returns 0 on success */ 116 | static int send_command(libusb_device_handle *udev, unsigned int command) 117 | { 118 | int ret = 0; 119 | int r = libusb_bulk_transfer(udev, DEVICE_OUT_ENDPOINT, (unsigned char *)&command, 120 | sizeof(command), &ret, ASIC_ID_TIMEOUT); 121 | if (r != 0) 122 | ret = 0; 123 | if (ret != COMMAND_SIZE) { 124 | APP_ERROR 125 | ("CMD:Expected to write %ld, " 126 | "actual write %d - err str: %s\n", 127 | (long int)sizeof(command), ret, strerror(errno)); 128 | } 129 | 130 | return !(ret == COMMAND_SIZE); 131 | } 132 | 133 | /*************** ACTUAL TRANSMISSION OF FILE *****************/ 134 | int send_file(libusb_device_handle *udev, char *f_name) 135 | { 136 | int ret = 0; 137 | unsigned long cur_size = 0; 138 | unsigned int filesize; 139 | unsigned char asic_buffer[ASICID_SIZE_OMAP4]; 140 | unsigned char read_buffer[READ_BUFFER_SIZE]; 141 | int fail = 0; 142 | int r; 143 | 144 | filesize = f_size(f_name); 145 | if (filesize > MAX_SIZE) { 146 | APP_ERROR("Filesize %d >%d max\n", 147 | (unsigned int)filesize, MAX_SIZE); 148 | return -1; 149 | } 150 | 151 | ret = f_open(f_name); 152 | if (ret < 0) { 153 | APP_ERROR("error opening file! -%d\n", ret); 154 | return -1; 155 | } 156 | if (verbose >= 0) { 157 | f_status_init(filesize, NORMAL_PRINT); 158 | } 159 | /* Grab the interface for us to send data */ 160 | ret = libusb_claim_interface(udev, INTERFACE_INDEX_DEFAULT); 161 | if (ret) { 162 | APP_ERROR("error claiming usb interface %d-%s\n", ret, 163 | strerror(errno)); 164 | return (ret); 165 | } 166 | 167 | /* read ASIC ID */ 168 | r = 169 | libusb_bulk_transfer(udev, DEVICE_IN_ENDPOINT, asic_buffer, asicid_size, &ret, 170 | ASIC_ID_TIMEOUT); 171 | if (r != 0) 172 | ret = 0; 173 | 174 | /* if no ASIC ID, request it explicitly */ 175 | if (ret != asicid_size) { 176 | if (send_command(udev, GET_ASICID_COMMAND)) { 177 | APP_ERROR("Can't get ASIC ID out of the wretched chip.\n"); 178 | fail = -1; 179 | goto closeup; 180 | } 181 | /* now try again */ 182 | r = libusb_bulk_transfer(udev, DEVICE_IN_ENDPOINT, asic_buffer, 183 | asicid_size, &ret, ASIC_ID_TIMEOUT); 184 | if (r != 0) 185 | ret = 0; 186 | if (ret != asicid_size) { 187 | APP_ERROR("Expected to read %d, read %d - err str: %s\n", 188 | asicid_size, ret, strerror(errno)); 189 | fail = -1; 190 | goto closeup; 191 | } 192 | } 193 | if (verbose > 0) { 194 | int i = 0; 195 | printf("ASIC ID:\n"); 196 | while (i < asicid_size) { 197 | printf("%d: 0x%x[%c]\n", i, asic_buffer[i], 198 | asic_buffer[i]); 199 | i++; 200 | } 201 | } 202 | usb_sleep(50); 203 | /* Send the Continue Peripheral boot command */ 204 | if (send_command(udev, DOWNLOAD_COMMAND)) { 205 | fail = -1; 206 | goto closeup; 207 | } 208 | usb_sleep(50); 209 | /* Send in the filesize */ 210 | r = 211 | libusb_bulk_transfer(udev, DEVICE_OUT_ENDPOINT, (unsigned char *)&filesize, 212 | sizeof(filesize), &ret, ASIC_ID_TIMEOUT); 213 | if (r != 0) 214 | ret = 0; 215 | if (ret != sizeof(filesize)) { 216 | APP_ERROR 217 | ("FSize:Expected to write %ld, " 218 | "actual write %d - err str: %s\n", 219 | (long int)sizeof(filesize), ret, strerror(errno)); 220 | fail = -1; 221 | goto closeup; 222 | } 223 | /* pump in the data */ 224 | while (filesize) { 225 | int r_size = f_read((unsigned char *)read_buffer, 226 | sizeof(read_buffer)); 227 | r = 228 | libusb_bulk_transfer(udev, DEVICE_OUT_ENDPOINT, read_buffer, 229 | r_size, &ret, ASIC_ID_TIMEOUT); 230 | if (r != 0) 231 | ret = 0; 232 | if (ret != r_size) { 233 | APP_ERROR 234 | ("DDump:Expected to write %d, actual write %d %s\n", 235 | r_size, ret, strerror(errno)); 236 | fail = -1; 237 | goto closeup; 238 | } 239 | filesize -= r_size; 240 | if (verbose >= 0) { 241 | cur_size += r_size; 242 | f_status_show(cur_size); 243 | } 244 | } 245 | /* close the device */ 246 | closeup: 247 | ret = libusb_release_interface(udev, INTERFACE_INDEX_DEFAULT); 248 | if (ret) { 249 | APP_ERROR("error releasing usb interface %d-%s\n", ret, 250 | strerror(errno)); 251 | /* Fall thru */ 252 | fail = ret; 253 | } 254 | 255 | libusb_close(udev); 256 | 257 | ret = f_close(); 258 | if (ret) { 259 | APP_ERROR("error closing file %d-%s\n", ret, strerror(errno)); 260 | /* Fall thru */ 261 | fail = ret; 262 | } 263 | return fail; 264 | } 265 | 266 | void help(void) 267 | { 268 | printf("App description:\n" 269 | "---------------\n" 270 | "This Application helps download a second file as " 271 | "response to ASIC ID over USB\n\n" 272 | "Syntax:\n" 273 | "------\n" 274 | " %s [-v] [-V] [-d device_ID] -f input_file \n" 275 | "Where:\n" "-----\n" 276 | " -v : (optional) verbose messages\n" 277 | " -V : (optional) verbose messages + usblib debug messages\n" 278 | " -q : (optional) Ultra quiet - no outputs other than error\n" 279 | " -d device_ID: (optional) USB Device id (Uses default of 0x%X)\n" 280 | " -f input_file: input file to be transmitted to target\n" 281 | "NOTE: it is required to run this program in sudo mode to get access at times\n" 282 | "Usage Example:\n" "-------------\n" 283 | "sudo %s -f F_NAME \n", program_name, search_product, 284 | program_name); 285 | REVPRINT(); 286 | LIC_PRINT(); 287 | } 288 | 289 | int main(int argc, char *argv[]) 290 | { 291 | char *filename = NULL; 292 | int found = 0; 293 | int x = 0; 294 | int old_dev = 0; 295 | int new_dev = 0; 296 | /* NOTE: mingw did not like this.. */ 297 | int c; 298 | int filesize = -1; 299 | 300 | program_name = argv[0]; 301 | /* Options supported: 302 | * -f input filename - file to send 303 | * -d deviceID - USB deviceID 304 | * -v -verbose 305 | * -q -ultraquiet 306 | */ 307 | while ((c = getopt(argc, argv, ":vVqd:f:4")) != -1) { 308 | switch (c) { 309 | case 'q': 310 | verbose = -1; 311 | break; 312 | case 'v': 313 | verbose = 1; 314 | break; 315 | case 'V': 316 | verbose = 2; 317 | break; 318 | case 'f': 319 | filename = optarg; 320 | break; 321 | case 'd': 322 | sscanf(optarg, "%x", &search_product); 323 | break; 324 | case '4': 325 | asicid_size = ASICID_SIZE_OMAP4; 326 | break; 327 | case '?': 328 | default: 329 | APP_ERROR("Missing/Wrong Arguments\n"); 330 | help(); 331 | return -1; 332 | } 333 | } 334 | if (filename) 335 | filesize = f_size(filename); 336 | /* Param validate */ 337 | if ((NULL == filename) || (filesize == -1)) { 338 | APP_ERROR("Missing file to download\n"); 339 | help(); 340 | return -2; 341 | } 342 | /* 343 | if (verbose == 2) { 344 | usb_set_debug(255); 345 | } 346 | */ 347 | libusb_init(NULL); 348 | N_PRINT("Waiting for USB device vendorID=0x%X " 349 | "and productID=0x%X:\n", search_vendor, search_product); 350 | while (1) { 351 | udev = libusb_open_device_with_vid_pid(NULL, search_vendor, search_product); 352 | if (udev) 353 | break; 354 | /* sleep a bit, just to not do too much busy waiting */ 355 | usb_sleep(50); 356 | } 357 | c = configure_device(udev); 358 | if (c) { 359 | APP_ERROR("configure dev failed\n"); 360 | goto exit; 361 | } 362 | c = send_file(udev, filename); 363 | if (c) { 364 | APP_ERROR("send file failed\n"); 365 | } 366 | if (!c) { 367 | N_PRINT("\n%s downloaded successfully to target\n", filename); 368 | } 369 | exit: 370 | return c; 371 | } 372 | -------------------------------------------------------------------------------- /src/sysrq.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Linux serial port breaker routine 4 | * 5 | * FileName: src/sysrq.c 6 | * 7 | * Just generate the magic sysrq sequence given a serial port. 8 | * 9 | */ 10 | /* 11 | * (C) Copyright 2015 12 | * Texas Instruments, 13 | * Nishanth Menon 14 | * 15 | * This program is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU General Public License as published by the 17 | * Free Software Foundation version 2. 18 | * 19 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 20 | * whether express or implied; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 27 | * MA 02111-1307 USA 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "rev.h" 36 | #include "serial.h" 37 | #include "file.h" 38 | #include "f_status.h" 39 | 40 | #define ASIC_ID_SIZE 7 41 | #define ASIC_ID_OMAP4430 0x4430 42 | #define ASIC_ID_OMAP3430 0x3430 43 | #define ASIC_ID_OMAP3630 0x3630 44 | 45 | #define MAX_BUF 2048 46 | #define TOT_SIZE MAX_BUF 47 | #define PRINT_SIZE 100 48 | 49 | #define PORT_ARG "p" 50 | #define PORT_ARG_C 'p' 51 | #define SYSRQ_ARG "f" 52 | #define SYSRQ_ARG_C 'f' 53 | 54 | /** 55 | * @brief send_sysrq - send a file to the host 56 | * 57 | * @param sysrq_key: key sequence to send 58 | * 59 | * @return fail/success 60 | */ 61 | static int send_sysrq(unsigned char *sysrq_key) 62 | { 63 | signed int ret; 64 | 65 | /* Apply break for 1 second */ 66 | ret = s_break(1, 0); 67 | if (ret < 0) { 68 | APP_ERROR("Opps.. failed to send break\n"); 69 | return -1; 70 | } 71 | /* Send the sysrq key */ 72 | ret = s_write(sysrq_key, 1); 73 | if (ret != 1) { 74 | APP_ERROR("Oops.. did not send size properly :(\n") 75 | return -1; 76 | } 77 | 78 | return 0; 79 | } 80 | 81 | /** 82 | * @brief usage - help info 83 | * 84 | * @param appname my name 85 | */ 86 | static void usage(char *appname) 87 | { 88 | #ifdef __WIN32__ 89 | #define PORT_NAME "COM1" 90 | #else 91 | #define PORT_NAME "/dev/ttyS0" 92 | #endif 93 | printf("App description:\n" 94 | "---------------\n" 95 | "This Application sends a sysrq keysequence over serial port\n\n" 96 | "Syntax:\n" 97 | "------\n" 98 | "%s -" PORT_ARG " portName -" SYSRQ_ARG " sysrq_key\n\n" 99 | "Where:\n" "-----\n" 100 | "portName - RS232 device being used. Example: " PORT_NAME "\n" 101 | "sysrq_key - Sysrq key\n" 102 | "\nUsage Example:\n" "-------------\n" 103 | "%s -" PORT_ARG " " PORT_NAME " -" SYSRQ_ARG " t\n", 104 | appname, appname); 105 | REVPRINT(); 106 | LIC_PRINT(); 107 | 108 | } 109 | 110 | /** 111 | * @brief main application entry 112 | * 113 | * @param argc 114 | * @param *argv 115 | * 116 | * @return pass/fail 117 | */ 118 | int main(int argc, char **argv) 119 | { 120 | signed char ret = 0; 121 | char *port = NULL; 122 | char *sysrq_key = NULL; 123 | char *appname = argv[0]; 124 | int c; 125 | /* Option validation */ 126 | opterr = 0; 127 | 128 | while ((c = getopt(argc, argv, PORT_ARG ":" SYSRQ_ARG ":")) != -1) 129 | switch (c) { 130 | case PORT_ARG_C: 131 | port = optarg; 132 | break; 133 | case SYSRQ_ARG_C: 134 | sysrq_key = optarg; 135 | break; 136 | case '?': 137 | if ((optopt == SYSRQ_ARG_C) || (optopt == PORT_ARG_C)) { 138 | APP_ERROR("Option -%c requires an argument.\n", 139 | optopt) 140 | } else if (isprint(optopt)) { 141 | APP_ERROR("Unknown option `-%c'.\n", optopt) 142 | } else { 143 | APP_ERROR("Unknown option character `\\x%x'.\n", 144 | optopt) 145 | } 146 | usage(appname); 147 | return 1; 148 | default: 149 | abort(); 150 | } 151 | if ((port == NULL) || (sysrq_key == NULL)) { 152 | APP_ERROR("Error: Not Enough Args\n") 153 | usage(appname); 154 | return -1; 155 | } 156 | 157 | /* Setup the port */ 158 | ret = s_open(port); 159 | if (ret != SERIAL_OK) { 160 | APP_ERROR("serial open failed\n") 161 | return ret; 162 | } 163 | ret = s_configure(115200, NOPARITY, ONE_STOP_BIT, 8); 164 | if (ret != SERIAL_OK) { 165 | s_close(); 166 | APP_ERROR("serial configure failed\n") 167 | return ret; 168 | } 169 | 170 | if (send_sysrq((unsigned char *)sysrq_key) != 0) { 171 | APP_ERROR("send file failed!\n") 172 | } 173 | 174 | ret = s_close(); 175 | if (ret != SERIAL_OK) { 176 | APP_ERROR("serial close failed\n") 177 | return ret; 178 | } 179 | printf("\nFile download completed.\n"); 180 | 181 | return ret; 182 | } 183 | -------------------------------------------------------------------------------- /src/tagger.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tagging utility for zImage files 4 | * 5 | * FileName: src/tagger.c 6 | * 7 | * Generate ATAG information and add external data to 8 | * a zImage to allow the image to boot out of the box 9 | */ 10 | /* 11 | * tagger: 12 | * (C) Copyright 2010 13 | * Texas Instruments, 14 | * 15 | * Nishanth Menon 16 | * Original code from: u-boot/include/asm-arm/setup.h 17 | * linux/include/asm/setup.h 18 | * 19 | * Copyright (C) 1997-1999 Russell King 20 | * 21 | * This program is free software; you can redistribute it and/or modify 22 | * it under the terms of the GNU General Public License version 2 as 23 | * published by the Free Software Foundation. 24 | * 25 | * Structure passed to kernel to tell it about the 26 | * hardware it's running on. See linux/Documentation/arm/Setup 27 | * for more info. 28 | */ 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #ifndef __APPLE__ 36 | #include 37 | #endif 38 | #include 39 | 40 | #include "lcfg_static.h" 41 | #include "tagger.h" 42 | #include "rev.h" 43 | #include "compare.h" 44 | 45 | #define CONFIG_FILE_ARG "c" 46 | #define CONFIG_FILE_ARG_C 'c' 47 | #define IMAGE_FILE_ARG "f" 48 | #define IMAGE_FILE_ARG_C 'f' 49 | 50 | static void setup_start_tag(struct tag **_params) 51 | { 52 | struct tag *params = *_params; 53 | params->hdr.tag = ATAG_CORE; 54 | params->hdr.size = tag_size(tag_core); 55 | params->u.core.flags = 0; 56 | params->u.core.pagesize = 0; 57 | params->u.core.rootdev = 0; 58 | params = tag_next(params); 59 | *_params = params; 60 | } 61 | 62 | static void setup_memory_tags(struct tag **_params, struct board *b) 63 | { 64 | int i; 65 | struct tag *params = *_params; 66 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { 67 | if (!b->ram[i].size) 68 | continue; 69 | params->hdr.tag = ATAG_MEM; 70 | params->hdr.size = tag_size(tag_mem32); 71 | params->u.mem.start = b->ram[i].start; 72 | params->u.mem.size = b->ram[i].size; 73 | params = tag_next(params); 74 | } 75 | *_params = params; 76 | } 77 | 78 | static void setup_videolfb_tag(struct tag **_params, struct board *b) 79 | { 80 | struct tag *params = *_params; 81 | 82 | if (!b->fb.size) 83 | return; 84 | 85 | /* An ATAG_VIDEOLFB node tells the kernel where and how large 86 | * the framebuffer for video was allocated (among other things). 87 | * Note that a _physical_ address is passed ! 88 | * 89 | * We only use it to pass the address and size, the other entries 90 | * in the tag_videolfb are not of interest. 91 | */ 92 | params->hdr.tag = ATAG_VIDEOLFB; 93 | params->hdr.size = tag_size(tag_videolfb); 94 | params->u.videolfb.lfb_base = b->fb.base; 95 | 96 | /* Fb size is calculated according to parameters for our panel 97 | */ 98 | params->u.videolfb.lfb_size = b->fb.size; 99 | params = tag_next(params); 100 | *_params = params; 101 | } 102 | 103 | static void setup_serial_tag(struct tag **_params, struct board *b) 104 | { 105 | struct tag *params = *_params; 106 | if (!(b->serial.high + b->serial.low)) 107 | return; 108 | params->hdr.tag = ATAG_SERIAL; 109 | params->hdr.size = tag_size(tag_serialnr); 110 | params->u.serialnr.low = b->serial.low; 111 | params->u.serialnr.high = b->serial.high; 112 | params = tag_next(params); 113 | *_params = params; 114 | } 115 | 116 | static void setup_revision_tag(struct tag **_params, struct board *b) 117 | { 118 | struct tag *params = *_params; 119 | if (!b->board_rev) 120 | return; 121 | params->hdr.tag = ATAG_REVISION; 122 | params->hdr.size = tag_size(tag_revision); 123 | params->u.revision.rev = b->board_rev; 124 | params = tag_next(params); 125 | *_params = params; 126 | } 127 | 128 | #if 0 129 | static void setup_initrd_tag(struct tag **_params, u32 initrd_start, 130 | u32 initrd_end) 131 | { 132 | struct tag *params = *_params; 133 | 134 | /* an ATAG_INITRD node tells the kernel where the compressed 135 | * ramdisk can be found. ATAG_RDIMG is a better name, actually. 136 | */ 137 | params->hdr.tag = ATAG_INITRD2; 138 | params->hdr.size = tag_size(tag_initrd); 139 | params->u.initrd.start = initrd_start; 140 | params->u.initrd.size = initrd_end - initrd_start; 141 | params = tag_next(params); 142 | *_params = params; 143 | } 144 | #endif 145 | 146 | static void setup_commandline_tag(struct tag **_params, struct board *b) 147 | { 148 | char *p; 149 | struct tag *params = *_params; 150 | char *commandline = b->bootargs; 151 | if (!commandline) 152 | return; 153 | 154 | /* eat leading white space */ 155 | for (p = commandline; *p == ' '; p++) ; 156 | 157 | /* skip non-existent command lines so the kernel will still 158 | * use its default command line. 159 | */ 160 | if (*p == '\0') 161 | return; 162 | params->hdr.tag = ATAG_CMDLINE; 163 | params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 4) >> 2; 164 | strcpy(params->u.cmdline.cmdline, p); 165 | params = tag_next(params); 166 | *_params = params; 167 | } 168 | 169 | static void setup_end_tag(struct tag **_params) 170 | { 171 | struct tag *params = *_params; 172 | params->hdr.tag = ATAG_NONE; 173 | params->hdr.size = 0; 174 | params = ((struct tag *)(((u8 *)(params)) +sizeof(struct tag_header))); 175 | *_params = params; 176 | } 177 | 178 | static int generate_tag(unsigned char *buffer, struct board *b) 179 | { 180 | struct tag *param = (struct tag *)buffer; 181 | setup_start_tag(¶m); 182 | setup_serial_tag(¶m, b); 183 | setup_revision_tag(¶m, b); 184 | setup_memory_tags(¶m, b); 185 | setup_commandline_tag(¶m, b); 186 | #if 0 187 | setup_initrd_tag(b, images->rd_start, images->rd_end); 188 | #endif 189 | setup_videolfb_tag(¶m, b); 190 | setup_end_tag(¶m); 191 | return (u32) param - (u32) buffer; 192 | } 193 | 194 | static struct board myboard; 195 | static struct compare_map variable_map[] = { 196 | /* *INDENT-OFF* */ 197 | {"board.mach_id", &myboard.mach_id, TYPE_U32}, 198 | {"board.board_rev",&myboard.board_rev, TYPE_U32}, 199 | {"board.bootargs", myboard.bootargs,TYPE_S}, 200 | {"board.ram0.start", &myboard.ram[0].start, TYPE_U32}, 201 | {"board.ram0.size", &myboard.ram[0].size, TYPE_U32}, 202 | {"board.ram1.start", &myboard.ram[1].start, TYPE_U32}, 203 | {"board.ram1.size", &myboard.ram[1].size, TYPE_U32}, 204 | {"board.fb.base", &myboard.fb.base, TYPE_U32}, 205 | {"board.fb.size", &myboard.fb.size, TYPE_U32}, 206 | {"board.serial.high", &myboard.serial.high, TYPE_U32}, 207 | {"board.serial.low", &myboard.serial.low, TYPE_U32}, 208 | {"board.sty_file", myboard.sty_file, TYPE_S}, 209 | /* *INDENT-ON* */ 210 | }; 211 | 212 | /** 213 | * @brief usage - help info 214 | * 215 | * @param appname my name 216 | * @param extend extended help 217 | */ 218 | static void usage(char *appname, int extend) 219 | { 220 | int i; 221 | struct compare_map *c = NULL; 222 | printf("App description:\n" 223 | "---------------\n" 224 | "generates a formatted image which may be used for\n" 225 | "nand, onenand or mmc boot on a OMAP GP device.\n" 226 | "This can also add a configuration header which\n" 227 | "allows for preconfiguration of various clock,ram\n" 228 | "GPMC or MMC settings prior to the image starting.\n" 229 | "Syntax:\n" 230 | "%s [-" CONFIG_FILE_ARG " config file] [-" 231 | IMAGE_FILE_ARG " input_file] [-?]\n" 232 | "Where:\n" 233 | "------\n" 234 | " -" CONFIG_FILE_ARG " config_file: configuration file" 235 | "[Default none]\n" 236 | " -" IMAGE_FILE_ARG " input_file: input binary to sign " 237 | "[Default zImage]\n" 238 | " -? : provide extended help including a sample config file\n" 239 | "------\n", appname); 240 | REVPRINT(); 241 | LIC_PRINT(); 242 | COLOR_PRINT(GREEN, OMAP_UBOOT_UTILS_LICENSE 243 | "\nThis uses http://liblcfg.carnivore.it/ (libcfg)for parsing " 244 | "configuration files\n" 245 | "Copyright (c) 2007--2009 Paul Baecher\n" 246 | "This program is free software; you can redistribute it and/or\n" 247 | "modify it under the terms of the GNU General Public License\n" 248 | "as published by the Free Software Foundation; either version\n" 249 | "2 of the License, or (at your option) any later version.\n"); 250 | if (extend) { 251 | char line[62]; 252 | memset(line, '-', sizeof(line)); 253 | line[sizeof(line) - 1] = 0; 254 | printf("\nExtended help\n" "---------------\n" 255 | "Configuration options used from config file:\n"); 256 | printf("+%s+\n| %-49s | %7s |\n+%s+\n", line, 257 | "Section.Variable_name", "size", line); 258 | for (i = 0; 259 | i < sizeof(variable_map) / sizeof(struct compare_map); 260 | i++) { 261 | c = &variable_map[i]; 262 | printf("| %-49s | %7s |\n", c->name, 263 | (c->type == TYPE_U32) ? "32bit" : (c->type == 264 | TYPE_U16) ? 265 | "16bit" : (c->type == TYPE_U8) ? "8bit": "String"); 266 | } 267 | printf("+%s+\n", line); 268 | } 269 | } 270 | 271 | int main(int argc, char **argv) 272 | { 273 | char *ifname, ofname[FILENAME_MAX], *cfile, ch; 274 | FILE *ifile, *ofile, *sty_file; 275 | unsigned long len, tlen; 276 | struct stat sinfo; 277 | int c; 278 | char *appname = argv[0]; 279 | unsigned char buffer[1024]; 280 | int i; 281 | 282 | /* Default to zImage */ 283 | ifname = "zImage"; 284 | cfile = NULL; 285 | 286 | while ((c = 287 | getopt(argc, argv, 288 | CONFIG_FILE_ARG ":" IMAGE_FILE_ARG ":")) != -1) 289 | switch (c) { 290 | case CONFIG_FILE_ARG_C: 291 | cfile = optarg; 292 | break; 293 | case IMAGE_FILE_ARG_C: 294 | ifname = optarg; 295 | break; 296 | case '?': 297 | i = 0; 298 | if ((optopt == IMAGE_FILE_ARG_C) 299 | || (optopt == CONFIG_FILE_ARG_C)) { 300 | APP_ERROR("Option -%c requires an argument.\n", 301 | optopt); 302 | } else if (optopt == '?') { 303 | APP_ERROR("EXTENDED help\n") 304 | i = 1; 305 | } else if (isprint(optopt)) { 306 | APP_ERROR("Unknown option `-%c'.\n", optopt) 307 | } else { 308 | APP_ERROR("Unknown option character `\\x%x'.\n", 309 | optopt) 310 | } 311 | usage(appname, i); 312 | return 1; 313 | default: 314 | abort(); 315 | } 316 | /* 317 | * reset the struct params 318 | * This is completely uneccesary in most cases, but I like being 319 | * paranoid 320 | */ 321 | memset(&myboard, 0, sizeof(struct board)); 322 | /* Parse the configuration header */ 323 | if (cfile != NULL) { 324 | /* parse Configuration file */ 325 | struct lcfg *c = lcfg_new(cfile); 326 | enum lcfg_status stat; 327 | if (!c) { 328 | APP_ERROR("Config file %s init failed\n", cfile) 329 | usage(appname, 0); 330 | return -2; 331 | } 332 | stat = lcfg_parse(c); 333 | if (stat == lcfg_status_ok) { 334 | variable_map_g = variable_map; 335 | size_var_map = 336 | sizeof(variable_map) / sizeof(struct compare_map); 337 | lcfg_accept(c, compare_eventhandler, 0); 338 | } else { 339 | APP_ERROR("Config file %s: %s\n", cfile, 340 | lcfg_error_get(c)) 341 | } 342 | lcfg_delete(c); 343 | if (stat != lcfg_status_ok) { 344 | usage(appname, 1); 345 | return -3; 346 | } 347 | } 348 | 349 | /* Form the output file name. */ 350 | strcpy(ofname, ifname); 351 | strcat(ofname, ".tag"); 352 | 353 | sty_file = fopen(myboard.sty_file, "rb"); 354 | if (sty_file == NULL) { 355 | APP_ERROR("Cannot open Styfile %s in cfile %s\n", 356 | myboard.sty_file, cfile); 357 | usage(appname, 0); 358 | return -3; 359 | } 360 | /* Open the input file. */ 361 | ifile = fopen(ifname, "rb"); 362 | if (ifile == NULL) { 363 | APP_ERROR("Cannot open %s\n", ifname); 364 | usage(appname, 0); 365 | return -3; 366 | } 367 | /* Open the output file and write it. */ 368 | ofile = fopen(ofname, "wb"); 369 | if (ofile == NULL) { 370 | APP_ERROR("Cannot open %s\n", ofname); 371 | fclose(ifile); 372 | exit(0); 373 | } 374 | 375 | /* lets first generate the tag */ 376 | tlen = generate_tag(buffer, &myboard); 377 | /* 1. Fill up the sty */ 378 | stat(myboard.sty_file, &sinfo); 379 | len = sinfo.st_size; 380 | for (i = 0; i < (len/4); i++) { 381 | u32 sty_val = 0; 382 | int z = fread(&sty_val, 4, 1, sty_file); 383 | if (!z) 384 | APP_ERROR("Styfile:%s no data?%d 0x%04X\n", 385 | myboard.sty_file, z, sty_val) 386 | switch (sty_val) { 387 | case MAGIC_MACHID: 388 | sty_val = myboard.mach_id; 389 | break; 390 | case MAGIC_INTERIMSIZE: 391 | sty_val = tlen; 392 | break; 393 | } 394 | fwrite(&sty_val, 4, 1, ofile); 395 | } 396 | fclose(sty_file); 397 | 398 | /* 2: Fill up the ATAG */ 399 | fwrite(buffer, 1, tlen, ofile); 400 | 401 | /* 3. Fill in the zImage */ 402 | stat(ifname, &sinfo); 403 | len = sinfo.st_size; 404 | for (i = 0; i < len; i++) { 405 | int z = fread(&ch, 1, 1, ifile); 406 | if (!z) 407 | APP_ERROR("no data?\n"); 408 | fwrite(&ch, 1, 1, ofile); 409 | } 410 | fclose(ifile); 411 | 412 | fclose(ofile); 413 | return 0; 414 | } 415 | -------------------------------------------------------------------------------- /src/ucmd.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tiny little app which sends a command to uboot and waits 4 | * for a response 5 | * 6 | * FileName: src/ucmd.c 7 | * 8 | * This sends a command to the serial port for uboot and exepects a 9 | * matching response 10 | * 11 | */ 12 | /* 13 | * (C) Copyright 2008-2009 14 | * Texas Instruments, 15 | * Nishanth Menon 16 | * 17 | * This program is free software; you can redistribute it and/or modify it 18 | * under the terms of the GNU General Public License as published by the 19 | * Free Software Foundation version 2. 20 | * 21 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 22 | * whether express or implied; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | * General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 29 | * MA 02111-1307 USA 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "rev.h" 38 | #include "serial.h" 39 | 40 | #define PORT_ARG "p" 41 | #define PORT_ARG_C 'p' 42 | #define CMD_ARG "c" 43 | #define CMD_ARG_C 'c' 44 | #define EXP_ARG "e" 45 | #define EXP_ARG_C 'e' 46 | 47 | /** 48 | * @brief send_cmd - send the command to uboot 49 | * 50 | * @param cmd - command to send 51 | * 52 | * @return - result 53 | */ 54 | static int send_cmd(char *cmd) 55 | { 56 | int ret = 0; 57 | char *buffer; 58 | int len = strlen(cmd); 59 | buffer = calloc(len + 2, 1); 60 | if (buffer == NULL) { 61 | APP_ERROR("failed to allocate %d bytes\n", len + 2) 62 | perror("fail reason:"); 63 | return SERIAL_FAILED; 64 | } 65 | /* The command */ 66 | strcpy(buffer, cmd); 67 | /* The enter key */ 68 | strcat(buffer, "\n"); 69 | 70 | ret = s_write((unsigned char *)buffer, strlen(buffer)); 71 | free(buffer); 72 | if (ret < 0) 73 | return SERIAL_FAILED; 74 | return SERIAL_OK; 75 | } 76 | 77 | /** 78 | * @brief get_response - get the response from uboot 79 | * 80 | * @param expected - expected string from uboot 81 | * 82 | * @return -match or fail 83 | */ 84 | static int get_response(char *expected) 85 | { 86 | int match_idx = 0; 87 | int len = strlen(expected); 88 | char current_char; 89 | int ret = 0; 90 | while (match_idx < len) { 91 | ret = s_getc(); 92 | if (ret < 0) { 93 | APP_ERROR("Failed to read character\n") 94 | return ret; 95 | } 96 | current_char = (char)ret; 97 | if (current_char == expected[match_idx]) { 98 | match_idx++; 99 | } else 100 | match_idx = 0; 101 | /* Dump the character to user screen */ 102 | printf("%c", current_char); 103 | fflush(stdout); 104 | } 105 | /* Hoorah!! match found */ 106 | return 0; 107 | 108 | } 109 | 110 | /** 111 | * @brief usage - help info 112 | * 113 | * @param appname my name 114 | */ 115 | static void usage(char *appname) 116 | { 117 | #ifdef __WIN32__ 118 | #define PORT_NAME "COM1" 119 | #else 120 | #define PORT_NAME "/dev/ttyS0" 121 | #endif 122 | printf("App description:\n" 123 | "---------------\n" 124 | "This sends a command and expects a provided matching response " 125 | "from target\n\n" 126 | "Syntax:\n" 127 | "------\n" 128 | "%s -" PORT_ARG " portName -" CMD_ARG " \"command to send\" -" 129 | EXP_ARG " \"Expect String\"\n\n" 130 | "Where:\n" "-----\n" 131 | "portName - RS232 device being used. Example: " PORT_NAME "\n" 132 | "command to send - Command to send to uboot\n" 133 | "Expect string - String to expect from target - on match" 134 | " the application returns\n" 135 | "Usage Example:\n" "-------------\n" 136 | "%s -" PORT_ARG " " PORT_NAME " -" CMD_ARG " \"help\" -" EXP_ARG 137 | " \"U-Boot>\"\n", appname, appname); 138 | REVPRINT(); 139 | LIC_PRINT(); 140 | } 141 | 142 | /** 143 | * @brief main application entry 144 | * 145 | * @param argc 146 | * @param *argv 147 | * 148 | * @return pass/fail 149 | */ 150 | int main(int argc, char **argv) 151 | { 152 | signed char ret = 0; 153 | char *port = NULL; 154 | char *command = NULL; 155 | char *expect = NULL; 156 | char *appname = argv[0]; 157 | int c; 158 | /* Option validation */ 159 | opterr = 0; 160 | 161 | while ((c = 162 | getopt(argc, argv, PORT_ARG ":" CMD_ARG ":" EXP_ARG ":")) != -1) 163 | switch (c) { 164 | case PORT_ARG_C: 165 | port = optarg; 166 | break; 167 | case CMD_ARG_C: 168 | command = optarg; 169 | break; 170 | case EXP_ARG_C: 171 | expect = optarg; 172 | break; 173 | case '?': 174 | if ((optopt == CMD_ARG_C) || (optopt == EXP_ARG_C) 175 | || (optopt == PORT_ARG_C)) { 176 | APP_ERROR("Option -%c requires an argument.\n", 177 | optopt) 178 | } else if (isprint(optopt)) { 179 | APP_ERROR("Unknown option `-%c'.\n", optopt) 180 | } else { 181 | APP_ERROR("Unknown option character `\\x%x'.\n", 182 | optopt) 183 | } 184 | usage(appname); 185 | return 1; 186 | default: 187 | abort(); 188 | } 189 | if ((port == NULL) || (command == NULL) || (expect == NULL)) { 190 | APP_ERROR("Error: Not Enough Args\n") 191 | usage(appname); 192 | return -1; 193 | } 194 | 195 | /* Setup the port */ 196 | ret = s_open(port); 197 | if (ret != SERIAL_OK) { 198 | APP_ERROR("serial open failed\n") 199 | return ret; 200 | } 201 | ret = s_configure(115200, NOPARITY, ONE_STOP_BIT, 8); 202 | if (ret != SERIAL_OK) { 203 | s_close(); 204 | APP_ERROR("serial configure failed\n") 205 | return ret; 206 | } 207 | 208 | /* Dump all previous data */ 209 | ret = s_flush(NULL, NULL); 210 | if (ret != SERIAL_OK) { 211 | s_close(); 212 | APP_ERROR("Failed to flush data\n") 213 | return ret; 214 | } 215 | /* send the command to uboot */ 216 | ret = send_cmd(command); 217 | if (ret != SERIAL_OK) { 218 | s_close(); 219 | APP_ERROR("Failed to send command '%s'\n", command) 220 | return ret; 221 | } 222 | 223 | printf("Output:\n"); 224 | /* Wait for the response to come from target */ 225 | ret = get_response(expect); 226 | if (ret != SERIAL_OK) { 227 | s_close(); 228 | APP_ERROR("Failed to get expected '%s'\n", expect) 229 | return ret; 230 | } 231 | 232 | ret = s_close(); 233 | if (ret != SERIAL_OK) { 234 | APP_ERROR("serial close failed\n") 235 | return ret; 236 | } 237 | printf("\nMatch Found. Operation completed!\n"); 238 | 239 | return ret; 240 | } 241 | -------------------------------------------------------------------------------- /src/ukermit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Reverse of kermit protocol implemented by uboot 4 | * 5 | * FileName: src/ukermit.c 6 | * 7 | * Ref: http://git.denx.de/?p=u-boot/u-boot-v2.git;f=commands/loadb.c;hb=HEAD 8 | * 9 | * Much of this code is based on loadb.c in U-Boot. This provides the 10 | * reverse logic of providing data packets alone to the host. we support 11 | * Kermit Data packet format only. 12 | * Typical usage is to run loadb in uboot, close the same and run this app 13 | * 14 | * Kermit Protocol consists of multiple packets flowing back and froth b/w 15 | * a Host a client. First implemented by columbia university can be seen here: 16 | * http://www.columbia.edu/kermit/ 17 | * 18 | * Motivation: 19 | * 20 | * For a full fledged implementation, look for ckermit(Linux), kermit95(win), 21 | * gkermit or ekermit. Many terminal applications such as Hyperterminal(win) 22 | * support kermit. However, in many cases, users desire to have a simple app 23 | * which can send data to uboot by exploiting the crc checks over serial. 24 | * 25 | * Details: 26 | * 27 | * This code is written by reversing the sequence of data reception expected by 28 | * U-Boot. it may not be compatible with standard kermit protocol 29 | * 30 | * Kermit protocol in it's simplest form is described as a transmission 31 | * followed by a end of transmission character. Each transmission consists of 32 | * multiple packets. Each packet can be a session initiation, data packet or 33 | * many other packet types. This application supports only sending data packets. 34 | * So, it is not complete on it's own, but this is fine, since U-Boot cares only 35 | * for data packets. 36 | * 37 | * Every packet is an individual entity of it's own. Every packet has a start 38 | * and end packet marker. Data packets come in two flavors - large packets and 39 | * small packets. Data packets have their own header kermit_data_header_small 40 | * structure shows how it looks like. Following the header, there is a bunch of 41 | * data bytes which end with a CRC and end character. 42 | * 43 | * The data bytes could create confusing state for kermit protocol, hence the 44 | * control characters are specially encoded by the protocol. encoding is simple: 45 | * an escape character is prefixed to characters which are specially encoded. 46 | * 47 | * If the reciever gets the packet properly, it acknowledges the receipt of 48 | * packet. The kermit_ack_nack_type packet describes how it looks like. If a 49 | * NAK(negative acknowledgement) or the recieved ack packet itself is corrupted, 50 | * the transmitter retries the old packet. 51 | * 52 | * The packet sequence number allows for the sender and reciever to keep track 53 | * of the packet flow sequence. 54 | */ 55 | /* 56 | * 57 | * (C) Copyright 2008-2009 58 | * Texas Instruments, 59 | * Nishanth Menon 60 | * 61 | * (C) Copyright 2000-2004 62 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 63 | * 64 | * See file CREDITS for list of people who contributed to this 65 | * project. 66 | * 67 | * This program is free software; you can redistribute it and/or 68 | * modify it under the terms of the GNU General Public License as 69 | * published by the Free Software Foundation; either version 2 of 70 | * the License, or (at your option) any later version. 71 | * 72 | * This program is distributed in the hope that it will be useful, 73 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 74 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 75 | * GNU General Public License for more details. 76 | * 77 | * You should have received a copy of the GNU General Public License 78 | * along with this program; if not, write to the Free Software 79 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 80 | * MA 02111-1307 USA 81 | */ 82 | #ifdef __WIN32__ 83 | #include /* for sleep() in dos/mingw */ 84 | #endif 85 | 86 | #include 87 | #include 88 | #include 89 | #include 90 | #include 91 | #include "rev.h" 92 | #include "serial.h" 93 | #include "file.h" 94 | #include "f_status.h" 95 | 96 | #define XON_CHAR 17 97 | #define XOFF_CHAR 19 98 | #define START_CHAR 0x01 99 | #define ETX_CHAR 0x03 100 | #define END_CHAR 0x0D 101 | #define SPACE 0x20 102 | #define K_ESCAPE 0x23 103 | #define SEND_TYPE 'S' 104 | #define DATA_TYPE 'D' 105 | #define ACK_TYPE 'Y' 106 | #define NACK_TYPE 'N' 107 | #define BREAK_TYPE 'B' 108 | #define tochar(x) ((char) (((x) + SPACE) & 0xff)) 109 | #define untochar(x) ((int) (((x) - SPACE) & 0xff)) 110 | #define escape_it(ch) ((ch) ^ 0x40 ) 111 | 112 | #define SEQ_ERROR 0x40 113 | #define CHK_ERROR 0x41 114 | 115 | /* Enable Large packet transfers? */ 116 | #undef LARGE_PACKETS_ENABLE 117 | 118 | #ifdef CONSOLE_TEST 119 | /* Debugging */ 120 | #define console_getc() getc(stdin) 121 | #define console_putc(x) printf ("->0x%02X[%c]0x%x\n",(x)&0xFF,(x)&0xFF,\ 122 | ((x>=SPACE)?untochar(x):x)) 123 | #endif 124 | 125 | /* use page sized chunks */ 126 | #ifdef LARGE_PACKETS_ENABLE 127 | #define MAX_CHUNK 500 128 | #else 129 | #define MAX_CHUNK 100 130 | #endif 131 | #define RETRY_MAX 4 132 | #define PRINT_SIZE 100 133 | 134 | #define PORT_ARG "p" 135 | #define PORT_ARG_C 'p' 136 | #define DNLD_ARG "f" 137 | #define DNLD_ARG_C 'f' 138 | #define DLY_ARG "d" 139 | #define DLY_ARG_C 'd' 140 | #define SILENT_STAT_ARG "q" 141 | #define SILENT_STAT_C 'q' 142 | 143 | #ifdef LARGE_PACKETS_ENABLE 144 | struct kermit_data_header_large { 145 | unsigned char start; 146 | unsigned char length_normal; 147 | unsigned char sequence_number; 148 | unsigned char packet_type; 149 | unsigned char length_hi; 150 | unsigned char length_lo; 151 | unsigned char header_checksum; 152 | }; 153 | #endif 154 | 155 | /** 156 | * Kermit data packet header 157 | */ 158 | struct kermit_data_header_small { 159 | unsigned char start; 160 | unsigned char length_normal; 161 | unsigned char sequence_number; 162 | unsigned char packet_type; 163 | }; 164 | 165 | /** 166 | * Kermit ack packet type 167 | */ 168 | struct kermit_ack_nack_type { 169 | /** start marker */ 170 | unsigned char start; 171 | unsigned char length_norm; 172 | unsigned char sequence_number; 173 | unsigned char packet_type; 174 | unsigned char checksum; 175 | /** end marker */ 176 | unsigned char eol; 177 | }; 178 | 179 | static unsigned int delay; 180 | /** 181 | * @brief s1_getpacket - get a packet from the target 182 | * s_read is expected to be blocking in this case 183 | * @param packet - the buffer to which data is stored 184 | * @param size the size of the packet 185 | */ 186 | static void s1_getpacket(char *packet, int size) 187 | { 188 | #ifdef CONSOLE_TEST 189 | while (size) { 190 | *packet = console_getc(); 191 | packet++; 192 | size--; 193 | } 194 | #else 195 | memset((void *)packet, 0x00, size); 196 | if (delay) 197 | #ifndef __WIN32__ 198 | usleep(1000 * delay); 199 | #else 200 | Sleep(delay); 201 | #endif 202 | s_read((unsigned char *)packet, size); 203 | #endif 204 | } 205 | 206 | /** 207 | * @brief s1_sendpacket - send a data packet to the target 208 | * 209 | * @param packet - buffer containing the data buffer 210 | * @param size - size of the buffer 211 | */ 212 | static void s1_sendpacket(char *packet, int size) 213 | { 214 | #ifdef CONSOLE_TEST 215 | while (size) { 216 | console_putc(*packet); 217 | packet++; 218 | size--; 219 | } 220 | #else 221 | s_write((unsigned char *)packet, size); 222 | #endif 223 | } 224 | 225 | #ifdef DEBUG 226 | /* Converts escaped kermit char to binary char 227 | * This is from loadb.c in U-Boot 228 | */ 229 | static char ktrans(char in) 230 | { 231 | if ((in & 0x60) == 0x40) { 232 | return (char)(in & ~0x40); 233 | } else if ((in & 0x7f) == 0x3f) { 234 | return (char)(in | 0x40); 235 | } else 236 | return in; 237 | } 238 | #endif 239 | 240 | /** 241 | * @brief should_escape - decides if a binary character should be escaped 242 | * as per kermit protocol 243 | * 244 | * Escape is a concept which prefixes '#' in front of a converted character 245 | * The idea is to deny CONTROL characters from going over serial port directly. 246 | * so all characters 0 to 31 and 127 ASCII code is considered control 247 | * characters 248 | * 249 | * @param out - character to be analyzed 250 | * 251 | * @return -1 if it should be escaped, else 0 252 | */ 253 | static int should_escape(char out) 254 | { 255 | char a = out & 0x7F; /* Get low 7 bits of character */ 256 | /* If data is control prefix, OR 257 | * Data is the escape character itself 258 | */ 259 | if ((a < SPACE || a == 0x7F) 260 | || (a == K_ESCAPE)) 261 | return 1; 262 | return 0; 263 | } 264 | 265 | /** 266 | * @brief k_escape - provide escape character convertion 267 | * 268 | * @param out - character to be escaped 269 | * 270 | * @return -escaped character 271 | */ 272 | static char k_escape(char out) 273 | { 274 | char a = out & 0x7F; /* Get low 7 bits of character */ 275 | if (a != K_ESCAPE) 276 | out = escape_it(out); /* and make character printable. */ 277 | /* Escape character send as is */ 278 | return out; 279 | } 280 | 281 | /** 282 | * @brief k_send_data_packet_small - send a small data packet 283 | * 284 | * Kermit protocol allows for two types of data packets ->small and large. 285 | * This function sends a small packet to the target. the identification of a 286 | * small packet is if length_normal ==0 in which case length_hi and lo are 287 | * used from k_large structure. 288 | * 289 | * @param buffer - buffer to send 290 | * @param size -size of the buffer to send 291 | * @param sequence - sequence number of the transmission. 292 | * 293 | * @return success/fail 294 | */ 295 | static signed int k_send_data_packet_small(unsigned char *buffer, 296 | unsigned int size, 297 | unsigned char sequence) 298 | { 299 | struct kermit_data_header_small k_small; 300 | int sum = 0; 301 | int count = 0; 302 | int new_size = 0; 303 | /* Allocation assuming all need escape characters.. */ 304 | char *my_new_buffer = calloc(1, (size * 2) + 3); 305 | if (my_new_buffer == NULL) { 306 | APP_ERROR("failed to allocate memory \n") 307 | perror(NULL); 308 | return -1; 309 | } 310 | memset(&k_small, 0, sizeof(struct kermit_data_header_small)); 311 | k_small.start = START_CHAR; 312 | k_small.sequence_number = tochar(sequence); 313 | k_small.packet_type = DATA_TYPE; 314 | while (count < size) { 315 | 316 | /* handle kermit escape character in buffer */ 317 | if (should_escape(*(buffer + count))) { 318 | *(my_new_buffer + new_size) = K_ESCAPE; 319 | sum += *(my_new_buffer + new_size); 320 | new_size++; 321 | *(my_new_buffer + new_size) = 322 | k_escape(*(buffer + count)); 323 | #ifdef DEBUG 324 | printf("escape - Ori=0x%x New = 0x%x ReTrans=0x%x\n", 325 | (0xFF) & (*(buffer + count)), 326 | (0xFF) & *(my_new_buffer + new_size), 327 | (0xFF) & ktrans(*(my_new_buffer + new_size))); 328 | #endif 329 | } else 330 | *(my_new_buffer + new_size) = (*(buffer + count)); 331 | 332 | #ifdef DEBUG 333 | printf("**>[%d]-%d 0x%02x 0x%02x[%c]\n", count, new_size, 334 | (char)*(buffer + count), 335 | (char)*(my_new_buffer + new_size), 336 | (char)*(my_new_buffer + new_size)); 337 | #endif 338 | sum += *(my_new_buffer + new_size); 339 | count++; 340 | new_size++; 341 | } 342 | /* Add to cover for sequence, packet type and checksum */ 343 | k_small.length_normal = tochar((new_size) + 3); 344 | sum += 345 | k_small.length_normal + k_small.sequence_number + 346 | k_small.packet_type; 347 | /* Store the checksum for the packet */ 348 | *(my_new_buffer + new_size) = 349 | tochar((sum + ((sum >> 6) & 0x03)) & 0x3f); 350 | new_size++; 351 | /* Add end character */ 352 | *(my_new_buffer + new_size) = END_CHAR; 353 | new_size++; 354 | #ifdef DEBUG 355 | { 356 | int i = 0; 357 | char *buf = (char *)&k_small; 358 | 359 | printf("ksmall\n"); 360 | for (i = 0; i < sizeof(k_small); i++) { 361 | printf("k_small[%d]=0x%x[%c]-%d\n", i, (char)buf[i], 362 | (char)buf[i], untochar(buf[i])); 363 | } 364 | printf("buffer\n"); 365 | for (i = 0; i < new_size; i++) { 366 | printf("buff[%d]=0x%02x[%c]-%d\n", i, 367 | (char)my_new_buffer[i], (char)my_new_buffer[i], 368 | untochar(my_new_buffer[i])); 369 | } 370 | } 371 | #endif 372 | s1_sendpacket((char *)&k_small, sizeof(k_small)); 373 | s1_sendpacket(my_new_buffer, new_size); 374 | free(my_new_buffer); 375 | 376 | return 0; 377 | } 378 | 379 | #ifdef LARGE_PACKETS_ENABLE 380 | /** 381 | * @brief k_send_data_packet_large - send a large data packet 382 | * 383 | * Kermit protocol allows for two types of data packets ->small and large. 384 | * This function sends a large packet to the target. the identification of a 385 | * large packet is if length_normal ==0 in which case length_hi and lo are 386 | * used from k_large structure. 387 | * 388 | * @param buffer - buffer to send 389 | * @param size -size of the buffer to send 390 | * @param sequence - sequence number of the transmission. 391 | * 392 | * @return success/fail 393 | */ 394 | static signed int k_send_data_packet_large(unsigned char *buffer, 395 | unsigned int size, 396 | unsigned char sequence) 397 | { 398 | struct kermit_data_header_large k_large; 399 | int sum = 0; 400 | int sum_pkt = 0; 401 | int count = 0; 402 | int new_size = 0; 403 | /* Allocation assuming all need escape characters.. */ 404 | char *my_new_buffer = calloc(1, (size * 2) + 3); 405 | if (my_new_buffer == NULL) { 406 | APP_ERROR("failed to allocate memory \n") 407 | perror(NULL); 408 | return -1; 409 | } 410 | memset(&k_large, 0, sizeof(struct kermit_data_header_large)); 411 | k_large.start = START_CHAR; 412 | k_large.sequence_number = tochar(sequence); 413 | k_large.packet_type = DATA_TYPE; 414 | while (count < size) { 415 | 416 | /* handle kermit escape character in buffer */ 417 | if (should_escape(*(buffer + count))) { 418 | *(my_new_buffer + new_size) = K_ESCAPE; 419 | sum += *(my_new_buffer + new_size); 420 | new_size++; 421 | *(my_new_buffer + new_size) = 422 | k_escape(*(buffer + count)); 423 | #ifdef DEBUG 424 | printf("escape - Ori=0x%x New = 0x%x ReTrans=0x%x\n", 425 | (0xFF) & (*(buffer + count)), 426 | (0xFF) & *(my_new_buffer + new_size), 427 | (0xFF) & ktrans(*(my_new_buffer + new_size))); 428 | #endif 429 | } else 430 | *(my_new_buffer + new_size) = (*(buffer + count)); 431 | 432 | #ifdef DEBUG 433 | printf("**>[%d]-%d 0x%02x 0x%02x[%c]\n", count, new_size, 434 | (char)*(buffer + count), 435 | (char)*(my_new_buffer + new_size), 436 | (char)*(my_new_buffer + new_size)); 437 | #endif 438 | sum += *(my_new_buffer + new_size); 439 | count++; 440 | new_size++; 441 | } 442 | /* Add to cover checksum */ 443 | new_size += 1; 444 | k_large.length_normal = tochar(0x0); 445 | k_large.length_hi = new_size / 95; 446 | k_large.length_lo = new_size - (k_large.length_hi * 95); 447 | k_large.length_hi = tochar(k_large.length_hi); 448 | k_large.length_lo = tochar(k_large.length_lo); 449 | sum_pkt = 450 | k_large.length_normal + k_large.sequence_number + 451 | k_large.packet_type + k_large.length_lo + k_large.length_hi; 452 | k_large.header_checksum = 453 | tochar((sum_pkt + ((sum_pkt >> 6) & 0x03)) & 0x3f); 454 | new_size -= 1; 455 | sum += sum_pkt + k_large.header_checksum; 456 | /* Store the checksum for the packet */ 457 | *(my_new_buffer + new_size) = 458 | tochar((sum + ((sum >> 6) & 0x03)) & 0x3f); 459 | new_size++; 460 | /* Add end character */ 461 | *(my_new_buffer + new_size) = END_CHAR; 462 | new_size++; 463 | #ifdef DEBUG 464 | { 465 | int i = 0; 466 | char *buf = (char *)&k_large; 467 | 468 | printf("klarge\n"); 469 | for (i = 0; i < sizeof(k_large); i++) { 470 | printf("k_large[%d]=0x%x[%c]-%d\n", i, (char)buf[i], 471 | (char)buf[i], untochar(buf[i])); 472 | } 473 | printf("buffer\n"); 474 | for (i = 0; i < new_size; i++) { 475 | printf("buff[%d]=0x%02x[%c]-%d\n", i, 476 | (char)my_new_buffer[i], (char)my_new_buffer[i], 477 | untochar(my_new_buffer[i])); 478 | } 479 | } 480 | #endif 481 | s1_sendpacket((char *)&k_large, sizeof(k_large)); 482 | s1_sendpacket(my_new_buffer, new_size); 483 | free(my_new_buffer); 484 | 485 | return 0; 486 | } 487 | #endif 488 | 489 | /** 490 | * @brief print_ack_packet - Debug print of the ack packet from target 491 | * 492 | * @param k_ack -ack structure 493 | */ 494 | static void print_ack_packet(struct kermit_ack_nack_type *k_ack) 495 | { 496 | char *buffer = (char *)k_ack; 497 | int x = 0; 498 | printf("start = 0x%x\n", k_ack->start); 499 | printf("length =0x%x %d\n", k_ack->length_norm, 500 | untochar(k_ack->length_norm)); 501 | printf("sequence_num = 0x%x[%d]\n", k_ack->sequence_number, 502 | untochar(k_ack->sequence_number)); 503 | printf("packet_type = 0x%x[%c]\n", k_ack->packet_type, 504 | k_ack->packet_type); 505 | printf("checksum= 0x%x %d\n", k_ack->checksum, 506 | untochar(k_ack->checksum)); 507 | printf("eol = 0x%x\n", k_ack->eol); 508 | for (x = 0; x < sizeof(struct kermit_ack_nack_type); x++) 509 | printf("[%d] 0x%x [%c]\n", x, buffer[x], buffer[x]); 510 | 511 | } 512 | 513 | /** 514 | * @brief kermit_ack_type - Analyse the ack packet 515 | * 516 | * @param seq_num - sequence number expected 517 | * 518 | * @return - result 519 | */ 520 | static signed int kermit_ack_type(int seq_num) 521 | { 522 | struct kermit_ack_nack_type k_ack; 523 | int sum = 0; 524 | memset((void *)&k_ack, 0, sizeof(k_ack)); 525 | s1_getpacket((char *)&k_ack, sizeof(k_ack)); 526 | sum = k_ack.length_norm + k_ack.sequence_number + k_ack.packet_type; 527 | 528 | /* Check if this is a valid packet by checking checksum */ 529 | if (k_ack.checksum != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f)) { 530 | #ifdef DEBUG 531 | APP_ERROR("checksum mismatch\n") 532 | print_ack_packet(&k_ack); 533 | #endif 534 | return CHK_ERROR; 535 | } 536 | /* message for the right seq? */ 537 | if (untochar(k_ack.sequence_number) != seq_num) { 538 | APP_ERROR("sequence_num mismatch. expected [%d] Got %d\n", 539 | seq_num, untochar(k_ack.sequence_number)) 540 | #ifdef DEBUG 541 | print_ack_packet(&k_ack); 542 | #endif 543 | return SEQ_ERROR; 544 | } 545 | if (k_ack.packet_type == NACK_TYPE) { 546 | APP_ERROR("NACKed!!\n") 547 | return NACK_TYPE; 548 | } 549 | if (k_ack.packet_type == ACK_TYPE) { 550 | return ACK_TYPE; 551 | } 552 | /* other chars */ 553 | APP_ERROR("Unexpected packet type\n") 554 | print_ack_packet(&k_ack); 555 | return -3; 556 | } 557 | 558 | /** 559 | * @brief k_send_data - send a file to the target using kermit 560 | * 561 | * @param f_name - file name to send 562 | * 563 | * @return -success/failure 564 | */ 565 | static signed int k_send_data(char *f_name, int silent_status) 566 | { 567 | unsigned char sequence = 0; 568 | unsigned int send_size = MAX_CHUNK; 569 | unsigned char retry = 0; 570 | int ret = 0; 571 | signed long ori_size, size = 0; 572 | char done_transmit = ETX_CHAR; 573 | char buffer[MAX_CHUNK]; 574 | 575 | ori_size = size = f_size(f_name); 576 | 577 | if (size < 0) { 578 | APP_ERROR("File Size Operation failed! File exists?\n") 579 | return size; 580 | } 581 | if (f_open(f_name) != FILE_OK) { 582 | APP_ERROR("File Open failed!File Exists & readable?\n") 583 | return -1; 584 | } 585 | if (!silent_status) 586 | f_status_init(ori_size, NORMAL_PRINT); 587 | else 588 | COLOR_PRINT(BLUE, "Transfer start (%ld bytes)\n", ori_size); 589 | while (size) { 590 | send_size = (size > MAX_CHUNK) ? MAX_CHUNK : size; 591 | send_size = f_read((unsigned char *)buffer, send_size); 592 | if (send_size < 0) { 593 | APP_ERROR("Oops.. file read failed!\n") 594 | break; 595 | } 596 | retry = 0; 597 | /* we will retry packets to an extent! */ 598 | do { 599 | #ifdef LARGE_PACKETS_ENABLE 600 | if (send_size < 95) 601 | ret = k_send_data_packet_small((unsigned char *) 602 | buffer, 603 | send_size, 604 | sequence); 605 | else 606 | ret = k_send_data_packet_large((unsigned char *) 607 | buffer, 608 | send_size, 609 | sequence); 610 | #else 611 | ret = k_send_data_packet_small((unsigned char *) 612 | buffer, 613 | send_size, sequence); 614 | #endif 615 | if (ret < 0) { 616 | APP_ERROR("Failedin send\n") 617 | return ret; 618 | } 619 | ret = kermit_ack_type(sequence); 620 | if (ret < 0) { 621 | APP_ERROR("Failedin ack %d\n", ret) 622 | return ret; 623 | } 624 | if (ret != ACK_TYPE) { 625 | retry++; 626 | } 627 | } while ((ret != ACK_TYPE) && (retry < RETRY_MAX)); 628 | if (retry == RETRY_MAX) { 629 | APP_ERROR("Failed after %d retries in sequence %d - " 630 | "success send = %ld bytes\n", 631 | RETRY_MAX, sequence, (ori_size - size)) 632 | return -1; 633 | } 634 | sequence++; 635 | /* Roll over sequence number */ 636 | if (sequence > 0x7F) 637 | sequence = 0; 638 | 639 | size -= send_size; 640 | if (!silent_status) 641 | f_status_show(ori_size - size); 642 | } 643 | /* Send the completion char */ 644 | s1_sendpacket(&done_transmit, 1); 645 | if (f_close() != FILE_OK) { 646 | APP_ERROR("File Close failed\n") 647 | } 648 | if (silent_status) 649 | COLOR_PRINT(GREEN, "Transfer complete\n"); 650 | return 0; 651 | } 652 | 653 | /** 654 | * @brief usage help 655 | * 656 | * @param appname my application name 657 | * 658 | * @return none 659 | */ 660 | static void usage(char *appname) 661 | { 662 | #ifdef __WIN32__ 663 | #define PORT_NAME "COM1" 664 | #define F_NAME "c:\\temp\\u-boot.bin" 665 | #else 666 | #define PORT_NAME "/dev/ttyS0" 667 | #define F_NAME "~/tmp/u-boot.bin" 668 | #endif 669 | printf("App description:\n" 670 | "---------------\n" 671 | "This Application helps download a file" 672 | "using U-Boot's kermit protocol over serial port\n\n" 673 | "Syntax:\n" 674 | "------\n" 675 | "%s -" PORT_ARG " portName -" DNLD_ARG " fileToDownload" 676 | " [-" DLY_ARG " delay_time] [-" SILENT_STAT_ARG "]\n\n" 677 | "Where:\n" "-----\n" 678 | "portName - RS232 device being used. Example: " PORT_NAME "\n" 679 | "fileToDownload - file to be downloaded\n\n" 680 | "delay_time - delay time in ms for ack reciept(optional)\n\n" 681 | SILENT_STAT_ARG "- quiet status download status\n\n" 682 | "Usage Example:\n" "-------------\n" 683 | "%s -" PORT_ARG " " PORT_NAME " -" DNLD_ARG " " F_NAME "\n", 684 | appname, appname); 685 | REVPRINT(); 686 | LIC_PRINT(); 687 | } 688 | 689 | /** 690 | * @brief application entry 691 | * 692 | * @param argc -argument count 693 | * @param *argv - argument string 694 | * 695 | * @return fail/pass 696 | */ 697 | int main(int argc, char **argv) 698 | { 699 | char *port = NULL; 700 | char *download_file = NULL; 701 | char *appname = argv[0]; 702 | int c; 703 | int ret = 0; 704 | int silent = 0; 705 | 706 | /* Option validation */ 707 | opterr = 0; 708 | 709 | while ((c = 710 | getopt(argc, argv, 711 | DLY_ARG ":" PORT_ARG ":" DNLD_ARG ":" SILENT_STAT_ARG)) != -1) 712 | switch (c) { 713 | case DLY_ARG_C: 714 | sscanf(optarg, "%d", &delay); 715 | break; 716 | case PORT_ARG_C: 717 | port = optarg; 718 | break; 719 | case DNLD_ARG_C: 720 | download_file = optarg; 721 | break; 722 | case SILENT_STAT_C: 723 | silent = 1; 724 | break; 725 | case '?': 726 | if ((optopt == DNLD_ARG_C) || (optopt == PORT_ARG_C)) { 727 | APP_ERROR("Option -%c requires an argument.\n", 728 | optopt) 729 | } else if (isprint(optopt)) { 730 | APP_ERROR("Unknown option `-%c'.\n", optopt) 731 | } else { 732 | APP_ERROR("Unknown option character `\\x%x'.\n", 733 | optopt) 734 | } 735 | usage(appname); 736 | return 1; 737 | default: 738 | abort(); 739 | } 740 | if ((port == NULL) || (download_file == NULL)) { 741 | APP_ERROR("Error: Not Enough Args\n") 742 | usage(appname); 743 | return -1; 744 | } 745 | 746 | /* Setup the port */ 747 | ret = s_open(port); 748 | if (ret != SERIAL_OK) { 749 | APP_ERROR("serial open failed\n") 750 | return ret; 751 | } 752 | ret = s_configure(115200, NOPARITY, ONE_STOP_BIT, 8); 753 | if (ret != SERIAL_OK) { 754 | s_close(); 755 | APP_ERROR("serial configure failed\n") 756 | return ret; 757 | } 758 | 759 | s_flush(NULL, NULL); 760 | ret = k_send_data(download_file, silent); 761 | if (ret != 0) { 762 | s_close(); 763 | APP_ERROR("Data transmit failed\n") 764 | return ret; 765 | } 766 | ret = s_close(); 767 | if (ret != SERIAL_OK) { 768 | APP_ERROR("serial close failed\n") 769 | return ret; 770 | } 771 | printf("\nFile Download completed\n"); 772 | return 0; 773 | } 774 | --------------------------------------------------------------------------------