Re: [PATCH] Input: ilitek_ts_i2c - support firmware update

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux