diff options
Diffstat (limited to 'arch/powerpc/boot')
59 files changed, 2835 insertions, 1497 deletions
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile index 65d1a8454d2..aac1406ccba 100644 --- a/arch/powerpc/boot/Makefile +++ b/arch/powerpc/boot/Makefile @@ -310,8 +310,11 @@ $(obj)/dtbImage.%: vmlinux $(wrapperbits) $(obj)/%.dtb $(obj)/vmlinux.strip: vmlinux $(STRIP) -s -R .comment $< -o $@ +# The iseries hypervisor won't take an ET_DYN executable, so this +# changes the type (byte 17) in the file to ET_EXEC (2). $(obj)/zImage.iseries: vmlinux $(STRIP) -s -R .comment $< -o $@ + printf "\x02" | dd of=$@ conv=notrunc bs=1 seek=17 $(obj)/uImage: vmlinux $(wrapperbits) $(call if_changed,wrap,uboot) diff --git a/arch/powerpc/boot/addnote.c b/arch/powerpc/boot/addnote.c index b1e5611b2ab..dcc9ab2ca82 100644 --- a/arch/powerpc/boot/addnote.c +++ b/arch/powerpc/boot/addnote.c @@ -11,7 +11,12 @@ * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * - * Usage: addnote zImage + * Usage: addnote zImage [note.elf] + * + * If note.elf is supplied, it is the name of an ELF file that contains + * an RPA note to use instead of the built-in one. Alternatively, the + * note.elf file may be empty, in which case the built-in RPA note is + * used (this is to simplify how this is invoked from the wrapper script). */ #include <stdio.h> #include <stdlib.h> @@ -43,27 +48,29 @@ char rpaname[] = "IBM,RPA-Client-Config"; */ #define N_RPA_DESCR 8 unsigned int rpanote[N_RPA_DESCR] = { - 0, /* lparaffinity */ - 64, /* min_rmo_size */ + 1, /* lparaffinity */ + 128, /* min_rmo_size */ 0, /* min_rmo_percent */ - 40, /* max_pft_size */ + 46, /* max_pft_size */ 1, /* splpar */ -1, /* min_load */ - 0, /* new_mem_def */ - 1, /* ignore_my_client_config */ + 1, /* new_mem_def */ + 0, /* ignore_my_client_config */ }; #define ROUNDUP(len) (((len) + 3) & ~3) unsigned char buf[512]; +unsigned char notebuf[512]; -#define GET_16BE(off) ((buf[off] << 8) + (buf[(off)+1])) -#define GET_32BE(off) ((GET_16BE(off) << 16) + GET_16BE((off)+2)) +#define GET_16BE(b, off) (((b)[off] << 8) + ((b)[(off)+1])) +#define GET_32BE(b, off) ((GET_16BE((b), (off)) << 16) + \ + GET_16BE((b), (off)+2)) -#define PUT_16BE(off, v) (buf[off] = ((v) >> 8) & 0xff, \ - buf[(off) + 1] = (v) & 0xff) -#define PUT_32BE(off, v) (PUT_16BE((off), (v) >> 16), \ - PUT_16BE((off) + 2, (v))) +#define PUT_16BE(b, off, v) ((b)[off] = ((v) >> 8) & 0xff, \ + (b)[(off) + 1] = (v) & 0xff) +#define PUT_32BE(b, off, v) (PUT_16BE((b), (off), (v) >> 16), \ + PUT_16BE((b), (off) + 2, (v))) /* Structure of an ELF file */ #define E_IDENT 0 /* ELF header */ @@ -88,15 +95,71 @@ unsigned char buf[512]; unsigned char elf_magic[4] = { 0x7f, 'E', 'L', 'F' }; +unsigned char *read_rpanote(const char *fname, int *nnp) +{ + int notefd, nr, i; + int ph, ps, np; + int note, notesize; + + notefd = open(fname, O_RDONLY); + if (notefd < 0) { + perror(fname); + exit(1); + } + nr = read(notefd, notebuf, sizeof(notebuf)); + if (nr < 0) { + perror("read note"); + exit(1); + } + if (nr == 0) /* empty file */ + return NULL; + if (nr < E_HSIZE || + memcmp(¬ebuf[E_IDENT+EI_MAGIC], elf_magic, 4) != 0 || + notebuf[E_IDENT+EI_CLASS] != ELFCLASS32 || + notebuf[E_IDENT+EI_DATA] != ELFDATA2MSB) + goto notelf; + close(notefd); + + /* now look for the RPA-note */ + ph = GET_32BE(notebuf, E_PHOFF); + ps = GET_16BE(notebuf, E_PHENTSIZE); + np = GET_16BE(notebuf, E_PHNUM); + if (ph < E_HSIZE || ps < PH_HSIZE || np < 1) + goto notelf; + + for (i = 0; i < np; ++i, ph += ps) { + if (GET_32BE(notebuf, ph + PH_TYPE) != PT_NOTE) + continue; + note = GET_32BE(notebuf, ph + PH_OFFSET); + notesize = GET_32BE(notebuf, ph + PH_FILESZ); + if (notesize < 34 || note + notesize > nr) + continue; + if (GET_32BE(notebuf, note) != strlen(rpaname) + 1 || + GET_32BE(notebuf, note + 8) != 0x12759999 || + strcmp((char *)¬ebuf[note + 12], rpaname) != 0) + continue; + /* looks like an RPA note, return it */ + *nnp = notesize; + return ¬ebuf[note]; + } + /* no RPA note found */ + return NULL; + + notelf: + fprintf(stderr, "%s is not a big-endian 32-bit ELF image\n", fname); + exit(1); +} + int main(int ac, char **av) { int fd, n, i; int ph, ps, np; int nnote, nnote2, ns; + unsigned char *rpap; - if (ac != 2) { - fprintf(stderr, "Usage: %s elf-file\n", av[0]); + if (ac != 2 && ac != 3) { + fprintf(stderr, "Usage: %s elf-file [rpanote.elf]\n", av[0]); exit(1); } fd = open(av[1], O_RDWR); @@ -107,6 +170,7 @@ main(int ac, char **av) nnote = 12 + ROUNDUP(strlen(arch) + 1) + sizeof(descr); nnote2 = 12 + ROUNDUP(strlen(rpaname) + 1) + sizeof(rpanote); + rpap = NULL; n = read(fd, buf, sizeof(buf)); if (n < 0) { @@ -124,16 +188,19 @@ main(int ac, char **av) exit(1); } - ph = GET_32BE(E_PHOFF); - ps = GET_16BE(E_PHENTSIZE); - np = GET_16BE(E_PHNUM); + if (ac == 3) + rpap = read_rpanote(av[2], &nnote2); + + ph = GET_32BE(buf, E_PHOFF); + ps = GET_16BE(buf, E_PHENTSIZE); + np = GET_16BE(buf, E_PHNUM); if (ph < E_HSIZE || ps < PH_HSIZE || np < 1) goto notelf; if (ph + (np + 2) * ps + nnote + nnote2 > n) goto nospace; for (i = 0; i < np; ++i) { - if (GET_32BE(ph + PH_TYPE) == PT_NOTE) { + if (GET_32BE(buf, ph + PH_TYPE) == PT_NOTE) { fprintf(stderr, "%s already has a note entry\n", av[1]); exit(0); @@ -148,37 +215,42 @@ main(int ac, char **av) /* fill in the program header entry */ ns = ph + 2 * ps; - PUT_32BE(ph + PH_TYPE, PT_NOTE); - PUT_32BE(ph + PH_OFFSET, ns); - PUT_32BE(ph + PH_FILESZ, nnote); + PUT_32BE(buf, ph + PH_TYPE, PT_NOTE); + PUT_32BE(buf, ph + PH_OFFSET, ns); + PUT_32BE(buf, ph + PH_FILESZ, nnote); /* fill in the note area we point to */ /* XXX we should probably make this a proper section */ - PUT_32BE(ns, strlen(arch) + 1); - PUT_32BE(ns + 4, N_DESCR * 4); - PUT_32BE(ns + 8, 0x1275); + PUT_32BE(buf, ns, strlen(arch) + 1); + PUT_32BE(buf, ns + 4, N_DESCR * 4); + PUT_32BE(buf, ns + 8, 0x1275); strcpy((char *) &buf[ns + 12], arch); ns += 12 + strlen(arch) + 1; for (i = 0; i < N_DESCR; ++i, ns += 4) - PUT_32BE(ns, descr[i]); + PUT_32BE(buf, ns, descr[i]); /* fill in the second program header entry and the RPA note area */ ph += ps; - PUT_32BE(ph + PH_TYPE, PT_NOTE); - PUT_32BE(ph + PH_OFFSET, ns); - PUT_32BE(ph + PH_FILESZ, nnote2); + PUT_32BE(buf, ph + PH_TYPE, PT_NOTE); + PUT_32BE(buf, ph + PH_OFFSET, ns); + PUT_32BE(buf, ph + PH_FILESZ, nnote2); /* fill in the note area we point to */ - PUT_32BE(ns, strlen(rpaname) + 1); - PUT_32BE(ns + 4, sizeof(rpanote)); - PUT_32BE(ns + 8, 0x12759999); - strcpy((char *) &buf[ns + 12], rpaname); - ns += 12 + ROUNDUP(strlen(rpaname) + 1); - for (i = 0; i < N_RPA_DESCR; ++i, ns += 4) - PUT_32BE(ns, rpanote[i]); + if (rpap) { + /* RPA note supplied in file, just copy the whole thing over */ + memcpy(buf + ns, rpap, nnote2); + } else { + PUT_32BE(buf, ns, strlen(rpaname) + 1); + PUT_32BE(buf, ns + 4, sizeof(rpanote)); + PUT_32BE(buf, ns + 8, 0x12759999); + strcpy((char *) &buf[ns + 12], rpaname); + ns += 12 + ROUNDUP(strlen(rpaname) + 1); + for (i = 0; i < N_RPA_DESCR; ++i, ns += 4) + PUT_32BE(buf, ns, rpanote[i]); + } /* Update the number of program headers */ - PUT_16BE(E_PHNUM, np + 2); + PUT_16BE(buf, E_PHNUM, np + 2); /* write back */ lseek(fd, (long) 0, SEEK_SET); diff --git a/arch/powerpc/boot/dtc-src/Makefile.dtc b/arch/powerpc/boot/dtc-src/Makefile.dtc index d607fdb8df8..6ddf9ecac66 100644 --- a/arch/powerpc/boot/dtc-src/Makefile.dtc +++ b/arch/powerpc/boot/dtc-src/Makefile.dtc @@ -5,21 +5,5 @@ # DTC_SRCS = dtc.c flattree.c fstree.c data.c livetree.c treesource.c srcpos.c \ checks.c -DTC_EXTRA = dtc.h srcpos.h -DTC_LEXFILES = dtc-lexer.l -DTC_BISONFILES = dtc-parser.y - -DTC_LEX_SRCS = $(DTC_LEXFILES:%.l=%.lex.c) -DTC_BISON_SRCS = $(DTC_BISONFILES:%.y=%.tab.c) -DTC_BISON_INCLUDES = $(DTC_BISONFILES:%.y=%.tab.h) - -DTC_GEN_SRCS = $(DTC_LEX_SRCS) $(DTC_BISON_SRCS) -DTC_GEN_ALL = $(DTC_GEN_SRCS) $(DTC_BISON_INCLUDES) +DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o) - -DTC_CLEANFILES = $(DTC_GEN_ALL) - -# We assume the containing Makefile system can do auto-dependencies for most -# things, but we supply the dependencies on generated header files explicitly - -$(addprefix $(DTC_objdir)/,$(DTC_GEN_SRCS:%.c=%.o)): $(addprefix $(DTC_objdir)/,$(DTC_BISON_INCLUDES)) diff --git a/arch/powerpc/boot/dtc-src/checks.c b/arch/powerpc/boot/dtc-src/checks.c index 2ce961cd414..95485796f25 100644 --- a/arch/powerpc/boot/dtc-src/checks.c +++ b/arch/powerpc/boot/dtc-src/checks.c @@ -242,6 +242,42 @@ static void check_duplicate_property_names(struct check *c, struct node *dt, } NODE_CHECK(duplicate_property_names, NULL, ERROR); +#define LOWERCASE "abcdefghijklmnopqrstuvwxyz" +#define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +#define DIGITS "0123456789" +#define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-" + +static void check_node_name_chars(struct check *c, struct node *dt, + struct node *node) +{ + int n = strspn(node->name, c->data); + + if (n < strlen(node->name)) + FAIL(c, "Bad character '%c' in node %s", + node->name[n], node->fullpath); +} +NODE_CHECK(node_name_chars, PROPNODECHARS "@", ERROR); + +static void check_node_name_format(struct check *c, struct node *dt, + struct node *node) +{ + if (strchr(get_unitname(node), '@')) + FAIL(c, "Node %s has multiple '@' characters in name", + node->fullpath); +} +NODE_CHECK(node_name_format, NULL, ERROR, &node_name_chars); + +static void check_property_name_chars(struct check *c, struct node *dt, + struct node *node, struct property *prop) +{ + int n = strspn(prop->name, c->data); + + if (n < strlen(prop->name)) + FAIL(c, "Bad character '%c' in property name \"%s\", node %s", + prop->name[n], prop->name, node->fullpath); +} +PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR); + static void check_explicit_phandles(struct check *c, struct node *root, struct node *node) { @@ -280,16 +316,29 @@ NODE_CHECK(explicit_phandles, NULL, ERROR); static void check_name_properties(struct check *c, struct node *root, struct node *node) { - struct property *prop; + struct property **pp, *prop = NULL; + + for (pp = &node->proplist; *pp; pp = &((*pp)->next)) + if (streq((*pp)->name, "name")) { + prop = *pp; + break; + } - prop = get_property(node, "name"); if (!prop) return; /* No name property, that's fine */ if ((prop->val.len != node->basenamelen+1) - || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) + || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) { FAIL(c, "\"name\" property in %s is incorrect (\"%s\" instead" " of base node name)", node->fullpath, prop->val.val); + } else { + /* The name property is correct, and therefore redundant. + * Delete it */ + *pp = prop->next; + free(prop->name); + data_free(prop->val); + free(prop); + } } CHECK_IS_STRING(name_is_string, "name", ERROR); NODE_CHECK(name_properties, NULL, ERROR, &name_is_string); @@ -301,23 +350,23 @@ NODE_CHECK(name_properties, NULL, ERROR, &name_is_string); static void fixup_phandle_references(struct check *c, struct node *dt, struct node *node, struct property *prop) { - struct marker *m = prop->val.markers; - struct node *refnode; - cell_t phandle; - - for_each_marker_of_type(m, REF_PHANDLE) { - assert(m->offset + sizeof(cell_t) <= prop->val.len); - - refnode = get_node_by_ref(dt, m->ref); - if (! refnode) { - FAIL(c, "Reference to non-existent node or label \"%s\"\n", - m->ref); - continue; - } - - phandle = get_node_phandle(dt, refnode); - *((cell_t *)(prop->val.val + m->offset)) = cpu_to_be32(phandle); - } + struct marker *m = prop->val.markers; + struct node *refnode; + cell_t phandle; + + for_each_marker_of_type(m, REF_PHANDLE) { + assert(m->offset + sizeof(cell_t) <= prop->val.len); + + refnode = get_node_by_ref(dt, m->ref); + if (! refnode) { + FAIL(c, "Reference to non-existent node or label \"%s\"\n", + m->ref); + continue; + } + + phandle = get_node_phandle(dt, refnode); + *((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle); + } } CHECK(phandle_references, NULL, NULL, fixup_phandle_references, NULL, ERROR, &duplicate_node_names, &explicit_phandles); @@ -498,6 +547,7 @@ TREE_CHECK(obsolete_chosen_interrupt_controller, NULL, WARN); static struct check *check_table[] = { &duplicate_node_names, &duplicate_property_names, + &node_name_chars, &node_name_format, &property_name_chars, &name_is_string, &name_properties, &explicit_phandles, &phandle_references, &path_references, @@ -511,10 +561,7 @@ static struct check *check_table[] = { &obsolete_chosen_interrupt_controller, }; -int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys); - -void process_checks(int force, struct boot_info *bi, - int checkflag, int outversion, int boot_cpuid_phys) +void process_checks(int force, struct boot_info *bi) { struct node *dt = bi->dt; int i; @@ -537,214 +584,4 @@ void process_checks(int force, struct boot_info *bi, "output forced\n"); } } - - if (checkflag) { - if (error) { - fprintf(stderr, "Warning: Skipping semantic checks due to structural errors\n"); - } else { - if (!check_semantics(bi->dt, outversion, - boot_cpuid_phys)) - fprintf(stderr, "Warning: Input tree has semantic errors\n"); - } - } -} - -/* - * Semantic check functions - */ - -#define ERRMSG(...) if (quiet < 2) fprintf(stderr, "ERROR: " __VA_ARGS__) -#define WARNMSG(...) if (quiet < 1) fprintf(stderr, "Warning: " __VA_ARGS__) - -#define DO_ERR(...) do {ERRMSG(__VA_ARGS__); ok = 0; } while (0) - -#define CHECK_HAVE(node, propname) \ - do { \ - if (! (prop = get_property((node), (propname)))) \ - DO_ERR("Missing \"%s\" property in %s\n", (propname), \ - (node)->fullpath); \ - } while (0); - -#define CHECK_HAVE_WARN(node, propname) \ - do { \ - if (! (prop = get_property((node), (propname)))) \ - WARNMSG("%s has no \"%s\" property\n", \ - (node)->fullpath, (propname)); \ - } while (0) - -#define CHECK_HAVE_STRING(node, propname) \ - do { \ - CHECK_HAVE((node), (propname)); \ - if (prop && !data_is_one_string(prop->val)) \ - DO_ERR("\"%s\" property in %s is not a string\n", \ - (propname), (node)->fullpath); \ - } while (0) - -#define CHECK_HAVE_STREQ(node, propname, value) \ - do { \ - CHECK_HAVE_STRING((node), (propname)); \ - if (prop && !streq(prop->val.val, (value))) \ - DO_ERR("%s has wrong %s, %s (should be %s\n", \ - (node)->fullpath, (propname), \ - prop->val.val, (value)); \ - } while (0) - -#define CHECK_HAVE_ONECELL(node, propname) \ - do { \ - CHECK_HAVE((node), (propname)); \ - if (prop && (prop->val.len != sizeof(cell_t))) \ - DO_ERR("\"%s\" property in %s has wrong size %d (should be 1 cell)\n", (propname), (node)->fullpath, prop->val.len); \ - } while (0) - -#define CHECK_HAVE_WARN_ONECELL(node, propname) \ - do { \ - CHECK_HAVE_WARN((node), (propname)); \ - if (prop && (prop->val.len != sizeof(cell_t))) \ - DO_ERR("\"%s\" property in %s has wrong size %d (should be 1 cell)\n", (propname), (node)->fullpath, prop->val.len); \ - } while (0) - -#define CHECK_HAVE_WARN_PHANDLE(xnode, propname, root) \ - do { \ - struct node *ref; \ - CHECK_HAVE_WARN_ONECELL((xnode), (propname)); \ - if (prop) {\ - cell_t phandle = propval_cell(prop); \ - if ((phandle == 0) || (phandle == -1)) { \ - DO_ERR("\"%s\" property in %s contains an invalid phandle %x\n", (propname), (xnode)->fullpath, phandle); \ - } else { \ - ref = get_node_by_phandle((root), propval_cell(prop)); \ - if (! ref) \ - DO_ERR("\"%s\" property in %s refers to non-existant phandle %x\n", (propname), (xnode)->fullpath, propval_cell(prop)); \ - } \ - } \ - } while (0) - -#define CHECK_HAVE_WARN_STRING(node, propname) \ - do { \ - CHECK_HAVE_WARN((node), (propname)); \ - if (prop && !data_is_one_string(prop->val)) \ - DO_ERR("\"%s\" property in %s is not a string\n", \ - (propname), (node)->fullpath); \ - } while (0) - -static int check_root(struct node *root) -{ - struct property *prop; - int ok = 1; - - CHECK_HAVE_STRING(root, "model"); - CHECK_HAVE_WARN(root, "compatible"); - - return ok; -} - -static int check_cpus(struct node *root, int outversion, int boot_cpuid_phys) -{ - struct node *cpus, *cpu; - struct property *prop; - struct node *bootcpu = NULL; - int ok = 1; - - cpus = get_subnode(root, "cpus"); - if (! cpus) { - ERRMSG("Missing /cpus node\n"); - return 0; - } - - if (cpus->addr_cells != 1) - DO_ERR("%s has bad #address-cells value %d (should be 1)\n", - cpus->fullpath, cpus->addr_cells); - if (cpus->size_cells != 0) - DO_ERR("%s has bad #size-cells value %d (should be 0)\n", - cpus->fullpath, cpus->size_cells); - - for_each_child(cpus, cpu) { - CHECK_HAVE_STREQ(cpu, "device_type", "cpu"); - - CHECK_HAVE_ONECELL(cpu, "reg"); - if (prop) { - cell_t unitnum; - char *eptr; - - unitnum = strtol(get_unitname(cpu), &eptr, 16); - if (*eptr) { - WARNMSG("%s has bad format unit name %s (should be CPU number\n", - cpu->fullpath, get_unitname(cpu)); - } else if (unitnum != propval_cell(prop)) { - WARNMSG("%s unit name \"%s\" does not match \"reg\" property <%x>\n", - cpu->fullpath, get_unitname(cpu), - propval_cell(prop)); - } - } - -/* CHECK_HAVE_ONECELL(cpu, "d-cache-line-size"); */ -/* CHECK_HAVE_ONECELL(cpu, "i-cache-line-size"); */ - CHECK_HAVE_ONECELL(cpu, "d-cache-size"); - CHECK_HAVE_ONECELL(cpu, "i-cache-size"); - - CHECK_HAVE_WARN_ONECELL(cpu, "clock-frequency"); - CHECK_HAVE_WARN_ONECELL(cpu, "timebase-frequency"); - - prop = get_property(cpu, "linux,boot-cpu"); - if (prop) { - if (prop->val.len) - WARNMSG("\"linux,boot-cpu\" property in %s is non-empty\n", - cpu->fullpath); - if (bootcpu) - DO_ERR("Multiple boot cpus (%s and %s)\n", - bootcpu->fullpath, cpu->fullpath); - else - bootcpu = cpu; - } - } - - if (outversion < 2) { - if (! bootcpu) - WARNMSG("No cpu has \"linux,boot-cpu\" property\n"); - } else { - if (bootcpu) - WARNMSG("\"linux,boot-cpu\" property is deprecated in blob version 2 or higher\n"); - if (boot_cpuid_phys == 0xfeedbeef) - WARNMSG("physical boot CPU not set. Use -b option to set\n"); - } - - return ok; -} - -static int check_memory(struct node *root) -{ - struct node *mem; - struct property *prop; - int nnodes = 0; - int ok = 1; - - for_each_child(root, mem) { - if (! strneq(mem->name, "memory", mem->basenamelen)) - continue; - - nnodes++; - - CHECK_HAVE_STREQ(mem, "device_type", "memory"); - CHECK_HAVE(mem, "reg"); - } - - if (nnodes == 0) { - ERRMSG("No memory nodes\n"); - return 0; - } - - return ok; -} - -int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys) -{ - int ok = 1; - - ok = ok && check_root(dt); - ok = ok && check_cpus(dt, outversion, boot_cpuid_phys); - ok = ok && check_memory(dt); - if (! ok) - return 0; - - return 1; } diff --git a/arch/powerpc/boot/dtc-src/data.c b/arch/powerpc/boot/dtc-src/data.c index a94718c731a..dd2e3d39d4c 100644 --- a/arch/powerpc/boot/dtc-src/data.c +++ b/ |