2019年9月17日 星期二

FreeDOS 製作

雖然是 UEFI 當道的時代,但工作上總是有人要 legacy BIOS support
這時候就需要個 FreeDOS 做驗證

A. 簡易製作法 (使用 rufus)
  1. 準備一顆 USB隨身碟
  2. 到 https://rufus.ie/ 下載 rufus
  3. 做以下設定後選擇執行,過程會清除隨身碟
 



















   4. 完成後就可以使用 USB 隨身碟開啟 FreeDOS



B. FreeDOS 官網(麻煩)製作法
  1. 準備兩顆 USB 隨身碟
  2. 到 https://www.freedos.org/download/ 下載  <USB “Full” installer> 的版本
  3. 用 rufus 把解壓縮的 FD12FULL.img 加入




















  4. 完成後得到 FreeDOS的開機安裝碟
  5. 將兩顆 USB 隨身碟接到電腦上 (需要把 CSM 功能打開)
  6. 依照安裝指示選取,注意選對磁碟,建議移除自己使用的硬碟
      部分步驟可參考 http://wiki.freedos.org/install/
  7. 完成後就可以使用 USB 隨身碟開啟 FreeDOS




2019年3月19日 星期二

簡易架設 Windows debug(WinDbg)

簡易架設 windows debug以及追蹤 method的方法

1. 首先 Host端下載 Windows SDK,可以只選 debug tool來安裝,下載 ISO檔可跳過此步驟
https://developer.microsoft.com/zh-tw/windows/downloads/sdk-archive





2. 到指定下載位置進行安裝SDK




3. Target端設定
  • 搜尋 msconfig->開機->進階選項->開啟偵錯->選擇USB->輸入名稱


4. 另外也可以用 CMD的方式
參考 https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-a-usb-3-0-debug-cable-connection

bcdedit /debug on
bcdedit /dbgsettings usb targetname:TargetName
==>  "TargetName"="USB 目標名稱"
bcdedit /set "{dbgsettings}" busparams b.d.f
==> b.d.f ==> bus : device : function (usb XHCI PCIE controller)


5. Host端執行 WinDbg (X64)




6. 使用 USB3.0線將 Host Target連線
Target重新開機後就可以 Windbg就可以 Work



7. 故障排除
當某些狀況無法更換版本時,將以下路徑手動移除
 C:\Program Files (x86)\Windows Kits\10\Debuggers

2019年1月2日 星期三

在 Windows中讀取 ESP(EFI System Partition)的方法

1. 以管理員身分開啟 CMD
2. 輸入 "mountvol X: /s"
3. 下載  Explorer++
4. 以管理員身分執行  Explorer++可以看到多一個 X槽選擇

2018年4月2日 星期一

多重作業系統安裝

1. 使用 WinSetupFromUSB製作多重作業系統開機碟
參考下列連結
製作USB多重系統選單式的開機碟工具 – WinSetupFromUSB

2. 移除或修改已經安裝的開機碟
http://www.winsetupfromusb.com/faq/
15. How to remove already added sources?
16. How to edit boot menu names?

3. 使用 Visual BCD注意
選項 Store -> Open system store
        Store -> Import store
以及剛啟動 VisualBcd.exe時,修改對象都是現在使用的 OS
隨意修改可能使系統無法開機

2018年3月29日 星期四

[ACPI] EC AC ASL

最近有機會碰到 ASL code
做個紀錄

1. 範例程式碼
External(\_PR.POWS)

Scope(\_SB.PCI0.LPCB)
{
  Device(EC) {
    Name(_HID, EISAID("PNP0C09"))
    Name(_GPE, 0x00)
    Name(_CRS, ResourceTemplate() {
      IO(Decode16, 0x62, 0x62, 0x00, 0x01)
      IO(Decode16, 0x66, 0x66, 0x00, 0x01)
    })

    OperationRegion(ERAM,EmbeddedControl,0,0xFF)
    Field(ERAM,ByteAcc,Lock,Preserve) {
    // Field definitions
    }

    Method(_QXX) {
      ...
    }

    Device(AC) {
      Name(_HID, "ACPI0003")
      Name(_PCL, Package(1) {\_SB})

      Method(_PSR, 0, NotSerialized)
      {
        ...
      }
    }
  } 
}
2. External (Declare External Objects)
Syntax
  External (ObjectName, ObjectType, ReturnType, ParameterTypes)


