2026年10月2日 星期五

UEFI LL#01 - Setup Build Environment (EDK II/stable202505 on Linux/Ubuntu-22.04 on Window11 x64)

Install WSL2 and Ubuntu-22.04
    > wsl --install -d Ubuntu-22.04




Download Container in guest Ubuntu-22.04
    REF: How to Develop With Containers · tianocore/tianocore.github.io Wiki
    REF: Package containers/ubuntu-22-dev
        $ sudo docker pull ghcr.io/tianocore/containers/ubuntu-22-dev:latest
            (latest is commit 6d71a30)


Download EDK II/stable202505
    $ cd ~
    $ git clone https://github.com/tianocore/edk2.git
    $ cd edk2
    $ git checkout -f edk2-stable202505 -b stable202505
    $ git submodule update --init

Launch Container for EDK II
    $ docker run -it \
       -v "${HOME}":"${HOME}" -e EDK2_DOCKER_USER_HOME="${HOME}" \
       --workdir ${HOME}/edk2 \
       ghcr.io/tianocore/containers/ubuntu-22-dev:latest /bin/bash
    -------------------------------------------------------------------------
    Error: 
        docker: permission denied while trying to connect to the Docker daemon socket         at unix:///var/run/docker.sock: Head "http://%2Fvar%2Frun%2Fdocker.sock/_ping":         dial unix /var/run/docker.sock: connect: permission denied
    Reason:    
        Docker daemon binds to a Unix socket owned by root. By default, other users can         only access it using sudo.

    Solution:
        #Create the docker group if it doesn't already exist 
            $ sudo groupadd docker 
        #Add your current user ($USER) to the docker group 
            $ sudo usermod -aG docker $USER 
        #To apply changes immediately without logging out
            $ newgrp docker

Build BaseTools
    $ source edksetup.sh
    $ make -C BaseTools

Build Module Development Elements of EDK II
    $ build -p MdeModulePkg/MdeModulePkg.dsc -t GCC5 -a X64 -b DEBUG
     (GCC5 is the default toolchain tag defined in container, not version)

Mount a FAT32 USB drive in WSL2
    Identify the drive letter in Windows Explorer (e.g., H:).
    Create a mount point in your WSL2 terminal:
        sudo mkdir /mnt/usb
    Mount the drive using the drvfs type
        sudo mount -t drvfs -o uid=$(id -u),gid=$(id -g),metadata H: /mnt/usb




yulin@DESKTOP-00KBDL6:~/tianocore$ pwd
/home/yulin/tianocore


yulin@DESKTOP-00KBDL6:~/tianocore$ cat ~/env_edk2
#!/bin/bash
docker run -it \
        -v "${HOME}":"${HOME}" -e EDK2_DOCKER_USER_HOME="${HOME}" \
        --workdir ${HOME} \
            ghcr.io/tianocore/containers/ubuntu-22-dev:latest /bin/bash


yulin@DESKTOP-00KBDL6:~/tianocore$ cat ~/.bashrc
...
#Yulin: setup build environment in the container for EDK2.
if [ "edk2" == "$USER" ]; then
    TC="$PWD/tianocore"
    VENDOR="Intel"
    EDK_EDK2="$TC/edk2"
    EDK_PLTF="$TC/edk2-platforms"
    EDK_NOSI="$TC/edk2-non-osi"
#   export PACKAGES_PATH=~/edk2:~/edk2-platforms:~/edk2-non-osi
    #Find name of the only folder inside ~/tianocore/edk2-platforms/Platform
    #Assuming ~/tianocore/edk2-platforms/Platform/Intel, PLATFORM=Intel
    export PACKAGES_PATH=$EDK_EDK2:$EDK_PLTF/Platform/$VENDOR:$EDK_PLTF/Silicon/$VENDOR:$EDK_NOSI
    cd $TC
    source $EDK_EDK2/edksetup.sh
    echo
    echo "Reminder: build -t GCC -a X64 -b DEBUG -p <Module>/<Module>.dsc"
    echo "Vendor: $VENDOR"
    echo
