navienginebsp/naviengine_assp/uart/ubootldrkeybport.cpp
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * naviengine_assp\uart\vserialkeyb.cpp
       
    16 * Serial keyboard driver
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalTechnology
       
    24 */
       
    25 
       
    26 #include <e32keys.h>
       
    27 #include <comm.h>
       
    28 #include <assp.h>
       
    29 #include "../naviengine.h"
       
    30 #include <kernel/kern_priv.h>
       
    31 #include "uart16550_ne.h"
       
    32 #include "vserialkeyb.h"
       
    33 #include "bootloader_variantconfig.h"
       
    34 
       
    35 TInt TSerialKeyboard::GetSerialPort(TUint& aBaud)
       
    36 	{
       
    37 	// Get the Ymodem serial port from NOR Flash config values and set the keyboard port appropriately.
       
    38 	//
       
    39 	// The debug port should be the same as the Ymodem port.  The keyboard port should never be the same
       
    40 	// as the Ymodem port or else the image will fail to boot.
       
    41 	//
       
    42 	// Don't use port 2 as the keyboard port because we may not have a port 2 on the board.
       
    43 	//
       
    44 	// Therefore, depending on the YmodemG download port, set the keyboard port as follows:
       
    45 	//
       
    46 	//    Ymodem  Keyboard
       
    47 	//    0       1
       
    48 	//    1       0
       
    49 	//    2       1
       
    50 
       
    51 	TInt    keyboardPort           = 1;
       
    52 	aBaud = 115200;
       
    53 	TUint32 ConfigBlockAddressPhys = KNORFlashMaxBootloaderSize - KFlashEraseBlockSize;
       
    54 
       
    55 	__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: KNORFlashTargetAddr        = %x", KNORFlashTargetAddr       ));
       
    56 	__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: KNORFlashTargetSize        = %x", KNORFlashTargetSize       ));
       
    57 	__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: KNORFlashMaxBootloaderSize = %x", KNORFlashMaxBootloaderSize));
       
    58 	__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: KNORFlashMaxImageSize      = %x", KNORFlashMaxImageSize     ));
       
    59 	__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: KFlashEraseBlockSize       = %x", KFlashEraseBlockSize      ));
       
    60 	__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: ConfigBlockAddressPhys     = %x", ConfigBlockAddressPhys    ));
       
    61 
       
    62 	{
       
    63 		DPlatChunkHw * chunk;
       
    64 
       
    65 		TInt errorCode = DPlatChunkHw::New(chunk, ConfigBlockAddressPhys, KFlashEraseBlockSize, EMapAttrSupRw | EMapAttrFullyBlocking);
       
    66 		
       
    67 		if (errorCode == KErrNone)
       
    68 		{
       
    69 			TUint32 linearAddr         = (TUint)chunk->LinearAddress();
       
    70 
       
    71 			__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: linearAddr = %x", linearAddr));
       
    72 
       
    73 			SBootloaderConfig * configBlockPtr = (SBootloaderConfig * )linearAddr;
       
    74 
       
    75 			//TUint32 magic = *((TUint32*)linearAddr);
       
    76 			if (configBlockPtr->iMagic == KUidUBootldrCfgMagic)
       
    77 				{
       
    78 				// valid config block
       
    79 				__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: Valid config block, magic=%x", configBlockPtr->iMagic));
       
    80 				__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: ymodemPort == %d from NOR flash", configBlockPtr->iPortNumber));
       
    81 
       
    82 				switch (configBlockPtr->iPortNumber)
       
    83 					{
       
    84 					default:
       
    85 					case 0: keyboardPort=1; break;
       
    86 					case 1: keyboardPort=0; break;
       
    87 					case 2: keyboardPort=1; break;
       
    88 					}
       
    89 
       
    90 				// Set the debug port to be the same as the Ymodem download port so that error messages get logged by trgtest
       
    91 				Kern::SuperPage().iDebugPort = configBlockPtr->iPortNumber;
       
    92 				}
       
    93 			else
       
    94 				{
       
    95 				// invalid config block
       
    96 				__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: Invlaid config block, magic=%x", configBlockPtr->iMagic));
       
    97 				}
       
    98 		}
       
    99 		else
       
   100 		{
       
   101 			__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: error: failed to allocate chunk (%d)", errorCode));
       
   102 		}
       
   103 
       
   104 		// close the chunk
       
   105 		chunk->Close(chunk);
       
   106 	}
       
   107 
       
   108 	__KTRACE_OPT(KEXTENSION,Kern::Printf("ubootldrkeyb: keyboardPort == %d", keyboardPort));
       
   109 	return keyboardPort;
       
   110 	}
       
   111