用來引用不同 ACPI Table中的 ObjectName時使用
常見於 DSDT和 SSDT之間的互動
舉例
  先在 DSDT中宣告 External(\_PR.POWS)  // 位於CpuSsdt.asl中的變數
  就可直接使用 Store(1, \_PR.POWS) 改變數值

3. Scope (Open Named Scope)
Syntax
  Scope (Location) {ObjectList}

Example:
  Device(AC) 目前的位置是 \_SB.PCI0.LPCB.EC

  如果在外層加上
    Scope(\_SB) {
      Device(AC) {
        ...
      }
    }

  則新的 Device(AC)位置會變為 \_SB
  用來定義括號包含物件的層級位置,不會受到描寫時的位置影響

4. _HID (Hardware ID)

判斷 Device用的 ID,非必要,主要是提供給 OSPM判斷用的
Example ASL:
Name (_HID, EISAID ("PNP0C0C")) // Control-Method Power Button
Name (_HID, EISAID ("INT0800"))    // Firmware Hub
Name (_HID, "ACPI0003")                 // AC adapter device
Name (_HID, "MSFT0003")                // Vendor-defined device
Name (_HID, "80860003")                  // PCI-assigned device identifier

5. _GPE, _QXX

這兩個是一組的,_QXX是 Q event,也是一種 SCI,由 EC透過 GPIO發出
XX 的值可由對 IO 60h下指令 0x84,再到 IO 64h讀取

_GPE 的值是由 GPIO轉換後對應,OS會將此 GPE發送的訊息傳入 Device(EC)
爾後判斷對應的_QXX,執行不同的任務

6. OperationRegion()

OperationRegion (Declare Operation Region)
  Syntax
    OperationRegion (RegionName, RegionSpace, Offset, Length)


用來定義 ASL使用的空間,RegionSpace判斷不同 Type使用

範例 OperationRegion(ERAM,EmbeddedControl,0,0xFF)
指的是在 EC space中,開始位置為 0,範圍 0x100 Bytes,取名 ERAM




7. Field()

Field (Declare Field Objects)
  Syntax
    Field (RegionName, AccessType, LockRule, UpdateRule) {FieldUnitList}


將取過名的空間作細部配置,可以利用 Offset()做非連續的空間配置
另外同一空間中可以不同配置名稱重複定義

Field(ERAM,ByteAcc,Lock,Preserve) {
  AB11, 8,         // offset 0x00
  AB22, 8,         // offset 0x01
  AB33, 8,         // offset 0x02
  Offset(0x21),  //
  AB33, 8          // offset 0x21
}

Field(ERAM,ByteAcc,Lock,Preserve) {
  CD11, 16,       // offset 0x00
  CD22, 8,         // offset 0x02
}


8. AC Adapters and Power Source Objects

當 device的 _HID為"ACPI0003",會被認為是 AC power source
ACPI spec中定義的 Object有以下四種


 如果只有單一 AC輸入只需要 _PCL / _PSR就能正常運作

8-1. _PCL (Power Consumer List)
This object evaluates to a list of pointers, each pointing to a device or a bus powered by the power source device. Pointing to a bus indicates that all devices under the bus are powered by the power source device.

Return Value:
  A variable-length Package containing a list of References to devices or buses


8-2. _PSR (Power Source)
Returns whether the power source device is currently in use. This can be used to determine if system is running off this power supply or adapter. On mobile systes this will report that the system is not running on the AC adapter if any of the batteries in the system is being forced to discharge. In systems that contains multiple power sources, this object reports the power source’s online or offline status.

Return Value:
  An Integer containing the power source status
  0 – Off-line (not on AC power)
  1 – On-line


8-3. Notify()

改變 _PSR的狀態可以透過 Notify(AC, 0x80)實現
一般會放在 AC插拔的 Q event中去觸發

Method(_Q0A) {
  sleep(500)           // 等待hardware反應
  Notify(AC, 0x80)  // 改變 _PSR
}