2 years agoFix the problem of strict aliasing 54/41354/3 factory-4128.B factory-4290.B factory-4455.B factory-pit-4280.B factory-pit-4390.B factory-pit-4471.B factory-spring-3842.B factory-spring-4131.B factory-spring-4262.B firmware-falco_peppy-4389.B firmware-leon-4389.26.B firmware-pit-4482.B firmware-spring-3824.4.B firmware-spring-3824.55.B firmware-spring-3824.84.B firmware-spring-3824.B firmware-spring-3833.B firmware-wolf-4389.24.B master release-R26-3701.B release-R27-3912.B release-R28-4100.B release-R29-4319.B release-R30-4537.B stabilize-3658.0.0 stabilize-3701.30.0 stabilize-3701.30.0b stabilize-3701.46.B stabilize-3701.81.B stabilize-3881.0.B stabilize-3912.79.B stabilize-4008.0.B stabilize-4035.0.B stabilize-4068.0.B stabilize-4100.38.B stabilize-4255.B stabilize-4287.B stabilize-4443.B stabilize-4512.B stabilize-bluetooth-smart stabilize-spring-4100.53.B toolchain-3701.42.B toolchainA toolchainB
Joseph Hwang [Wed, 16 Jan 2013 10:56:46 +0000 (18:56 +0800)]
Fix the problem of strict aliasing

The strict-aliasing flag has been enabled in gcc. This leads to
the following compiling error:

  yapa_fw_update.c:1136:5: error: dereferencing type-punned pointer
  will break strict-aliasing rules [-Werror=strict-aliasing]
  cc1: all warnings being treated as errors

The term 'aliasing' indicates that pointers of different types
point to the same memory address. The dereference of the type-punned
pointer will lead to undefined behavior. In the particular problem
here, it tries to type cast a char pointer to an integer pointer,
and then dereferences the integer pointer.

The solution is not to type cast different pointer types (except
char pointer which is allowed in the strict aliasing rules).

TEST=Should emerge cypress-tools successfully.
(cr) emerge-{BOARD} cypress-tools

Change-Id: Id2c6fe668261383aa8b0f5824128abb1da65ce0e
Reviewed-by: Benson Leung <>
Commit-Queue: Joseph Shyh-In Hwang <>
Tested-by: Joseph Shyh-In Hwang <>
3 years agoAdd 0x7900 as a fixup region for firmware backup bins 64/13364/2 factory-1987.B factory-2268.16.B factory-2305.B factory-2338.B factory-2368.B factory-2394.B factory-2460.B factory-2475.B factory-2569.B factory-2717.B factory-2723.14.B factory-2846.B factory-2848.B factory-2914.B factory-2985.B factory-2993.B factory-3004.B factory-3536.B firmware-butterfly-2788.B firmware-link-2348.B firmware-link-2695.2.B firmware-link-2695.B firmware-parrot-2685.B firmware-snow-2695.90.B firmware-snow-2695.B firmware-stout-2817.B release-R18-1660.B release-R19-2046.B release-R20-2268.B release-R21-2465.B release-R22-2723.B release-R23-2913.B release-R25-3428.B stabilize stabilize-3428.110.0 stabilize-3428.149 stabilize-3428.149.B stabilize-3428.193 stabilize-daisy stabilize-link stabilize-link-2913.278 stabilize2 toolchain-3428.65.B
Benson Leung [Wed, 21 Dec 2011 23:34:01 +0000 (15:34 -0800)]
Add 0x7900 as a fixup region for firmware backup bins

A binary diff of the output of cyapa_fw_update -c <iic>
and cyapa_fw_update -b shows that a region that corresponds
to firmware address 0x7900 to 0x797F is different in the
backed up binary. In the converted binary, it is always filled
with 0x08.

TEST=cyapa_fw_update -b -o /lib/firmware/cyapa.bin
echo -n 1 > /sys/bus/i2c/devices/15-0067/update_fw
Ensure that the fw update succeeds. Check dmesg after
this command is finished, check to see that cyapa device
shows up as an input device.

