blob: 5fcd839940f3c87936100c52129c5c6e846de188 [file] [log] [blame]
Vladimir Serbinenko3129f792014-10-15 21:51:47 +02001/* This is just an experiment. Full automatic porting
2 is probably not possible but a lot can be automated. */
3package main
4
5import (
6 "bytes"
7 "flag"
8 "fmt"
9 "log"
10 "os"
11 "sort"
12 "strings"
13)
14
15type PCIAddr struct {
16 Bus int
17 Dev int
18 Func int
19}
20
21type PCIDevData struct {
22 PCIAddr
23 PCIVenID uint16
24 PCIDevID uint16
25 ConfigDump []uint8
26}
27
28type PCIDevice interface {
29 Scan(ctx Context, addr PCIDevData)
30}
31
32type InteltoolData struct {
33 GPIO map[uint16]uint32
34 RCBA map[uint16]uint32
35 IGD map[uint32]uint32
36}
37
38type DMIData struct {
39 Vendor string
40 Model string
41 Version string
42 IsLaptop bool
43}
44
45type AzaliaCodec struct {
46 Name string
47 VendorID uint32
48 SubsystemID uint32
49 CodecNo int
50 PinConfig map[int]uint32
51}
52
53type DevReader interface {
54 GetPCIList() []PCIDevData
55 GetDMI() DMIData
56 GetInteltool() InteltoolData
57 GetAzaliaCodecs() []AzaliaCodec
58 GetACPI() map[string][]byte
59 GetCPUModel() []uint32
60 GetEC() []byte
61 GetIOPorts() []IOPorts
Vladimir Serbinenko91195c62015-05-29 23:53:37 +020062 HasPS2() bool
Vladimir Serbinenko3129f792014-10-15 21:51:47 +020063}
64
65type IOPorts struct {
66 Start uint16
67 End uint16
68 Usage string
69}
70
71type SouthBridger interface {
72 GetGPIOHeader() string
73 EncodeGPE(int) int
74 DecodeGPE(int) int
75 EnableGPE(int)
76 NeedRouteGPIOManually()
77}
78
79var SouthBridge SouthBridger
80var ROMStageFiles map[string]string = map[string]string{}
81var RAMStageFiles map[string]string = map[string]string{}
82var SMMFiles map[string]string = map[string]string{}
83var MainboardInit string
84var MainboardEnable string
85var MainboardIncludes []string
86
87type Context struct {
88 MoboID string
89 KconfigName string
90 Vendor string
91 Model string
92 BaseDirectory string
93 InfoSource DevReader
Vladimir Serbinenko2d615e52015-05-29 21:43:51 +020094 SaneVendor string
Vladimir Serbinenko3129f792014-10-15 21:51:47 +020095}
96
97type IOAPICIRQ struct {
98 APICID int
99 IRQNO [4]int
100}
101
102var IOAPICIRQs map[PCIAddr]IOAPICIRQ = map[PCIAddr]IOAPICIRQ{}
103var KconfigBool map[string]bool = map[string]bool{}
104var KconfigComment map[string]string = map[string]string{}
105var KconfigString map[string]string = map[string]string{}
106var KconfigStringUnquoted map[string]string = map[string]string{}
107var KconfigHex map[string]uint32 = map[string]uint32{}
108var KconfigInt map[string]int = map[string]int{}
109var ROMSizeKB = 0
110var ROMProtocol = ""
111var FlashROMSupport = ""
112
113func GetLE16(inp []byte) uint16 {
114 return uint16(inp[0]) | (uint16(inp[1]) << 8)
115}
116
117func FormatHexLE16(inp []byte) string {
118 return fmt.Sprintf("0x%04x", GetLE16(inp))
119}
120
121func FormatHex32(u uint32) string {
122 return fmt.Sprintf("0x%08x", u)
123}
124
125func FormatHex8(u uint8) string {
126 return fmt.Sprintf("0x%02x", u)
127}
128
129func FormatInt32(u uint32) string {
130 return fmt.Sprintf("%d", u)
131}
132
133func FormatHexLE32(d []uint8) string {
134 u := uint32(d[0]) | (uint32(d[1]) << 8) | (uint32(d[2]) << 16) | (uint32(d[3]) << 24)
135 return FormatHex32(u)
136}
137
138func FormatBool(inp bool) string {
139 if inp {
140 return "1"
141 } else {
142 return "0"
143 }
144}
145
146func sanitize(inp string) string {
147 result := strings.ToLower(inp)
148 result = strings.Replace(result, " ", "_", -1)
149 result = strings.Replace(result, ",", "_", -1)
Arthur Heymansc8c3aca2018-01-18 22:20:25 +0100150 result = strings.Replace(result, "-", "_", -1)
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200151 for strings.HasSuffix(result, ".") {
152 result = result[0 : len(result)-1]
153 }
154 return result
155}
156
157func AddROMStageFile(Name string, Condition string) {
158 ROMStageFiles[Name] = Condition
159}
160
161func AddRAMStageFile(Name string, Condition string) {
162 RAMStageFiles[Name] = Condition
163}
164
165func AddSMMFile(Name string, Condition string) {
166 SMMFiles[Name] = Condition
167}
168
169func IsIOPortUsedBy(ctx Context, port uint16, name string) bool {
170 for _, io := range ctx.InfoSource.GetIOPorts() {
171 if io.Start <= port && port <= io.End && io.Usage == name {
172 return true
173 }
174 }
175 return false
176}
177
178var FlagOutDir = flag.String("coreboot_dir", ".", "Resulting coreboot directory")
179
180func writeMF(mf *os.File, files map[string]string, category string) {
181 keys := []string{}
182 for file, _ := range files {
183 keys = append(keys, file)
184 }
185
186 sort.Strings(keys)
187
188 for _, file := range keys {
189 condition := files[file]
190 if condition == "" {
191 fmt.Fprintf(mf, "%s-y += %s\n", category, file)
192 } else {
193 fmt.Fprintf(mf, "%s-$(%s) += %s\n", category,
194 condition, file)
195 }
196 }
197}
198
199func Create(ctx Context, name string) *os.File {
200 li := strings.LastIndex(name, "/")
201 if li > 0 {
202 os.MkdirAll(ctx.BaseDirectory+"/"+name[0:li], 0700)
203 }
204 mf, err := os.Create(ctx.BaseDirectory + "/" + name)
205 if err != nil {
206 log.Fatal(err)
207 }
208 return mf
209}
210
Arthur Heymans59302852017-05-01 10:33:56 +0200211func Add_gpl(fp *os.File) {
212 fp.WriteString(`/*
213 * This file is part of the coreboot project.
214 *
215 * Copyright (C) 2008-2009 coresystems GmbH
216 * Copyright (C) 2014 Vladimir Serbinenko
217 *
218 * This program is free software; you can redistribute it and/or
219 * modify it under the terms of the GNU General Public License as
220 * published by the Free Software Foundation; version 2 of
221 * the License.
222 *
223 * This program is distributed in the hope that it will be useful,
224 * but WITHOUT ANY WARRANTY; without even the implied warranty of
225 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
226 * GNU General Public License for more details.
227 */
228
229`)
230}
231
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200232func RestorePCI16Simple(f *os.File, pcidev PCIDevData, addr uint16) {
233 fmt.Fprintf(f, " pci_write_config16(PCI_DEV(%d, 0x%02x, %d), 0x%02x, 0x%02x%02x);\n",
234 pcidev.Bus, pcidev.Dev, pcidev.Func, addr,
235 pcidev.ConfigDump[addr+1],
236 pcidev.ConfigDump[addr])
237}
238
239func RestorePCI32Simple(f *os.File, pcidev PCIDevData, addr uint16) {
240 fmt.Fprintf(f, " pci_write_config32(PCI_DEV(%d, 0x%02x, %d), 0x%02x, 0x%02x%02x%02x%02x);\n",
241 pcidev.Bus, pcidev.Dev, pcidev.Func, addr,
242 pcidev.ConfigDump[addr+3],
243 pcidev.ConfigDump[addr+2],
244 pcidev.ConfigDump[addr+1],
245 pcidev.ConfigDump[addr])
246}
247
248func RestoreRCBA32(f *os.File, inteltool InteltoolData, addr uint16) {
249 fmt.Fprintf(f, "\tRCBA32(0x%04x) = 0x%08x;\n", addr, inteltool.RCBA[addr])
250}
251
252type PCISlot struct {
253 PCIAddr
254 additionalComment string
255 writeEmpty bool
256}
257
258type DevTreeNode struct {
259 Bus int
260 Dev int
261 Func int
262 Disabled bool
263 Registers map[string]string
264 IOs map[uint16]uint16
265 Children []DevTreeNode
266 PCISlots []PCISlot
267 PCIController bool
268 ChildPCIBus int
269 MissingParent string
270 SubVendor uint16
271 SubSystem uint16
272 Chip string
273 Comment string
274}
275
276var DevTree DevTreeNode
277var MissingChildren map[string][]DevTreeNode = map[string][]DevTreeNode{}
278var unmatchedPCIChips map[PCIAddr]DevTreeNode = map[PCIAddr]DevTreeNode{}
279var unmatchedPCIDevices map[PCIAddr]DevTreeNode = map[PCIAddr]DevTreeNode{}
280
281func Offset(dt *os.File, offset int) {
282 for i := 0; i < offset; i++ {
283 fmt.Fprintf(dt, "\t")
284 }
285}
286
287func MatchDev(dev *DevTreeNode) {
288 for idx := range dev.Children {
289 MatchDev(&dev.Children[idx])
290 }
291
292 for _, slot := range dev.PCISlots {
293 slotChip, ok := unmatchedPCIChips[slot.PCIAddr]
294
295 if !ok {
296 continue
297 }
298
299 if slot.additionalComment != "" && slotChip.Comment != "" {
300 slotChip.Comment = slot.additionalComment + " " + slotChip.Comment
301 } else {
302 slotChip.Comment = slot.additionalComment + slotChip.Comment
303 }
304
305 delete(unmatchedPCIChips, slot.PCIAddr)
306 MatchDev(&slotChip)
307 dev.Children = append(dev.Children, slotChip)
308 }
309
310 if dev.PCIController {
311 for slot, slotDev := range unmatchedPCIChips {
312 if slot.Bus == dev.ChildPCIBus {
313 delete(unmatchedPCIChips, slot)
314 MatchDev(&slotDev)
315 dev.Children = append(dev.Children, slotDev)
316 }
317 }
318 }
319
320 for _, slot := range dev.PCISlots {
321 slotDev, ok := unmatchedPCIDevices[slot.PCIAddr]
322 if !ok {
323 if slot.writeEmpty {
324 dev.Children = append(dev.Children,
325 DevTreeNode{
326 Registers: map[string]string{},
327 Chip: "pci",
328 Bus: slot.Bus,
329 Dev: slot.Dev,
330 Func: slot.Func,
331 Comment: slot.additionalComment,
332 Disabled: true,
333 },
334 )
335 }
336 continue
337 }
338
339 if slot.additionalComment != "" && slotDev.Comment != "" {
340 slotDev.Comment = slot.additionalComment + " " + slotDev.Comment
341 } else {
342 slotDev.Comment = slot.additionalComment + slotDev.Comment
343 }
344
345 MatchDev(&slotDev)
346 dev.Children = append(dev.Children, slotDev)
347 delete(unmatchedPCIDevices, slot.PCIAddr)
348 }
349
350 if dev.MissingParent != "" {
351 for _, child := range MissingChildren[dev.MissingParent] {
352 MatchDev(&child)
353 dev.Children = append(dev.Children, child)
354 }
355 delete(MissingChildren, dev.MissingParent)
356 }
357
358 if dev.PCIController {
359 for slot, slotDev := range unmatchedPCIDevices {
360 if slot.Bus == dev.ChildPCIBus {
361 MatchDev(&slotDev)
362 dev.Children = append(dev.Children, slotDev)
363 delete(unmatchedPCIDevices, slot)
364 }
365 }
366 }
367}
368
369func writeOn(dt *os.File, dev DevTreeNode) {
370 if dev.Disabled {
371 fmt.Fprintf(dt, "off")
372 } else {
373 fmt.Fprintf(dt, "on")
374 }
375}
376
377func WriteDev(dt *os.File, offset int, dev DevTreeNode) {
378 Offset(dt, offset)
379 switch dev.Chip {
380 case "cpu_cluster", "lapic", "domain", "ioapic":
381 fmt.Fprintf(dt, "device %s 0x%x ", dev.Chip, dev.Dev)
382 writeOn(dt, dev)
383 case "pci", "pnp":
384 fmt.Fprintf(dt, "device %s %02x.%x ", dev.Chip, dev.Dev, dev.Func)
385 writeOn(dt, dev)
386 case "i2c":
387 fmt.Fprintf(dt, "device %s %02x ", dev.Chip, dev.Dev)
388 writeOn(dt, dev)
389 default:
390 fmt.Fprintf(dt, "chip %s", dev.Chip)
391 }
392 if dev.Comment != "" {
393 fmt.Fprintf(dt, " # %s", dev.Comment)
394 }
395 fmt.Fprintf(dt, "\n")
396 if dev.Chip == "pci" && dev.SubSystem != 0 && dev.SubVendor != 0 {
397 Offset(dt, offset+1)
398 fmt.Fprintf(dt, "subsystemid 0x%04x 0x%04x\n", dev.SubVendor, dev.SubSystem)
399 }
400
401 ioapic, ok := IOAPICIRQs[PCIAddr{Bus: dev.Bus, Dev: dev.Dev, Func: dev.Func}]
402 if dev.Chip == "pci" && ok {
403 for pin, irq := range ioapic.IRQNO {
404 if irq != 0 {
405 Offset(dt, offset+1)
406 fmt.Fprintf(dt, "ioapic_irq %d INT%c 0x%x\n", ioapic.APICID, 'A'+pin, irq)
407 }
408 }
409 }
410
411 keys := []string{}
412 for reg, _ := range dev.Registers {
413 keys = append(keys, reg)
414 }
415
416 sort.Strings(keys)
417
418 for _, reg := range keys {
419 val := dev.Registers[reg]
420 Offset(dt, offset+1)
421 fmt.Fprintf(dt, "register \"%s\" = \"%s\"\n", reg, val)
422 }
423
424 ios := []int{}
425 for reg, _ := range dev.IOs {
426 ios = append(ios, int(reg))
427 }
428
429 sort.Ints(ios)
430
431 for _, reg := range ios {
432 val := dev.IOs[uint16(reg)]
433 Offset(dt, offset+1)
434 fmt.Fprintf(dt, "io 0x%x = 0x%x\n", reg, val)
435 }
436
437 for _, child := range dev.Children {
438 WriteDev(dt, offset+1, child)
439 }
440
441 Offset(dt, offset)
442 fmt.Fprintf(dt, "end\n")
443}
444
445func PutChip(domain string, cur DevTreeNode) {
446 MissingChildren[domain] = append(MissingChildren[domain], cur)
447}
448
449func PutPCIChip(addr PCIDevData, cur DevTreeNode) {
450 unmatchedPCIChips[addr.PCIAddr] = cur
451}
452
453func PutPCIDevParent(addr PCIDevData, comment string, parent string) {
454 cur := DevTreeNode{
455 Registers: map[string]string{},
456 Chip: "pci",
457 Bus: addr.Bus,
458 Dev: addr.Dev,
459 Func: addr.Func,
460 MissingParent: parent,
461 Comment: comment,
462 }
463 if addr.ConfigDump[0xa] == 0x04 && addr.ConfigDump[0xb] == 0x06 {
464 cur.PCIController = true
465 cur.ChildPCIBus = int(addr.ConfigDump[0x19])
466
467 loopCtr := 0
468 for capPtr := addr.ConfigDump[0x34]; capPtr != 0; capPtr = addr.ConfigDump[capPtr+1] {
469 /* Avoid hangs. There are only 0x100 different possible values for capPtr.
470 If we iterate longer than that, we're in endless loop. */
471 loopCtr++
472 if loopCtr > 0x100 {
473 break
474 }
475 if addr.ConfigDump[capPtr] == 0x0d {
476 cur.SubVendor = GetLE16(addr.ConfigDump[capPtr+4 : capPtr+6])
477 cur.SubSystem = GetLE16(addr.ConfigDump[capPtr+6 : capPtr+8])
478 }
479 }
480 } else {
481 cur.SubVendor = GetLE16(addr.ConfigDump[0x2c:0x2e])
482 cur.SubSystem = GetLE16(addr.ConfigDump[0x2e:0x30])
483 }
484 unmatchedPCIDevices[addr.PCIAddr] = cur
485}
486
487func PutPCIDev(addr PCIDevData, comment string) {
488 PutPCIDevParent(addr, comment, "")
489}
490
491type GenericPCI struct {
492 Comment string
493 Bus0Subdiv string
494 MissingParent string
495}
496
497type GenericVGA struct {
498 GenericPCI
499}
500
501type DSDTInclude struct {
502 Comment string
503 File string
504}
505
506type DSDTDefine struct {
507 Key string
508 Comment string
509 Value string
510}
511
512var DSDTIncludes []DSDTInclude
513var DSDTPCI0Includes []DSDTInclude
514var DSDTDefines []DSDTDefine
515
516func (g GenericPCI) Scan(ctx Context, addr PCIDevData) {
517 PutPCIDevParent(addr, g.Comment, g.MissingParent)
518}
519
520func (g GenericVGA) Scan(ctx Context, addr PCIDevData) {
521 KconfigString["VGA_BIOS_ID"] = fmt.Sprintf("%04x,%04x",
522 addr.PCIVenID,
523 addr.PCIDevID)
524 KconfigString["VGA_BIOS_FILE"] = fmt.Sprintf("pci%04x,%04x.rom",
525 addr.PCIVenID,
526 addr.PCIDevID)
527 PutPCIDevParent(addr, g.Comment, g.MissingParent)
528}
529
530func makeKconfigName(ctx Context) {
531 kn := Create(ctx, "Kconfig.name")
532 defer kn.Close()
533
534 fmt.Fprintf(kn, "config %s\n\tbool \"%s\"\n", ctx.KconfigName, ctx.Model)
535}
536
537func makeComment(name string) string {
538 cmt, ok := KconfigComment[name]
539 if !ok {
540 return ""
541 }
542 return " # " + cmt
543}
544
545func makeKconfig(ctx Context) {
546 kc := Create(ctx, "Kconfig")
547 defer kc.Close()
548
549 fmt.Fprintf(kc, "if %s\n\n", ctx.KconfigName)
550
551 fmt.Fprintf(kc, "config BOARD_SPECIFIC_OPTIONS # dummy\n\tdef_bool y\n")
552 keys := []string{}
553 for name, val := range KconfigBool {
554 if val {
555 keys = append(keys, name)
556 }
557 }
558
559 sort.Strings(keys)
560
561 for _, name := range keys {
562 fmt.Fprintf(kc, "\tselect %s%s\n", name, makeComment(name))
563 }
564
565 keys = nil
566 for name, val := range KconfigBool {
567 if !val {
568 keys = append(keys, name)
569 }
570 }
571
572 sort.Strings(keys)
573
574 for _, name := range keys {
575 fmt.Fprintf(kc, `
576config %s%s
577 bool
578 default n
579`, name, makeComment(name))
580 }
581
582 keys = nil
583 for name, _ := range KconfigStringUnquoted {
584 keys = append(keys, name)
585 }
586
587 sort.Strings(keys)
588
589 for _, name := range keys {
590 fmt.Fprintf(kc, `
591config %s%s
592 string
593 default %s
594`, name, makeComment(name), KconfigStringUnquoted[name])
595 }
596
597 keys = nil
598 for name, _ := range KconfigString {
599 keys = append(keys, name)
600 }
601
602 sort.Strings(keys)
603
604 for _, name := range keys {
605 fmt.Fprintf(kc, `
606config %s%s
607 string
608 default "%s"
609`, name, makeComment(name), KconfigString[name])
610 }
611
612 keys = nil
613 for name, _ := range KconfigHex {
614 keys = append(keys, name)
615 }
616
617 sort.Strings(keys)
618
619 for _, name := range keys {
620 fmt.Fprintf(kc, `
621config %s%s
622 hex
623 default 0x%x
624`, name, makeComment(name), KconfigHex[name])
625 }
626
627 keys = nil
628 for name, _ := range KconfigInt {
629 keys = append(keys, name)
630 }
631
632 sort.Strings(keys)
633
634 for _, name := range keys {
635 fmt.Fprintf(kc, `
636config %s%s
637 int
638 default %d
639`, name, makeComment(name), KconfigInt[name])
640 }
641
642 fmt.Fprintf(kc, "endif\n")
643}
644
645const MoboDir = "/src/mainboard/"
646
647func makeVendor(ctx Context) {
648 vendor := ctx.Vendor
Vladimir Serbinenko2d615e52015-05-29 21:43:51 +0200649 vendorSane := ctx.SaneVendor
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200650 vendorDir := *FlagOutDir + MoboDir + vendorSane
651 vendorUpper := strings.ToUpper(vendorSane)
652 kconfig := vendorDir + "/Kconfig"
653 if _, err := os.Stat(kconfig); os.IsNotExist(err) {
654 f, err := os.Create(kconfig)
655 if err != nil {
656 log.Fatal(err)
657 }
658 defer f.Close()
659 f.WriteString(`if VENDOR_` + vendorUpper + `
660
661choice
662 prompt "Mainboard model"
663
664source "src/mainboard/` + vendorSane + `/*/Kconfig.name"
665
666endchoice
667
668source "src/mainboard/` + vendorSane + `/*/Kconfig"
669
670config MAINBOARD_VENDOR
671 string
672 default "` + vendor + `"
673
674endif # VENDOR_` + vendorUpper + "\n")
675 }
676 kconfigName := vendorDir + "/Kconfig.name"
677 if _, err := os.Stat(kconfigName); os.IsNotExist(err) {
678 f, err := os.Create(kconfigName)
679 if err != nil {
680 log.Fatal(err)
681 }
682 defer f.Close()
683 f.WriteString(`config VENDOR_` + vendorUpper + `
684 bool "` + vendor + `"
685`)
686 }
687
688}
689
690func GuessECGPE(ctx Context) int {
691 /* FIXME:XX Use iasl -d and/or better parsing */
692 dsdt := ctx.InfoSource.GetACPI()["DSDT"]
693 idx := bytes.Index(dsdt, []byte{0x08, '_', 'G', 'P', 'E', 0x0a}) /* Name (_GPE, byte). */
694 if idx > 0 {
695 return int(dsdt[idx+6])
696 }
697 return -1
698}
699
700func GuessSPDMap(ctx Context) []uint8 {
701 dmi := ctx.InfoSource.GetDMI()
702
703 if dmi.Vendor == "LENOVO" {
Vladimir Serbinenkodb0acf82015-05-29 22:09:06 +0200704 return []uint8{0x50, 0x52, 0x51, 0x53}
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200705 }
Vladimir Serbinenkodb0acf82015-05-29 22:09:06 +0200706 return []uint8{0x50, 0x51, 0x52, 0x53}
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200707}
708
709func main() {
710 flag.Parse()
711
712 ctx := Context{}
713
714 ctx.InfoSource = MakeLogReader()
715
716 dmi := ctx.InfoSource.GetDMI()
717
718 ctx.Vendor = dmi.Vendor
719
720 if dmi.Vendor == "LENOVO" {
721 ctx.Model = dmi.Version
722 } else {
723 ctx.Model = dmi.Model
724 }
725
726 if dmi.IsLaptop {
727 KconfigBool["SYSTEM_TYPE_LAPTOP"] = true
728 }
Vladimir Serbinenko2d615e52015-05-29 21:43:51 +0200729 ctx.SaneVendor = sanitize(ctx.Vendor)
730 for {
731 last := ctx.SaneVendor
732 for _, suf := range []string{"_inc", "_co", "_corp"} {
733 ctx.SaneVendor = strings.TrimSuffix(ctx.SaneVendor, suf)
734 }
735 if last == ctx.SaneVendor {
736 break
737 }
738 }
739 ctx.MoboID = ctx.SaneVendor + "/" + sanitize(ctx.Model)
740 ctx.KconfigName = "BOARD_" + strings.ToUpper(ctx.SaneVendor+"_"+sanitize(ctx.Model))
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200741 ctx.BaseDirectory = *FlagOutDir + MoboDir + ctx.MoboID
742 KconfigStringUnquoted["MAINBOARD_DIR"] = ctx.MoboID
743 KconfigString["MAINBOARD_PART_NUMBER"] = ctx.Model
744
745 os.MkdirAll(ctx.BaseDirectory, 0700)
746
747 makeVendor(ctx)
748
749 ScanRoot(ctx)
750
751 if len(ROMStageFiles) > 0 || len(RAMStageFiles) > 0 || len(SMMFiles) > 0 {
752 mf := Create(ctx, "Makefile.inc")
753 defer mf.Close()
754 writeMF(mf, ROMStageFiles, "romstage")
755 writeMF(mf, RAMStageFiles, "ramstage")
756 writeMF(mf, SMMFiles, "smm")
757 }
758
759 devtree := Create(ctx, "devicetree.cb")
760 defer devtree.Close()
761
762 MatchDev(&DevTree)
763 WriteDev(devtree, 0, DevTree)
764
765 if MainboardInit != "" || MainboardEnable != "" || MainboardIncludes != nil {
766 mainboard := Create(ctx, "mainboard.c")
767 defer mainboard.Close()
768 mainboard.WriteString("#include <device/device.h>\n")
769 for _, include := range MainboardIncludes {
770 mainboard.WriteString("#include <" + include + ">\n")
771 }
772 mainboard.WriteString("\n")
773 if MainboardInit != "" {
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200774 mainboard.WriteString(`static void mainboard_init(struct device *dev)
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200775{
776` + MainboardInit + "}\n\n")
777 }
778 if MainboardInit != "" || MainboardEnable != "" {
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200779 mainboard.WriteString("static void mainboard_enable(struct device *dev)\n{\n")
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200780 if MainboardInit != "" {
781 mainboard.WriteString("\tdev->ops->init = mainboard_init;\n\n")
782 }
783 mainboard.WriteString(MainboardEnable)
784 mainboard.WriteString("}\n\n")
785 mainboard.WriteString(`struct chip_operations mainboard_ops = {
786 .enable_dev = mainboard_enable,
787};
788`)
789 }
790 }
791
792 at := Create(ctx, "acpi_tables.c")
793 defer at.Close()
794 at.WriteString("/* dummy */\n")
795
796 bi := Create(ctx, "board_info.txt")
797 defer bi.Close()
798
799 fixme := ""
800
801 if dmi.IsLaptop {
802 bi.WriteString("Category: laptop\n")
803 } else {
804 bi.WriteString("Category: desktop\n")
805 fixme += "check category, "
806 }
807
808 missing := "ROM package, ROM socketed"
809
810 if ROMProtocol != "" {
811 fmt.Fprintf(bi, "ROM protocol: %s\n", ROMProtocol)
812 } else {
813 missing += ", ROM protocol"
814 }
815
816 if FlashROMSupport != "" {
817 fmt.Fprintf(bi, "Flashrom support: %s\n", FlashROMSupport)
818 } else {
819 missing += ", Flashrom support"
820 }
821
822 missing += ", Release year"
823
824 if fixme != "" {
825 fmt.Fprintf(bi, "FIXME: %s, put %s\n", fixme, missing)
826 } else {
827 fmt.Fprintf(bi, "FIXME: put %s\n", missing)
828 }
829
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200830 if ROMSizeKB == 0 {
831 KconfigBool["BOARD_ROMSIZE_KB_2048"] = true
832 KconfigComment["BOARD_ROMSIZE_KB_2048"] = "FIXME: correct this"
833 } else {
834 KconfigBool[fmt.Sprintf("BOARD_ROMSIZE_KB_%d", ROMSizeKB)] = true
835 }
836
837 makeKconfig(ctx)
838 makeKconfigName(ctx)
839
840 dsdt := Create(ctx, "dsdt.asl")
841 defer dsdt.Close()
842
843 for _, define := range DSDTDefines {
844 if define.Comment != "" {
845 fmt.Fprintf(dsdt, "\t/* %s. */\n", define.Comment)
846 }
847 dsdt.WriteString("#define " + define.Key + " " + define.Value + "\n")
848 }
849
850 dsdt.WriteString(
Elyes HAOUAS6d19a202018-11-22 11:15:29 +0100851 `#include <arch/acpi.h>
852DefinitionBlock(
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200853 "dsdt.aml",
854 "DSDT",
Elyes HAOUAS0cca6e22018-11-13 14:23:29 +0100855 0x02, // DSDT revision: ACPI 2.0 and up
Elyes HAOUAS6d19a202018-11-22 11:15:29 +0100856 OEM_ID,
857 ACPI_TABLE_CREATOR,
Vladimir Serbinenko3129f792014-10-15 21:51:47 +0200858 0x20141018 // OEM revision
859)
860{
861 // Some generic macros
862 #include "acpi/platform.asl"
863`)
864
865 for _, x := range DSDTIncludes {
866 if x.Comment != "" {
867 fmt.Fprintf(dsdt, "\t/* %s. */\n", x.Comment)
868 }
869 fmt.Fprintf(dsdt, "\t#include <%s>\n", x.File)
870 }
871
872 dsdt.WriteString(`
873 Scope (\_SB) {
874 Device (PCI0)
875 {
876`)
877 for _, x := range DSDTPCI0Includes {
878 if x.Comment != "" {
879 fmt.Fprintf(dsdt, "\t/* %s. */\n", x.Comment)
880 }
881 fmt.Fprintf(dsdt, "\t\t#include <%s>\n", x.File)
882 }
883 dsdt.WriteString(
884 ` }
885 }
886}
887`)
888
889}