Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Bright Star Engineering Inc. |
| 3 | * |
| 4 | * code for readng parameters from the |
| 5 | * parameter blocks of the boot block |
| 6 | * flash memory |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | static int strcmp(const char *s1, const char *s2) |
| 11 | { |
| 12 | while (*s1 != '\0' && *s1 == *s2) |
| 13 | { |
| 14 | s1++; |
| 15 | s2++; |
| 16 | } |
| 17 | |
| 18 | return (*(unsigned char *) s1) - (*(unsigned char *) s2); |
| 19 | } |
| 20 | |
| 21 | struct pblk_t { |
| 22 | char type; |
| 23 | unsigned short size; |
| 24 | }; |
| 25 | |
| 26 | static char *bse_getflashparam(char *name) { |
| 27 | unsigned int esize; |
| 28 | char *q,*r; |
| 29 | unsigned char *p,*e; |
| 30 | struct pblk_t *thepb = (struct pblk_t *) 0x00004000; |
| 31 | struct pblk_t *altpb = (struct pblk_t *) 0x00006000; |
| 32 | if (thepb->type&1) { |
| 33 | if (altpb->type&1) { |
| 34 | /* no valid param block */ |
| 35 | return (char*)0; |
| 36 | } else { |
| 37 | /* altpb is valid */ |
| 38 | struct pblk_t *tmp; |
| 39 | tmp = thepb; |
| 40 | thepb = altpb; |
| 41 | altpb = tmp; |
| 42 | } |
| 43 | } |
| 44 | p = (char*)thepb + sizeof(struct pblk_t); |
| 45 | e = p + thepb->size; |
| 46 | while (p < e) { |
| 47 | q = p; |
| 48 | esize = *p; |
| 49 | if (esize == 0xFF) break; |
| 50 | if (esize == 0) break; |
| 51 | if (esize > 127) { |
| 52 | esize = (esize&0x7F)<<8 | p[1]; |
| 53 | q++; |
| 54 | } |
| 55 | q++; |
| 56 | r=q; |
| 57 | if (*r && ((name == 0) || (!strcmp(name,r)))) { |
| 58 | while (*q++) ; |
| 59 | return q; |
| 60 | } |
| 61 | p+=esize; |
| 62 | } |
| 63 | return (char*)0; |
| 64 | } |
| 65 | |
| 66 | void bse_setup(void) { |
| 67 | /* extract the linux cmdline from flash */ |
| 68 | char *name=bse_getflashparam("linuxboot"); |
| 69 | char *x = (char *)0xc0000100; |
| 70 | if (name) { |
| 71 | while (*name) *x++=*name++; |
| 72 | } |
| 73 | *x=0; |
| 74 | } |