📄 tgt_machdep.c
字号:
#endif /*INET*//*************************************************************************//* * Target dependent Non volatile memory support code * ================================================= * * * On this target a part of the boot flash memory is used to store * environment. See EV96132.h for mapping details. (offset and size). *//* * Read in environment from NV-ram and set. */voidtgt_mapenv(int (*func) __P((char *, char *))){ char *ep; char env[512]; char *nvram; int i; /* * Check integrity of the NVRAM env area. If not in order * initialize it to empty. */#ifdef NVRAM_IN_FLASH nvram = (char *)(tgt_flashmap())->fl_map_base; if(fl_devident(nvram, NULL) == 0 || cksum(nvram + NVRAM_OFFS, NVRAM_SIZE, 0) != 0) {#else nvram = (char *)malloc(512); nvram_get(nvram); if(cksum(nvram, NVRAM_SIZE, 0) != 0) {#endif nvram_invalid = 1; } else { nvram += NVRAM_OFFS; ep = nvram+2;; while(*ep != 0) { char *val = 0, *p = env; i = 0; while((*p++ = *ep++) && (ep <= nvram + NVRAM_SIZE - 1) && i++ < 255) { if((*(p - 1) == '=') && (val == NULL)) { *(p - 1) = '\0'; val = p; } } if(ep <= nvram + NVRAM_SIZE - 1 && i < 255) { (*func)(env, val); } else { nvram_invalid = 2; break; } } } /* * Ethernet address for Galileo ethernet is stored in the last * six bytes of nvram storage. Set environment to it. */ bcopy(&nvram[ETHER_OFFS], hwethadr, 6); sprintf(env, "%02x:%02x:%02x:%02x:%02x:%02x", hwethadr[0], hwethadr[1], hwethadr[2], hwethadr[3], hwethadr[4], hwethadr[5]); (*func)("ethaddr", env);#ifndef NVRAM_IN_FLASH free(nvram);#endif#ifdef no_thank_you (*func)("vxWorks", env);#endif sprintf(env, "%d", memorysize / (1024 * 1024)); (*func)("memsize", env); sprintf(env, "%d", md_pipefreq); (*func)("cpuclock", env); sprintf(env, "%d", md_cpufreq); (*func)("busclock", env); (*func)("systype", "ev96132");}inttgt_unsetenv(char *name){ char *ep, *np, *sp; char *nvram; char *nvrambuf; char *nvramsecbuf; int status; if(nvram_invalid) { return(0); } /* Use first defined flash device (we probably have only one) */#ifdef NVRAM_IN_FLASH nvram = (char *)(tgt_flashmap())->fl_map_base; /* Map. Deal with an entire sector even if we only use part of it */ nvram += NVRAM_OFFS & ~(NVRAM_SECSIZE - 1); nvramsecbuf = (char *)malloc(NVRAM_SECSIZE); if(nvramsecbuf == 0) { printf("Warning! Unable to malloc nvrambuffer!\n"); return(-1); } memcpy(nvramsecbuf, nvram, NVRAM_SECSIZE); nvrambuf = nvramsecbuf + (NVRAM_OFFS & (NVRAM_SECSIZE - 1));#else nvramsecbuf = nvrambuf = nvram = (char *)malloc(512); nvram_get(nvram);#endif ep = nvrambuf + 2; status = 0; while((*ep != '\0') && (ep <= nvrambuf + NVRAM_SIZE)) { np = name; sp = ep; while((*ep == *np) && (*ep != '=') && (*np != '\0')) { ep++; np++; } if((*np == '\0') && ((*ep == '\0') || (*ep == '='))) { while(*ep++); while(ep <= nvrambuf + NVRAM_SIZE) { *sp++ = *ep++; } if(nvrambuf[2] == '\0') { nvrambuf[3] = '\0'; } cksum(nvrambuf, NVRAM_SIZE, 1);#ifdef NVRAM_IN_FLASH if(fl_erase_device(nvram, NVRAM_SECSIZE, FALSE)) { status = -1; break; } if(fl_program_device(nvram, nvramsecbuf, NVRAM_SECSIZE, FALSE)) { status = -1; break; }#else nvram_put(nvram);#endif status = 1; break; } else if(*ep != '\0') { while(*ep++ != '\0'); } } free(nvramsecbuf); return(status);}inttgt_setenv(char *name, char *value){ char *ep; int envlen; char *nvrambuf; char *nvramsecbuf;#ifdef NVRAM_IN_FLASH char *nvram;#endif /* Non permanent vars. */ if(strcmp(EXPERT, name) == 0) { return(1); } /* Calculate total env mem size requiered */ envlen = strlen(name); if(envlen == 0) { return(0); } if(value != NULL) { envlen += strlen(value); } envlen += 2; /* '=' + null byte */ if(envlen > 255) { return(0); /* Are you crazy!? */ } /* Use first defined flash device (we probably have only one) */#ifdef NVRAM_IN_FLASH nvram = (char *)(tgt_flashmap())->fl_map_base; /* Deal with an entire sector even if we only use part of it */ nvram += NVRAM_OFFS & ~(NVRAM_SECSIZE - 1);#endif /* If NVRAM is found to be uninitialized, reinit it. */ if(nvram_invalid) { nvramsecbuf = (char *)malloc(NVRAM_SECSIZE); if(nvramsecbuf == 0) { printf("Warning! Unable to malloc nvrambuffer!\n"); return(-1); }#ifdef NVRAM_IN_FLASH memcpy(nvramsecbuf, nvram, NVRAM_SECSIZE);#endif nvrambuf = nvramsecbuf + (NVRAM_OFFS & (NVRAM_SECSIZE - 1)); memset(nvrambuf, -1, NVRAM_SIZE); nvrambuf[2] = '\0'; nvrambuf[3] = '\0'; cksum((void *)nvrambuf, NVRAM_SIZE, 1); printf("Warning! NVRAM checksum fail. Reset!\n");#ifdef NVRAM_IN_FLASH if(fl_erase_device(nvram, NVRAM_SECSIZE, FALSE)) { printf("Error! Nvram erase failed!\n"); free(nvramsecbuf); return(-1); } if(fl_program_device(nvram, nvramsecbuf, NVRAM_SECSIZE, FALSE)) { printf("Error! Nvram init failed!\n"); free(nvramsecbuf); return(-1); }#else nvram_put(nvramsecbuf);#endif nvram_invalid = 0; free(nvramsecbuf); } /* Remove any current setting */ tgt_unsetenv(name); /* Find end of evironment strings */ nvramsecbuf = (char *)malloc(NVRAM_SECSIZE); if(nvramsecbuf == 0) { printf("Warning! Unable to malloc nvrambuffer!\n"); return(-1); }#ifndef NVRAM_IN_FLASH nvram_get(nvramsecbuf);#else memcpy(nvramsecbuf, nvram, NVRAM_SECSIZE);#endif nvrambuf = nvramsecbuf + (NVRAM_OFFS & (NVRAM_SECSIZE - 1)); /* Etheraddr is special case to save space */ if (strcmp("ethaddr", name) == 0) { char *s = value; int i; int32_t v; for(i = 0; i < 6; i++) { gethex(&v, s, 2); hwethadr[i] = v; s += 3; /* Don't get to fancy here :-) */ } } else { ep = nvrambuf+2; if(*ep != '\0') { do { while(*ep++ != '\0'); } while(*ep++ != '\0'); ep--; } if(((int)ep + NVRAM_SIZE - (int)ep) < (envlen + 1)) { free(nvramsecbuf); return(0); /* Bummer! */ } /* * Special case heaptop must always be first since it * can change how memory allocation works. */ if(strcmp("heaptop", name) == 0) { bcopy(nvrambuf+2, nvrambuf+2 + envlen, ep - nvrambuf+1); ep = nvrambuf+2; while(*name != '\0') { *ep++ = *name++; } if(value != NULL) { *ep++ = '='; while((*ep++ = *value++) != '\0'); } else { *ep++ = '\0'; } } else { while(*name != '\0') { *ep++ = *name++; } if(value != NULL) { *ep++ = '='; while((*ep++ = *value++) != '\0'); } else { *ep++ = '\0'; } *ep++ = '\0'; /* End of env strings */ } } cksum(nvrambuf, NVRAM_SIZE, 1); bcopy(hwethadr, &nvramsecbuf[ETHER_OFFS], 6);#ifdef NVRAM_IN_FLASH if(fl_erase_device(nvram, NVRAM_SECSIZE, FALSE)) { printf("Error! Nvram erase failed!\n"); free(nvramsecbuf); return(0); } if(fl_program_device(nvram, nvramsecbuf, NVRAM_SECSIZE, FALSE)) { printf("Error! Nvram program failed!\n"); free(nvramsecbuf); return(0); }#else nvram_put(nvramsecbuf);#endif free(nvramsecbuf); return(1);}/* * Calculate checksum. If 'set' checksum is calculated and set. */static intcksum(void *p, size_t s, int set){ u_int16_t sum = 0; u_int8_t *sp = p; int sz = s / 2; if(set) { *sp = 0; /* Clear checksum */ *(sp+1) = 0; /* Clear checksum */ } while(sz--) { sum += (*sp++) << 8; sum += *sp++; } if(set) { sum = -sum; *(u_int8_t *)p = sum >> 8; *((u_int8_t *)p+1) = sum; } return(sum);}#ifndef NVRAM_IN_FLASH/* * Read and write data into non volatile memory in clock chip. */voidnvram_get(char *buffer){ int i; for(i = 0; i < 256; i++) { outb(RTC_BASE+0x10, i); /* Address */ buffer[i] = inb(RTC_BASE+0x13); }}voidnvram_put(char *buffer){ int i; for(i = 0; i < 256; i++) { outb(RTC_BASE+0x10, i); /* Address */ outb(RTC_BASE+0x13, buffer[i]); }}#endif/*************************************************************************//* * Target dependent miscelaneous support code * ========================================== * *//* * Simple display function to display a 4 char string or code. * Called during startup to display progress on any feasible * display before any serial port have been initialized. */voidtgt_display(char *msg, int x){ /* Have simple serial port driver */ tgt_putchar(msg[0]); tgt_putchar(msg[1]); tgt_putchar(msg[2]); tgt_putchar(msg[3]); tgt_putchar('\r'); tgt_putchar('\n');}voidclrhndlrs(){}inttgt_getmachtype(){ return(md_cputype());}/* * Reboot system. Do the best possible and if we are lucky the HW * designers put in a way to pull the reset input from SW. If they * goofed and forgot about this feature, well it may be very * unreliable so it may be better to leave it alone and depend on * the ol'e 'thumb'... */voidtgt_reboot(){ if(clk_invalid) { printf("No device module or clock, can't reset to reboot!\n"); while(1); } outb(RTC_BASE+DS_REG_WDSEC, 0x00); /* Give it half a second */ outb(RTC_BASE+DS_REG_WDMS, 0x50); /* Give it half a second */ outb(RTC_BASE+DS_REG_CTLB, DS_CTLB_TE|DS_CTLB_WDS|DS_CTLB_WDE); outb(RTC_BASE+DS_REG_CTLA, inb(RTC_BASE+DS_REG_CTLA) & ~DS_CTLA_WDF); while((inb(RTC_BASE+DS_REG_CTLA) & DS_CTLA_WDF) == 0); printf("Hey! Reset did not work! Check that jumper J33 is IN!\n"); while(1);}/* * Put all machine dependent initialization here. This call * is done after console has been initialized so it's safe * to output configuration and debug information with printf. */voidtgt_devconfig(){ /* * PCI device initialization */ _pci_devinit(1); config_init(); configure();}voidtgt_devinit(){ /* * Set up GT96132 pin routing etc. */ GT_WRITE(0x101ac0,0x800003fc); // ciu_arb GT_WRITE(0x100a00,0xffff0003); // gpc0 GT_WRITE(0x100a20,0x46462000); // gpio0 GT_WRITE(0x100a04,0xffffffff); // gpc1 GT_WRITE(0x100a24,0x46464646); // gpio1 GT_WRITE(0x100a08,0x7fff7fff); // gpc2 GT_WRITE(0x100a28,0x003d003d); // gpio2 GT_WRITE(0x101a00,0x00000000); // mrr GT_WRITE(0x101a10,0x00000000); // Rcrr GT_WRITE(0x101a20,0x00000000); // Tcrr GT_WRITE(0x102a00,0x00050001); // Brg0_bcr GT_WRITE(0x102a04,0x00000000); // Brg0_btr GT_WRITE(ETH_PHY_ADDR_REG, (PHY_ADD1 << 5) | PHY_ADD0); /* * PCI device initialization */ _pci_businit(1);}voidtgt_machreset(){ tgt_netreset();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -