os/kernelhwsrv/brdbootldr/ubootldr/ymodemu.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/brdbootldr/ubootldr/ymodemu.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,207 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// bootldr\src\ymodemb.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#define FILE_ID		0x594D4442
    1.22 +
    1.23 +#include "bootldr.h"
    1.24 +#include <d32comm.h>
    1.25 +#include "ymodemu.h"
    1.26 +
    1.27 +_LIT(KSerialLddName, "ECOMM");
    1.28 +_LIT(KSerialPddName, "EUART");
    1.29 +
    1.30 +#if 0
    1.31 +GLREF_C void RequestSignal(TInt aCount);
    1.32 +GLREF_C void HandleClose(TInt aHandle);
    1.33 +GLREF_C TInt OpenCommPort(TInt aPort, TInt& aHandle);
    1.34 +GLREF_C void WriteToCommPort(TInt aHandle, TRequestStatus& aStatus, const TDesC8& aDes);
    1.35 +GLREF_C void CommReadOneOrMore(TInt aHandle, TRequestStatus& aStatus, TDes8& aDes);
    1.36 +GLREF_C void CommRead(TInt aHandle, TRequestStatus& aStatus, TDes8& aDes);
    1.37 +GLREF_C void CommReadCancel(TInt aHandle);
    1.38 +#endif 
    1.39 +
    1.40 +YModemU* TheYModem;
    1.41 +TInt DownloadMode;
    1.42 +
    1.43 +YModemU::YModemU(TBool aG)
    1.44 +	: YModem(aG)
    1.45 +	{
    1.46 +	}
    1.47 +
    1.48 +YModemU::~YModemU()
    1.49 +	{
    1.50 +	iComm.Close();
    1.51 +	iTimer.Close();
    1.52 +	}
    1.53 +
    1.54 +TInt YModemU::Create(TInt aPort)
    1.55 +	{
    1.56 +	TInt r=iComm.Open(aPort);
    1.57 +	if (r!=KErrNone)
    1.58 +		return r;
    1.59 +	TCommConfig cfg;
    1.60 +	TCommConfigV01& c=cfg();
    1.61 +	iComm.Config(cfg);
    1.62 +	c.iRate=SerialBaud;
    1.63 +	c.iDataBits=EData8;
    1.64 +	c.iStopBits=EStop1;
    1.65 +	c.iParity=EParityNone;
    1.66 +//	c.iHandshake=KConfigFreeRTS|KConfigFreeDTR;
    1.67 +	c.iHandshake=0;
    1.68 +	c.iFifo=EFifoEnable;
    1.69 +	c.iTerminatorCount=0;
    1.70 +	r=iComm.SetConfig(cfg);
    1.71 +	if (r!=KErrNone)
    1.72 +		return r;
    1.73 +	r=iComm.SetReceiveBufferLength(8192);
    1.74 +	if (r!=KErrNone)
    1.75 +		return r;
    1.76 +	return iTimer.CreateLocal();
    1.77 +	}
    1.78 +
    1.79 +YModemU* YModemU::NewL(TInt aPort, TBool aG)
    1.80 +	{
    1.81 +	YModemU* p=new YModemU(aG);
    1.82 +	TInt r=p->Create(aPort);
    1.83 +	if (r!=KErrNone)
    1.84 +		{
    1.85 +		delete p;
    1.86 +		User::Leave(r);
    1.87 +		}
    1.88 +	return p;
    1.89 +	}
    1.90 +
    1.91 +void YModemU::WriteC(TUint aChar)
    1.92 +	{
    1.93 +	TBuf8<1> b;
    1.94 +	b.SetLength(1);
    1.95 +	b[0]=(TUint8)aChar;
    1.96 +	TRequestStatus s;
    1.97 +	iComm.Write(s,b);
    1.98 +	User::WaitForRequest(s);
    1.99 +	}
   1.100 +
   1.101 +TInt YModemU::ReadBlock(TDes8& aDest)
   1.102 +	{
   1.103 +	aDest.Zero();
   1.104 +	TRequestStatus s1, s2;
   1.105 +	iTimer.After(s1,iTimeout);
   1.106 +//	test.Printf(_L("@%dms %d\n"),User::FastCounter(),iComm.QueryReceiveBuffer());
   1.107 +	iComm.Read(s2,aDest);
   1.108 +	User::WaitForRequest(s1,s2);
   1.109 +	if (s2!=KRequestPending)
   1.110 +		{
   1.111 +		iTimer.Cancel();
   1.112 +		User::WaitForRequest(s1);
   1.113 +		return s2.Int();
   1.114 +		}
   1.115 +	iComm.ReadCancel();
   1.116 +	User::WaitForRequest(s2);
   1.117 +	return KErrTimedOut;
   1.118 +	}
   1.119 +
   1.120 +TInt ReadYModemInputData(TUint8* aDest, TInt& aLength)
   1.121 +	{
   1.122 +	if( TheYModem->IsHeaderStored() )
   1.123 +	    {
   1.124 +	    DEBUG_PRINT((_L(">>ReadYModemInputData(aDest:0x%08x, aLength:%d)\r\n"), aDest, aLength))
   1.125 +	    TInt r = TheYModem->GetHeaderBufferContent(aDest, aLength);
   1.126 +	    DEBUG_PRINT((_L("<<ReadYModemInputData(aDest:0x%08x, aLength:%d):%d\r\n"), aDest, aLength, r))
   1.127 +	    return r;
   1.128 +	    }
   1.129 +    else
   1.130 +        {
   1.131 +        TUint8* pD=aDest;
   1.132 +    	TInt r=TheYModem->ReadPackets(pD,aLength);
   1.133 +    	aLength=pD-aDest;
   1.134 +    	return r;    
   1.135 +        }	    
   1.136 +	
   1.137 +	}
   1.138 +
   1.139 +void CloseYModem()
   1.140 +	{
   1.141 +	DEBUG_PRINT((_L(">>CloseYModem()\r\n")));
   1.142 +	TBuf<256> name;
   1.143 +	TInt size=-1;
   1.144 +	TheYModem->StartDownload(DownloadMode, size, name);
   1.145 +	DEBUG_PRINT((_L("<<CloseYModem()\r\n")));
   1.146 +	}
   1.147 +
   1.148 +GLDEF_C TInt InitSerialDownload(TInt aPort)
   1.149 +	{
   1.150 +//	RThread().SetSystem(ETrue);
   1.151 +
   1.152 +	TInt r=LoadDriver(KSerialLddName,0);
   1.153 +	if (r!=KErrNone)
   1.154 +		BOOT_FAULT();
   1.155 +	r=LoadDriver(KSerialPddName,1);
   1.156 +	if (r!=KErrNone)
   1.157 +		BOOT_FAULT();
   1.158 +
   1.159 +	TInt PortNumber=aPort;
   1.160 +	DownloadMode=KYModemGMode;
   1.161 +	
   1.162 +	TRAP(r,TheYModem=YModemU::NewL(PortNumber,ETrue));
   1.163 +	if (r!=KErrNone || TheYModem==NULL)
   1.164 +		BOOT_FAULT();
   1.165 +
   1.166 +//	r=YModemB::New(TheYModem,PortNumber,DownloadMode);
   1.167 +//	TEST(r==KErrNone && TheYModem!=NULL);
   1.168 +	YModemU* pY=TheYModem;
   1.169 +
   1.170 +	TBuf<256> name;
   1.171 +	r=pY->StartDownload(DownloadMode, FileSize, name);
   1.172 +	if (r!=KErrNone)
   1.173 +		return r;
   1.174 +
   1.175 +#ifdef __SUPPORT_UNZIP__
   1.176 +	if (name.Length()>=4 && name.Right(4).MatchF(_L(".zip"))==0 && FileSize!=0)
   1.177 +		ImageZip=ETrue;
   1.178 +	else
   1.179 +#endif
   1.180 +		ImageZip=EFalse;
   1.181 +
   1.182 +#ifdef __SUPPORT_FLASH_REPRO__
   1.183 +	if (name.Length()>=8 && (name.Left(8).MatchF(_L("FLASHIMG"))==0 || name.Left(8).MatchF(_L("FLASHLDR"))==0) && FileSize!=0)
   1.184 +		{
   1.185 +		LoadToFlash=ETrue;
   1.186 +		if (name.Left(8).MatchF(_L("FLASHLDR"))==0)
   1.187 +			FlashBootLoader=ETrue;
   1.188 +
   1.189 +		}
   1.190 +	else
   1.191 +#endif
   1.192 +		LoadToFlash=EFalse;
   1.193 +
   1.194 +    if (!ImageZip)
   1.195 +        {
   1.196 +        r = pY->GetInnerCompression(ImageDeflated, RomLoaderHeaderExists);
   1.197 +        if(KErrNone != r)
   1.198 +            {
   1.199 +            PrintToScreen(_L("Unable to determine the compression!\r\n"));
   1.200 +		    BOOT_FAULT();    
   1.201 +            }
   1.202 +        }
   1.203 +	LoadDevice=ELoadSerial;
   1.204 +	InputFunction=ReadYModemInputData;
   1.205 +	CloseInputFunction=CloseYModem;
   1.206 +	FileName=name;
   1.207 +
   1.208 +	return KErrNone;
   1.209 +	}
   1.210 +