2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Add a bootable device into the system.
10 #include <aros/debug.h>
12 #include <exec/memory.h>
13 #include <exec/execbase.h>
14 #include <dos/filehandler.h>
16 #include <proto/exec.h>
17 #include <proto/dos.h>
19 #include "expansion_intern.h"
21 /*****************************************************************************
24 #include <libraries/configvars.h>
25 #include <proto/expansion.h>
27 AROS_LH4(BOOL
, AddBootNode
,
30 AROS_LHA(LONG
, bootPri
, D0
),
31 AROS_LHA(ULONG
, flags
, D1
),
32 AROS_LHA(struct DeviceNode
*, deviceNode
, A0
),
33 AROS_LHA(struct ConfigDev
*, configDev
, A1
),
36 struct ExpansionBase
*, ExpansionBase
, 6, Expansion
)
39 AddBootNode() will add a device into the system. It does this in
42 1. If DOS is running, add the device to DOS's list of devices
44 2. Otherwise, save the information for later use by DOS, possibly
47 This allows device drivers to add devices into the system's disk
48 device list at any time, without having to worry about whether DOS
51 If a device is added before DOS is running, then it is possible for
52 the device to be used as a boot device. This allows for the user
53 to choose which device he/she wishes to boot from, and even which
54 OS they may wish to boot from.
56 The bootstrap will attempt to boot from the highest priority device
57 on the Expansion eb_BootNode list, and if that fails continue
58 through the list until it can succeed.
60 Floppy disk devices should always be given the highest priority, to
61 allow a user to prevent a hard disk or network boot by inserting a
64 AddBootNode() will also perform a second bit of magic, that if there
65 is no filesystem specified for this device, (i.e. dn_SegList, dn_Task
66 and dn_Handler are all NULL), then the standard DOS filesystem
67 will be used for this device.
70 bootPri - a BYTE describing the boot priority for this disk.
71 Recommended priorities are:
73 +5 - unit 0 on the floppy disk. The floppy
74 should be the highest priority.
75 0 - standard hard disk priority
76 -5 - recommended for a network disk
77 -128 - don't bother trying
79 flags - Additional information:
81 ADNF_STARTPROC (bit 0)-
82 if set this will cause AddBootNode() to start
83 a filesystem handler for the device node from
84 the information contained in the deviceNode
85 packet. This bit is only useful when there is
86 no running handler for this task (ie dn_Task
89 deviceNode - DOS device node for this device. Typically created
92 configDev - A valid expansion board ConfigDev structure, this
93 is required for an autoboot before DOS is running.
94 If left NULL, the node cannot be BootPoint booted.
97 TRUE if everything was ok,
98 FALSE if for some reason we failed (lack of memory etc).
101 The address of the ConfigDev structure is stored in the ln_Name
102 field of the BootNode structure.
115 *****************************************************************************/
123 if(deviceNode
== NULL
)
126 D(bug("[AddBootNode] Adding %b from Task %s\n", deviceNode
->dn_Name
, FindTask(NULL
)->tc_Node
.ln_Name
));
128 /* See if DOS is up and running... */
129 DOSBase
= OpenLibrary("dos.library", 0);
132 /* Don't add the same node twice */
133 ForeachNode(&ExpansionBase
->MountList
, bn
)
135 if (stricmp(AROS_BSTR_ADDR(
136 ((struct DeviceNode
*) bn
->bn_DeviceNode
)->dn_Name
),
137 AROS_BSTR_ADDR(deviceNode
->dn_Name
)) == 0)
139 /* so there was already an entry with that DOS name */
140 D(bug("[AddBootNode] Rejecting attempt to add duplicate device\n"));
145 if ((bn
= AllocMem(sizeof(struct BootNode
), MEMF_CLEAR
| MEMF_PUBLIC
)))
147 bn
->bn_Node
.ln_Name
= (STRPTR
)configDev
;
148 bn
->bn_Node
.ln_Type
= NT_BOOTNODE
;
149 bn
->bn_Node
.ln_Pri
= bootPri
;
150 bn
->bn_Flags
= flags
;
151 bn
->bn_DeviceNode
= deviceNode
;
152 D(bug("[AddBootNode] Add BootNode %p to the MountList\n", bn
));
154 Enqueue(&ExpansionBase
->MountList
, (struct Node
*)bn
);
162 /* If DOS isn't up yet, that's fine */
167 /* We should add the filesystem to the DOS device list. It will
168 * be usable from this point onwards.
170 * The DeviceNode structure that was passed to us can be added
171 * to the DOS list as it is, and we will let DOS start the
172 * filesystem task if it is necessary to do so.
174 if (AddDosEntry((struct DosList
*)deviceNode
))
176 if (!(flags
& ADNF_STARTPROC
))
183 BYTE len
= AROS_BSTR_strlen(deviceNode
->dn_Name
);
185 /* append a colon to the name, DeviceProc() needs a full path */
186 dosname
= AllocVec(len
+ 1 + 1, MEMF_ANY
);
189 CopyMem(AROS_BSTR_ADDR(deviceNode
->dn_Name
), dosname
, len
);
190 dosname
[len
++] = ':';
193 /* DeviceProc() will see that dn_Device for this node is NULL
194 * and start up the handler.
196 D(bug("[AddBootNode] Starting up \"%s\"\n", dosname
));
204 CloseLibrary((struct Library
*)DOSBase
);