[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Uisp-dev] [patch] Alignment on ARM
From: |
Raphael Assenat |
Subject: |
[Uisp-dev] [patch] Alignment on ARM |
Date: |
Tue, 19 Apr 2005 11:47:41 -0400 |
User-agent: |
Mozilla Thunderbird 1.0 (X11/20050118) |
Hi,
I have cross-compiled uisp for an arm target (a sharp zaurus, easier for
updates in the field than a laptop) but I have encountered a problem.
When uisp tries to communicate with the programmer (avrisp), it fails
every time with a 'Device is not responding correctly' error. I have
enabled verbose mode and compared the output given by uisp on my PC and
the ARM.
At some point, the ARM version sends 24 bytes instead of 22: (see below
for full log)
Transmit: { B [42] . [b2] . [00] . [00] . [01] . [01] . [01] . [01] .
[03] . [ff] . [ff] . [ff] . [ff] . [01] . [00] . [10] . [00] . [00] .
[02] . [00] . [00] [20] . [00] . [00] }
^^ ^^^
Supplemental bytes
The supplemental bytes are due to the sizeof(struct SPrgParams) being
equal to 24 on arm due to alignment/padding of the struct by the
compiler. On an x86, it is 22 bytes.
I tried using #pragma pack(1), -fpack-structs, but the size of the
struct stayed at 24. Finally, I decided to copy manually all the members
of the structure into the buffer and I hardcoded the length to 22 (see
diff below). That worked.
I'm not sure this is the cleanest way around alignment problems, but at
least now it works on my zaurus.
What do you think? Please let me know if I should change anything.
Otherwise, please consider applying the patch to the CVS version.
Regards,
Raphael Assenat
diff -Nru uisp/src/Stk500.C uisp-edited/src/Stk500.C
--- uisp/src/Stk500.C 2004-12-28 09:54:11.000000000 -0500
+++ uisp-edited/src/Stk500.C 2005-04-19 10:23:39.480352728 -0400
@@ -622,19 +622,37 @@
TByte buf[100];
TByte vmajor;
TByte vminor;
-
+
TByte num_ext_parms = 3;
+ SPrgParams *params;
memcpy(buf, pSTK500, sizeof(pSTK500));
Send(buf, sizeof(pSTK500), sizeof(pSTK500_Reply));
if (memcmp(buf, pSTK500_Reply, sizeof(pSTK500_Reply)) != 0) {
throw Error_Device ("[VP 1] Device is not responding correctly."); }
- memcpy(buf, &prg_part[desired_part].params,
- sizeof(prg_part[desired_part].params));
-
- Send(buf, sizeof(prg_part[desired_part].params),
- sizeof(DeviceParam_Reply));
+ params = &prg_part[desired_part].params;
+ buf[0] = params->cmd;
+ buf[1] = params->devicecode;
+ buf[2] = params->revision;
+ buf[3] = params->progtype;
+ buf[4] = params->parmode;
+ buf[5] = params->polling;
+ buf[6] = params->selftimed;
+ buf[7] = params->lockbytes;
+ buf[8] = params->fusebytes;
+ buf[9] = params->flashpollval1;
+ buf[10] = params->flashpollval2;
+ buf[11] = params->eeprompollval1;
+ buf[12] = params->eeprompollval2;
+ buf[13] = params->pagesize[0];
+ buf[14] = params->pagesize[1];
+ buf[15] = params->eepromsize[0];
+ buf[16] = params->eepromsize[1];
+ memcpy(&buf[17], params->flashsize, 4);
+ buf[21] = params->sync;
+
+ Send(buf, 22, sizeof(DeviceParam_Reply));
if (memcmp(buf, DeviceParam_Reply, sizeof(DeviceParam_Reply)) != 0) {
throw Error_Device ("[VP 2] Device is not responding correctly."); }
** Full error log:
Transmit: { 0 [30] [20] }
Receive: { . [14] . [10] }
Transmit: { B [42] . [b2] . [00] . [00] . [01] . [01] . [01] . [01] .
[03] . [ff] . [ff] . [ff] . [ff] . [01] . [00] . [10] . [00] . [00] .
[02] . [00] . [00] [20] . [00] . [00] }
Receive: { . [14] . [10] }
Transmit: { A [41] . [82] [20] }
Receive: { . [15] }
Receive: { . [15] . [15] }
Transmit: { A [41] . [81] [20] }
Receive: { . [15] }
Receive: { . [15] . [15] }
Transmit: { E [45] . [04] . [08] . [d7] . [a0] . [00] [20] }
Receive: { . [15] }
Receive: { . [15] }
Firmware Version: 21.21
[VP 3] Device is not responding correctly.