System Menu/BS2

From WiiBrew
Jump to navigation Jump to search

States taken from System Menu 257 (3.1U); they may or may not be consistent across versions. This is a mess, because the state can be examined or modified by 9 different functions; only 1 is accounted for here (BS2Tick). Most of the complication seems to come from the desire to use asynchronous calls everywhere.

There is a similar (but simpler) state machine used in SaveMii mode BS2BootIRD.

Types

State number Action Next state(s)
0 prints out status flags ("No Disk", "Drive Reset", "Wait Spinup", "Boot from Cache"), delay?, enable waiting-for-disk? 2, 52
1 delay 2
2 delay, enable waiting-for-disk?, DVDResetAsync 3
3 bs2_issue_dvd_command, delay, __DVDGetCoverStatusAsync, create cache.dat? 4
4 ReadDriveInfo via cache.dat or DVDInquiryAsync 5
5 wait for dvd & nand commands to finish, update cache.dat if necessary, setup 800030E6 [16bit] based on drive info and console type 8
6 DVDDownRotationAsync 7
7 wait for dvd & nand commands to finish 8
8 Read 0x20 bytes of disk id [from cache.dat or disk via DVDReadDiskID] 9
9/10 wait for dvd & nand commands to finish, update cache.dat if necessary, copy the 0x20 byte long disk id to 0x80000000.

if [disk_id + 0x18] is 0x5d1c9ea3, and the [disk_id + 0] is not 'RAAE', treat as a wii disc.

otherwise, if [disk_id + 0x1c] is 0xc2339f3d, treat as gamecube disk

otherwise, the disk type is unknown

gamecube disk = 11, wii disk = 15, unknown = 54
11 if not waiting for a disk, exit to state 50

if waiting, disable the waiting-for-disk and check streaming [0x80000008]

if streaming and no streaming buffer size defined [0x80000009], set to size 10

if streaming, setup via __DVDAudioBufferConfig

go to state 12

12, 50
12 wait for dvd & nand commands to finish 13
13 async unencrypted 0x2000 byte dvd read 14
14 wait for dvd & nand commands to finish

once finished, check game region

region ok = 50

region not match = 54

15 unknown check can switch to state 70

read 0x20 bytes from disk (game toc?)

16
16 wait for dvd & nand commands to finish, update cache.dat if necessary 17
17 read partition info from disk 18
18 wait for dvd & nand commands to finish, update cache.dat if necessary

go through the game partition, making note of those of type 0 and 1

19
19 read 0x2000 bytes from disk 20
20 wait for dvd & nand commands to finish, update cache.dat if necessary

if 0xc3f81a8e not found at the end of read block, go to state 54

if region check fails (SCGetProductGameRegion), go to state 54

if BS2IsValidDisc check fails, go to state 54

if booting from cache, go to state 37

if there's a partition of type 1, go to state 21

if there's a partition of type 0, go to state 37

otherwise, go to state 54

21,37,54
21 DVDOpenPartitionAsync opens the type 1 partition 22
22 wait for dvd & nand commands to finish and print out TMD info 23
23 use DVDReadAbsAsyncForBS to read disk header 24
24 wait for dvd & nand commands to finish

check for 0x5d1c9ea3 in header (wii or gc disc)

24, 25 (non-wii/gc disc), 35 (wii/gc disc)
25 DVDReadAbsAsyncForBS [read 0x20 bytes from 0x910 (<<2?) in the partition] 26
26 wait for dvd & nand commands to finish, update cache.dat if necessary

print out appLoaderLength / appLoaderFunc1

27
27 DVDReadAbsAsyncForBS [read (appLoaderLength rounded up to next 0x20 multiple) bytes from 0x918 (<<2?) in the partition to 0x81200000 ] 28
28 wait for dvd & nand commands to finish, update cache.dat if necessary

ICInvalidateRange from 0x81200000 to length of apploader, rounded up to nearest 0x20 multiple call apploader init func with 3 parameters call callback1 from apploader_init

29
29 call apploader main func, returns address, length, offset

print "Addr [0x%x] length [0x%x] offset [0x%x]" DVDReadAbsAsyncForBS using offset, length to load to address if check value in 0x800030D4 is set, cache some other values

30 (apploader main returned non-zero)

31 (apploader main returned zero)

30 wait for dvd & nand commands to finish, update cache.dat if necessary 29
31 __DVDFSInit

BS2UpdateInit - spawn off a thread that does the __update.inf/etc stuff

32
32 BS2UpdateState

if an update is in progress:

BS2GetUpdateEntryNum
BS2UpdateState
BS2GetUpdateEntryNum
BS2Report("%d entries")
__DVDGetCoverStatusAsync
state 33

otherwise:

__DVDGetDriveStatus
based on status (?), DVDCancelAllAsync
32

1 (no update) 33 (update present) 35 ("No Entry"?)

33 bs2_issue_dvd_command?

BS2UpdateState __DVDGetCoverStatusAsync

33 or 34
34 BS2UpdateState

__DVDGetDriveStatus based on status (?), DVDCancelAllAsync based on return code of BS2UpdateState, print "Update success", "Update success\nPlease reboot", or "Update failed"

34

35 (update success) 58 (update failed)

35 DVDClosePartitionAsync 36
36 bs2_issue_dvd_command?

BS2UpdateState

37

54 65

37 Open partition from cache.dat, or DVDPartitionOpenAsync 38
38 print TMD info? 39
39 read from cache? 40
40 print appLoaderLength / appLoaderFunc1 41
41 read from cache? 42
42 call apploader init func 43
43 call apploader main func 44 or 45
44 ? 43 or 44
45 check for banner; if present, open it and read it from disc 46 (banner)

47 (no banner)

46 ? 47
47 DVDClosePartitionAsync 48
48 ? 49

69 72

49/69/72 bs2_issue_dvd_command?

__DVDGetCoverStatusAsync

49/69/72 (state changed by bs2_async_callback?)
50 bs2_issue_dvd_command

__DVDGetCoverStatusAsync

50 (state changed by bs2_async_callback?)
51 deallocate something? 2
52/53 deallocate something?

bs2_issue_dvd_command? __DVDGetCoverStatusAsync

52/53 (state changed by bs2_async_callback?)
54 deallocate something?

DVDChangeDiskAsyncForBS

55
55/56 bs2_issue_dvd_command? 55/56 (?)
57/58 deallocate something? 57/58?
59/63 ? 58

59 64

60 something with disc cache? 61
61 DVDClosePartitionAsync 62
62 something with disc cache? 63
64 ? 2

3 15 57 64

65 deallocate something? 65 (?)
66 __DVDGetCoverStatusAsync 66, 67
67/68 bs2_issue_dvd_command? 67/68?
70 DVDGetPartitionParamsAsync 71
71 something with ticket?

DVDOpenPartitionWithParams

38

71