OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [zipload.cpp] - Diff between revs 45 and 52

Show entire file | Details | Blame | View Log

Rev 45 Rev 52
Line 77... Line 77...
                0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff,
                //
                //
                0xaa, 0x99, 0x55, 0x66 };
                0xaa, 0x99, 0x55, 0x66 };
        unsigned char   buf[SEARCHLN];
        unsigned char   buf[SEARCHLN];
 
        size_t  nr;
 
 
        rewind(fp);
        rewind(fp);
        fread(buf, sizeof(char), SEARCHLN, fp);
        nr = fread(buf, sizeof(char), SEARCHLN, fp);
 
        if (nr != SEARCHLN) {
 
                fprintf(stderr, "Cannot read the Xilinx bitfile header\n");
 
                perror("O/S Err:");
 
                exit(EXIT_FAILURE);
 
        }
        for(int start=0; start+MATCHLN<SEARCHLN; start++) {
        for(int start=0; start+MATCHLN<SEARCHLN; start++) {
                int     mloc;
                int     mloc;
 
 
                // Search backwards, since the starting bytes just aren't that
                // Search backwards, since the starting bytes just aren't that
                // interesting.
                // interesting.
                for(mloc = MATCHLN-1; mloc >= 0; mloc--)
                for(mloc = MATCHLN-1; mloc >= 0; mloc--)
                        if (buf[start+mloc] != matchstr[mloc])
                        if (buf[start+mloc] != matchstr[mloc])
                                break;
                                break;
                if (mloc < 0) {
                if (mloc < 0) {
                        fseek(fp, start, SEEK_SET);
                        if (fseek(fp, (long)start, SEEK_SET) != 0) {
                        return;
                                fprintf(stderr, "Cannot seek to the end of the Xilinx header\n");
 
                                perror("O/S Err:");
 
                                exit(EXIT_FAILURE);
 
                        } return;
                }
                }
        }
        }
 
 
        fprintf(stderr, "Could not find bin-file header within bit file\n");
        fprintf(stderr, "Could not find bin-file header within bit file\n");
        fclose(fp);
        fclose(fp);
