Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // ubootldr\loadzip.cpp
18 #define FILE_ID 0x4C5A4950
21 #include <e32std_private.h>
27 GLDEF_C void AcceptUnzippedBlock(TZipInfo& aInfo, TUint8*& aOutPtr, TInt aError)
31 PrintToScreen(_L("Error!\r\n"));
34 #ifdef __SUPPORT_FLASH_REPRO__
37 // signal flash programming thread
38 TInt got=(TInt)((TLinAddr)aOutPtr-(TLinAddr)DestinationAddress());
39 NotifyDataAvailable(got);
44 GLDEF_C TInt UnzipComplete(TZipInfo& a, TUint8* aOutPtr, TInt aError)
46 #ifdef __SUPPORT_FLASH_REPRO__
48 NotifyDownloadComplete();
53 _LIT(KLitThreadName,"Unzip");
54 TInt Initialise(TZipInfo& a)
59 a.iFileBufSize=4*a.iInBufSize;
60 TAny* pFileBuf=MALLOC(a.iFileBufSize);
63 a.iFileBuf=(TUint8*)pFileBuf;
65 r=t.Create(KLitThreadName,UnzipThread,0x2000,NULL,&a);
72 t.SetPriority(EPriorityLess);
73 t.Logon(a.iThreadStatus);
75 a.iThreadHandle=t.Handle();
79 void ProcessHeader(TZipInfo& a)
82 LoadSize=a.iUncompressedSize;
83 TInt size_mod_4k=LoadSize & 0xfff;
85 ImageHeaderPresent=EFalse;
86 else if (size_mod_4k==256)
87 ImageHeaderPresent=ETrue;
90 PrintToScreen(_L("\r\n\r\nInvalid size\r\n"));
93 ImageSize=ImageHeaderPresent ? LoadSize-256 : LoadSize;
95 PrintToScreen(_L("Unzip %lS, size %d\r\n"),&FileName,LoadSize);
97 #ifdef __SUPPORT_FLASH_REPRO__
100 TInt r=InitFlashWrite();
103 PrintToScreen(_L("InitFlashWrite returned %d\r\n"),r);
109 a.iOutBuf=(TUint8*)DestinationAddress();
112 TRequestStatus* pS=&a.iProcessedHeader;
116 t.SetHandle(a.iThreadHandle);
117 t.RequestComplete(pS,0);
120 void Cleanup(TZipInfo& a)
125 RThread& t=*(RThread*)&a.iThreadHandle;
129 TInt DoZipDownload(RFile &aBootFile)
133 InitProgressBar(0,(TUint)FileSize,_L("LOAD"));
134 TInt r=Initialise(z);
137 t.SetHandle(z.iThreadHandle);
139 while (z.iRemain && z.iThreadStatus==KRequestPending)
141 TRequestStatus dummy;
142 TRequestStatus* pS=&dummy;
144 r=ReadBlockToBuffer(z, aBootFile);
147 PrintToScreen(_L("FAULT: Unzip Error %d\r\n"),r);
148 if (z.iFileBufW-z.iFileBufR==z.iFileBufSize)
150 PrintToScreen(_L("Check there is only one image\n\rin the zip file.\r\n"));
155 UpdateProgressBar(0,(TUint)(FileSize-z.iRemain));
156 t.RequestComplete(pS,0); // same process
157 while(z.iHeaderDone==0 && z.iThreadStatus==KRequestPending)
161 if (z.iHeaderDone==1 && z.iThreadStatus==KRequestPending)
163 // after reading first block, process the header
168 User::WaitForRequest(z.iThreadStatus);
170 TInt exitType=t.ExitType();
171 TInt exitReason=t.ExitReason();
172 if (z.iRemain || exitType!=EExitKill || exitReason!=KErrNone)
174 TBuf<32> exitCat=t.ExitCategory();
175 PrintToScreen(_L("Exit code %d,%d,%S\n"),exitType,exitReason,&exitCat);
179 PrintToScreen(_L("Unzip complete\r\n"));
184 r=ReadInputData(pD,len);