Change-Id: I5c27bd80323d75cb461a16849c5799edb0f63007
Signed-off-by: Benson Leung <>
3 years agoAdd option to convert from .iic to .bin 29/12029/5 factory-1412.B release-R17-1412.B
Daniel Kurtz [Fri, 2 Dec 2011 04:20:26 +0000 (12:20 +0800)]
Add option to convert from .iic to .bin

The "--convert" option reads in an .iic file and converts it to a .bin
file.  The .bin file is saved to the output file specified with the
--output option.

TEST=cyapa --convert --output=/tmp/CYTRA.bin  CYTRA.iic

Change-Id: I0ded7079c79552aa9613923015bc4f633966182b

3 years agoDo not automatically reboot 30/12030/5
Daniel Kurtz [Fri, 2 Dec 2011 04:18:28 +0000 (12:18 +0800)]
Do not automatically reboot

Rebooting the machine should be handled by the process driving a touchpad
firmware update, not by the updater itself.
Besides, reboot was only performed between gen2 and gen3 firmware versions.
By now, all firmware is gen3, so reboot should never be required.

Signed-off-by: Daniel Kurtz <>
TEST=Update cyapa firmware from gen2 to gen3.  No automatic resets.
     Also, cyapa_fw_update should not warn about reseting.

Change-Id: I8fa277254fb76cff7e1dedd0de55ac1688564576

3 years agoSet permissions when creating .bak file 65/12365/2
Daniel Kurtz [Fri, 2 Dec 2011 03:12:39 +0000 (11:12 +0800)]
Set permissions when creating .bak file

When opening the .bak file, truncate to 0 length if it already exists,
or create with the following permissions if it doesn't exist:
  * reading and writing by the owner
  * reading only by group members and others

Fixes compiler error on x86.
TEST=builds clean for x86-generic, arm & x86_64

Change-Id: Iaface75c8f78d4b7e36c50d677fc452297eebeb0

3 years agoBackup: speedup 93/10093/3 factory-1235.B factory-1284.B firmware-kiev-2.112.B firmware-uboot_v2-1299.B
Daniel Kurtz [Wed, 19 Oct 2011 09:44:32 +0000 (17:44 +0800)]
Backup: speedup

The touchpad firmware should not actually requires at least 1 ms,
not 10 ms a 10 msec pause between writing bootloader 'read' command and a
subsequent data buffer read.

Also, instead of reading the command header (first 16 registers) time,
only read the data registers (starting with byte 16).

Combined, this reduces backup time from ~45 seconds to ~10 seconds.
Eliminating the msleep(1) could speed up by almost another factor of 2,
down to ~5.5 seconds.

TEST=backup 100 times, no false reads

Change-Id: I3344b38af0614ba233d8e7072bc0c9587a13a001

3 years agoCleanup checksum calculation 95/10095/3
Daniel Kurtz [Fri, 14 Oct 2011 11:50:26 +0000 (19:50 +0800)]
Cleanup checksum calculation

TEST=downloaded firmware passes checksum test

Change-Id: Id1727e0e242a106b0a263b3b8c347a415ce4c5fa

3 years agoCleanup elapsed time calculation 94/10094/3
Daniel Kurtz [Fri, 14 Oct 2011 11:46:51 +0000 (19:46 +0800)]
Cleanup elapsed time calculation

Note: this also fixes a bug where the fractional second was incorectly
displayed.  Since the usec wasn't zero-padded, it was being left shifted:
For example, the value "6.000005" was being printed as "6.5".

TEST=Inspect timer output.
It should always have 6 decimal places, even if usec < 100000.

Change-Id: Ia41a11428aedde45419d99821a411144156e273a

