Allows you to easily debug the software download function in single-board security mode in Win32 environments.

Source: Internet
Author: User
Allows you to easily debug the software download function in single-board security mode in Win32 environments.Wen Huimin (wenhm@sina.com) Abstract:This article first introduces the low efficiency and complexity of software download debugging in a single board environment, and then analyzes the feasibility of debugging software download in a Win32 environment. The specific implementation process for debugging the software download function in Win32 environment is given. As it can be developed and debugged using a good ide such as VC ++ in Win32 environment, it also avoids the whole system upgrade process when the system is upgraded or broken, greatly improving the efficiency and providing great reference for projects that require the software download function development in the single board security mode. I. Question proposalThe local MCU project needs to download the secure mode software. The main program of this project is a single board program running on the idt438 chip. In the secure mode, the file system is ramdisk, that is, all file systems are stored in the memory, and all file operations are in the memory and will not be actually reflected in flash. Therefore, to save data to flash, you can only directly operate the flash partition device (standard character device. If this function is directly debugged on a single board, the following problems exist: l the Single Board can only be tracked and debugged through gdbserver, which is more difficult to debug. L there is no good way to check whether the data written to flash is correct. L writing error data is inevitable during the debugging phase (unless the program is not tested once, ^ _ ^). When the program writes error data to flash, the original data is damaged, after the system is restarted, it cannot be started. You can only upgrade the entire system. However, each overall upgrade takes a long time, greatly reducing the efficiency. Based on the above problems, in order to quickly and effectively complete this function, we decided to try whether debugging can be completed in the Win32 environment. After debugging is correct, we can test on the board, which can greatly shorten the development and debugging time. [1] Ii. Solution 2.1 Feasibility AnalysisRead/write operations on flash partitions on a single board are performed by performing MTD (memory technology device) operations. MTD devices use standard character device operation interfaces. You can perform read and write operations on the device files with the corresponding characters. That is to say, normal read and write operations on flash can be performed as normal files (Consistent positioning and read/write operations ), the differences between flash device operations and common file operations are as follows: 1) use special interfaces to obtain the flash partition size; 2) before writing an area, ensure that the area has been erased, only when the byte content is 0xff can the flash interface allow you to write data into it; 3) the erasure of a region is based on blocks, the block unit is the erasesize obtained through IOCTL. Similarly, an erase block is also implemented through IOCTL. [2] That is, the flash operation interfaces we need to use are different from the general file operations: l obtain the flash partition size, including the block size, the Interface Name Is flash_getsize (provided by the underlying driver ). L erase the Flash content of a region. The interface name is flash_erase (provided by the underlying driver ). Other operations use open, write, read, and other character device operation interfaces, as long as we implement two corresponding interfaces flash_getsize and flash_erase on the Win32 platform, we can run the flash code on the Win32 platform, on the Win32 platform, you can use file simulation as the MTD device on the board. 2.2 Implementation 2.2.1 interface implementationFor the Win32 implementation of the flash_getsize interface, the partition size returned by this function can be set to the operated file size; block Size because the operating system and driver on the board are fixed once the block value is customized, the block size is returned to the fixed block size on the board. The Win32 implementation of the flash_erase interface can be implemented to set all the bytes in the operated area to 0xff. After completing the above work, the logic code for operating flash can run on the Win32 platform, and the common file is used to simulate the reading and writing of the Single Board MTD device. On win32, you can use the VC ++ IDE environment for convenient debugging. open the file for the corresponding operation and directly view the binary content to see whether the content written to flash is correct. 2.2.2 precautionsIn Windows, the o_binary option must be added to the open binary file. Otherwise, the text file is opened by default, and the carriage return or line break will be replaced, resulting in inconsistent file content and written data. Iii. PracticeAfter completing all the preparations, you can start debugging the logic code of the flash operation in the Win32 environment. Because you can view the binary content of the corresponding file directly, you can easily view the written data, the following functions were quickly called: l set whether to enter the Secure Mode flag function at the next Startup l set the function of entering the work mode area by IP address l set the function of addressing a partition header in Flash l Image File Download function Iv. Performance EvaluationThe most important part of the Software downloading and updating function in security mode is to ensure that the data written to flash must be consistent with the content of the downloaded source file, you only need to use a binary file comparison tool to compare the files on the simulated MTD device that have completed the download operation with the source files to see if the download is completed correctly. If you verify this operation on a single board, you must restart the system. If you want the old Tianbao to be able to enter the system, you must upgrade the entire system again if you cannot access the system. This shows that the efficiency is remarkable. The entire debugging process can be completed in the VC ++ IDE environment, which is much more convenient than using gdbserver. Although many developers prefer to use the Win32 environment for programming, they like to write code using the VI editor in Linux and debug code using GDB, the emergence and popularization of the visual integrated development environment in Linux, such as kdevelop and magic C ++, is also due to the inconvenience of GDB debugging and the limitations of the VI editor. 5. Promotion suggestionsThis article is suitable for all projects that require flash read/write operations on a single board (except for common file operations with file systems), especially flash operations such as software upgrades in security mode, if the product code cannot be all transplanted to the Win32 environment, you only need to transplant the part of the flash logic code to the Win32 environment for testing. The author has the C ++ Implementation of the interface in section 2.2. If necessary, you can obtain it from the author. References[1]. Some suggestions from colleagues Li Chunsheng. [2]. http://www.linux-mtd.infradead.org/. Let's share some suggestions from Weidong and leiming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.