Line 102... Line 111...
}
}
 
 
int main(int argc, char **argv) {
int main(int argc, char **argv) {
        int             skp=0, argn;
        int             skp=0, argn;
        bool            debug_only = false, verbose = false;
        bool            debug_only = false, verbose = false;
        bool            ignore_missing_memory = false;
        bool            ignore_missing_memory = true;
        unsigned        entry = 0;
        unsigned        entry = 0;
        FLASHDRVR       *flash = NULL;
        FLASHDRVR       *flash = NULL;
        const char      *bitfile = NULL, *altbitfile = NULL, *execfile = NULL;
        const char      *bitfile = NULL, *altbitfile = NULL, *execfile = NULL;
        size_t          bitsz;
        size_t          bitsz;
        FILE            *fp;
        FILE            *fp;
Line 144... Line 153...
                }
                }
        } argc -= skp;
        } argc -= skp;
 
 
 
 
        for(argn=0; argn<argc; argn++) {
        for(argn=0; argn<argc; argn++) {
                if (iself(argv[argn])) {
                if (access(argv[argn], R_OK)!=0) {
 
                        printf("ERR: Cannot open %s\n", argv[argn]);
 
                        usage();
 
                        exit(EXIT_FAILURE);
 
                } else if (iself(argv[argn])) {
                        if (execfile) {
                        if (execfile) {
                                printf("Too many executable files given, %s and %s\n", execfile, argv[argn]);
                                printf("Too many executable files given, %s and %s\n", execfile, argv[argn]);
                                usage();
                                usage();
                                exit(EXIT_FAILURE);
                                exit(EXIT_FAILURE);
                        } execfile = argv[argn];
                        } execfile = argv[argn];
Line 184... Line 197...
        }
        }
 
 
        if ((bitfile)&&(access(bitfile,R_OK)!=0)) {
        if ((bitfile)&&(access(bitfile,R_OK)!=0)) {
                // If there's no code file, or the code file cannot be opened
                // If there's no code file, or the code file cannot be opened
                fprintf(stderr, "Cannot open bitfile, %s\n", bitfile);
                fprintf(stderr, "Cannot open bitfile, %s\n", bitfile);
 
                if (iself(bitfile))
 
                        fprintf(stderr, "Is %s an ELF executable??\n", bitfile);
                exit(EXIT_FAILURE);
                exit(EXIT_FAILURE);
        }
        }
 
 
        if ((altbitfile)&&(access(altbitfile,R_OK)!=0)) {
        if ((altbitfile)&&(access(altbitfile,R_OK)!=0)) {
                // If there's no code file, or the code file cannot be opened
                // If there's no code file, or the code file cannot be opened
Line 196... Line 211...
        } if ((execfile)&&(access(execfile,R_OK)!=0)) {
        } if ((execfile)&&(access(execfile,R_OK)!=0)) {
                // If there's no code file, or the code file cannot be opened
                // If there's no code file, or the code file cannot be opened
                fprintf(stderr, "Cannot open executable, %s\n\n", execfile);
                fprintf(stderr, "Cannot open executable, %s\n\n", execfile);
                usage();
                usage();
                exit(EXIT_FAILURE);
                exit(EXIT_FAILURE);
        } else if (!iself(execfile)) {
        } else if ((execfile)&&(!iself(execfile))) {
                printf("%s is not an executable file\n\n", execfile);
                printf("%s is not an executable file\n\n", execfile);
                usage();
                usage();
                exit(EXIT_FAILURE);
                exit(EXIT_FAILURE);
        }
        }
 
 
Line 233... Line 248...
 
 
        // First, see if we need to load a bit file
        // First, see if we need to load a bit file
        if (bitfile) {
        if (bitfile) {
 
 
                fp = fopen(bitfile, "r");
                fp = fopen(bitfile, "r");
                if (strcmp(&argv[argn][strlen(argv[argn])-4],".bit")==0)
                if (strcmp(&bitfile[strlen(bitfile)-4],".bit")==0)
                        skip_bitfile_header(fp);
                        skip_bitfile_header(fp);
                bitsz = fread(&fbuf[CONFIG_ADDRESS-SPIFLASH],
                bitsz = fread(&fbuf[CONFIG_ADDRESS-SPIFLASH],
                                sizeof(fbuf[0]),
                                sizeof(fbuf[0]),
                                FLASHLEN - (CONFIG_ADDRESS-SPIFLASH), fp);
                                FLASHLEN - (CONFIG_ADDRESS-SPIFLASH), fp);
                fclose(fp);
                fclose(fp);
Line 296... Line 311...
                        if ((secp->m_start >= RESET_ADDRESS)
                        if ((secp->m_start >= RESET_ADDRESS)
                                &&(secp->m_start+secp->m_len
                                &&(secp->m_start+secp->m_len
                                                <= SPIFLASH+FLASHLEN))
                                                <= SPIFLASH+FLASHLEN))
                                valid = true;
                                valid = true;
                        if (!valid) {
                        if (!valid) {
                                fprintf(stderr, "No such memory on board: 0x%08x - %08x\n",
                                if (ignore_missing_memory)
 
                                        fprintf(stderr, "WARNING: No such memory on board: 0x%08x - %08x\n",
 
                                                secp->m_start, secp->m_start+secp->m_len);
 
                                else {
 
                                        fprintf(stderr, "ERROR: No such memory on board: 0x%08x - %08x\n",
                                        secp->m_start, secp->m_start+secp->m_len);
                                        secp->m_start, secp->m_start+secp->m_len);
                                if (!ignore_missing_memory)
 
                                        exit(EXIT_FAILURE);
                                        exit(EXIT_FAILURE);
                        }
                        }
                }
                }
 
                }
 
 
                unsigned        startaddr = RESET_ADDRESS, codelen = 0;
                unsigned        startaddr = RESET_ADDRESS, codelen = 0;
                for(int i=0; secpp[i]->m_len; i++) {
                for(int i=0; secpp[i]->m_len; i++) {
                        secp = secpp[i];
                        secp = secpp[i];
 
 
Line 349... Line 368...
        } catch(BUSERR a) {
        } catch(BUSERR a) {
                fprintf(stderr, "S6-BUS error: %08x\n", a.addr);
                fprintf(stderr, "S6-BUS error: %08x\n", a.addr);
                exit(-2);
                exit(-2);
        }
        }
 
 
 
        if (flash) delete       flash;
        if (m_fpga) delete      m_fpga;
        if (m_fpga) delete      m_fpga;
 
 
        return EXIT_SUCCESS;
        return EXIT_SUCCESS;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.