UEFI 下存取記憶體時,有時會有 C4305 和 C4306 的編譯警告,但是那個 address 就是我們要的,暫時解法可以使用 marco 來取消此警告。
#pragma warning(push)
#pragma warning(disable:4305)
#pragma warning(disable:4306)
//your code.
#pragma warning(pop)
另外一種方式是使用 command line 參數
/wd4305 /wd4306
pretty code
2019年7月12日 星期五
UEFI Boot Variable 取值注意事項
困擾我一個星期的問題終於解決了!
一般來說,我們在取 Boot Variable 時,會先取得 BootOrder 這個變數的內容,因為裡面的 1 個開機項目是 2 Byte,故我們會把取到的 BootOrder size 除以 2 好方便我們取得所有項目個數,之後就可以用 for 迴圈依序取得 Boot Variable。
好死不死的,我們系統的的 BootOrder 是長底下這樣,故我先取 Boot0001 當然會取不到,害我一直往 EDK1/EDK2 的方向去找問題。另外,變數名稱前面不需要加上 "Efi:"。
sample code 如下:
一般來說,我們在取 Boot Variable 時,會先取得 BootOrder 這個變數的內容,因為裡面的 1 個開機項目是 2 Byte,故我們會把取到的 BootOrder size 除以 2 好方便我們取得所有項目個數,之後就可以用 for 迴圈依序取得 Boot Variable。
好死不死的,我們系統的的 BootOrder 是長底下這樣,故我先取 Boot0001 當然會取不到,害我一直往 EDK1/EDK2 的方向去找問題。另外,變數名稱前面不需要加上 "Efi:"。
sample code 如下:
orderValue = mGetVariable(L"BootOrder", &gEfiGlobalVariableGuid, &size);
if (orderValue == NULL) {
printf("Can't get BootOrder Variable \n");
return ERROR;
}
varCount = size / 2;
for (i = 0; i < varCount; i++) {
ptr = (char*)orderValue;
num = (UINT16*)(ptr + i * 2);
UnicodeSPrint(bootString, sizeof(bootString), L"Boot%04x", *num);
value = mGetVariable(bootString, &gEfiGlobalVariableGuid, &size);
if (value == NULL) {
printf("Can't get Boot%04X Variable \n", i);
return ERROR;
}
// 底下省略
}
UEFI Memory Map and BIOS E820 Table
趁著手上的事暫時告一段落的空檔,把幾天前 Google 到的資料整理一下,免得之後還要再查一次。
RU Tool 有一個可以看 BIOS E820 Table 的功能,E820 名稱是從指令 INT15h, AX=E820h 來的,因為我們對 AX 設值 E820,故命名為 E820 Table。Legacy BIOS 會把這個 Table 建好,OS 就知道那些 RAM 是可以用的。
來到了 UEFI 的時代,取而代之的是 UEFI Memory Map,我們可以透過 BootService 的 GetMemoryMap 函數來取得相關資訊,雖然我沒試過,但應該會等於 Shell memmap 指令的結果。
另外,從網路上查到的資料,Linux 似乎傾向使用 E820 Table,故會將 UEFI Memory Map 的資料轉換後填寫到原 E820 Structure。
有興趣的可以看此篇文章。
2020/06/03 更新
最近在看 dmesg log 時,無意間看到 E820 資訊,拍張照片記錄一下。
RU Tool 有一個可以看 BIOS E820 Table 的功能,E820 名稱是從指令 INT15h, AX=E820h 來的,因為我們對 AX 設值 E820,故命名為 E820 Table。Legacy BIOS 會把這個 Table 建好,OS 就知道那些 RAM 是可以用的。
來到了 UEFI 的時代,取而代之的是 UEFI Memory Map,我們可以透過 BootService 的 GetMemoryMap 函數來取得相關資訊,雖然我沒試過,但應該會等於 Shell memmap 指令的結果。
另外,從網路上查到的資料,Linux 似乎傾向使用 E820 Table,故會將 UEFI Memory Map 的資料轉換後填寫到原 E820 Structure。
有興趣的可以看此篇文章。
2020/06/03 更新
最近在看 dmesg log 時,無意間看到 E820 資訊,拍張照片記錄一下。
2019年7月10日 星期三
UEFI IndexVar in for loop
英文果然不是我的菜,一直卡在 IndexVar 怎麼命名都不對的情況!
查了一下 Code,發現 Code 只允許一個字元!
靜一下心,再把文字說明看一下,原來 IndexVar 只允許一個字元,真不知道是那個人想出來的,都不能使用有意義的變數名稱。
If after expansion no such files are found, the literal string itself is kept. Indexvar is any alphabet character from ‘a’ to ‘z’ or ‘A’ to ‘Z’, and they are case sensitive. It should not be a digit (0-9) because %digit will be interpreted as a positional argument on the command line that launches the script. The namespace for index variables is separate from that for environment variables, so if indexvar has the same name as an existing environment variable, the environment variable will remain unchanged by the for loop.
查了一下 Code,發現 Code 只允許一個字元!
靜一下心,再把文字說明看一下,原來 IndexVar 只允許一個字元,真不知道是那個人想出來的,都不能使用有意義的變數名稱。
If after expansion no such files are found, the literal string itself is kept. Indexvar is any alphabet character from ‘a’ to ‘z’ or ‘A’ to ‘Z’, and they are case sensitive. It should not be a digit (0-9) because %digit will be interpreted as a positional argument on the command line that launches the script. The namespace for index variables is separate from that for environment variables, so if indexvar has the same name as an existing environment variable, the environment variable will remain unchanged by the for loop.
2019年7月9日 星期二
Onyx Boox Note Lite 拆機照片
無意間發現之前拆 Treo 600 買的特殊規格螺絲起子就可以用來拆解 Note Lite。
雖然有了工具,但由於卡榫過多,故需要花費一番力氣,但不用擔心會把卡榫用斷。
雖然有了工具,但由於卡榫過多,故需要花費一番力氣,但不用擔心會把卡榫用斷。
把它拆開後,目測倒是看不出來什麼問題,可惜手上沒有三用電表,無法確認電池好壞,拍張照留作紀念,致我失去的 NT$13,400!
2019年7月4日 星期四
python package 待解疑問
貌似 python package 名稱使用 "-" 會有問題,我還找不到文件說明的地方,但是 PyPI 網站卻允許使用 "-",有點被搞糊塗了,以後再回來找答案。
2019/07/04 更新
在 PEP 8 中有提到命名的規則,如下所述。
Package and Module Names
Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.
When an extension module written in C or C++ has an accompanying Python module that provides a higher level (e.g. more object oriented) interface, the C/C++ module has a leading underscore (e.g. _socket).
2019/07/04 更新
在 PEP 8 中有提到命名的規則,如下所述。
Package and Module Names
Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.
When an extension module written in C or C++ has an accompanying Python module that provides a higher level (e.g. more object oriented) interface, the C/C++ module has a leading underscore (e.g. _socket).
2019/09/17 更新
在 Python bug 討論中看到,確實 "-" 是不合法的,只是不知道還適不適用在 Python 3。
訂閱:
文章 (Atom)






