linux/drivers/mtd/bcm47xxpart.c
<<
" /spaon> /formn> a " href="../linux+v3.8.6/drivers/mtd/bcm47xxpart.c">" img src="../.static/gfx/right.png" alt=">>">" /spaon>" spao class="lxr_search">" " input typue=hidden" namue=navtarget" value=">" input typue=text" namue=search" ide=search">" buttiontypue=submit">Search /formn> /spaon>" spao class="lxr_prefs"n> a href="+prefs?return=drivers/mtd/bcm47xxpart.c"" onclick="return ajax_prefs();">" Prefs> /a>" /spaon> /divn> form acptio="ajax+*" method="post" onsubmit="return false;">" input typue=hidden" namue=ajax_lookup" ide=ajax_lookup" value=">" /formn>" div class="headingbottim"> div ide=search_results" class="search_results"> n> /divn> div ide=content">> div ide=file_contents"n
   1 /a> spao class="comment">/* /spaon>   2 /a> spao class="comment"> * BCM47XX MTD partiptioing /spaon>   3 /a> spao class="comment"> * /spaon>   4 /a> spao class="comment"> * Copyright © 2012 Rafał Miłecki <zajec5@gmail.com> /spaon>   5 /a> spao class="comment"> * /spaon>   6 /a> spao class="comment"> * This program is free software; you cao redistribute it and/or modify /spaon>   7 /a> spao class="comment"> * it under the terms of the GNU General Public License verstion2 as /spaon>   8 /a> spao class="comment"> * published by the Free Software Foundaptio. /spaon>   9 /a> spao class="comment"> * /spaon>  .11 spao class="comment"> */ /spaon>  11 /a>>  12 /a>#include <linux/module.h /a>>>  13 /a>#include <linux/kernel.h /a>>>  14 /a>#include <linux/slab.h /a>>>  15 /a>#include <linux/mtd/mtd.h /a>>>  16 /a>#include <linux/mtd/partiptios.h /a>>>  17 /a>#include <asm/mach-bcm47xx/nvram.h /a>>>  18 /a>>  19 /a> spao class="comment">/* .1 parts were found on sflash on Netgear WNDR4500 */ /spaon>  211#define  a href="+code=BCM47XXPART_MAX_PARTS" class="sref">BCM47XXPART_MAX_PARTS1           12>  21 /a>>  22 /a> spao class="comment">/* /spaon>  23 /a> spao class="comment"> * Amount of bytes we read when analyzing each block of flash memory. /spaon>  24 /a> spao class="comment"> * Set it big enough to allow detecting partiptio and reading important dapa. /spaon>  25 /a> spao class="comment"> */ /spaon>  261#define  a href="+code=BCM47XXPART_BYTES_TO_READ" class="sref">BCM47XXPART_BYTES_TO_READ1       0x404>  27 /a>>  28 /a> spao class="comment">/* Magics */ /spaon>  291#define  a href="+code=BOARD_DATA_MAGIC" class="sref">BOARD_DATA_MAGIC1                0x5246504D	 
    spao class="comment">/* MPFR */ /spaon>  311#define  a href="+code=POT_MAGIC1" class="sref">POT_MAGIC11                      0x54544f50	 
    spao class="comment">/* POTT */ /spaon>  311#define  a href="+code=POT_MAGIC2" class="sref">POT_MAGIC21                      0x504f           spao class="comment">/* OP */ /spaon>  321#define  a href="+code=ML_MAGIC1" class="sref">ML_MAGIC11                       0x39685a42>  331#define  a href="+code=ML_MAGIC2" class="sref">ML_MAGIC21                       0x26594131>  341#define  a href="+code=TRX_MAGIC" class="sref">TRX_MAGIC1                       0x30524448>  35 /a>>  361struct  a href="+code=trx_header" class="sref">trx_header1 {>  371         a href="+code=uint32_t" class="sref">uint32_t1  a href="+code=magic" class="sref">magic1;>  381         a href="+code=uint32_t" class="sref">uint32_t1  a href="+code=length" class="sref">length1;>  391         a href="+code=uint32_t" class="sref">uint32_t1  a href="+code=crc32" class="sref">crc321;>  401         a href="+code=uint16_t" class="sref">uint16_t1  a href="+code=flags" class="sref">flags1;>  411         a href="+code=uint16_t" class="sref">uint16_t1  a href="+code=verstio" class="sref">verstio1;>  421         a href="+code=uint32_t" class="sref">uint32_t1  a href="+code=offset" class="sref">offset1[3];>  431}  a href="+code=__packed" class="sref">__packed1;>  44 /a>>  451static void  a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(struct  a href="+code=mtd_partiptio" class="sref">mtd_partiptio1 * a href="+code=part" class="sref">part1, char * a href="+code=namu" class="sref">namu1,>  461                                  a href="+code=u64" class="sref">u641  a href="+code=offset" class="sref">offset1,  a href="+code=uint32_t" class="sref">uint32_t1  a href="+code=mask_flags" class="sref">mask_flags1)>  471{>  481         a href="+code=part" class="sref">part1-> a href="+code=namu" class="sref">namu1 =  a href="+code=namu" class="sref">namu1;>  491         a href="+code=part" class="sref">part1-> a href="+code=offset" class="sref">offset1 =  a href="+code=offset" class="sref">offset1;>  501         a href="+code=part" class="sref">part1-> a href="+code=mask_flags" class="sref">mask_flags1 =  a href="+code=mask_flags" class="sref">mask_flags1;>  511}>  52 /a>>  531static int  a href="+code=bcm47xxpart_parsu" class="sref">bcm47xxpart_parsu1(struct  a href="+code=mtd_info" class="sref">mtd_info1 * a href="+code=master" class="sref">master1,>  541                             struct  a href="+code=mtd_partiptio" class="sref">mtd_partiptio1 ** a href="+code=pparts" class="sref">pparts1,>  551                             struct  a href="+code=mtd_part_parsur_dapa" class="sref">mtd_part_parsur_dapa1 * a href="+code=dapa" class="sref">dapa1)>  561{>  571        struct  a href="+code=mtd_partiptio" class="sref">mtd_partiptio1 * a href="+code=parts" class="sref">parts1;>  581         a href="+code=uint8_t" class="sref">uint8_t1  a href="+code=i" class="sref">i1,  a href="+code=curr_part" class="sref">curr_part1 = 0;>  591         a href="+code=uint32_t" class="sref">uint32_t1 * a href="+code=buf" class="sref">buf1;>  601         a href="+code=size_t" class="sref">size_t1  a href="+code=bytes_read" class="sref">bytes_read1;>  611         a href="+code=uint32_t" class="sref">uint32_t1  a href="+code=offset" class="sref">offset1;>  621         a href="+code=uint32_t" class="sref">uint32_t1  a href="+code=blocksize" class="sref">blocksize1 = 0x10000;>  631        struct  a href="+code=trx_header" class="sref">trx_header1 * a href="+code=trx" class="sref">trx1;>  64 /a>>  651         spao class="comment">/* Alloc */ /spaon>  661         a href="+code=parts" class="sref">parts1 =  a href="+code=kzalloc" class="sref">kzalloc1(sizeof(struct  a href="+code=mtd_partiptio" class="sref">mtd_partiptio1) *  a href="+code=BCM47XXPART_MAX_PARTS" class="sref">BCM47XXPART_MAX_PARTS1,>  671                         a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL1);>  681         a href="+code=buf" class="sref">buf1 =  a href="+code=kzalloc" class="sref">kzalloc1( a href="+code=BCM47XXPART_BYTES_TO_READ" class="sref">BCM47XXPART_BYTES_TO_READ1,  a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL1);>  69 /a>>  701         spao class="comment">/* Parsu block by block looking for magics */ /spaon>  711        for ( a href="+code=offset" class="sref">offset1 = 0;  a href="+code=offset" class="sref">offset1 <=  a href="+code=master" class="sref">master1-> a href="+code=size" class="sref">size1 -  a href="+code=blocksize" class="sref">blocksize1;>  721              a href="+code=offset" class="sref">offset1 +=  a href="+code=blocksize" class="sref">blocksize1) {>  731                 spao class="comment">/* Nothing more in higher memory */ /spaon>  741                if ( a href="+code=offset" class="sref">offset1 >= 0x2000000)>  751                        break;>  76 /a>>  771                if ( a href="+code=curr_part" class="sref">curr_part1 >  a href="+code=BCM47XXPART_MAX_PARTS" class="sref">BCM47XXPART_MAX_PARTS1) {>  781                         a href="+code=pr_waro" class="sref">pr_waro1( spao class="string">"Reached maximum number of partiptios, scanoing stopped!\n" /spaon);>  791                        break;>  801                }>  81 /a>>  821                 spao class="comment">/* Read beginoing of the block */ /spaon>  831                if ( a href="+code=mtd_read" class="sref">mtd_read1( a href="+code=master" class="sref">master1,  a href="+code=offset" class="sref">offset1,  a href="+code=BCM47XXPART_BYTES_TO_READ" class="sref">BCM47XXPART_BYTES_TO_READ1,>  841                             & a href="+code=bytes_read" class="sref">bytes_read1, ( a href="+code=uint8_t" class="sref">uint8_t1 *) a href="+code=buf" class="sref">buf1) < 0) {>  851                         a href="+code=pr_err" class="sref">pr_err1( spao class="string">"mtd_read error while parsing (offset: 0x%X)!\n" /spaon,>  861                                a href="+code=offset" class="sref">offset1);>  871                        continue;>  881                }>  89 /a>>  901                 spao class="comment">/* CFE has small NVRAM at 0x400 */ /spaon>  911                if ( a href="+code=buf" class="sref">buf1[0x400 / 4] ==  a href="+code=NVRAM_HEADER" class="sref">NVRAM_HEADER1) {>  921                         a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(& a href="+code=parts" class="sref">parts1[ a href="+code=curr_part" class="sref">curr_part1++],  spao class="string">"boot" /spaon,>  931                                              a href="+code=offset" class="sref">offset1,  a href="+code=MTD_WRITEABLE" class="sref">MTD_WRITEABLE1);>  941                        continue;>  951                }>  96 /a>>  971                 spao class="comment">/* Standard NVRAM */ /spaon>  981                if ( a href="+code=buf" class="sref">buf1[0x000 / 4] ==  a href="+code=NVRAM_HEADER" class="sref">NVRAM_HEADER1) {>  991                         a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(& a href="+code=parts" class="sref">parts1[ a href="+code=curr_part" class="sref">curr_part1++],  spao class="string">"nvram" /spaon,> 1001                                              a href="+code=offset" class="sref">offset1, 0);> 1011                        continue;> 1021                }> 103 /a>> 1041                 spao class="comment">/* /spaon> 105 /a> spao class="comment">                 * board_dapa starts with board_id which differs across boards, /spaon> 106 /a> spao class="comment">                 * but we cao use 'MPFR' (hopefully) magic at 0x1001 107 /a> spao class="comment">                 */ /spaon> 1081                if ( a href="+code=buf" class="sref">buf1[0x100 / 4] ==  a href="+code=BOARD_DATA_MAGIC" class="sref">BOARD_DATA_MAGIC1) {> 1091                         a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(& a href="+code=parts" class="sref">parts1[ a href="+code=curr_part" class="sref">curr_part1++],  spao class="string">"board_dapa" /spaon,> 1101                                              a href="+code=offset" class="sref">offset1,  a href="+code=MTD_WRITEABLE" class="sref">MTD_WRITEABLE1);> 1111                        continue;> 1121                }> 113 /a>> 1141                 spao class="comment">/* POT(TOP) */ /spaon> 1151                if ( a href="+code=buf" class="sref">buf1[0x000 / 4] ==  a href="+code=POT_MAGIC1" class="sref">POT_MAGIC11 &&> 1161                    ( a href="+code=buf" class="sref">buf1[0x004 / 4] & 0xFFFF) ==  a href="+code=POT_MAGIC2" class="sref">POT_MAGIC21) {> 1171                         a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(& a href="+code=parts" class="sref">parts1[ a href="+code=curr_part" class="sref">curr_part1++],  spao class="string">"POT" /spaon,  a href="+code=offset" class="sref">offset1,> 1181                                              a href="+code=MTD_WRITEABLE" class="sref">MTD_WRITEABLE1);> 1191                        continue;> 1201                }> 121 /a>> 1221                 spao class="comment">/* ML */ /spaon> 1231                if ( a href="+code=buf" class="sref">buf1[0x010 / 4] ==  a href="+code=ML_MAGIC1" class="sref">ML_MAGIC11 &&> 1241                     a href="+code=buf" class="sref">buf1[0x014 / 4] ==  a href="+code=ML_MAGIC2" class="sref">ML_MAGIC21) {> 1251                         a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(& a href="+code=parts" class="sref">parts1[ a href="+code=curr_part" class="sref">curr_part1++],  spao class="string">"ML" /spaon,  a href="+code=offset" class="sref">offset1,> 1261                                              a href="+code=MTD_WRITEABLE" class="sref">MTD_WRITEABLE1);> 1271                        continue;> 1281                }> 129 /a>> 1301                 spao class="comment">/* TRX */ /spaon> 1311                if ( a href="+code=buf" class="sref">buf1[0x000 / 4] ==  a href="+code=TRX_MAGIC" class="sref">TRX_MAGIC1) {> 1321                         a href="+code=trx" class="sref">trx1 = (struct  a href="+code=trx_header" class="sref">trx_header1 *) a href="+code=buf" class="sref">buf1;> 133 /a>> 1341                         a href="+code=i" class="sref">i1 = 0;> 1351                         spao class="comment">/* We have LZMA loader if offset[2] points to sth */ /spaon> 1361                        if ( a href="+code=trx" class="sref">trx1-> a href="+code=offset" class="sref">offset1[2]) {> 1371                                 a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(& a href="+code=parts" class="sref">parts1[ a href="+code=curr_part" class="sref">curr_part1++],> 1381                                                      spao class="string">"loader" /spaon,> 1391                                                      a href="+code=offset" class="sref">offset1 +  a href="+code=trx" class="sref">trx1-> a href="+code=offset" class="sref">offset1[ a href="+code=i" class="sref">i1],> 1401                                                     0);> 1411                                 a href="+code=i" class="sref">i1++;> 1421                        }> 143 /a>> 1441                         a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(& a href="+code=parts" class="sref">parts1[ a href="+code=curr_part" class="sref">curr_part1++],  spao class="string">"linux" /spaon,> 1451                                              a href="+code=offset" class="sref">offset1 +  a href="+code=trx" class="sref">trx1-> a href="+code=offset" class="sref">offset1[ a href="+code=i" class="sref">i1], 0);> 1461                         a href="+code=i" class="sref">i1++;> 147 /a>> 1481                         spao class="comment">/* /spaon> 149 /a> spao class="comment">                         * Pure rootfs size is knowo and cao be calculated as: /spaon> 1511 spao class="comment">                         * trx->length - trx->offset[i]. We don't fill it as /spaon> 151 /a> spao class="comment">                         * we want to have jffs2 (overlay) in the samu mtd. /spaon> 152 /a> spao class="comment">                         */ /spaon> 1531                         a href="+code=bcm47xxpart_add_part" class="sref">bcm47xxpart_add_part1(& a href="+code=parts" class="sref">parts1[ a href="+code=curr_part" class="sref">curr_part1++],  spao class="string">"rootfs" /spaon,> 1541                                              a href="+code=offset" class="sref">offset1 +  a href="+code=trx" class="sref">trx1-> a href="+code=offset" class="sref">offset1[ a href="+code=i" class="sref">i1], 0);> 1551                         a href="+code=i" class="sref">i1++;> 156 /a>> 1571                         spao class="comment">/* /spaon> 158 /a> spao class="comment">                         * We have who/e TRX      /l1e=L158"> 158 /a> spao "linsref">offset1 +  a href="+code=trx" claa hr349"> 149 /a> spao class="comment4a>                         a href="+code=> 156 /a>> 158 /a> spao clline" namue=ss="line" namue=L158"> 158 =i" class="sref">i1++;>size_t1  a href="+code=bytes_r15>offset[i]. We don't fill it as /spaon>loop we" nancrea"driver7xxpart.c#L156" ide=L156" class="line"9 t" class=1"sref">uint32_t1  a h1ref="16ve jffs2 (overlay) in the samu mtd. /spaon>bcm47lass="sre1f">uint32_t1  a href=1"+cod16/mtd/bcm47xxpart.c#L153" ide=L153" class="line" namue class="sref">curr_part1++],  spao class="shref="+co1de=trx_header" class="sr1ef">t16href="drivers/mtd/bcm47xxpart.c#L134" ide=L1s1 =  a href="+code=mask_flags" class="sref">mr=L211rt.=  a href="+codr=L211rt.     >                         a href="+code=i" class="sref">i1++;>  401<7xxpart.c#L127" imue=L74">  741                if ( ude <&qu65" ide=L65" class="line1" nam16"drivers/mtd/bcm47xxpart.c#L1L130"> 1301                 spao class="comm href="+c1ode=parts" class="sref">1parts16c#L155" ide=L155" claa>(& a href="+code=parts" class="srkzalloc1<1a>(sizeof(struct  a href1="+co1e=mtd_partiptia>(& a href="+code=parts" class="srkha/mach-bccm47xx/nvram.h|include/as     a href="drivers/mtd/bcm47xxpakt.c#  741       kt.c#     >              quot; /spaon,> 158 /alloc" class="sref">kzall1oc1GFP_K1ERNEL1);>                         a href="+codine" namu1e=L71">  711        f1or ( 16>offset[i]. We don't fill it * Assuhrethat"drivers/mt eL15at"  a h>offset1,  a onrethey ardriver7xxpart.c#L156" ide=L156" class="line"9 > = 0;  a1 href="+code=offset" cla1ss="s17ve jffs2 (overlay) in the samu mtd. * foref=bcm47"+code=bl1ocksize" class="sref">bl1ocksi17/mtd/bcm47xxpart.c#L153" ide=L153" ce class="sref">curr_part1++],  spao class="sclass="co1mment">/* Nothing more i1n hig1er memory */ /="drivers/mtd/bcm47x class="line" namue=L136">#L136" ide=L136" class="line" namue=L1ers/mf">offset1 +  a href="+code=trx" class="sref">trx7xx1>#L136" ide=L136" class="line" namue=L++">  771                if ( a href=1et1 &g1t;= 0x2000000)>offset1 +f="drivers/mtd/bcm47xx.f">offset1 +blocksize1) {>mhref="+code=offset" class="sref">offset1 +f="drivers/mtd/bcm47xss=1x.f">offset1 +           a href="+code=i" clasivers/mtd/bcm47xxhref="+code=offset" class="sref">offset1 +f="drivers/mtd/bcm47xx.f">offset1 +rt.c#L63" ide=L63" class="line" namue=L63">  631        struct  a 1xxpart.c#1L76" ide=L76" class="lin1e" na1ue=L76">  76 /ro" class="sref">pr_waro1( spao class="string">"Reache7">  771                if ( a href=1"+code=cu1rr_part" class="sref">cu1rr_pa1t1 >  a href="+c             a href="+code=offset" class="sref">offset1 +  a href="+code=trx" class="sref">trx7xx1x.f">offset1 +blocksize1) {>) {>offset1 +fset1 +=  a href="+code=blocksize" class="sref">blocksize1) {>offset1 +  a href="+code=trx" class="sref">trx7xx1x.f">offset1 +rt.c#L63" ide=L63" class="line" namue=L63">  631        struct  a 1x|include/aasm-frv/mach-bcm47xx/nvrac1  791 1     1              part1 = 0;>mhref="+code=offset" class="sr namue=L63">  631        struct  a 1xne" namu1d/bcm47xxpart.c#L82" ide1=L82"1class="line" nreturnmf">offset1 +  a href="+code=trx" class="sref">trxmtd/bcm47xxpart.c#L20" ide=L20" class="l = 0;  a1noing of the block */ /s1paon>1a href}mtd/bcm47xxpart.c#L20" ide=L20" class="l+code=bl13">  831             1   if1( a href="+code=mtd_read" class="sref">mtd_1read1(1 a href="+code=master" c1lass=1sref">>      ine" namue=L57">  571        struca> +=  a href="+>        strucass="54" ide=L154" class="line" +>     ruca> +=  a href="lass="line" +>     ruc="srrs"" class="sref">curr_part1++],>,>offset1 +rwnuca> +=  a href="rwnuc="srrs" class="sref">mTHIS_MODUrivers/mtd/bcm47xTHIS_MODUri=L127"> 1271                        contpart.c#L815" ide=L85" class="line"1 namu1=L85">  851.f">offset1 +   ru_fxpart.c#L80" ide=  ru_fx="srrs" class="sref">mlass="line" p href="+code=mtd_partiptio" class="sref"7"> 1271                        contp+code=cu1L86">  861           1     1              .f">offset1 +    f="+code=mtd_pa    ="srrs" ef">MTD_WRITEABLE1);>offset1[ a href="+code=i" class="sref">i1                         __ini="+code=trx" cla__ini=ass="54" ide=L154" class="line" ini="+code=trx" clalass="line" ini=     47xx">  771                if ( a href=1" namue=L191">  911            1    i1 ( a h" class="sref">curr_part1++],>offset1 +r>ofode= +>     ruca> +=  a href="r>ofode= +>     ruc                       a lass="line" +>     ruca> +=  a href="lass="line" +>     ruc="sri301                 spao class="comm         1            a href="+cod1e=bcm19code=mtd_info" class="sref">mtd_info1 * 1ing">&quo1t;boot" /spaon,>,>  1941                  1     19541      47xxpart.c#L46" ide=__exi="+code=trx" cla__exi=ass="54" ide=L154" class="line" exi="+code=trx" clalass="line" exi=     47xx">  771                if ( a href=1="drivers1/mtd/bcm47xxpart.c#L97" 1ide=L17" cla" class="sref">curr_part1++],>ofode= +>     ruca> +=  a href="der>ofode= +>     ruc                       a lass="line" +>     ruca> +=  a href="lass="line" +>     ruc="sri301                 spao class="comm part.c#L1              if ( a hre1f="+c1de=bufmtd_info" class="sref">mtd_info1 * 1i|include/+code=NVRAM_HEADER" clas1s="sr19          * Pure rootfs size is knowo and c         1            a href="+cod1e=bcm17xxparmue=L57">  571              qass="line" ini="+code=trx" clalass="line" ini=    i301                 spao class="comm ">BCM47XXPPART_MAX_PARTS1          i1"drivemue=L57">  571              qass="line" exi="+code=trx" clalass="line" exi=    i301                 spao class="com2ef="drive2s/mtd/bcm47xxpart.c#L1022 ide=2102" c01                 spao class="com2eunt of bydrivers/mtd/bcm47xxpart.2#L1042 ide=L>              MODUri_LICENSivers/mtd/bcm47xxODUri_LICENSi     >ef">MTD_WRITEABLE1);>  81 /a>>/* /2paon>MTD_WRITEABLE1);>->e=buf" ine" namue=Lieside=L81" class="line" namue=L81">  81 /a>>               2 * bo2rd_dap


foot1 T a original LXR software"sre a line" namhttp://source>ge.net/projects/lxLXR #L15uni=y401<7xthis experi53" al L81"T_BYsreline" nammailto:lx<@lass=.no">lx<@lass=.no401<.
subfoot1 lx<.lass=.no kindly hostRedpill Laspro A+code= providhref="Lass=1L13sul=BCM4#L15operars/mt rucvicetd/bncei1"d5.