|
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // bootldr\src\ymodemb.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #define FILE_ID 0x594D4442 |
|
19 |
|
20 #include "bootldr.h" |
|
21 #include <d32comm.h> |
|
22 #include "ymodemu.h" |
|
23 |
|
24 _LIT(KSerialLddName, "ECOMM"); |
|
25 _LIT(KSerialPddName, "EUART"); |
|
26 |
|
27 #if 0 |
|
28 GLREF_C void RequestSignal(TInt aCount); |
|
29 GLREF_C void HandleClose(TInt aHandle); |
|
30 GLREF_C TInt OpenCommPort(TInt aPort, TInt& aHandle); |
|
31 GLREF_C void WriteToCommPort(TInt aHandle, TRequestStatus& aStatus, const TDesC8& aDes); |
|
32 GLREF_C void CommReadOneOrMore(TInt aHandle, TRequestStatus& aStatus, TDes8& aDes); |
|
33 GLREF_C void CommRead(TInt aHandle, TRequestStatus& aStatus, TDes8& aDes); |
|
34 GLREF_C void CommReadCancel(TInt aHandle); |
|
35 #endif |
|
36 |
|
37 YModemU* TheYModem; |
|
38 TInt DownloadMode; |
|
39 |
|
40 YModemU::YModemU(TBool aG) |
|
41 : YModem(aG) |
|
42 { |
|
43 } |
|
44 |
|
45 YModemU::~YModemU() |
|
46 { |
|
47 iComm.Close(); |
|
48 iTimer.Close(); |
|
49 } |
|
50 |
|
51 TInt YModemU::Create(TInt aPort) |
|
52 { |
|
53 TInt r=iComm.Open(aPort); |
|
54 if (r!=KErrNone) |
|
55 return r; |
|
56 TCommConfig cfg; |
|
57 TCommConfigV01& c=cfg(); |
|
58 iComm.Config(cfg); |
|
59 c.iRate=SerialBaud; |
|
60 c.iDataBits=EData8; |
|
61 c.iStopBits=EStop1; |
|
62 c.iParity=EParityNone; |
|
63 // c.iHandshake=KConfigFreeRTS|KConfigFreeDTR; |
|
64 c.iHandshake=0; |
|
65 c.iFifo=EFifoEnable; |
|
66 c.iTerminatorCount=0; |
|
67 r=iComm.SetConfig(cfg); |
|
68 if (r!=KErrNone) |
|
69 return r; |
|
70 r=iComm.SetReceiveBufferLength(8192); |
|
71 if (r!=KErrNone) |
|
72 return r; |
|
73 return iTimer.CreateLocal(); |
|
74 } |
|
75 |
|
76 YModemU* YModemU::NewL(TInt aPort, TBool aG) |
|
77 { |
|
78 YModemU* p=new YModemU(aG); |
|
79 TInt r=p->Create(aPort); |
|
80 if (r!=KErrNone) |
|
81 { |
|
82 delete p; |
|
83 User::Leave(r); |
|
84 } |
|
85 return p; |
|
86 } |
|
87 |
|
88 void YModemU::WriteC(TUint aChar) |
|
89 { |
|
90 TBuf8<1> b; |
|
91 b.SetLength(1); |
|
92 b[0]=(TUint8)aChar; |
|
93 TRequestStatus s; |
|
94 iComm.Write(s,b); |
|
95 User::WaitForRequest(s); |
|
96 } |
|
97 |
|
98 TInt YModemU::ReadBlock(TDes8& aDest) |
|
99 { |
|
100 aDest.Zero(); |
|
101 TRequestStatus s1, s2; |
|
102 iTimer.After(s1,iTimeout); |
|
103 // test.Printf(_L("@%dms %d\n"),User::FastCounter(),iComm.QueryReceiveBuffer()); |
|
104 iComm.Read(s2,aDest); |
|
105 User::WaitForRequest(s1,s2); |
|
106 if (s2!=KRequestPending) |
|
107 { |
|
108 iTimer.Cancel(); |
|
109 User::WaitForRequest(s1); |
|
110 return s2.Int(); |
|
111 } |
|
112 iComm.ReadCancel(); |
|
113 User::WaitForRequest(s2); |
|
114 return KErrTimedOut; |
|
115 } |
|
116 |
|
117 TInt ReadYModemInputData(TUint8* aDest, TInt& aLength) |
|
118 { |
|
119 if( TheYModem->IsHeaderStored() ) |
|
120 { |
|
121 DEBUG_PRINT((_L(">>ReadYModemInputData(aDest:0x%08x, aLength:%d)\r\n"), aDest, aLength)) |
|
122 TInt r = TheYModem->GetHeaderBufferContent(aDest, aLength); |
|
123 DEBUG_PRINT((_L("<<ReadYModemInputData(aDest:0x%08x, aLength:%d):%d\r\n"), aDest, aLength, r)) |
|
124 return r; |
|
125 } |
|
126 else |
|
127 { |
|
128 TUint8* pD=aDest; |
|
129 TInt r=TheYModem->ReadPackets(pD,aLength); |
|
130 aLength=pD-aDest; |
|
131 return r; |
|
132 } |
|
133 |
|
134 } |
|
135 |
|
136 void CloseYModem() |
|
137 { |
|
138 DEBUG_PRINT((_L(">>CloseYModem()\r\n"))); |
|
139 TBuf<256> name; |
|
140 TInt size=-1; |
|
141 TheYModem->StartDownload(DownloadMode, size, name); |
|
142 DEBUG_PRINT((_L("<<CloseYModem()\r\n"))); |
|
143 } |
|
144 |
|
145 GLDEF_C TInt InitSerialDownload(TInt aPort) |
|
146 { |
|
147 // RThread().SetSystem(ETrue); |
|
148 |
|
149 TInt r=LoadDriver(KSerialLddName,0); |
|
150 if (r!=KErrNone) |
|
151 BOOT_FAULT(); |
|
152 r=LoadDriver(KSerialPddName,1); |
|
153 if (r!=KErrNone) |
|
154 BOOT_FAULT(); |
|
155 |
|
156 TInt PortNumber=aPort; |
|
157 DownloadMode=KYModemGMode; |
|
158 |
|
159 TRAP(r,TheYModem=YModemU::NewL(PortNumber,ETrue)); |
|
160 if (r!=KErrNone || TheYModem==NULL) |
|
161 BOOT_FAULT(); |
|
162 |
|
163 // r=YModemB::New(TheYModem,PortNumber,DownloadMode); |
|
164 // TEST(r==KErrNone && TheYModem!=NULL); |
|
165 YModemU* pY=TheYModem; |
|
166 |
|
167 TBuf<256> name; |
|
168 r=pY->StartDownload(DownloadMode, FileSize, name); |
|
169 if (r!=KErrNone) |
|
170 return r; |
|
171 |
|
172 #ifdef __SUPPORT_UNZIP__ |
|
173 if (name.Length()>=4 && name.Right(4).MatchF(_L(".zip"))==0 && FileSize!=0) |
|
174 ImageZip=ETrue; |
|
175 else |
|
176 #endif |
|
177 ImageZip=EFalse; |
|
178 |
|
179 #ifdef __SUPPORT_FLASH_REPRO__ |
|
180 if (name.Length()>=8 && (name.Left(8).MatchF(_L("FLASHIMG"))==0 || name.Left(8).MatchF(_L("FLASHLDR"))==0) && FileSize!=0) |
|
181 { |
|
182 LoadToFlash=ETrue; |
|
183 if (name.Left(8).MatchF(_L("FLASHLDR"))==0) |
|
184 FlashBootLoader=ETrue; |
|
185 |
|
186 } |
|
187 else |
|
188 #endif |
|
189 LoadToFlash=EFalse; |
|
190 |
|
191 if (!ImageZip) |
|
192 { |
|
193 r = pY->GetInnerCompression(ImageDeflated, RomLoaderHeaderExists); |
|
194 if(KErrNone != r) |
|
195 { |
|
196 PrintToScreen(_L("Unable to determine the compression!\r\n")); |
|
197 BOOT_FAULT(); |
|
198 } |
|
199 } |
|
200 LoadDevice=ELoadSerial; |
|
201 InputFunction=ReadYModemInputData; |
|
202 CloseInputFunction=CloseYModem; |
|
203 FileName=name; |
|
204 |
|
205 return KErrNone; |
|
206 } |
|
207 |