github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/exp/console/console_linux.go (about)

     1  // Copyright 2015-2020 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"io"
    10  	"os"
    11  )
    12  
    13  func console(serial string) (io.Reader, io.Writer, error) {
    14  	in, out := io.Reader(os.Stdin), io.Writer(os.Stdout)
    15  
    16  	// This switch is kind of hokey, true, but it's also quite convenient for users.
    17  	switch {
    18  	// A raw IO port for serial console
    19  	case []byte(serial)[0] == '0':
    20  		u, err := openUART(serial)
    21  		if err != nil {
    22  			return nil, nil, fmt.Errorf("Console exits: sorry, can't get a uart: %v", err)
    23  		}
    24  		in, out = u, u
    25  	case serial == "i8042":
    26  		u, err := openi8042()
    27  		if err != nil {
    28  			return nil, nil, fmt.Errorf("Console exits: sorry, can't get an i8042: %v", err)
    29  		}
    30  		in, out = u, os.Stdout
    31  	case serial == "stdio":
    32  	default:
    33  		return nil, nil, fmt.Errorf("Cconsole must be one of stdio, i8042, or an IO port with a leading 0 (e.g. 0x3f8)")
    34  	}
    35  
    36  	return in, out, nil
    37  }