0

我想通过将代码添加到{u-boot_sources}/arch/arm/cpu/armv7/omap-common/hwinit-common.c. U-boot 应在 PandaBoard ES (omap4460 SoC) 上使用。

因此,首先我在我的 x86 电脑上成功实现了代码,并将其移植到基于 ARM 的 PandaBoard。完整的代码可以在这里找到(作为旁注,“main”函数是 s_init()):

http://pastebin.com/iaz13Yn9

但是,我预计会有几十个意想不到的效果,这会导致在代码执行期间停止、在读取 u-boot.img 后停止 u-boot 或根本不发送输出(因此不启动)。

例如,我想在一个-loop 中调用两个函数 ( computeSyndrome, ) ,它是另一个函数的一部分。decodeErrorsforgolayDecode

对于我的第一个问题,请忽略以/* >>>> These lines of code below totally break u-boot. 同样只有computeSyndrome与调用函数结合的函数golayDecode很重要。

问题:如果注释掉这两个功能computeSyndrome并且decodeErrors一切正常并且操作系统(Android)正在启动。但是,如果computeSyndrome未注释掉并因此得到处理,则 u-boot 在显示reading u-boot.img. 关于它的有趣之处在于:即使我computeSyndrome用一个不会迭代值或显示内容的虚假函数替换,u-boot 也会卡住。

此外,如果我删除下面的多行注释以还包含残留代码,则 u-boot 不会显示任何字符。(1*)

我是微处理器编程的初学者,但我根本无法弄清楚这 12 行 computeSyndrome 函数或 u-boot 的一般行为中可能存在的错误。(2*)

有人知道我错过了什么吗?

谢谢,P。

1* 我正在使用 minicom 显示 u-boot 的输出,我通过串行 USB 转换器接收到该输出。
2* 我使用以下编译器标志来确保编译时没有错误:-Wall -Wstrict-prototypes -Wdisabled-optimization -W -pedantic

void golayDecode(volatile int x[12], volatile int y[12], volatile unsigned int golayEncodedSecret[30], volatile unsigned int s, volatile unsigned char repetitionDecodedSecretBits[360]){

printf("\n[I] - Performing Golay decoding\r\n");
volatile unsigned char secret[22] = {0};
volatile unsigned char currentByte = 0, tmpByte = 0;
volatile unsigned int golayDecodedSecret[30] ={0};
volatile int twelveBitCounter = 0;//, j = 0, k = 0, q = 0, aux = 0, found = 0, bitCounter = 0, i_2 = 7, currentSecretEncByte = 0x00;
volatile int c_hat[2] = {0}, e[2] = {0};
e[0] = s;
e[1] = 0;

for(twelveBitCounter = 0; twelveBitCounter < 30; twelveBitCounter+=2){
    printf("Computing syndrome and decoding errors for bytes %03x & %03x\n", golayEncodedSecret[twelveBitCounter], golayEncodedSecret[twelveBitCounter+1]);
      computeSyndrome(golayEncodedSecret[twelveBitCounter], golayEncodedSecret[twelveBitCounter+1], x, y, s);
      decodeErrors(golayEncodedSecret[i], golayEncodedSecret[i+1], x, y, s);
}

printf("\n[D] - Reconstructing secret bytes\r\n");


/*        >>>> These lines of code below totally break u-boot
for(i = 0; i < 30; i+=2){
    currentSecretEncByte = golayDecodedSecret[i];
    volatile int j = 11;

    // Access each source bit       
    for(; 0<=j; j--){           
        volatile int currentSourceBit = (currentSecretEncByte >> j) & 0x01; 

        repetitionDecodedSecretBits[bitCounter] = currentSourceBit;
        bitCounter++;
    }
}

k = 0;
for(i = 0; i<176; i++){
    tmpByte =  repetitionDecodedSecretBits[i] << i_2;
    currentByte = currentByte | tmpByte;
    i_2--;
    if(i_2==0){ // We collected 8 bits and created a byte
        secret[k] = currentByte;
        i_2 = 7;
        tmpByte = 0x00;
        currentByte = 0x00;
        k++;
    }       
}

SHA256_CTX ctx;
unsigned char hash[32];

printf("\n[I] - Generating secret key K\n");
sha256_init(&ctx);
sha256_update(&ctx,secret,strlen((const char*)secret));
sha256_final(&ctx,hash);

printf("\n[I] - This is our secret key K\n\t==================================\n\t");
print_hash(hash);
printf("\t==================================\n");
*/
}


