[Galaxy Note II Original Android Development] Phil3759:
Hi pongster.

I reviewed the source you linked me, at AndreiLux github.

This is the last sensor hub commit he made:

https://github.com/AndreiLux/Perseus-S3/commit/bac17df1a0dd18dcab03a9ae2049ff1b6cf55dbb

Look especially at these parts:

drivers/sensor/ak8963.c

if (retry_count < 5) {
retry_count++;
pr_warn("############################################");
pr_warn("%s, retry_count=%d\n", __func__, retry_count);
pr_warn("############################################");
goto retry;
} else {

Basically, he added a trial routine to be repeated 5 times, and on each repeat count a goto loop. The retry loop restarts much above in the code

retry:

#ifdef FACTORY_TESTstatic int ak8963c_selftest(struct akm8963_data *ak_data, int *sf){
.
.
.
retry:
/* read device info */
i2c_smbus_read_i2c_block_data(ak_data->this_client,
AK8963_REG_WIA, 2, buf);
pr_info("%s: device id = 0x%x, info = 0x%x\n",
__func__, buf[0], buf[1]);

/* set ATSC self test bit to 1 */
i2c_smbus_write_byte_data(ak_data->this_client,
AK8963_REG_ASTC, 0x40);

/* start self test */
i2c_smbus_write_byte_data(ak_data->this_client,
AK8963_REG_CNTL1,
AK8963_CNTL1_SELF_TEST);

/* wait for data ready */
while (1) {
msleep(20);
if (i2c_smbus_read_byte_data(ak_data->this_client,
AK8963_REG_ST1) == 1) {
break;
}
}

i2c_smbus_read_i2c_block_data(ak_data->this_client,
AK8963_REG_HXL, sizeof(buf), buf);

/* set ATSC self test bit to 0 */
i2c_smbus_write_byte_data(ak_data->this_client,
AK8963_REG_ASTC, 0x00);

x = buf[0] | (buf[1] << 8);
y = buf[2] | (buf[3] << 8);
z = buf[4] | (buf[5] << 8);

/* Hadj = (H*(Asa+128))/256 */
x = (x*(ak_data->asa[0] + 128)) >> 8;
y = (y*(ak_data->asa[1] + 128)) >> 8;
z = (z*(ak_data->asa[2] + 128)) >> 8;

pr_info("%s: self test x = %d, y = %d, z = %d\n",
__func__, x, y, z);
if ((x >= -200) && (x <= 200))
pr_info("%s: x passed self test, expect -200<=x<=200\n",
__func__);
else
pr_info("%s: x failed self test, expect -200<=x<=200\n",
__func__);
if ((y >= -200) && (y <= 200))
pr_info("%s: y passed self test, expect -200<=y<=200\n",
__func__);
else
pr_info("%s: y failed self test, expect -200<=y<=200\n",
__func__);
if ((z >= -3200) && (z <= -800))
pr_info("%s: z passed self test, expect -3200<=z<=-800\n",
__func__);
else
pr_info("%s: z failed self test, expect -3200<=z<=-800\n",
__func__);

sf[0] = x;
sf[1] = y;
sf[2] = z;

if (((x >= -200) && (x <= 200)) &&
((y >= -200) && (y <= 200)) &&
((z >= -3200) && (z <= -800))) {
pr_info("%s, Selftest is successful.\n", __func__);
return 1;
} else {
if (retry_count < 5) {
retry_count++;
pr_warn("############################################");
pr_warn("%s, retry_count=%d\n", __func__, retry_count);
pr_warn("############################################");
goto retry;
}

Basically, that code will make it repeat the self test in a loop usinga very time consuming way, the goto statement instead of a for loop

Also, later in the commit, you see same other changes.

I took a look to your sources and you use the same code patch. I am not a kernel code expert, but seems to me a very bad coding approach that would explain the issues with recovery in that case

Basically, it goes in a time expensive loop while self testing. It explains why the recovery based on such kernels takes a lot of time tostart.

Again I am not a kernel coder, I mainly focused on cwm, so not used tokernel sources, but the issue could be related to that part.

My recoveries are based on a stock kernel and while started from a stock ROM kernel, they cause no issues on that self test routine, if it is really the cause of the issue as you suggested.

Your kernel is clearly based on that source code from your github though...

Is it because you have a bundled recovery that your kernel will trigger when booting to recovery? I am not used to the devices with a recovery.img partition, so not sure.

At this point, I do not see what I can do on my side, but maybe you could look at your code to make it compatible with stock kernels, if it is even possible. Looking at that loop part could be a start point