/* * This command is designed for booting systems which use the Linux kernel * boot-sequence. */ static int cmd_bootm(int argc, char **argv) { if(argc != 4 && argc != 6) { printf("Usage: %s {--core [coreID]} [start-addr] [initrd-addr | '-'] [fdt-addr | '-']\n", argv[0]); return -1; } BT_u32 coreID = 0; BT_u32 start_addr = 0; BT_u32 initrd_addr = 0; BT_u32 fdt_addr = 0; BT_u32 argoffset = 0; if(argc == 6) { argoffset = 2; if(strcmp(argv[1], "--core")) { printf("Invalid argument %s\n", argv[1]); return -1; } coreID = strtol(argv[2], NULL, 10); } start_addr = strtol(argv[argoffset+1], NULL, 16); initrd_addr = strtol(argv[argoffset+2], NULL, 16); fdt_addr = strtol(argv[argoffset+3], NULL, 16); int error = fdt_chosen(fdt_addr, 1); // Update the bootargs! return arch_bootm(coreID, start_addr, initrd_addr, fdt_addr); }
static int bootm_linux_fdt(int machid, bootm_headers_t *images) { ulong rd_len; void (*kernel_entry)(int zero, int dt_machid, void *dtblob); ulong bootmap_base = getenv_bootm_low(); ulong of_size = images->ft_len; char **of_flat_tree = &images->ft_addr; ulong *initrd_start = &images->initrd_start; ulong *initrd_end = &images->initrd_end; struct lmb *lmb = &images->lmb; int ret; kernel_entry = (void (*)(int, int, void *))images->ep; rd_len = images->rd_end - images->rd_start; ret = boot_ramdisk_high(lmb, images->rd_start, rd_len, initrd_start, initrd_end); if (ret) return ret; ret = boot_relocate_fdt(lmb, bootmap_base, of_flat_tree, &of_size); if (ret) return ret; debug("## Transferring control to Linux (at address %08lx) ...\n", (ulong) kernel_entry); fdt_chosen(*of_flat_tree, 1); fixup_memory_node(*of_flat_tree); fdt_fixup_ethernet(*of_flat_tree); #ifdef CONFIG_DMAMEM fdt_fixup_dmamem(*of_flat_tree); #endif #ifdef CONFIG_SWITCH fdt_fixup_switch(*of_flat_tree); #endif fdt_initrd(*of_flat_tree, *initrd_start, *initrd_end, 1); announce_and_cleanup(); kernel_entry(0, machid, *of_flat_tree); /* does not return */ return 1; }
int image_setup_libfdt(bootm_headers_t *images, void *blob, int of_size, struct lmb *lmb) { ulong *initrd_start = &images->initrd_start; ulong *initrd_end = &images->initrd_end; int ret; if (fdt_chosen(blob, 1) < 0) { puts("ERROR: /chosen node create failed"); puts(" - must RESET the board to recover.\n"); return -1; } arch_fixup_memory_node(blob); if (IMAGE_OF_BOARD_SETUP) ft_board_setup(blob, gd->bd); fdt_fixup_ethernet(blob); /* Delete the old LMB reservation */ lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob, (phys_size_t)fdt_totalsize(blob)); ret = fdt_resize(blob); if (ret < 0) return ret; of_size = ret; if (*initrd_start && *initrd_end) { of_size += FDT_RAMDISK_OVERHEAD; fdt_set_totalsize(blob, of_size); } /* Create a new LMB reservation */ lmb_reserve(lmb, (ulong)blob, of_size); fdt_initrd(blob, *initrd_start, *initrd_end, 1); if (!ft_verify_fdt(blob)) return -1; return 0; }
int image_setup_libfdt(bootm_headers_t *images, void *blob, int of_size, struct lmb *lmb) { ulong *initrd_start = &images->initrd_start; ulong *initrd_end = &images->initrd_end; int ret = -EPERM; int fdt_ret; if (fdt_root(blob) < 0) { printf("ERROR: root node setup failed\n"); goto err; } if (fdt_chosen(blob) < 0) { printf("ERROR: /chosen node create failed\n"); goto err; } if (arch_fixup_fdt(blob) < 0) { printf("ERROR: arch-specific fdt fixup failed\n"); goto err; } if (IMAGE_OF_BOARD_SETUP) { fdt_ret = ft_board_setup(blob, gd->bd); if (fdt_ret) { printf("ERROR: board-specific fdt fixup failed: %s\n", fdt_strerror(fdt_ret)); goto err; } } if (IMAGE_OF_SYSTEM_SETUP) { fdt_ret = ft_system_setup(blob, gd->bd); if (fdt_ret) { printf("ERROR: system-specific fdt fixup failed: %s\n", fdt_strerror(fdt_ret)); goto err; } } fdt_fixup_ethernet(blob); /* Delete the old LMB reservation */ lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob, (phys_size_t)fdt_totalsize(blob)); ret = fdt_shrink_to_minimum(blob); if (ret < 0) goto err; of_size = ret; if (*initrd_start && *initrd_end) { of_size += FDT_RAMDISK_OVERHEAD; fdt_set_totalsize(blob, of_size); } /* Create a new LMB reservation */ lmb_reserve(lmb, (ulong)blob, of_size); fdt_initrd(blob, *initrd_start, *initrd_end); if (!ft_verify_fdt(blob)) goto err; #if defined(CONFIG_SOC_KEYSTONE) if (IMAGE_OF_BOARD_SETUP) ft_board_setup_ex(blob, gd->bd); #endif return 0; err: printf(" - must RESET the board to recover.\n\n"); return ret; }
/* * Flattened Device Tree command, see the help for parameter definitions. */ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { char op; if (argc < 2) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* * Figure out which subcommand was given */ op = argv[1][0]; /******************************************************************** * Set the address of the fdt ********************************************************************/ if (op == 'a') { /* * Set the address [and length] of the fdt. */ fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); if (!fdt_valid()) { return 1; } if (argc >= 4) { int len; int err; /* * Optional new length */ len = simple_strtoul(argv[3], NULL, 16); if (len < fdt_totalsize(fdt)) { printf ("New length %d < existing length %d, ignoring.\n", len, fdt_totalsize(fdt)); } else { /* * Open in place with a new length. */ err = fdt_open_into(fdt, fdt, len); if (err != 0) { printf ("libfdt: %s\n", fdt_strerror(err)); } } } /******************************************************************** * Move the fdt ********************************************************************/ } else if (op == 'm' && argv[1][1] == 'o') { struct fdt_header *newaddr; int len; int err; if (argc != 5) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* * Set the address and length of the fdt. */ fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); if (!fdt_valid()) { return 1; } newaddr = (struct fdt_header *)simple_strtoul(argv[3], NULL, 16); len = simple_strtoul(argv[4], NULL, 16); if (len < fdt_totalsize(fdt)) { printf ("New length %d < existing length %d, aborting.\n", len, fdt_totalsize(fdt)); return 1; } /* * Copy to the new location. */ err = fdt_open_into(fdt, newaddr, len); if (err != 0) { printf ("libfdt: %s\n", fdt_strerror(err)); return 1; } fdt = newaddr; /******************************************************************** * mknode ********************************************************************/ } else if (op == 'm' && argv[1][1] == 'k') { char *pathp = argv[2]; char *node = argv[3]; int nodeoffset; if (argc != 4) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* * See if the node already exists */ if (strcmp(pathp, "/") == 0) nodeoffset = 0; else nodeoffset = fdt_path_offset (fdt, pathp); if (nodeoffset < 0) { printf("parent node %s doesn't exist\n", pathp); return 1; } /* * Create the new node */ nodeoffset = fdt_add_subnode(fdt, nodeoffset, node); if (nodeoffset < 0) { printf("libfdt: %s\n", fdt_strerror(nodeoffset)); return 1; } /******************************************************************** * Set the value of a node in the fdt. ********************************************************************/ } else if (op == 's') { char *pathp; /* path */ char *prop; /* property */ struct fdt_property *nodep; /* node struct pointer */ char *newval; /* value from the user (as a string) */ char *vp; /* temporary value pointer */ char *cp; /* temporary char pointer */ int nodeoffset; /* node offset from libfdt */ int len; /* new length of the property */ int oldlen; /* original length of the property */ unsigned long tmp; /* holds converted values */ int ret; /* return value */ /* * Parameters: Node path, property, value. */ if (argc < 5) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } pathp = argv[2]; prop = argv[3]; newval = argv[4]; if (strcmp(pathp, "/") == 0) { nodeoffset = 0; } else { nodeoffset = fdt_path_offset (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt: %s\n", fdt_strerror(nodeoffset)); return 1; } } nodep = fdt_getprop (fdt, nodeoffset, prop, &oldlen); if (oldlen == 0) { /* * The specified property has no value */ printf("%s has no value, cannot set one (yet).\n", prop); return 1; } else { /* * Convert the new property */ vp = data; if (*newval == '<') { /* * Bigger values than bytes. */ len = 0; newval++; while ((*newval != '>') && (*newval != '\0')) { cp = newval; tmp = simple_strtoul(cp, &newval, 16); if ((newval - cp) <= 2) { *vp = tmp & 0xFF; vp += 1; len += 1; } else if ((newval - cp) <= 4) { *(uint16_t *)vp = __cpu_to_be16(tmp); vp += 2; len += 2; } else if ((newval - cp) <= 8) { *(uint32_t *)vp = __cpu_to_be32(tmp); vp += 4; len += 4; } else { printf("Sorry, I could not convert \"%s\"\n", cp); return 1; } while (*newval == ' ') newval++; } if (*newval != '>') { printf("Unexpected character '%c'\n", *newval); return 1; } } else if (*newval == '[') { /* * Byte stream. Convert the values. */ len = 0; newval++; while ((*newval != ']') && (*newval != '\0')) { tmp = simple_strtoul(newval, &newval, 16); *vp++ = tmp & 0xFF; len++; while (*newval == ' ') newval++; } if (*newval != ']') { printf("Unexpected character '%c'\n", *newval); return 1; } } else { /* * Assume it is a string. Copy it into our data area for * convenience (including the terminating '\0'). */ len = strlen(newval) + 1; strcpy(data, newval); } ret = fdt_setprop(fdt, nodeoffset, prop, data, len); if (ret < 0) { printf ("libfdt %s\n", fdt_strerror(ret)); return 1; } } /******************************************************************** * Print (recursive) / List (single level) ********************************************************************/ } else if ((op == 'p') || (op == 'l')) { /* * Recursively print (a portion of) the fdt. */ static int offstack[MAX_LEVEL]; static char tabs[MAX_LEVEL+1] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; int depth = MAX_LEVEL; /* how deep to print */ char *pathp; /* path */ char *prop; /* property */ void *nodep; /* property node pointer */ int nodeoffset; /* node offset from libfdt */ int nextoffset; /* next node offset from libfdt */ uint32_t tag; /* tag */ int len; /* length of the property */ int level = 0; /* keep track of nesting level */ /* * list is an alias for print, but limited to 1 level */ if (op == 'l') { depth = 1; } /* * Get the starting path. The root node is an oddball, * the offset is zero and has no name. */ pathp = argv[2]; if (argc > 3) prop = argv[3]; else prop = NULL; if (strcmp(pathp, "/") == 0) { nodeoffset = 0; printf("/"); } else { nodeoffset = fdt_path_offset (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt %s\n", fdt_strerror(nodeoffset)); return 1; } } /* * The user passed in a property as well as node path. Print only * the given property and then return. */ if (prop) { nodep = fdt_getprop (fdt, nodeoffset, prop, &len); if (len == 0) { printf("%s %s\n", pathp, prop); /* no property value */ return 0; } else if (len > 0) { printf("%s=", prop); print_data (nodep, len); printf("\n"); return 0; } else { printf ("libfdt %s\n", fdt_strerror(len)); return 1; } } /* * The user passed in a node path and no property, print the node * and all subnodes. */ offstack[0] = nodeoffset; while(level >= 0) { tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, &pathp); switch(tag) { case FDT_BEGIN_NODE: if(level <= depth) printf("%s%s {\n", &tabs[MAX_LEVEL - level], pathp); level++; offstack[level] = nodeoffset; if (level >= MAX_LEVEL) { printf("Aaaiii <splat> nested too deep.\n"); return 1; } break; case FDT_END_NODE: level--; if(level <= depth) printf("%s};\n", &tabs[MAX_LEVEL - level]); if (level == 0) { level = -1; /* exit the loop */ } break; case FDT_PROP: nodep = fdt_getprop (fdt, offstack[level], pathp, &len); if (len < 0) { printf ("libfdt %s\n", fdt_strerror(len)); return 1; } else if (len == 0) { /* the property has no value */ if(level <= depth) printf("%s%s;\n", &tabs[MAX_LEVEL - level], pathp); } else { if(level <= depth) { printf("%s%s=", &tabs[MAX_LEVEL - level], pathp); print_data (nodep, len); printf(";\n"); } } break; case FDT_NOP: break; case FDT_END: return 1; default: if(level <= depth) printf("Unknown tag 0x%08X\n", tag); return 1; } nodeoffset = nextoffset; } /******************************************************************** * Remove a property/node ********************************************************************/ } else if (op == 'r') { int nodeoffset; /* node offset from libfdt */ int err; /* * Get the path. The root node is an oddball, the offset * is zero and has no name. */ if (strcmp(argv[2], "/") == 0) { nodeoffset = 0; } else { nodeoffset = fdt_path_offset (fdt, argv[2]); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt %s\n", fdt_strerror(nodeoffset)); return 1; } } /* * Do the delete. A fourth parameter means delete a property, * otherwise delete the node. */ if (argc > 3) { err = fdt_delprop(fdt, nodeoffset, argv[3]); if (err < 0) { printf("fdt_delprop libfdt: %s\n", fdt_strerror(err)); return err; } } else { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { printf("fdt_del_node libfdt: %s\n", fdt_strerror(err)); return err; } } /******************************************************************** * Create a chosen node ********************************************************************/ } else if (op == 'c') { fdt_chosen(fdt, 0, 0, 1); #ifdef CONFIG_OF_HAS_UBOOT_ENV /******************************************************************** * Create a u-boot-env node ********************************************************************/ } else if (op == 'e') { fdt_env(fdt); #endif #ifdef CONFIG_OF_HAS_BD_T /******************************************************************** * Create a bd_t node ********************************************************************/ } else if (op == 'b') { fdt_bd_t(fdt); #endif /******************************************************************** * Unrecognized command ********************************************************************/ } else { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } return 0; }
void arm_cmd_start_linux(int argc, char **argv) { u64 kernel_addr, fdt_addr; u64 initrd_addr, initrd_size; int err; char cfg_str[10]; u64 meminfo[2]; if (argc != 5) { arm_puts ("start_linux: must provide <kernel_addr>, <initrd_addr>, <initrd_size> and <fdt_addr>\n"); return; } /* Parse the arguments from command line */ kernel_addr = arm_hexstr2ulonglong(argv[1]); initrd_addr = arm_hexstr2ulonglong(argv[2]); initrd_size = arm_hexstr2ulonglong(argv[3]); fdt_addr = arm_hexstr2ulonglong(argv[4]); meminfo[0] = arm_board_ram_start(); meminfo[1] = arm_board_ram_size(); /* Fillup/fixup the fdt blob with following: * - initrd start, end * - kernel cmd line * - number of cpus */ if ((err = fdt_fixup_memory_banks((void *)fdt_addr, (&meminfo[0]), (&meminfo[1]), 1))) { arm_printf("%s: fdt_fixup_memory_banks() failed: %s\n", __func__, fdt_strerror(err)); return; } sprintf(cfg_str, " mem=%dM maxcpus=%d", (int)(meminfo[1] >> 20), CONFIG_NR_CPUS); arm_strcat(linux_cmdline, cfg_str); if ((err = fdt_chosen((void *)fdt_addr, 1))) { arm_printf("%s: fdt_chosen() failed: %s\n", __func__, fdt_strerror(err)); return; } if ((err = fdt_initrd((void *)fdt_addr, initrd_addr, initrd_addr + initrd_size, 1))) { arm_printf("%s: fdt_initrd() failed: %s\n", __func__, fdt_strerror(err)); return; } /* Disable interrupts and timer */ arm_board_timer_disable(); arm_irq_disable(); arm_mmu_cleanup(); /* Jump to Linux Kernel * r0 -> dtb address */ arm_puts("Jumping into linux ...\n"); ((linux_entry_t)kernel_addr)(fdt_addr); /* We should never reach here */ while (1); return; }
/* * Flattened Device Tree command, see the help for parameter definitions. */ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { if (argc < 2) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /******************************************************************** * Set the address of the fdt ********************************************************************/ if (argv[1][0] == 'a') { /* * Set the address [and length] of the fdt. */ fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); if (!fdt_valid()) { return 1; } if (argc >= 4) { int len; int err; /* * Optional new length */ len = simple_strtoul(argv[3], NULL, 16); if (len < fdt_totalsize(fdt)) { printf ("New length %d < existing length %d, " "ignoring.\n", len, fdt_totalsize(fdt)); } else { /* * Open in place with a new length. */ err = fdt_open_into(fdt, fdt, len); if (err != 0) { printf ("libfdt fdt_open_into(): %s\n", fdt_strerror(err)); } } } /******************************************************************** * Move the fdt ********************************************************************/ } else if ((argv[1][0] == 'm') && (argv[1][1] == 'o')) { struct fdt_header *newaddr; int len; int err; if (argc < 4) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* * Set the address and length of the fdt. */ fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); if (!fdt_valid()) { return 1; } newaddr = (struct fdt_header *)simple_strtoul(argv[3],NULL,16); /* * If the user specifies a length, use that. Otherwise use the * current length. */ if (argc <= 4) { len = fdt_totalsize(fdt); } else { len = simple_strtoul(argv[4], NULL, 16); if (len < fdt_totalsize(fdt)) { printf ("New length 0x%X < existing length " "0x%X, aborting.\n", len, fdt_totalsize(fdt)); return 1; } } /* * Copy to the new location. */ err = fdt_open_into(fdt, newaddr, len); if (err != 0) { printf ("libfdt fdt_open_into(): %s\n", fdt_strerror(err)); return 1; } fdt = newaddr; /******************************************************************** * Make a new node ********************************************************************/ } else if ((argv[1][0] == 'm') && (argv[1][1] == 'k')) { char *pathp; /* path */ char *nodep; /* new node to add */ int nodeoffset; /* node offset from libfdt */ int err; /* * Parameters: Node path, new node to be appended to the path. */ if (argc < 4) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } pathp = argv[2]; nodep = argv[3]; nodeoffset = fdt_path_offset (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt fdt_path_offset() returned %s\n", fdt_strerror(nodeoffset)); return 1; } err = fdt_add_subnode(fdt, nodeoffset, nodep); if (err < 0) { printf ("libfdt fdt_add_subnode(): %s\n", fdt_strerror(err)); return 1; } /******************************************************************** * Set the value of a property in the fdt. ********************************************************************/ } else if (argv[1][0] == 's') { char *pathp; /* path */ char *prop; /* property */ char *newval; /* value from the user (as a string) */ int nodeoffset; /* node offset from libfdt */ static char data[SCRATCHPAD]; /* storage for the property */ int len; /* new length of the property */ int ret; /* return value */ /* * Parameters: Node path, property, value. */ if (argc < 5) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } pathp = argv[2]; prop = argv[3]; newval = argv[4]; nodeoffset = fdt_path_offset (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt fdt_path_offset() returned %s\n", fdt_strerror(nodeoffset)); return 1; } ret = fdt_parse_prop(pathp, prop, newval, data, &len); if (ret != 0) return ret; ret = fdt_setprop(fdt, nodeoffset, prop, data, len); if (ret < 0) { printf ("libfdt fdt_setprop(): %s\n", fdt_strerror(ret)); return 1; } /******************************************************************** * Print (recursive) / List (single level) ********************************************************************/ } else if ((argv[1][0] == 'p') || (argv[1][0] == 'l')) { int depth = MAX_LEVEL; /* how deep to print */ char *pathp; /* path */ char *prop; /* property */ int ret; /* return value */ static char root[2] = "/"; /* * list is an alias for print, but limited to 1 level */ if (argv[1][0] == 'l') { depth = 1; } /* * Get the starting path. The root node is an oddball, * the offset is zero and has no name. */ if (argc == 2) pathp = root; else pathp = argv[2]; if (argc > 3) prop = argv[3]; else prop = NULL; ret = fdt_print(pathp, prop, depth); if (ret != 0) return ret; /******************************************************************** * Remove a property/node ********************************************************************/ } else if (argv[1][0] == 'r') { int nodeoffset; /* node offset from libfdt */ int err; /* * Get the path. The root node is an oddball, the offset * is zero and has no name. */ nodeoffset = fdt_path_offset (fdt, argv[2]); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt fdt_path_offset() returned %s\n", fdt_strerror(nodeoffset)); return 1; } /* * Do the delete. A fourth parameter means delete a property, * otherwise delete the node. */ if (argc > 3) { err = fdt_delprop(fdt, nodeoffset, argv[3]); if (err < 0) { printf("libfdt fdt_delprop(): %s\n", fdt_strerror(err)); return err; } } else { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { printf("libfdt fdt_del_node(): %s\n", fdt_strerror(err)); return err; } } } #ifdef CONFIG_OF_BOARD_SETUP /* Call the board-specific fixup routine */ else if (argv[1][0] == 'b') ft_board_setup(fdt, gd->bd); #endif /* Create a chosen node */ else if (argv[1][0] == 'c') fdt_chosen(fdt, 0, 0, 1); #ifdef CONFIG_OF_HAS_UBOOT_ENV /* Create a u-boot-env node */ else if (argv[1][0] == 'e') fdt_env(fdt); #endif #ifdef CONFIG_OF_HAS_BD_T /* Create a bd_t node */ else if (argv[1][0] == 'b') fdt_bd_t(fdt); #endif else { /* Unrecognized command */ printf ("Usage:\n%s\n", cmdtp->usage); return 1; } return 0; }