phelum Posted April 30, 2016 Posted April 30, 2016 Hi, Recently I've made a custom kernel for an Olimex Lime board. The NAND driver refused to load and reported "kernel divide by zero". I believe the problem is in drivers/block/sunxi-nand/nfd/nand_block.c in function get_cmu_clk. The function (with my patch line) is: __u32 get_cmu_clk(void) { __u32 reg_val; __u32 div_p, factor_n; __u32 factor_k, factor_m; __u32 clock; reg_val = *(volatile unsigned int *)(0xf1c20000 + 0x20); div_p = (reg_val >> 16) & 0x3; factor_n = (reg_val >> 8) & 0x1f; factor_k = ((reg_val >> 4) & 0x3) + 1; factor_m = ((reg_val >> 0) & 0x3) + 1; div_p = 1 << ((reg_val >> 16) & 0x3)); // SJS 2016-04-30 clock = 24 * factor_n * factor_k/div_p/factor_m; return clock; } The problem occurs on my Lime board because Pll5.FactorP (div_p above) is zero. Other A20 boards have 1 here and I haven't figured why the Lime board is different. The A20 manual states FactorP is a two-bit field that can be 1/2/4/8. This means the value stored here is a power of two rather than a plain divisor. So I added the patch line to calculate the correct divisor. Any opinions or comments please ? The lt;< above is because HTML choke on less-than signs. Update: Testing on other boards shows that NAND access only works when div_p is set to 1. Maybe it should be dropped from the equation. Cheers, Steven
tkaiser Posted April 30, 2016 Posted April 30, 2016 Sorry, I didn't look into it at all but just to be sure: Are you using legacy or vanilla/mainline kernel?
phelum Posted April 30, 2016 Author Posted April 30, 2016 I'm using the legacy kernel. Is there a suitable NAND driver in the mainline kernel now ? The bug only afects my Lime board. All other A10/A20 boards I've checked work fine. But on the Lime I was getting "kernel divide by zero" when installing the sunxi_nand module. The odd thing about the Lime boards is that it has 0xB1049491 in the CCU PL5 register whereas other boards have 0xB1059491 or 0xB1059291. Update: I've just found a patch at https://github.com/linux-sunxi/linux-sunxi/blob/sunxi-3.4/drivers/block/sunxi_nand/nfd/nand_blk.cthat fixes the problem. I don't think this patch is in the Armbian 3.4.106 kernel but it might be in the later patches. My bug report here is old news. Cheers, Steven
Igor Posted May 1, 2016 Posted May 1, 2016 Update: I've just found a patch at https://github.com/l.../nfd/nand_blk.cthat fixes the problem. I don't think this patch is in the Armbian 3.4.106 kernel but it might be in the later patches. My bug report here is old news. We are using this repository (linux-sunxi) for some time, precisely from 1.9.2015 / 3.4.108, when we added A10 builds.
phelum Posted May 1, 2016 Author Posted May 1, 2016 Hi Igor, Thanks for the reply. Is there a repository for your current kernel or do I need to download the linux-sunxi one and apply your patch files ? I'm tempted to drop my modified kernel and start again with yours. Cheers, Steven
Igor Posted May 1, 2016 Posted May 1, 2016 No, I am using default linux-sunxi kernel source and all what's in here (and not .disabled): https://github.com/igorpecovnik/lib/tree/master/patch/kernel/sun7i-default Perhaps some file renaming would help for better overview. Once
Recommended Posts