搜尋此網誌

2016年8月5日 星期五

How to use __FILE__, __DATE__, __TIME__, __LINE__, __FUNCTION__, __FILE__ to debug in C?

================================================
__FILE__        current file nume.
__FUNCTION__    current functionnume.
__LINE__        current line number.
__DATE__        built date.

__TIME__        built time.
================================================

#include
#include
void call_test_fun(void);


#define DBG_PRINT(msg, arg...) printf("%s:%s(%d): " msg, __FILE__, __FUNCTION__, __LINE__, ##arg)

int main(void)
{
    printf( "The file is: %s\n", __FILE__ );
  
  printf( "This function is: %s\n", __FUNCTION__ );
    printf( "This is line: %d\n", __LINE__ );
    printf( "The date is: %s\n", __DATE__ );
    printf( "The time is: %s\n", __TIME__ );
    call_test_fun();
    return 0;
}

void call_test_fun(void)
{
    printf( "This function is: %s\n", __func__ );
    printf( "The file is: %s\n", __FILE__ );
    printf( "This is line: %d\n", __LINE__ );

    printf( "STDC: %d \n", __STDC__);
    printf( "STDC_HOSTED: %d \n", __STDC_HOSTED__);
    printf( "VERSION: %s \n", __VERSION__);
    printf( "TIMESTAMP: %s \n", __TIMESTAMP__);
    DBG_PRINT("number = %d, str = %s\n", index, str);
}

Create a Pop Up box in Hii(Human Interface Infrstructure)

u16 i;
EFI_INPUT_KEY                   Key;
DEBUG_PRINT (("Key scan.........\n"));
do {
    CreatePopUp (
        EFI_LIGHTGRAY | EFI_BACKGROUND_RED,
        &Key,
        L"",
        L"Would you like to create this virtual disk?",
        L"         [Yes]               [No]         ",
        L"",
        NULL
    );
    DEBUG_PRINT (("Unicode=0x%x, ScanCode=0x%x <%c>\n", Key.UnicodeChar, Key.ScanCode, Key.UnicodeChar));
} while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));

Print Messages:
Unicode=0x79, ScanCode=0x0
Unicode=0x59, ScanCode=0x0
Unicode=0x6E, ScanCode=0x0
Unicode=0x4E, ScanCode=0x0

ScanCode=0x0(SCAN_NULL)

//
// EFI Console Colours
//
#define EFI_BLACK                 0x00
#define EFI_BLUE                  0x01
#define EFI_GREEN                 0x02
#define EFI_CYAN                  (EFI_BLUE | EFI_GREEN)
#define EFI_RED                   0x04
#define EFI_MAGENTA               (EFI_BLUE | EFI_RED)
#define EFI_BROWN                 (EFI_GREEN | EFI_RED)
#define EFI_LIGHTGRAY             (EFI_BLUE | EFI_GREEN | EFI_RED)
#define EFI_BRIGHT                0x08
#define EFI_DARKGRAY              (EFI_BRIGHT)
#define EFI_LIGHTBLUE             (EFI_BLUE | EFI_BRIGHT)
#define EFI_LIGHTGREEN            (EFI_GREEN | EFI_BRIGHT)
#define EFI_LIGHTCYAN             (EFI_CYAN | EFI_BRIGHT)
#define EFI_LIGHTRED              (EFI_RED | EFI_BRIGHT)
#define EFI_LIGHTMAGENTA          (EFI_MAGENTA | EFI_BRIGHT)
#define EFI_YELLOW                (EFI_BROWN | EFI_BRIGHT)
#define EFI_WHITE                 (EFI_BLUE | EFI_GREEN | EFI_RED | EFI_BRIGHT)

#define EFI_TEXT_ATTR(f, b)       ((f) | ((b) << 4))

#define EFI_BACKGROUND_BLACK      0x00
#define EFI_BACKGROUND_BLUE       0x10
#define EFI_BACKGROUND_GREEN      0x20
#define EFI_BACKGROUND_CYAN       (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_GREEN)
#define EFI_BACKGROUND_RED        0x40
#define EFI_BACKGROUND_MAGENTA    (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_RED)
#define EFI_BACKGROUND_BROWN      (EFI_BACKGROUND_GREEN | EFI_BACKGROUND_RED)
#define EFI_BACKGROUND_LIGHTGRAY  (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_GREEN | EFI_BACKGROUND_RED)

