我想通過在{u-boot_sources}/arch/arm/cpu/armv7/omap-common/hwinit-common.c
中添加代碼,用一些模糊提取器邏輯來擴展u-boot SPL代碼。 U-boot應該用在PandaBoard ES(omap4460 SoC)上。U-Boot:移植代碼時出現意外問題
因此,首先我成功地在我的x86電腦上實現了代碼,並將其移植到基於ARM的PandaBoard上。完整的代碼可以在這裏找到(作爲一個側面說明了「主要」功能s_init()):
不過,我期待幾十unexptected影響,導致無論是在執行過程中停止的代碼,在閱讀完u-boot.img之後停止u-boot,或者根本不發送輸出(因此不啓動)。
例如,我想調用一個for
-loop,這是另一種功能golayDecode
的一部分內兩個函數(computeSyndrome
,decodeErrors
)。
對於我的第一個問題,請忽略以/* >>>> These lines of code below totally break u-boot
開頭的多行註釋下面的代碼。此外,只有功能computeSyndrome
與呼叫功能golayDecode
一起很重要。
問題:如果註釋掉功能computeSyndrome
和decodeErrors
一切正常,OS(Android)正在引導。但是,如果computeSyndrome
未被註釋掉並因此被處理,則在顯示reading u-boot.img
後,u-boot會出現問題。 有趣的是:即使我用一個假的函數代替computeSyndrome
,這個函數不是重複一個值或顯示的東西,而是u-boot函數。
此外,如果我刪除下面的多行註釋以包含殘留代碼,則u-boot不會顯示ony字符。 (1 *)
我是一名初學者,關於微處理器編程,但我無法弄清computeSyndrome函數的這12行中的一個可能的錯誤或u-boot的一般行爲。 (2 *)
有沒有人有線索我失蹤?
感謝, P.
1 *我使用小型機來顯示的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]);
}
您的新代碼不屬於'hwinit-common.c'(因爲這是CPU代碼),不應該在CPU初始化的早期執行。 U-Boot的主要功能(像其他任何引導加載程序一樣)是初始化最少量的硬件,加載目標程序並執行它。你應該爲你的代碼創建一個新的源文件,可能在熊貓板目錄中。然後嘗試執行代碼作爲「遲(板)初始化」階段的一部分。 – sawdust