原本撰寫 UEFI Application with C
關於網路部份我使用的是 HP porting 的 CurlLib
但這裡並沒有加上 HTTPS 的支援
CurlLib可以使用多種 SSL Lib
因為 UDK2014 在 CryptoLib porting 的是 openssl-0.9.8w
故我在這裡是選擇在 CurlLib 中打開 openssl
底下是我的步驟及遇到的問題,還有個人認為的解決方案
0. 使用 VC and UDK2014
1. 依照 "CryptoPkg\Library\OpensslLib\Patch-HOWTO.txt",安裝 openssl
2. Modify "HpNetworkPkg\HpNetworkPkg.dsc",add "OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf" in "[LibraryClasses]"
3. Modify "HpNetworkPkg\HpNetworkPkg.dec",add "../CryptoPkg/Include" in "[Includes]"
4. Modify "HpNetworkPkg\Library\CurlLib\lib\CurlLib.inf",add "CryptoPkg/CryptoPkg.dec" in "[Packages]" and "OpensslLib" in "[LibraryClasses]"
5. Modify "HpNetworkPkg\Library\CurlLib\lib\CurlLib.inf",add "/DUSE_SSLEAY /DUSE_OPENSSL" in "MSFT:*_*_*_CC_FLAGS"
此時會遇到很多 SSL 開頭函數的 Link Error
之所以會有這些問題是 UDK2014 雖然有 porting openssl-0.9.8w
但在 "OpensslLib.inf" 並沒有去編譯相關檔案
舉例來說 "CryptoPkg\Library\OpensslLib\openssl-0.9.8w\ssl" 裡的檔案都不在 "OpensslLib.inf"
故我認為有 2 個方式可以解決
1. Modify "OpensslLib.inf",編譯相關檔案,但我認為這是大工程
2. 使用 UEFI 原生的 HTTP_PROTOCOL,但不確定有沒有支援 HTTPS
留下測試的相關步驟以做記錄
2018年7月12日 星期四
2018年7月6日 星期五
UEFI Application - Python 3rd modules
今天想要試試如何在 UEFI 使用 Python 3rd modules
故挑了一個常用的 requests module 來測試
底下是相關的步驟
我使用的是 UDK 2014
1. pip install requests
2. pip show requests
3. copy step2 的相關 modules to EFI\StdLib\lib\python.27\site-packages
4. uncomment "default_socket_options = [(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]" in site-packages\urllib3\connection.py, and add "default_socket_options = []"
5. open "signal", "unicodedata", "zipimport", "zlib" in Python\Efi\config.c
6. define "WITH_THREAD" in Python\X64\pyconfig.h
7. add "Python-$(PYTHON_VERSION)/Modules/threadmodule.c" and "Python-$(PYTHON_VERSION)/Python/thread.c" in Python\PythonCore.inf
8. add your thread implement for uefi or you can use mine below. if this file is named "xxxx.h", remember to add "#include "xxxx.h" in Python\Python-2.7.2\Python\thread.c
9. rebuild Python.efi
故挑了一個常用的 requests module 來測試
底下是相關的步驟
我使用的是 UDK 2014
1. pip install requests
2. pip show requests
3. copy step2 的相關 modules to EFI\StdLib\lib\python.27\site-packages
4. uncomment "default_socket_options = [(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]" in site-packages\urllib3\connection.py, and add "default_socket_options = []"
5. open "signal", "unicodedata", "zipimport", "zlib" in Python\Efi\config.c
6. define "WITH_THREAD" in Python\X64\pyconfig.h
7. add "Python-$(PYTHON_VERSION)/Modules/threadmodule.c" and "Python-$(PYTHON_VERSION)/Python/thread.c" in Python\PythonCore.inf
8. add your thread implement for uefi or you can use mine below. if this file is named "xxxx.h", remember to add "#include "xxxx.h" in Python\Python-2.7.2\Python\thread.c
9. rebuild Python.efi
/*
* Initialization.
*/
static void
PyThread__init_thread(void)
{
}
/*
* Thread support.
*/
static int g_id = 123;
long
PyThread_start_new_thread(void (*func)(void *), void *arg)
{
return g_id;
}
long
PyThread_get_thread_ident(void)
{
return g_id;
}
void
PyThread_exit_thread(void)
{
}
/*
* Lock support.
*/
typedef struct {
char locked; /* 0=unlocked, 1=locked */
} thread_lock;
PyThread_type_lock
PyThread_allocate_lock(void)
{
thread_lock *lock = (thread_lock*)malloc(sizeof(thread_lock));
lock->locked = 0;
return (PyThread_type_lock)lock;
}
void
PyThread_free_lock(PyThread_type_lock lock)
{
thread_lock *p = (thread_lock*)lock;
free((void*)p);
}
int
PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
{
thread_lock *p = (thread_lock*)lock;
int success = p->locked == 0;
if ( !success && waitflag ) {
int count = 0;
while ( p->locked ) {
count++;
}
success = 1;
}
if (success) p->locked = 1;
return success;
}
void
PyThread_release_lock(PyThread_type_lock lock)
{
thread_lock *p = (thread_lock*)lock;
p->locked = 0;
}