One of the Linux chip driver firmware automatic upgrades: Function Description

Source: Internet
Author: User

In the driver development process, we sometimes encounter such an application: for example, the firmware of a chip is not fixed and can be upgraded later. Therefore, you need to perform a check every time the system is started. If a new firmware is detected, the firmware will be upgraded at the first boot. After that, because the new firmware version is saved for detection, you do not need to start the upgrade.

Taking an I2C touch screen chip as an example, assume that the new firmware file provided by the supplier is named us3x06eb_use.it, and place the file on the touch screen drive. C in the same directory, you need to add the corresponding version number detection processing in the probe function of the touch screen, and decide whether to upgrade. To upgrade the firmware, write the firmware to the target firmware through I2C.

Typedef Enum {err_ OK, err_mode, err_readid, err_erase, err_status, err_ecc, primary, err_dl_program_fail, primary} e_upgrade_err_type; # define fts_packet_length 2 // write two bytes, as a packetstatic unsigned char ctpm_fw [] = // load the target firmware {# include "us3x06eb_use.it"}; static int fts_i2c_txdata (u8 * txdata, int length) // transmit multi-byte data through I2C at a time {int ret; struct i2c_msg MSG; MSG. ADDR = i2c_client-> ADDR; MS G. flags = 0; MSG. len = length; MSG. buf = txdata; ret = i2c_transfer (i2c_client-> adapter, & MSG, 1); If (Ret <0) {pr_err ("% s I2C write error: % d \ n ", _ FUNC __, RET);} return ret;} static bool i2c_write_interface (u8 * pbt_buf, int dw_lenth) // write multiple data through I2C {int ret; ret = i2c_master_send (i2c_client, pbt_buf, dw_lenth); If (Ret <= 0) {printk ("[TSP] i2c_write_interface error line = % d, ret = % d \ n", _ line __, RET); Return fts_false;} return fts_true;} static bool i2c_read_interface (u8 * pbt_buf, int dw_lenth) // read multiple data through I2C {int ret; ret = i2c_master_recv (i2c_client, pbt_buf, dw_lenth); If (Ret <= 0) {printk ("[TSP] i2c_read_interface error \ n"); Return fts_false;} return fts_true ;} static bool fts_register_write (u8 reg_name, u8 * tx_buf) // write single-byte data to the Register {u8 write_cmd [2] = {0}; write_cmd [0] = reg_name; write_c MD [1] = * tx_buf; return i2c_write_interface (write_cmd, 2);} static bool fts_register_read (u8 reg_name, u8 * rx_buf, int rx_length) // read multiple data from the Register {u8 read_cmd [2] = {0}; u8 pai_len = 0; read_cmd [0] = reg_name; Len _len = 1; /* Send register ADDR */If (! I2c_write_interface (& read_cmd [0], cmd_len) {return fts_false;} If (! I2c_read_interface (rx_buf, rx_length) {return fts_false;} return fts_true ;}

E_upgrade_err_type fts_ctpm_fw_upgrade (u8 * pbt_buf, int dw_lenth) // The programming burning details are not described. The instance will be listed in the sequel to this blog

{

// Divide the data into corresponding packages and write them to the chip at one time through I2C. There are several issues that need to be noted: (1) Pay attention to the convergence of subcontracting, the data length may not be able to be divided into an integer package, so the last package should be separate

// Processing; (2) data verification. For example, if the chip has automatic rejection or verification, on the one hand, we must perform data verification operations in a timely manner during the sending process, and on the other hand, after the data is sent, you can check the verification value

// Compare the value of the Register to determine whether the current transfer is valid.

}

Int forward (void) {u8 * pbt_buf = 0x0; int ret; pbt_buf = ctpm_fw; ret = fts_ctpm_fw_upgrade (pbt_buf, sizeof (ctpm_fw )); // upgrade the specific file return ret;} static int _ devinit tpd_probe (struct i2c_client * client, const struct i2c_device_id * ID) // The probe function of TP {............. {u8 reg_val = 0; mdelay (50); fts_register_read (0xa6, _ Val, 1); // read the current version if (reg_val <tp_lib_version) // if the current version is earlier than the version to be upgraded, upgrade {printk ("TP firmware version OK, start upgrade \ n "); fts_ctpm_fw_upgrade_with_ I _file ();}}.............}

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.