ES
ES is an IOS module responsible for title management and launching.
Devices
Startup
After initializing the /dev/es device, ES calls the get_kernel_flavor syscall; if the flavor is below 3 (only happens for boot2 which uses 0), it checks for /sys/boot.sys on the NAND and finishes the Boot2 update it is present. After this, it calls the GetBusSpeed syscall to determine whether to load MIOS or the System Menu.
When the kernel flavor is greater than or equal to 3, ES checks for /sys/launch.sys and calls ES_LaunchTitle with the info in that file. If that file is absent, newer versions of ES check for /sys/disc.sys and set the access rights accordingly.
Title launching
Titles are launched with ES_LaunchTitle, which uses a context to track launching:
struct ESLaunchContext { struct TIK *ticket; struct TMD *tmd; u32 status; // 0 = unable to launch, 1 = launching/launched }
ES_LaunchTitle calls a function to initialize this struct. The function reads the system version from the TMD, and creates /sys/launch.sys with the given title ID and ticket view and recursively calls ES_LaunchTitle if the title is either 1-2 (System Menu) or anything that is not a system title, assuming /sys/launch.sys did not already exist; if /sys/launch.sys exists, the function replaces /sys/launch.sys with /sys/space.sys. If the title to be launched is an IOS, the system version is compared against the boot2 version; this could be used to require a minimum boot2 version, although Nintendo has never actually done this.
After this, ES_LaunchTitle builds the path to the main binary from the TMD content, and passes it to either ppc_boot
or ios_boot
(for everything between 1-3 and 1-257), and updates /sys/cc.sys if necessary.
Title import context
struct ESImportContext { struct TMD *tmd; // 0 u32 tmdSize; // 4 u32 unknown; // 8 u32 unknown2; // 0xc; possibly error u32 index; // 0x10 u32 unknown3[3]; u32 signatureLength; // 0x20 u32 unknown4[0x20]; u32 aesIv[0x10]; // 0xa0 }