//
// EFI Scan codes
//
#define SCAN_NULL       0x0000
#define SCAN_UP         0x0001
#define SCAN_DOWN       0x0002
#define SCAN_RIGHT      0x0003
#define SCAN_LEFT       0x0004
#define SCAN_HOME       0x0005
#define SCAN_END        0x0006
#define SCAN_INSERT     0x0007
#define SCAN_DELETE     0x0008
#define SCAN_PAGE_UP    0x0009
#define SCAN_PAGE_DOWN  0x000A
#define SCAN_F1         0x000B
#define SCAN_F2         0x000C
#define SCAN_F3         0x000D
#define SCAN_F4         0x000E
#define SCAN_F5         0x000F
#define SCAN_F6         0x0010
#define SCAN_F7         0x0011
#define SCAN_F8         0x0012
#define SCAN_F9         0x0013
#define SCAN_F10        0x0014
#define SCAN_F11        0x0015
#define SCAN_F12        0x0016

#define SCAN_ESC        0x0017

2016年6月24日 星期五

Convert __DATE__ to unsigned int

January => Jan. 
February => Feb. 
March => Mar. 
April => Apr. 
May => May. 
June => Jun. 
July => Jul. 
August => Aug. 
September => Sep. 
October => Oct. 
November => Nov. 
December => Dec. 


#include 〈stdio.h〉

#define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
+ (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))

#if 0 //fail when input "Jun"
#define MONTH (__DATE__ [2] == 'n' ? 0 \
: __DATE__ [2] == 'b' ? 1 \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 2 : 3) \
: __DATE__ [2] == 'y' ? 4 \
: __DATE__ [2] == 'n' ? 5 \
: __DATE__ [2] == 'l' ? 6 \
: __DATE__ [2] == 'g' ? 7 \
: __DATE__ [2] == 'p' ? 8 \
: __DATE__ [2] == 't' ? 9 \
: __DATE__ [2] == 'v' ? 10 : 11)
#endif

//fixed
#define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 0 : 5)  \
               : __DATE__ [2] == 'b' ? 1 \
               : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 2 : 3) \
               : __DATE__ [2] == 'y' ? 4 \
               : __DATE__ [2] == 'l' ? 6 \
               : __DATE__ [2] == 'g' ? 7 \
               : __DATE__ [2] == 'p' ? 8 \
               : __DATE__ [2] == 't' ? 9 \
               : __DATE__ [2] == 'v' ? 10 : 11)

#define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
+ (__DATE__ [5] - '0'))

#define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)

int main (void)
{
printf ("%d-%02d-%02d = %d\n", YEAR, MONTH + 1, DAY, DATE_AS_INT);
return 0;

}

2016年1月18日 星期一

UDK2014 How to Build

UDK2014 - How to build instructions
Download the UDK2014 Release with expanded workspace directories DownLoad

UDK2014 Release Files / Directories

What is included in the Downloaded zip file
  • UDK2014.MyWorkSpace.zip
  • BaseTools(Windows).zip
  • BaseTools(Unix).tar
  • Documents
  • Notes

Windows System Configuration

Microsoft Windows 7 Ultimate 64-bit*
1. Setup Build Environment
  • 1) Install Microsoft Visual Studio 2008* SP1 in the build machine and make sure that AMD64 complier was selected when installing.
2. Extract Common Source Code
  • 1) Extract files in [UDK2014.MyWorkSpace.zip] to the working space directory (e.g C:). Note the Directory "MyWorkSpace" will be created as a result. In this case, it is C:\MyWorkspace.
  • 2) There are two BaseTools package one is for Windows system and another is for UNIX-Like system. Please make sure BaseTools(Windows).zip is used here. Expand the appropriate BaseTools to C:\MyWorkSpace
3. Generate OpenSSL* Crypto Library Note: this does not need to be done for Nt32
  • Open file "C:\MyWorkspace\CryptoPkg\Library\OpensslLib\Patch-HOWTO.txt" and follow the instruction to install OpenSSL* for UEFI building.

http://ftp.vim.org/security/openssl/

=====================================================================
                                OpenSSL-Version
=====================================================================
  Current supported OpenSSL version for UEFI Crypto Library is 1.0.2d.
    http://www.openssl.org/source/openssl-1.0.2d.tar.gz
=====================================================================
                      HOW to Install Openssl for UEFI Building
