| |
| /pliant/fullpliant/boot.pli |
| |
| 1 |
abstract | |
| 2 |
[This is the boot script for the FullPLiant operating system.] | |
| 3 |
| |
| 4 |
module "/pliant/language/context.pli" | |
| 5 |
module "/pliant/fullpliant/this_computer.pli" | |
| 6 |
module "/pliant/language/stream.pli" | |
| 7 |
module "/pliant/linux/storage/partition.pli" | |
| 8 |
module "/pliant/linux/storage/filesystem.pli" | |
| 9 |
module "/pliant/linux/network/boot.pli" | |
| 10 |
module "/pliant/linux/kernel/module.pli" | |
| 11 |
module "/pliant/linux/kernel/device.pli" | |
| 12 |
module "/pliant/admin/file.pli" | |
| 13 |
module "/pliant/admin/execute.pli" | |
| 14 |
module "/pliant/language/os.pli" | |
| 15 |
| |
| 16 |
constant medium this_computer:env:"pliant":"system":"medium" | |
| 17 |
constant embedded this_computer:env:"pliant":"system":"embedded" | |
| 18 |
constant checkdisk (file_query "file:/boot/checkdisk.flag" standard)=defined | |
| 19 |
| |
| 20 |
function boot | |
| 21 |
plugin first | |
| 22 |
console character:27+"[lb]9;0[rb]" # no console blanking | |
| 23 |
console "This computer is "+computer_fullname eol | |
| 24 |
if medium<>"nfs" and medium<>"cdrom" | |
| 25 |
var Str root := this_computer:env:"partition":"root":"device" | |
| 26 |
var Int dev := (file_query "/" extended):options option "filesystem_device" Int | |
| 27 |
if dev<>undefined | |
| 28 |
var Array:FileInfo devs := file_list "file:/dev/" extended+recursive | |
| 29 |
for (var Int i) 0 devs:size-1 | |
| 30 |
if (devs:i:options option "device" Int)=dev | |
| 31 |
root := devs:i name | |
| 32 |
if root<>"" | |
| 33 |
var CBool force_check := this_computer:env:"partition":"root":"check"="true" | |
| 34 |
console "Remounting / read write" (shunt checkdisk ", check forced" "") "." eol | |
| 35 |
if (filesystem_mount root "file:/" "remount"+(shunt checkdisk or force_check " check" ""))=failure | |
| 36 |
console "Failed to remount / read write." eol | |
| 37 |
if checkdisk | |
| 38 |
file_delete "file:/boot/checkdisk.flag" | |
| 39 |
else | |
| 40 |
console "There is no root partition defined." eol | |
| 41 |
# os_chroot "/" | |
| 42 |
# os_chdir "/" | |
| 43 |
(var Stream log) open "file:/log/pliant.log" append+safe | |
| 44 |
log writeline "boot "+string:datetime | |
| 45 |
log close | |
| 46 |
if false # (file_query "file:/mnt/initrd/" standard+directories)=success | |
| 47 |
console "Unmounting initrd filesystem." eol | |
| 48 |
filesystem_dismount "file:/mnt/initrd/" | |
| 49 |
console "Mounting /proc and /sys filesystems." eol | |
| 50 |
if (filesystem_mount "file:proc" "file:/proc" "filesystem [dq]proc[dq]")=failure | |
| 51 |
console "Failed to mount /proc filesystem." eol | |
| 52 |
else | |
| 53 |
(var Stream s) open "file:/proc/sys/kernel/hostname" out+safe | |
| 54 |
s writeline computer_name | |
| 55 |
s open "file:/proc/sys/kernel/domain" out+safe | |
| 56 |
s writeline computer_domain | |
| 57 |
s close | |
| 58 |
if (file_query "file:/sys/" extended)=failure | |
| 59 |
file_tree_create "file:/sys/" | |
| 60 |
filesystem_mount "file:sys" "file:/sys" "filesystem [dq]sysfs[dq]" | |
| 61 |
if true # adjust processor frequency | |
| 62 |
if (this_computer:env:"hardware":"processor":"frequency" parse (var Float ghz)) | |
| 63 |
(var Stream s) open "file:/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" out+safe | |
| 64 |
s writeline (string 1000000*ghz) | |
| 65 |
s close | |
| 66 |
if (this_computer:env:"hardware":"processor":"frequency_minimum" parse (var Float ghz)) | |
| 67 |
(var Stream s) open "file:/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq" out+safe | |
| 68 |
s writeline (string 1000000*ghz "fixed 0") | |
| 69 |
s close | |
| 70 |
if (this_computer:env:"hardware":"processor":"frequency_maximum" parse (var Float ghz)) | |
| 71 |
(var Stream s) open "file:/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" out+safe | |
| 72 |
s writeline (string 1000000*ghz "fixed 0") | |
| 73 |
s close | |
| 74 |
if true | |
| 75 |
var Str scheduler := this_computer:env:"partition":"root":"linux_scheduler" | |
| 76 |
var Str block := this_computer:env:"partition":"root":"device" | |
| 77 |
while block:len>0 and (block block:len-1)>="0" and (block block:len-1)<="9" | |
| 78 |
block := block 0 block:len-1 | |
| 79 |
block := block (block search_last "/" -1)+1 block:len | |
| 80 |
(var Stream s) open "file:/sys/block/"+block+"/queue/scheduler" out+safe | |
| 81 |
s writeline (shunt scheduler<>"" scheduler "cfq") | |
| 82 |
s close | |
| 83 |
if medium="cdrom" | |
| 84 |
console "Mounting /tmp in a RAM filesystem" eol | |
| 85 |
partition_format "device:/ram1" "ext2" "standard" | |
| 86 |
if (filesystem_mount "device:/ram1" "file:/tmp" "")=failure | |
| 87 |
console "Failed to mount /tmp in a RAM read write filesystem." eol | |
| 88 |
console "Configuring kernel modules dependencies" eol | |
| 89 |
execute "depmod -a -n" output "file:/tmp/modules.dep" | |
| 90 |
else | |
| 91 |
console "Configuring kernel modules dependencies" eol | |
| 92 |
execute "depmod -a " | |
| 93 |
plugin early | |
| 94 |
each m this_computer:env:"module" | |
| 95 |
console "Loading " m:"module" " kernel module" eol | |
| 96 |
if (kernel_load_module m:"module" m:"options")=success and (m:"sleep" parse (var Float seconds)) | |
| 97 |
sleep seconds | |
| 98 |
console "Starting kernel helper daemons" eol | |
| 99 |
if (file_query "file:/bin/irqbalance" standard)=defined | |
| 100 |
console " IRQ balancing" eol | |
| 101 |
file_tree_create "file:/var/run/" # wallaround dirty Debian patch | |
| 102 |
execute "irqbalance" | |
| 103 |
file_delete "file:/var/run/irqbalance.pid" | |
| 104 |
file_delete "file:/var/run/" | |
| 105 |
file_delete "file:/var/" | |
| 106 |
if (file_query "file:/bin/cardmgr" standard)=defined | |
| 107 |
console "PCMCIA setup" eol | |
| 108 |
execute "cardmgr -o -c /bin/pcmcia -p /tmp/cardmgr.pid -s /tmp/cardmgr.stab" | |
| 109 |
filesystem_scan | |
| 110 |
each p this_computer:env:"partition" | |
| 111 |
if p:"filesystem"="swap" | |
| 112 |
execute "mkswap "+(file_os_name p:"device") | |
| 113 |
eif p:"mountpoint"<>"" and p:"mountpoint"<>"file:/" | |
| 114 |
var CBool force_check := p:"check"="true" | |
| 115 |
console "Mounting "+keyof:p+" partition" eol | |
| 116 |
if (filesystem_mount p:"device" p:"mountpoint" p:"options"+(shunt checkdisk or force_check " check" ""))=failure | |
| 117 |
console "Failed to mount "+keyof:p+" at "+p:"mountpoint" eol | |
| 118 |
if embedded<>"" | |
| 119 |
module "embedded/boot.pli" | |
| 120 |
embedded_boot1 this_computer | |
| 121 |
net_boot | |
| 122 |
if (constant this_computer:env:"pliant":"ui":"console"="true") | |
| 123 |
console "Configuring graphic console" eol | |
| 124 |
kernel_load_module "uhci_hcd" | |
| 125 |
kernel_load_module "usbkbd" | |
| 126 |
kernel_make_device "device:/tty0" | |
| 127 |
# kernel_make_device "device:/input/keyboard" | |
| 128 |
kernel_load_module "usbmouse" | |
| 129 |
kernel_make_device "device:/input/mice" | |
| 130 |
# kernel_load_module "vesafb_tng" | |
| 131 |
kernel_make_device "device:/fb0" | |
| 132 |
module "/pliant/graphic/console/framebuffer_configure.pli" | |
| 133 |
framebuffer_configure | |
| 134 |
if (constant this_computer:env:"hardware":"audio":"module"<>"") | |
| 135 |
module "/pliant/linux/multimedia/audio.pli" | |
| 136 |
console "Audio setup" eol | |
| 137 |
kernel_make_device "device:/dsp" | |
| 138 |
kernel_make_device "device:/mixer" | |
| 139 |
if embedded<>"" | |
| 140 |
kernel_make_device "embedded:/dev/dsp" | |
| 141 |
file_rights "embedded:/dev/dsp" undefined undefined 6*64+6*8+6 0 | |
| 142 |
kernel_make_device "embedded:/dev/mixer" | |
| 143 |
file_rights "embedded:/dev/mixer" undefined undefined 6*64+6*8+6 0 | |
| 144 |
kernel_load_module this_computer:env:"hardware":"audio":"module" | |
| 145 |
kernel_load_module "snd_pcm_oss" | |
| 146 |
if this_computer:env:"hardware":"audio":"volume"<>"" | |
| 147 |
(var Stream s) open "audio:" "volume "+this_computer:env:"hardware":"audio":"volume"+(shunt this_computer:env:"hardware":"audio":"mic_volume"<>"" " mic_volume "+this_computer:env:"hardware":"audio":"mic_volume" "") in+out+safe | |
| 148 |
s close | |
| 149 |
boot | |
| 150 |
| |
| 151 |
function boot_custom | |
| 152 |
safe | |
| 153 |
plugin boot | |
| 154 |
failure err | |
| 155 |
(var Stream log) open "file:/boot/boot.log" out+safe | |
| 156 |
log writeline err | |
| 157 |
boot_custom | |
| 158 |
| |
| 159 |
function boot2 | |
| 160 |
module "/pliant/fullpliant/export.pli" | |
| 161 |
if embedded<>"" | |
| 162 |
export_init | |
| 163 |
if this_computer:env:"debian":"nfs":"service"="true" | |
| 164 |
console "Starting NFS file sharing" eol | |
| 165 |
export_nfs_start | |
| 166 |
if this_computer:env:"debian":"samba":"service"="true" | |
| 167 |
console "Starting Samba file sharing" eol | |
| 168 |
export_samba_start | |
| 169 |
if this_computer:env:"debian":"netatalk":"service"="true" | |
| 170 |
console "Starting Netatalk file sharing" eol | |
| 171 |
export_netatalk_start | |
| 172 |
if (constant this_computer:env:"sip":"siproxd":"service"="true") | |
| 173 |
var Str root := this_computer:env:"sip":"siproxd":"root" | |
| 174 |
if root="" | |
| 175 |
root := shunt (file_query "file:/bin/siproxd" standard)=success "file:/" "embedded:/" | |
| 176 |
if not (this_computer:env:"sip":"siproxd":"user" parse (var Int uid)) | |
| 177 |
uid := os_getuid | |
| 178 |
if not (this_computer:env:"sip":"siproxd":"group" parse (var Int gid)) | |
| 179 |
gid := os_getgid | |
| 180 |
if (constant this_computer:env:"sip":"siproxd":"configure"="true") | |
| 181 |
var Str inbound := this_computer:env:"sip":"siproxd":"if_inbound" | |
| 182 |
var Str outbound := this_computer:env:"sip":"siproxd":"if_outbound" | |
| 183 |
var Str reg := this_computer:env:"sip":"siproxd":"hosts_allow_reg" | |
| 184 |
(var Stream s) open root+"etc/siproxd.conf" out+safe+mkdir | |
| 185 |
s writeline "if_inbound = "+(shunt inbound<>"" inbound "eth1") | |
| 186 |
s writeline "if_outbound = "+(shunt outbound<>"" outbound "eth0") | |
| 187 |
s writeline "hosts_allow_reg = "+(shunt reg<>"" reg "10.0.0.0/8,192.168.0.0/16") | |
| 188 |
s writeline "sip_listen_port = 5060" | |
| 189 |
s writeline "daemonize = 1" | |
| 190 |
s writeline "rtp_proxy_enable = 1" | |
| 191 |
s writeline "rtp_port_low = 7070" | |
| 192 |
s writeline "rtp_port_high = 7079" | |
| 193 |
s writeline "rtp_timeout = 300" | |
| 194 |
s writeline "rtp_dscp = 46" | |
| 195 |
s writeline "default_expires = 600" | |
| 196 |
s close | |
| 197 |
console "Starting SIP proxy" eol | |
| 198 |
execute "siproxd" root root path root user uid group gid detached # output root+"tmp/siproxd.out" error root+"tmp/siproxd.err" | |
| 199 |
(var Stream flag) open "file:/boot/boot.flag" out+safe ; flag close | |
| 200 |
boot2 | |
| 201 |
| |
| 202 |
if embedded<>"" | |
| 203 |
console "Booting embedded system" eol | |
| 204 |
module "/pliant/language/stream/filesystembase.pli" | |
| 205 |
module "/pliant/language/stream/multi.pli" | |
| 206 |
pliant_multi_file_system mount "target:/" "embedded:/" pliant_default_file_system | |
| 207 |
module "embedded/configure.pli" | |
| 208 |
embedded_configure this_computer false | |
| 209 |
pliant_multi_file_system dismount "target:/" | |
| 210 |
module "embedded/boot.pli" | |
| 211 |
embedded_boot2 this_computer | |
| |