meta-facebook: obmc-console: simplify console selection

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I797e6fe38e5db3ae25ab47f94a5cd0549f027c6d
diff --git a/meta-facebook/conf/recipes/fb-consoles.inc b/meta-facebook/conf/recipes/fb-consoles.inc
new file mode 100644
index 0000000..47cfcf3
--- /dev/null
+++ b/meta-facebook/conf/recipes/fb-consoles.inc
@@ -0,0 +1,23 @@
+# Default console to use if there is only one host.
+OBMC_CONSOLE_HOST_TTY = "ttyS2"
+
+# TTYs that are reserved for non-console purposes.
+OBMC_CONSOLE_TTY_SKIP = "4"
+
+# Calculate the TTY assignments for the hosts.
+def fb_get_consoles(d):
+    hosts = len(d.getVar('OBMC_HOST_INSTANCES', True).split())
+
+    if hosts <= 1:
+        return d.getVar('OBMC_CONSOLE_HOST_TTY', True)
+
+    skipped = \
+        [ int(i) for i in d.getVar('OBMC_CONSOLE_TTY_SKIP', True).split() ]
+    consoles = \
+        [ f"ttyS{i}" for i in sorted(set(range(0,16)).difference(skipped)) ]
+
+    return " ".join(consoles[:hosts])
+
+OBMC_CONSOLE_TTYS = "${@fb_get_consoles(d)}"
+
+