From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Joe Hung <joe_hung@ilitek.com>
Cc: devicetree@vger.kernel.org, linux-input@vger.kernel.org,
luca_hsu@ilitek.com
Subject: Re: [PATCH] Input: ilitek_ts_i2c - support firmware update
Date: Fri, 23 Jul 2021 12:50:04 -0700 [thread overview]
Message-ID: <YPsdbKgG5nOBqUei@google.com> (raw)
In-Reply-To: <20210511140506.378070-1-joe_hung@ilitek.com>
Hi Joe,
On Tue, May 11, 2021 at 10:05:06PM +0800, Joe Hung wrote:
> +static int ilitek_parse_hex(struct ilitek_ts_data *ts, u32 *fw_size, u8 *fw_buf)
> +{
> + int error;
> + char *fw_file;
> + const struct firmware *fw;
> + struct device *dev = &ts->client->dev;
> + u32 i, len, addr, type, exaddr = 0;
> + u8 info[4], data[16];
> +
> + fw_file = kasprintf(GFP_KERNEL, "ilitek_%04x.hex", ts->mcu_ver);
> + if (!fw_file)
> + return -ENOMEM;
> +
> + error = request_firmware(&fw, fw_file, dev);
> + kfree(fw_file);
> + if (error) {
> + dev_err(dev, "request firmware:%s failed, ret:%d\n",
> + fw_file, error);
> + return error;
> + }
> +
> + for (i = 0; i < fw->size; i++) {
> + if (fw->data[i] == ':' ||
> + fw->data[i] == 0x0D ||
> + fw->data[i] == 0x0A)
> + continue;
> +
> + error = hex2bin(info, fw->data + i, sizeof(info));
> + if (error)
> + goto release_fw;
> +
> + len = info[0];
> + addr = get_unaligned_be16(info + 1);
> + type = info[3];
> +
> + error = hex2bin(data, fw->data + i + 8, len);
> + if (error)
> + goto release_fw;
> +
> + switch (type) {
> + case 0x01:
> + goto release_fw;
> + case 0x02:
> + exaddr = get_unaligned_be16(data);
> + exaddr <<= 4;
> + break;
> + case 0x04:
> + exaddr = get_unaligned_be16(data);
> + exaddr <<= 16;
> + break;
> + case 0xAC:
> + case 0xAD:
> + break;
> + case 0x00:
> + addr += exaddr;
> + memcpy(fw_buf + addr, data, len);
> + *fw_size = addr + len;
> + break;
> + default:
> + dev_err(dev, "unexpected type:%x in hex\n", type);
> + goto err_invalid;
> + }
This looks like ihex. Is it? If so we have request_ihex_firmware() and
ihex2fw tool to convertihex firmware to compact binary format. Please
use it.
Thanks.
--
Dmitry
prev parent reply other threads:[~2021-07-23 19:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-11 14:05 [PATCH] Input: ilitek_ts_i2c - support firmware update Joe Hung
2021-07-23 19:50 ` Dmitry Torokhov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YPsdbKgG5nOBqUei@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=joe_hung@ilitek.com \
--cc=linux-input@vger.kernel.org \
--cc=luca_hsu@ilitek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.