3 years agoBackup: Fix IDAC regions after reading whole firmware 92/10092/2
Daniel Kurtz [Fri, 14 Oct 2011 13:36:10 +0000 (21:36 +0800)]
Backup: Fix IDAC regions after reading whole firmware

Instead of fake reading the IDAC regions, fix them after reading the
whole firmware into a local buffer, but saving to disk.

Plus, refactor the fixup operation itself to make it more flexible.

TEST=confirm that back up file has:
  0x08 from 0x7280-0x72FF
  0x90 from 0x7380-0x747F

Change-Id: Iea115777d9842ccbb83581b1c125f3a59e41d847

3 years agoBackup: first read into buffer, then write buffer to disk 91/10091/2
Daniel Kurtz [Fri, 14 Oct 2011 12:57:34 +0000 (20:57 +0800)]
Backup: first read into buffer, then write buffer to disk

TEST=builds clean;
  Check that backed up firmware images are correct

Change-Id: I9bc78ec086f68a2a1bc8b296cd45b08895baa578

3 years agoAllow reading a backup without doing an update 90/10090/2
Daniel Kurtz [Fri, 14 Oct 2011 14:44:33 +0000 (22:44 +0800)]
Allow reading a backup without doing an update

If no firmware image is provided, but --backup is requested, still read
the current image and save it to disk.

TEST=cyapa_fw_update -f -b -o /tmp/backup.bin
  => Should backup current firmware to /tmp/backup.bin

Change-Id: I10c79a2ead42038583a627024aca39a68731892b

3 years agoRefactor file open checks 89/10089/2
Daniel Kurtz [Fri, 14 Oct 2011 13:15:13 +0000 (21:15 +0800)]
Refactor file open checks

* Return 0 on success, <0 on error.
* No need to seek check the normal files.
* Use perror(): when a system call fails, it is useful to know why.
* If the checks fail, don't try to access the device in the error path.

TEST=builds clean
  file open/access checks pass in the normal case
  file open checks fail when:
    * no device present
    * firmware file doesn't exist
    * permissions are wrong for backup file

Change-Id: Ie7589c6bebed670974425c748f9107263dc01e5d

3 years agoRefactor Y/N prompts 88/10088/2
Daniel Kurtz [Thu, 13 Oct 2011 11:54:44 +0000 (19:54 +0800)]
Refactor Y/N prompts

Refactor common functionality to make code more readable.

Note: this code should have same behaviour, but that behavior isn't
actually correct.  It doesn't properly handle the case where there are
multiple Y|N questions asked.

TEST=builds clean; Y/N questions still asked and answered properly in Y
and N cases.

Change-Id: I1edc0e39dad70865015a442f9b655a1a4f1f5cca

3 years agoUse nanosleep instead of custom wait() 87/10087/2
Daniel Kurtz [Thu, 13 Oct 2011 13:16:20 +0000 (21:16 +0800)]
Use nanosleep instead of custom wait()

TEST=builds clean; build with debug and confirm operations are still
being delayed properly

Change-Id: I341b9b341fa7a28d7cd9ce7e06d90761bd2291ec

3 years agoUse getopt_long instead of custom arg parsing 86/10086/1 release-R16-1193.B
Daniel Kurtz [Fri, 14 Oct 2011 07:14:46 +0000 (15:14 +0800)]
Use getopt_long instead of custom arg parsing

One side affect of this change is we no longer copy the filename args into
malloc'ed buffers, we just use const char pointers.

This also fixes how we recognize filename extensions, to ensure that the
filename really ends with the extension (i.e. .bin, not .binary).

TEST=builds clean;
 Test following cases:
  cyapa_fw_update -h
  cyapa_fw_update -v
  cyapa_fw_update -f
  cyapa_fw_update -f -b
  cyapa_fw_update -b -o bkup.bin
  cyapa_fw_update -b -o bkup
  cyapa_fw_update -f fw.iic
  cyapa_fw_update -f -b fw.binary

