mkboot 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/rc
  2. #
  3. # this file configures a boot program (/boot) for a kernel.
  4. #
  5. if(! ~ $#* 1){
  6. echo usage: mkboot file >[1=2]
  7. exit 1
  8. }
  9. cat <<'---'
  10. #include <u.h>
  11. #include <libc.h>
  12. #include "../boot/boot.h"
  13. Method method[]={
  14. ---
  15. #
  16. # configure all remote methods, i.e. all methods in the 'boot' section
  17. #
  18. # EXAMPLE
  19. # boot
  20. # incon
  21. # 9600
  22. # 19200
  23. #
  24. ../port/mkextract boot 0 $* | awk '{
  25. printf " { \"" "" $1 "\", "\
  26. "config" $1 ", "\
  27. "connect" $1 ", "
  28. print fieldn(2) " },"
  29. }
  30. func fieldn(n, s,i)
  31. {
  32. s = $0
  33. while (n > 1) {
  34. sub(/^[ \t]*/, "", s)
  35. if (substr(s, 1, 1) == "\"") {
  36. sub(/^"[^\"]*"/, "", s)
  37. } else {
  38. sub(/^[^ \t]*/, "", s)
  39. }
  40. n--
  41. }
  42. sub(/^[ \t]*/, "", s)
  43. if (substr(s, 1, 1) == "\"") {
  44. i = index(substr(s, 2), "\"")
  45. if (i > 0)
  46. return substr(s, 1, i+1)
  47. else
  48. return s
  49. } else {
  50. sub(/[ \t].*/, "", s)
  51. return s
  52. }
  53. }'
  54. cat <<'---'
  55. { 0 },
  56. };
  57. ---
  58. awk '
  59. BEGIN { cpuflag = 0; bootprog = "boot"; bootdisk = "#S/sdC0/"; rootdir = "/root"; }
  60. $0 ~ "^boot" && $2=="cpu"\
  61. { cpuflag = 1
  62. if(NF == 4 && $3 == "boot")
  63. bootdisk = $4
  64. }
  65. $0 ~ "^boot" && $2=="rootdir" && NF==3\
  66. { rootdir = $3 }
  67. $0 ~ "^boot" && ($2=="bboot" || $2=="romboot" || $2=="dosboot")\
  68. { cpuflag = 1; bootprog = $2; }
  69. $0 ~ "^boot" && $2=="boot" && NF==3\
  70. { bootdisk = $3 }
  71. END { print "int cpuflag = " cpuflag ";"
  72. print "char* rootdir = \"" rootdir "\";"
  73. print "char* bootdisk = \"" bootdisk "\";"
  74. print "extern void " bootprog "(int, char**);"
  75. print "void"
  76. print "main(int argc, char **argv)"
  77. print "{"
  78. print "\t" bootprog "(argc, argv);"
  79. print "}"
  80. }
  81. ' $1
  82. #
  83. # configure in a cache file system if a
  84. # /386/bin/root appears in the bootdir section.
  85. #
  86. ../port/mkextract bootdir 0 $* | awk '
  87. BEGIN { cfs = 0 }
  88. $1 ~ "bin/cfs$" { cfs = 1 }
  89. END { if(cfs)
  90. print "int (*cfs)(int) = cache;"
  91. else
  92. print "int (*cfs)(int) = 0;"
  93. }
  94. '