Online upgrade of embedded devices using MTD Tools

Source: Internet
Author: User

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Directory (?) [+]

The main idea is to pass the upgrade file to the CGI program via web post, and then upgrade the device online through the MTD tool.

1. Page section

<form target= "_blank" enctype= "multipart/form-data" method= "POST" action= "./update.cgi" >

<p> Select Upgrade File:

<input type= "file" value= "" name= "File" >

<input type= "Submit" value= "confirm" name= "savebasesetting" >

</p>

</form>

This section is mainly for the file to be upgraded to the server (to update.cgi) processing.

Note the Form form property:

1 The required Action property specifies where to send the form data when the form is submitted.

The 2 Enctype property specifies how the form data should be encoded before it is sent to the server.

Value

Describe

application/x-www-form-urlencoded

Encode all characters before sending (default)

Multipart/form-data

Character encoding is not.

Text/plain

Spaces are converted to "+" plus signs, but special characters are not encoded.

The 3 Method property specifies how the form data is sent (the form data is sent to the page specified by the Action property).

The form data can be sent as a URL variable (method= "get") or HttpPost (method= "POST").

Method property

The browser uses the method property setting to route data from the form to the server for processing. There are two methods: the POST method and the GET method.

If the POST method is used, the browser will send the data in the following two steps. First, the browser will contact the form processing server specified in the Action property, and once the connection is established, the browser will send the data to the server in a segmented transfer.

On the server side, once the POST-style application starts executing, the parameters should be read from a flag location, and once the parameters are read, the parameters must be decoded before the application can use the form values. User-specific servers explicitly specify how the application should accept these parameters.

Another scenario is when a GET method is used, where the browser establishes a connection to the form processing server and then sends all the form data directly in a single transport step: The browser will attach the data directly to the action URL of the form. The two are separated by a question mark.

General browsers can transmit form information through either of these methods, whereas some servers only accept data provided by one of these methods. You can specify in the method property of the <form> tag how the form processing server will handle the data using the method to make the POST or GET.

Post or GET?

If the form processing server supports both the POST method and the GET method, which method do you choose? Here are some of the rules about this:

· If you want the best form transfer performance, you can use the Get method to send small forms with only a few short fields.

· Some server operating systems limit the number and length of command-line arguments that can be passed to an application immediately, in which case the POST method should be used for forms that have many fields or long text fields.

· If you are inexperienced in writing server-side form-processing applications, you should choose the GET method. If you use the POST method, you will need to do some extra work on the read and Decode methods, which may not be very difficult, but you may not be willing to deal with these problems.

· If security is a problem, then we recommend that you use the POST method. The GET method places form parameters directly in the URL of the application, so that network snooping can easily capture them and extract them from the server's log file. If the parameter contains sensitive information such as a credit card account, it can unknowingly compromise the user's security. There is no security vulnerability in the POST application, and at least an encrypted method can be used when transferring parameters as separate transactions to the server for processing.

· If you want to invoke the server-side application outside of the form, and include the procedure to pass parameters to it, take the GET method, because it allows parameters such as forms to be included as part of the URL. On the other hand, applications that use the post style want to have an additional transfer process from the browser after the URL, where the transferred content cannot be used as the content of the traditional <a> tag.

2 MTD Tools Introduction:

Mtd-util, the utilities of MTD, is a generic term for many of the MTD-related tools, including commonly used mtdinfo,flash_erase, Flash_eraseall,nanddump, Nandwrite, and so on, every tool, Basically it corresponds to a C file with the same file name.

Mtd-util, developed by the MTD official maintenance update, aims to provide a set of tools for the MTD layer of Linux to facilitate the management and maintenance of MTD partitions. The source code corresponding to the MTD tool, called Mtd-utils, is updated over time and released in many versions.

MTD Tools Source code download: http://git.infradead.org/,

MTD: Official website: http://git.infradead.org/,

3 Prepare before Upgrade:

Partition the Flash and pass the information to kernel via uboot:

Setenv Bootargs ' mem=64mconsole=ttyama0,115200 root=/dev/mtdblock3 rootfstype=cramfsmtdparts=hi_sfc:512k (boot), 512k (Bootargs), 3M (kernel), 13M (Rootfs), 13M (APP), 2M (config) '

Partitions are now manageable, and can be upgraded individually or only by upgrading the app Rootfs.

4. Upgrade your code

The upgrade code is divided into 4 main sections.

1 The main is to get the information of the uploaded file, such as file name, length. function GetFileInfo () 2 The main is to save the uploaded file in memory. Function: SaveFileToLocal3 is mainly to upload the file for CRC check: TESTCRC, for the Cramfs file system

4 Upgrading using the MTD tool:

Source file:

5 Upgrade Notes:

1 due to the use of the BOA Web server, temporary files will be used to upload the directory/tmp, so it is necessary to ensure that the directory is read and write. Since Cramfs is a read-only file system, it is possible to set the/TMP to the Tmpfs file system. (equivalent to memory).

Setting up the/etc/fstab file

Tmpfs/tmp Tmpfs size=16m

2 after repartitioning, it is necessary to mount each boot, so you can add in the RCS file

Mount-t cramfs/dev/mtdblock4/opt

Mount-t Jffs2/dev/mtdblock5/mnt/nand

3 The upgrade time can sometimes be too long, resulting in web pages not returning normally. Boa.conf, and Defines.h

#define REQUEST_TIMEOUT 60

Online upgrade of embedded devices using MTD Tools

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.