Change-Id: I48c2f686e2118e8b1ca91a54e87ee29c80f37b2e

3 years agoUse stdbool.h 85/10085/1
Daniel Kurtz [Fri, 14 Oct 2011 06:20:57 +0000 (14:20 +0800)]
Use stdbool.h

While we are at it, alphabetize (system) headers and clean up a typo.

TEST=builds clean

Change-Id: Ie93f0c0b86db43cdeb9aa7269e0d2ba42a9a63ae

3 years agoFix big endian conversion 84/10084/1
Daniel Kurtz [Fri, 14 Oct 2011 12:17:23 +0000 (20:17 +0800)]
Fix big endian conversion

16-bit quantities are sent big-endian in i2c commands.
Populate buffer with MSB and LSB in a platform independent way.

TEST=builds clean for x86, arm.
  offset / block_index should be sent big-endian for both arches.
  This should result in a properly backed up image for both arches.

Change-Id: I988c5a050027b2081abd5cb2634cb4221951b6b8

3 years agos/arguments/args 83/10083/1
Daniel Kurtz [Fri, 14 Oct 2011 12:09:51 +0000 (20:09 +0800)]

Less characters, no loss of readability.

TEST=builds clean

Change-Id: I7b5a34c6dc42487fdcddb14af9192a3c60c581bb

3 years agoFix segfault when parsing arguments with no filename 34/9934/1
Daniel Kurtz [Wed, 12 Oct 2011 09:47:38 +0000 (17:47 +0800)]
Fix segfault when parsing arguments with no filename

When user doesn't specify a filename, or specifies '-h' first,
new_fw_image won't be set.

TEST=emerge-${B} cypress-tools builds clean
  On device:
    cyapa_fw_update -h
  => prints help; no Segmentation fault

Change-Id: Iab8043587c99dede9a3a338175ebc61025fe2410

3 years agoFix compiler warnings. 33/9933/1
Daniel Kurtz [Wed, 12 Oct 2011 09:44:09 +0000 (17:44 +0800)]
Fix compiler warnings.

While we are at it, cleanup some spelling typos, and rename & simplify

TEST=emerge-${B} cypress-tools

Change-Id: I2fbd186bf655b7266cb0969efb72d13a1a9e9765

3 years agoAdd Makefile 32/9932/1
Daniel Kurtz [Wed, 12 Oct 2011 09:11:35 +0000 (17:11 +0800)]
Add Makefile

  make all
  make clean

Change-Id: I067ed79c4e00c07ff881ae1b0e972ada58714654

3 years agoDisable cros license & tab checks 31/9931/1
Daniel Kurtz [Wed, 12 Oct 2011 09:51:55 +0000 (17:51 +0800)]
Disable cros license & tab checks

cypress-tools is copyright Cypress Semiconductor Inc.
This file uses kernel C formatting, which uses tabs instead of spaces.

TEST=repo upload .
  => No errors about incorrect license.

Change-Id: I1b77f6e9cfb77483c206dd5ed68bad174093837d

3 years agoutility: cyapa_fw_update : Upload initial source code and documentation 27/4727/3 0.15.877.B factory-1020.B factory-980.B firmware-881-u-boot-v1 firmware-u-boot-v1 release-1011.B test-982.B
Du, Dudley [Thu, 28 Jul 2011 07:17:31 +0000 (15:17 +0800)]
utility: cyapa_fw_update : Upload initial source code and documentation

Upload intial source code and documentation for cyapa_fw_upate utility tool.

TEST=test with cyapa v0.9.8 and later version driver on Kaen board

Change-Id: I5030b84d8115676b6abd19b3ed8ece934c741862
Signed-off-by: Du, Dudley <>
3 years agoAdd a README.chromium file for the cypress-tools respository. 23/4323/2 0.14.811.B
Dave Parker [Tue, 19 Jul 2011 18:59:33 +0000 (11:59 -0700)]
Add a README.chromium file for the cypress-tools respository.