=====================================================================
1.  Download OpenSSL 1.0.2d from official website:
    http://www.openssl.org/source/openssl-1.0.2d.tar.gz

    NOTE: Some web browsers may rename the downloaded TAR file to openssl-1.0.2d.tar.tar.
          When you do the download, rename the "openssl-1.0.2d.tar.tar" to
          "openssl-1.0.2d.tar.gz" or rename the local downloaded file with ".tar.tar"
          extension to ".tar.gz".

2.  Extract TAR into CryptoPkg/Library/OpenSslLib/openssl-1.0.2d

    NOTE: If you use WinZip to unpack the openssl source in Windows, please
          uncheck the WinZip smart CR/LF conversion option (WINZIP: Options -->
          Configuration --> Miscellaneous --> "TAR file smart CR/LF conversion").

3.  Apply this patch: EDKII_openssl-1.0.2d.patch, and make installation

    For Windows Environment:
    ------------------------
    1) Make sure the patch utility has been installed in your machine.
       Install Cygwin or get the patch utility binary from
          http://gnuwin32.sourceforge.net/packages/patch.htm
    2) cd $(WORKSPACE)\CryptoPkg\Library\OpensslLib\openssl-1.0.2d
    3) patch -p0 -i ..\EDKII_openssl-1.0.2d.patch
    4) cd ..
    5) Install.cmd

    For Linux* Environment:
    -----------------------
    1) Make sure the patch utility has been installed in your machine.
       Patch utility is available from http://directory.fsf.org/project/patch/
    2) cd $(WORKSPACE)/CryptoPkg/Library/OpensslLib/openssl-1.0.2d
    3) patch -p0 -i ../EDKII_openssl-1.0.2d.patch
    4) cd ..
    5) ./Install.sh
=====================================================================

4. Build Steps *** NT32 ***
  • 1) Open a command prompt, type command "cd C:\MyWorkspace" to enter the workspace directory, and then type command
> edksetup --nt32
to initialize the working environment. See also: Windows_systems_ToolChain_Matrix for how to change the TOOL_CHAIN_TAG for supported compiler combinations.
  • 2) Type below commands to build platforms (below assumes Microsoft Visual Studio 2008)
> build -t VS2008x86
Note: There are two methods to select the tool chain (Use Microsoft Visual Studio 2008* as sample):
  • 1. Update TOOL_CHAIN_TAG in file Conf/target.txt: TOOL_CHAIN_TAG = VS2008
  • 2. Add -t build option in command line: "build -t VS2008 ... "
For 32-bit VS2008 on 64-bit WINDOWS OS, VS2008x86 should be selected instead of VS2008. Please refer to tools_def.txt for all supported tool chains and detailed descriptions. (tools_def.txt will be generated at Conf directory after running "edksetup".)
  • 3. Note Microsoft Visual Studio* 2010 is supported with -t VS2010 or -t VS2010x86


Unix-Like System Configuration

Ubuntu
DistributorID: Ubuntu*
Description: Ubuntu 10*
Release: Ubuntu 10.10*
Codename: Karmic*
1. Extract Common Source Code
  • 1) Create a working space directory in the build machine, for example, ~/src/
  • 2) Extract files in [UDK2014.MyWorkSpace.zip] the working space directory. In this case, it is ~/src/MyWorkSpace where /MyWorkSpace is created.
  • 3) There are two BaseTools packages, one is for Windows system and another is for UNIX-Like system. Please make sure BaseTools(Unix).tar is used here.
2. Generate OpenSSL* Crypto Library Note: This does not need to be done for Nt32 Open file "~/src/MyWorkspace/CryptoPkg/Library/OpensslLib/Patch-HOWTO.txt" and follow the instruction to install OpenSSL* for UEFI building.
3. See How to Set up Build environment Using EDK II with Native GCC for newer versions of Linux
  • a) Please note that here the root is "~/src/MyWorkSpace" instead of "~/src/edk2"
  • b) Make sure BaseTools is built and required software like iASL compiler is installed well.
  • c) Some operations need switch to user "root" to execute.
4. Build Steps *** Nt32 ***
  • 1) Open a terminal and type "cd ~/src/MyWorkSpace" to enter the workspace directory.
  • 2) Initialize the build environment by typing
>. edksetup.sh BaseTools
  • 3) Type below commands to build platforms
> build -t GCC44