]> git.ozlabs.org Git - petitboot/blobdiff - utils/hooks/30-dtb-updates.c
utils/hooks: Set stdout-path property
[petitboot] / utils / hooks / 30-dtb-updates.c
index aff3844dd5e9f613e8d1717085e108408eb76c9d..b8413fd361ddb6d22c0e2228d9010babb5275d54 100644 (file)
@@ -257,7 +257,7 @@ static int do_translate(void *fdt, int node,
        current_pci_flags = na > 2 ? of_read_number(addr, 1) : 0;
        child_pci_flags = cna > 2 ? of_read_number(ranges, 1) : 0;
        if (current_pci_flags != 0 && current_pci_flags != child_pci_flags) {
-               fprintf(stderr, "Unexpected change in flags: %lx, %lx\n",
+               fprintf(stderr, "Unexpected change in flags: %" PRIu64 ", %" PRIu64 "\n",
                        current_pci_flags, child_pci_flags);
                return -1;
        }
@@ -324,7 +324,7 @@ static int do_translate(void *fdt, int node,
 
        fprintf(stderr, "New address:\n\t");
        for (i = 0; i < *addr_cells; i++)
-               fprintf(stderr, " %lx ", of_read_number(&addr[i], 1));
+               fprintf(stderr, " %" PRIu64 " ", of_read_number(&addr[i], 1));
        fprintf(stderr, "\n");
 
        return 0;
@@ -382,7 +382,7 @@ static int create_translated_addresses(struct offb_ctx *ctx,
 
        fprintf(stderr, "Final address:\n\t");
        for (i = 0; i < addr_cells; i++)
-               fprintf(stderr, " %lx ", of_read_number(&addr[i], 1));
+               fprintf(stderr, " %" PRIu64 " ", of_read_number(&addr[i], 1));
        fprintf(stderr, "\n");
 
        if (addr_cells + size_cells > reg_cells) {
@@ -502,9 +502,8 @@ static int set_stdout(struct offb_ctx *ctx)
 {
        const char *boot_console, *ptr;
        long unsigned int termno;
-       const fdt32_t *prop;
-       int node, prop_len;
        char *stdout_path;
+       int node;
 
        boot_console = getenv("boot_console");
        if (!boot_console) {
@@ -515,7 +514,10 @@ static int set_stdout(struct offb_ctx *ctx)
        if (strncmp(boot_console, "/dev/", strlen("/dev/")) != 0) {
                /* We already have the full path */
                stdout_path = talloc_strdup(ctx, boot_console);
-       } else if (strstr(boot_console, "tty") != NULL) {
+               /* Check for a tty* console but don't accidentally catch
+                * ttyS* consoles */
+       } else if (strstr(boot_console, "tty") != NULL &&
+                       strstr(boot_console, "ttyS") == NULL) {
                fprintf(stderr, "TTY recognised: %s\n", boot_console);
                stdout_path = get_vga_path(ctx);
        } else {
@@ -551,12 +553,12 @@ static int set_stdout(struct offb_ctx *ctx)
                return -1;
        }
 
-       prop = fdt_getprop(ctx->dtb, node, "linux,stdout-path", &prop_len);
-       if (!prop) {
-               fprintf(stderr, "Failed to find linux,stdout-path\n");
-               return -1;
-       }
-
+       /*
+        * linux,stdout-path is deprecated after v3.14 but we don't know
+        * what the next kernel will be, so set both.
+        */
+       fdt_set_check(ctx->dtb, node, fdt_setprop_string, "stdout-path",
+                       stdout_path);
        fdt_set_check(ctx->dtb, node, fdt_setprop_string, "linux,stdout-path",
                        stdout_path);
 
@@ -576,20 +578,10 @@ static int write_devicetree(struct offb_ctx *ctx)
        return rc;
 }
 
-
-int main(void)
+static int set_offb(struct offb_ctx *ctx)
 {
-       struct offb_ctx *ctx;
        int rc;
 
-       ctx = talloc_zero(NULL, struct offb_ctx);
-
-       ctx->dtb_name = getenv("boot_dtb");
-       if (!ctx->dtb_name) {
-               talloc_free(ctx);
-               return EXIT_SUCCESS;
-       }
-
        rc = load_dtb(ctx);
        if (rc)
                goto out;
@@ -605,14 +597,39 @@ int main(void)
        rc = populate_devicetree(ctx);
        if (rc)
                goto out;
+out:
+       return rc;
+}
 
-       rc = set_stdout(ctx);
-       if (rc)
-               goto out;
 
-       rc = write_devicetree(ctx);
+int main(void)
+{
+       struct offb_ctx *ctx;
+       int rc;
+
+       ctx = talloc_zero(NULL, struct offb_ctx);
+
+       ctx->dtb_name = getenv("boot_dtb");
+       if (!ctx->dtb_name) {
+               talloc_free(ctx);
+               return EXIT_SUCCESS;
+       }
+
+       if (set_offb(ctx)) {
+               warn("Failed offb setup step");
+               rc = -1;
+       }
+
+       if (set_stdout(ctx)) {
+               warn("Failed stdout setup step\n");
+               rc = -1;
+       }
+
+       if (write_devicetree(ctx)) {
+               warn("Failed to write back device tree\n");
+               rc = -1;
+       }
 
-out:
        talloc_free(ctx);
        return rc ? EXIT_FAILURE : EXIT_SUCCESS;
 }