veyron_pinky: Set FIT compatible string dynamically from board_id

This patch adds code to veyron_pinky's board.c to set the kernel device
tree compatible string at runtime. The current algorithm just adds 1 to
the board_id (read by coreboot), since we cleverly started to add board
ID pins (and count them from 0) with the board that we labeled rev1.

BUG=chrome-os-partner:30167
TEST=Boot on rev1, see that it works and picks the right kernel DT.

Change-Id: I401428ba3a14e4af9b5af1e03abaf3ed0bdb4d57
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/217592
Reviewed-by: David Hendricks <dhendrix@chromium.org>
diff --git a/board/veyron_pinky/defconfig b/board/veyron_pinky/defconfig
index 5b4a44f..b499e05 100644
--- a/board/veyron_pinky/defconfig
+++ b/board/veyron_pinky/defconfig
@@ -23,7 +23,6 @@
 
 # Kernel format
 CONFIG_KERNEL_FIT=y
-CONFIG_KERNEL_FIT_COMPAT="rockchip,veyron"
 CONFIG_KERNEL_FIT_FDT_ADDR=0x6400000
 
 # Drivers
diff --git a/src/board/veyron_pinky/board.c b/src/board/veyron_pinky/board.c
index 05661ff..e0bbd2e 100644
--- a/src/board/veyron_pinky/board.c
+++ b/src/board/veyron_pinky/board.c
@@ -20,6 +20,7 @@
 #include <arch/io.h>
 
 #include "base/init_funcs.h"
+#include "boot/fit.h"
 #include "drivers/gpio/rockchip.h"
 #include "drivers/bus/i2c/rockchip.h"
 #include "drivers/flash/spi.h"
@@ -41,8 +42,17 @@
 
 #include "drivers/bus/usb/usb.h"
 
+/* Careful: dt_compat gets retained in fit.c, must not be allocated on stack! */
+static const char dt_compat_pattern[] = "google,veyron-pinky-rev%d";
+static char dt_compat[sizeof(dt_compat_pattern)];
+
 static int board_setup(void)
 {
+	/* We started adding board IDs (from 0) with the rev1 board... m( */
+	snprintf(dt_compat, sizeof(dt_compat), dt_compat_pattern,
+		 lib_sysinfo.board_id + 1);
+	fit_override_kernel_compat(dt_compat);
+
 	RkSpi *spi2 = new_rockchip_spi(0xff130000, 0, 0, 0);
 	flash_set_ops(&new_spi_flash(&spi2->ops, 0x400000)->ops);