/* Function for syndrome computation */
void computeSyndrome(int r0, int r1, volatile int x[12], volatile int y[12], volatile unsigned int s){
unsigned int syndromeBitCounter, syndromeMatrixCounter, syndromeAux;

s = 0;
for(syndromeMatrixCounter=0; syndromeMatrixCounter<12; syndromeMatrixCounter++){
    syndromeAux = 0;

    for(syndromeBitCounter=0; syndromeBitCounter<12; syndromeBitCounter++){
        syndromeAux = syndromeAux^((x[syndromeMatrixCounter]&r0)>>syndromeBitCounter &0x01);
    }
    for(syndromeBitCounter=0; syndromeBitCounter<12; syndromeBitCounter++){
        syndromeAux = syndromeAux^((y[syndromeMatrixCounter]&r1)>>syndromeBitCounter &0x01);
    }
    s = (s<<1)^syndromeAux;

}
}



/* Funcion to recover original byte */
void decodeErrors(int r0, int r1, volatile int x[12], volatile int y[12], volatile unsigned int s){
//printf("\n[D] - Starting to decode errors for %3x | %3x\n", r0, r1);
volatile unsigned int c_hat[2] = {0xaa}, e[2] = {0xaa};
volatile unsigned int q;
unsigned int i, j, aux, found;

//printf("Step 2\n");
if(weight(s)<=3){
    e[0] = s;
    e[1] = 0;
}else{
    /******* STEP 3 */
    //printf("Step 3\n");
    i = 0;
    found = 0;
    do{
        if (weight(s^y[i]) <=2){
                e[0] = s^y[i];
                e[1] = x[i];
                found = 1;
            printf("\ntest 2\n");
        }
        i++;
        }while ((i<12) && (!found));

        if (( i==12 ) && (!found)){
         /******* STEP 4 */
        //printf("Step 4\n");
        q = 0;
        for (j=0; j<12; j++){
                aux = 0;
                for (i=0; i<12; i++)
                aux = aux ^ ( (y[j]&s)>>i & 0x01 ); 
                q = (q<<1) ^ aux;
            }

        /******* STEP 5 */
        //printf("Step 5\n");
        if (weight(q) <=3){
                e[0] = 0;
                e[1] = q;
            }else{
                /******* STEP 6 */
                //printf("Step 6\n");
                i = 0;
                found = 0;
                do{
                if (weight(q^y[i]) <=2){
                        e[0] = x[i];
                        e[1] = q^y[i];
                        found = 1;
                }
                i++;
            }while((i<12) && (!found));

                if ((i==12) && (!found)){
                /******* STEP 7 */
                printf("\n[E] - uncorrectable error pattern! (%3x | %3x)\n", r0, r1);
                /* You can raise a flag here, or output the vector as is */
                //exit(1);
            }
        }
    }
}

c_hat[0] = r0^e[0];
c_hat[1] = r1^e[1];
//printf("\t\tEstimated codeword = %x%x\n", c_hat[0], c_hat[1]);
}
4

1 回答 1

0

事实上,代码有点过于复杂,无法在启动时执行。此时没有真正的 CRT,我只有一个最小的堆栈。因此,我将仍然是 SPL 一部分的
代码移至其中。board_init_f()它给出了更稳定的结果,我的算法现在可以按预期工作。

于 2013-09-06T08:00:46.037 回答