📄 cmdline.cpp
字号:
/* * This file is part of Jelie, * (c) 2002 Julien Pilet <julien.pilet@epfl.ch> and * Stephane Magnenat <stephane.magnenat@epfl.ch> * * Jelie is free software; you can redistribute it * and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * Jelie is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Foobar; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//*! \file * \brief command line implementation * * This is the implementation of command line * for the pxa250 JTAG controller. * * \author Julien Pilet <julien.pilet@epfl.ch> * \author Stephane Magnenat <stephane.magnenat@epfl.ch> */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <ctype.h>#include <stdlib.h>#include <stdio.h>#include <sys/time.h>#include "cmdline.h"#include "jtagpxa250.h"#include "filemanager.h"#include "debug.h"#include <unistd.h>/////////////////////////////////////// Commands/////////////////////////////////////char *LoadICCmd::getDescr() { return "loadic <file> <address> [mini]\n" "Load the file given as parameter into the instruction cache\n" "If \"mini\" is not specified, code will be loaded in main IC.\n" "Example:\n\tloadic file.bin 0f0000 mini\n";}int LoadICCmd::exec(int argc, char *argv[]) { assert(pxa250Ptr); if (argc < 3) { printf(getDescr()); return 1; } unsigned int address; sscanf(argv[2], "%x", &address); FILE *f = fileManagerPtr->openFP(argv[1], "r"); if (!f) { perror(argv[1]); return 1; } else { bool mini = argc >= 4 && strcmp(argv[3], "mini")==0; unsigned int buffer[8*1024]; // 32kbyte buffer (8k instructions) int nbi = fread(buffer, 4, 8*1024, f); // read instructions printf("%d instructions read from file %s\n", nbi, argv[1]); printf("Ready to upload in the %s instruction cache, at address 0x%X\n", mini ? "mini" : "main", address); printf("First instruction: 0x%08X (lsB 0x%02X)\n", buffer[0], buffer[0]&0xFF);#ifdef WORDS_BIGENDIAN for (int i=0; i<nbi;i++) { unsigned char *cp= (unsigned char *) &buffer[i]; buffer[i] = JTAGpxa250::charArrayLEToInt(cp); }#endif if (mini & nbi > 512) { printf("WARNING: trying to load more than 512 instructions in the mini instruction cache!\n"); } pxa250Ptr->loadIC(mini, address, buffer, nbi); // wait for proc to be ready return 0; }}int CheckCmd::exec(int argc, char *argv[]) { assert(pxa250Ptr); if (pxa250Ptr->check()) { printf("Success\n"); return 0; } else { printf("Failure\n"); return 1; }}int InitCmd::exec(int argc, char *argv[]) { assert(pxa250Ptr); if (pxa250Ptr->init(argc, argv)) { printf("Success\n"); return 0; } else { printf("Failure\n"); return 1; }}int StopCmd::exec(int argc, char *argv[]) { assert(pxa250Ptr); pxa250Ptr->getReadyForUpload(); return 0;}int BootCmd::exec(int argc, char *argv[]) { assert(pxa250Ptr); pxa250Ptr->boot(); return 0;}int ResetCmd::exec(int argc, char *argv[]) { assert(pxa250Ptr); pxa250Ptr->jtag->jtagReset(); return 0;}int QuitCmd::exec(int argc, char *argv[]) { printf("quitting.\n"); return -1;}int HelpCmd::exec(int argc, char *argv[]) { if (argc > 1) { // look for the command whose name is passed as argument std::vector<Command *>::iterator it; for (it = cmds.begin(); it != cmds.end(); ++it) { if (strcmp(argv[1], (*it)->getName()) == 0) { printf("%s:\n%s\n", argv[1], (*it)->getDescr()); return 0; } } printf("%s: command not found.\n", argv[1]); return 1; } else { // list all commands std::vector<Command *>::iterator it; for (it = cmds.begin(); it != cmds.end(); ++it) { printf("%20s - %s\n", (*it)->getName(), (*it)->getBrief()); } return 0; }}long long GetTick(){ struct timeval now; gettimeofday(&now, NULL); return (now.tv_sec)*1000+(now.tv_usec)/1000;}int LoadCmd::exec(int argc, char *argv[]){ assert(pxa250Ptr); unsigned int address; unsigned int fileSize; unsigned int fileSizeAligned; unsigned int *data; bool halfword = false; if (argc < 2) { printf(getDescr()); return 1; } else if (argc == 2) { address = 0xa0000000; } else { sscanf(argv[2], "%x", &address); if (argc>= 4 && argv[3][0] == 'h') halfword = true; } FILE *fp=fileManagerPtr->openFP(argv[1], "r"); if (fp) { // get file length fseek(fp, 0, SEEK_END); fileSize=ftell(fp); fileSizeAligned = (fileSize&0x3) ? ((fileSize&(~0x3))+4) : fileSize; fseek(fp, 0, SEEK_SET); if (halfword) { fileSizeAligned*=2; } // allocate array data = (unsigned int *)malloc(fileSizeAligned); // read data if (halfword) { for (unsigned int i=0; i<fileSizeAligned; i++) { unsigned short s; fread(&s, 2, 1, fp); data[i] = s; } } else { fread(data, 1, fileSize, fp); } fclose(fp); // put data into memory long long startTick=GetTick(); printf("Sending %d words into the device's memory... ", fileSizeAligned / 4); fflush(stdout); pxa250Ptr->putData(address, fileSizeAligned / 4, data); float duration= ((float)GetTick()-startTick)/1000.0f; printf("done in %.3f s (%.3f KByte/s)\n", duration, fileSizeAligned/(duration*1000.0f)); /* Verification phase, skipped // get data from memory printf("Verifying %d bytes from the device's memory", fileSize); fflush(stdout); pxa250Ptr->getData(address, fileSize, data); printf("done\n"); */ free(data); return 0; } else return 1;}int PutCmd::exec(int argc, char *argv[]){ assert(pxa250Ptr); if (argc < 3) { printf(getDescr()); return 1; } bool halfword = false; if ((argc >= 4) && (argv[3][0]=='h')) halfword = true; unsigned int address, value; sscanf(argv[1], "%x", &address); sscanf(argv[2], "%x", &value); pxa250Ptr->putData(address, 1, &value, halfword); return 0;}int EraseFlashCmd::exec(int argc, char *argv[]){ assert(pxa250Ptr); bool fullErase = false; // chip erase if (argc == 1) fullErase = true; // erase command pxa250Ptr->putData(0x555 * 2, 0xaa, true); pxa250Ptr->putData(0x2aa * 2, 0x55, true); pxa250Ptr->putData(0x555 * 2, 0x80, true); pxa250Ptr->putData(0x555 * 2, 0xaa, true); pxa250Ptr->putData(0x2aa * 2, 0x55, true); // sector by sector or full unsigned int address, data; if (fullErase) { // full chip erase command address = 0x555 * 2; // we prepare address for the DQ7 polling next in the program pxa250Ptr->putData(0x555 * 2, 0x10, true); } else { // get address unsigned int i; for (i=1; i<(unsigned)argc; i++) { sscanf(argv[i], "%x", &address); // wait for DQ3 == 0 do { pxa250Ptr->getData(address, 1, &data); } while ((data&(1<<3)) != 0); // erase sector pxa250Ptr->putData(address, 0x30, true); } } // wait for DQ7 == 1 do { pxa250Ptr->getData(address, 1, &data); } while ((data&(1<<7)) == 0); return 0;}ProgramFlashCmd::ProgramFlashCmd(CmdLine &cmdLine) : cmdLine(cmdLine){}/*! Program the flash by uploading the program "flash.bin". The data to flash * is sent to SDRAM, and it's the PXA itself that take care of programming. * * The remote call is done in the script named "enp.lnj", which stands for: * erase and program linked jelie script. */int ProgramFlashCmd::exec(int argc, char *argv []){ assert(pxa250Ptr); unsigned int address, i; unsigned int fileSize; unsigned int fileSizeAligned; unsigned short *data; if (argc < 2) { printf(getDescr()); return 1; } else if (argc == 2) { address = 0x00000000; } else { sscanf(argv[2], "%x", &address); } // check flash id, before continuing pxa250Ptr->putData(0x555 * 2, 0xaa, true); pxa250Ptr->putData(0x2aa * 2, 0x55, true); pxa250Ptr->putData(0x555 * 2, 0x90, true); unsigned flashid=0; pxa250Ptr->getData(0, 1, &flashid); if (flashid != 0x225b0052) { printf("The flash is not AS29LV800B. Sorry.\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -