hw-bse.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. static int strcmp(const char *s1, const char *s2)
  10. {
  11. while (*s1 != '\0' && *s1 == *s2)
  12. {
  13. s1++;
  14. s2++;
  15. }
  16. return (*(unsigned char *) s1) - (*(unsigned char *) s2);
  17. }
  18. struct pblk_t {
  19. char type;
  20. unsigned short size;
  21. };
  22. static char *bse_getflashparam(char *name) {
  23. unsigned int esize;
  24. char *q,*r;
  25. unsigned char *p,*e;
  26. struct pblk_t *thepb = (struct pblk_t *) 0x00004000;
  27. struct pblk_t *altpb = (struct pblk_t *) 0x00006000;
  28. if (thepb->type&1) {
  29. if (altpb->type&1) {
  30. /* no valid param block */
  31. return (char*)0;
  32. } else {
  33. /* altpb is valid */
  34. struct pblk_t *tmp;
  35. tmp = thepb;
  36. thepb = altpb;
  37. altpb = tmp;
  38. }
  39. }
  40. p = (char*)thepb + sizeof(struct pblk_t);
  41. e = p + thepb->size;
  42. while (p < e) {
  43. q = p;
  44. esize = *p;
  45. if (esize == 0xFF) break;
  46. if (esize == 0) break;
  47. if (esize > 127) {
  48. esize = (esize&0x7F)<<8 | p[1];
  49. q++;
  50. }
  51. q++;
  52. r=q;
  53. if (*r && ((name == 0) || (!strcmp(name,r)))) {
  54. while (*q++) ;
  55. return q;
  56. }
  57. p+=esize;
  58. }
  59. return (char*)0;
  60. }
  61. void bse_setup(void) {
  62. /* extract the linux cmdline from flash */
  63. char *name=bse_getflashparam("linuxboot");
  64. char *x = (char *)0xc0000100;
  65. if (name) {
  66. while (*name) *x++=*name++;
  67. }
  68. *x=0;
  69. }