fi


yulin@DESKTOP-00KBDL6:~/tianocore$ ls -l
drwxr-xr-x 39 yulin yulin 4096 Dec 23 15:27 edk2
drwxr-xr-x  7 yulin yulin 4096 Jul 22 18:45 edk2-non-osi
drwxr-xr-x  8 yulin yulin 4096 Dec 23 15:00 edk2-platforms


edk2@5698206cd934:~/tianocore$ build -t GCC -a X64 -b DEBUG -p edk2-platforms/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc


edk2@5698206cd934:~/tianocore$ ls -l
drwxr-xr-x  5 edk2 edk2 4096 Dec 24 07:37 Build
drwxr-xr-x 39 edk2 edk2 4096 Dec 23 07:27 edk2
drwxr-xr-x  7 edk2 edk2 4096 Jul 22 10:45 edk2-non-osi
drwxr-xr-x  8 edk2 edk2 4096 Dec 23 07:00 edk2-platforms


Q: Does the ubuntu-22-dev found in https://github.com/tianocore/containers work in a Ubuntu24 host?

A by GoogleAI: 
Yes, the
ubuntu-22-dev container from the TianoCore repository is compatible with an Ubuntu 24.04 (Noble Numbat) host. 
In 2026, using older development containers on newer Ubuntu hosts is a common practice for maintaining stable EDK2 build environments. However, the TianoCore project has also released a native ubuntu-24-dev image specifically for newer systems. 

Compatibility & Usage
  • Docker/Podman Support: Since containers isolate the user-space, an Ubuntu 22.04-based image runs seamlessly on an Ubuntu 24.04 kernel via Docker or Podman.
  • Recommended Command: To use the Ubuntu 22 dev image while sharing your host's home directory (as intended by the TianoCore entry-point script), use:
      docker run -it \
        -v "${HOME}":"${HOME}" \
        -e EDK2_DOCKER_USER_HOME="${HOME}" \
        ghcr.io/tianocore/containers/ubuntu-22-dev:latest /bin/bash
    
  • KVM Acceleration: If you are using this container for the QEMU testing described in your previous scripts, ensure you pass the KVM device to the container by adding --device /dev/kvm to the run command. 

Why use ubuntu-22-dev vs ubuntu-24-dev?
  • Legacy Projects: If your specific UEFI project requires older versions of gcc or python-edk2-pytool-extensions that were validated on 22.04, stick with ubuntu-22-dev.
  • Newer Native Support: If you are starting a fresh project, the ubuntu-24-dev image (available at ghcr.io/tianocore/containers/ubuntu-24-dev:latest) provides updated toolchains natively matched to your host OS. 
Known Issues on Ubuntu 24.04 Hosts 
  • AppArmor: Ubuntu 24.04 introduced stricter AppArmor restrictions for unprivileged user namespaces. If you encounter permission errors when running the container, you may need to install the apparmor-utils package on your host or run the container with --security-opt apparmor=unconfined.


==========================================================
git clone https://github.com/tianocore/edk2.git
cd edk2
git submodule update --init
setx PYTHON_COMMAND "python"
setx NASM_PREFIX "C:\NASM"  NASM executable must be in system PATH variable

#Spawn a new CMD
call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=x86 -host_arch=x64
edksetup.bat Rebuild

#Spawn a new CMD
chcp 65001
call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=x64 -host_arch=x64 -vcvars_ver=14.29
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
edksetup.bat
build -p MdeModulePkg\MdeModulePkg.dsc -a X64 -b DEBUG -t VS2022 -n 1 -v
build -p MdeModulePkg\MdeModulePkg_CdcAcm.dsc -a X64 -b DEBUG -t VS2022 -n 1 -v
build -p MdeModulePkg\UT_UsbCdcAcm.dsc -a X64 -b DEBUG -t VS2022 -n 1 -v


Create a bootable USB disk of UEFI Shell

rufus-4.11.exe + UEFI-Shell-2.2-25H1-DEBUG.iso + GPT partition + BIOS Boot Device Priority

沒有留言: