3

设置:一个运行busybox-Linux的ARM-CPU (A9)。这个与网络对话并获得一个预编译的静态链接精灵。第二个 CPU 运行裸机应用程序。我在那个上有newlib,整个“操作系统”都在内存中,只是执行那个基本程序。两者共享强迫症。

我已经成功地让两个处理器“说话”了。我可以从 linux 将十六进制值写入内存,其他处理器读取它,反之亦然。现在我想解析上述精灵,将其发送到 OCM,让裸机将其读入内存,通过 asm 设置程序计数器并执行所述精灵(也可以使用 .o 文件)。我已经被困在解析精灵了......

#include <sys/types.h>                                                                                                                    
#include <sys/stat.h>                                                                                                                     
#include <fcntl.h>                                                                                                                        
#include <byteswap.h>                                                                                                                     
#include <unistd.h>                                                                                                                       
#include <stdlib.h>                                                                                                                       
#include <stdio.h>                                                                                                                        
#include <stdint.h>                                                                                                                       
#include <errno.h>                                                                                                                        
#include <sys/mman.h>                                                                                                                     

#define PAGE_SIZE ((size_t)getpagesize())                                                                                                 
#define PAGE_MASK ((uint64_t)(long)~(PAGE_SIZE - 1))                                                                                      

const unsigned int COMM_RX_DATA  = 0xFFFF900c;                                                                                            

int main(int argc, char **argv){                                                                                                          

    int     fd;                                                                                                                           
    int cached = 0;                                                                                                                       
    unsigned char* c;                                                                                                                     
    //uint32_t value;                                                                                                                     
    unsigned char value;                                                                                                                  
    uint64_t offset = COMM_RX_DATA;                                                                                                       
    uint64_t base;                                                                                                                        
    volatile uint8_t *mm;                                                                                                                 


    fprintf(stderr, "Nr. 0\n");                                                                                                           

    FILE* f_read;                                                                                                                         

    if ((argc != 1) && (argc != 2)) {                                                                                                     
        fprintf(stderr, "usage: %s  ELF_NAME\n", argv[0]);                                                                                
        return 1;                                                                                                                         
    }                                                                                                                                     

  fd = open("/dev/mem", O_RDWR);//|(!cached ? O_SYNC : 0));                                                                               
    if (fd < 0) {                                                                                                                         
        fprintf(stderr, "open(/dev/mem) failed (%d)\n", errno);                                                                           
        return 1;                                                                                                                         
    }                                                                                                                                     


    f_read = fopen(argv[1], "rb");                                                                                                        
    if(!f_read){                                                                                                                          
        fprintf(stderr, "read failed");                                                                                                   
        return 1;                                                                                                                         
    }                                                                                                                                     

    else {                                                                                                                                
        printf("Nr. 1\n");                                                                                                                
        base = offset & PAGE_MASK;                                                                                                        
        offset &= ~PAGE_MASK;                                                                                                             

        mm = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, base);                                                         

        fseek(f_read, 0, SEEK_END);                                                                                                       
        int size = ftell(f_read);                                                                                                         
        fseek(f_read, 0, SEEK_SET); //Reset stream                                                                                        
        c = malloc(size);                                                                                                                 
        //malloc error checking!                                                                                                          

        while (fgets(c, size, f_read) != NULL ){ //tried fgetc but segfaults                                                              
            //tmp-output to stdout                                                                                                        
            puts(c);                                                                                                                      
            value = c;//strtoull((char*)c, NULL, 0);                                                                                      
            printf("Writing %d to %d", (int)value, (int)(mm + offset));                                                                   
            *(volatile uint32_t *)(mm + offset) = value;                                                                                  
            printf("size: %d , value = %s\n", size, value);                                                                               
        }                                                                                                                                 

    }                                                                                                                                     
    munmap((void *)mm, PAGE_SIZE);                                                                                                        
    fclose(f_read);                                                                                                                       

    return 0;                                                                                                                             
}                                                                                            

_asm-idea.S:

ExecuteR0:
        mov  lr, r0 /* move the destination address into link register */

        mcr  15,0,r0,cr7,cr5,0      /* Invalidate Instruction cache */
        mcr  15,0,r0,cr7,cr5,6      /* Invalidate branch predictor array */

        dsb
        isb                 /* make sure it completes */

    ldr r4, =0
        mcr  15,0,r4,cr1,cr0,0      /* disable the ICache and MMU */

        isb                 /* make sure it completes */


        bx      lr  /* force the switch, destination should have been in r0 */

帮助我强大所以你是我唯一的希望。

4

0 回答 0