iPXE
Macros | Functions | Variables
fdtcon.c File Reference

Flattened Device Tree serial console. More...

#include <string.h>
#include <ipxe/serial.h>
#include <ipxe/devtree.h>
#include <ipxe/fdt.h>

Go to the source code of this file.

Macros

#define SERIAL_PREFIX_fdt   __fdt_
 
#define colour   &fdtcon_parent
 Colour for debug messages. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static struct uartfdtcon_default (void)
 Identify default serial console. More...
 
 PROVIDE_SERIAL (fdt, default_serial_console, fdtcon_default)
 

Variables

static struct device fdtcon_parent
 FDT console parent device. More...
 

Detailed Description

Flattened Device Tree serial console.

Definition in file fdtcon.c.

Macro Definition Documentation

◆ SERIAL_PREFIX_fdt

#define SERIAL_PREFIX_fdt   __fdt_

Definition at line 40 of file fdtcon.c.

◆ colour

#define colour   &fdtcon_parent

Colour for debug messages.

Definition at line 51 of file fdtcon.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ fdtcon_default()

static struct uart* fdtcon_default ( void  )
static

Identify default serial console.

Return values
uartDefault serial console UART, or NULL

Definition at line 58 of file fdtcon.c.

58  {
59  unsigned int chosen;
60  unsigned int stdout;
61  const char *path;
62  struct uart *prev;
63  struct uart *uart;
64  int rc;
65 
66  /* Record existing UART, if any */
67  prev = list_last_entry ( &uarts, struct uart, list );
68 
69  /* Locate "/chosen" node */
70  if ( ( rc = fdt_path ( &sysfdt, "/chosen", &chosen ) ) != 0 ) {
71  DBGC ( colour, "FDTCON could not locate \"/chosen\": %s\n",
72  strerror ( rc ) );
73  return NULL;
74  }
75 
76  /* Get console device path (or alias) */
77  path = fdt_string ( &sysfdt, chosen, "stdout-path" );
78  if ( ! path ) {
79  DBGC ( colour, "FDTCON has no console device\n" );
80  return NULL;
81  }
82  DBGC ( colour, "FDTCON console device is \"%s\"\n", path );
83 
84  /* Locate device */
85  if ( ( ( rc = fdt_path ( &sysfdt, path, &stdout ) ) != 0 ) &&
86  ( ( rc = fdt_alias ( &sysfdt, path, &stdout ) ) != 0 ) ) {
87  DBGC ( colour, "FDTCON could not locate \"/%s\": %s\n",
88  path, strerror ( rc ) );
89  return NULL;
90  }
91 
92  /* Probe device */
93  if ( ( rc = dt_probe_node ( &fdtcon_parent, stdout ) ) != 0 ) {
94  DBGC ( colour, "FDTCON could not probe \"%s\": %s\n",
95  path, strerror ( rc ) );
96  return NULL;
97  }
98 
99  /* Use newly added UART, if any */
100  uart = list_last_entry ( &uarts, struct uart, list );
101  if ( uart == prev )
102  return NULL;
103 
104  DBGC ( colour, "FDTCON using UART %s\n", uart->name );
105  return uart;
106 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int fdt_alias(struct fdt *fdt, const char *name, unsigned int *offset)
Find node by alias.
Definition: fdt.c:465
A generic UART.
Definition: uart.h:17
int fdt_path(struct fdt *fdt, const char *path, unsigned int *offset)
Find node by path.
Definition: fdt.c:425
#define DBGC(...)
Definition: compiler.h:505
#define list_last_entry(list, type, member)
Get the container of the last entry in a list.
Definition: list.h:346
const char * name
Name.
Definition: uart.h:21
struct list_head list
List of registered UARTs.
Definition: uart.h:23
static struct device fdtcon_parent
FDT console parent device.
Definition: fdtcon.c:44
const char * fdt_string(struct fdt *fdt, unsigned int offset, const char *name)
Find string property.
Definition: fdt.c:578
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct list_head uarts
int dt_probe_node(struct device *parent, unsigned int offset)
Probe devicetree node.
Definition: devtree.c:196
#define colour
Colour for debug messages.
Definition: fdtcon.c:51
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:44

References colour, DBGC, dt_probe_node(), fdt_alias(), fdt_path(), fdt_string(), fdtcon_parent, uart::list, list_last_entry, uart::name, NULL, rc, strerror(), sysfdt, and uarts.

◆ PROVIDE_SERIAL()

PROVIDE_SERIAL ( fdt  ,
default_serial_console  ,
fdtcon_default   
)

Variable Documentation

◆ fdtcon_parent

struct device fdtcon_parent
static
Initial value:
= {
.name = "fdtcon",
}
static struct device fdtcon_parent
FDT console parent device.
Definition: fdtcon.c:44
struct list_head siblings
Devices on the same bus.
Definition: device.h:84
struct list_head children
Devices attached to this device.
Definition: device.h:86
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30

FDT console parent device.

Definition at line 44 of file fdtcon.c.

Referenced by fdtcon_default().