0001-Update-carl9170-to-latest-upstream.patch 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983
  1. From c164bf7f87f9081fee7e1a186dd7a87a9a020b9e Mon Sep 17 00:00:00 2001
  2. From: Jason Self <j@jxself.org>
  3. Date: Thu, 4 Jul 2019 15:12:33 -0700
  4. Subject: [PATCH 1/8] Update carl9170 to latest upstream
  5. Based on commit 001384147050b9cd9daadb4d3115cc0f13f5b319
  6. Dated May 5 2019.
  7. ---
  8. WHENCE | 4 +-
  9. carl9170fw/carlfw/include/wl.h | 2 +-
  10. carl9170fw/carlfw/src/hostif.c | 8 +-
  11. carl9170fw/carlfw/src/printf.c | 0
  12. carl9170fw/carlfw/src/wlantx.c | 5 +-
  13. carl9170fw/config/CMakeLists.txt | 6 +-
  14. carl9170fw/config/conf.c | 210 ++++++----
  15. carl9170fw/config/confdata.c | 329 +++++++++------
  16. carl9170fw/config/expr.c | 206 +++++++---
  17. carl9170fw/config/expr.h | 105 ++++-
  18. carl9170fw/config/kconf_id.c | 54 ---
  19. carl9170fw/config/lkc.h | 50 +--
  20. carl9170fw/config/lkc_proto.h | 19 +-
  21. carl9170fw/config/menu.c | 259 +++++++++---
  22. carl9170fw/config/preprocess.c | 573 +++++++++++++++++++++++++++
  23. carl9170fw/config/symbol.c | 255 ++++--------
  24. carl9170fw/config/util.c | 86 ++--
  25. carl9170fw/config/zconf.l | 336 ++++++++++------
  26. carl9170fw/config/zconf.y | 403 +++++++++----------
  27. carl9170fw/include/linux/ieee80211.h | 24 +-
  28. carl9170fw/include/shared/wlan.h | 2 +-
  29. carl9170fw/toolchain/Makefile | 8 +-
  30. carl9170fw/toolchain/SHA256SUMS | 18 +-
  31. 23 files changed, 1942 insertions(+), 1020 deletions(-)
  32. mode change 100755 => 100644 carl9170fw/carlfw/src/printf.c
  33. delete mode 100644 carl9170fw/config/kconf_id.c
  34. create mode 100644 carl9170fw/config/preprocess.c
  35. diff --git a/WHENCE b/WHENCE
  36. index dd8ec20..2932155 100644
  37. --- a/WHENCE
  38. +++ b/WHENCE
  39. @@ -142,8 +142,8 @@ From https://git.kernel.org/pub/scm/utils/cis-tools/cis-tools.git
  40. Driver: carl9170 -- Atheros AR9170 802.11 draft-n USB driver
  41. -Version: Based on commit 370b7919114a02149088c482c8709cafb9bf7478
  42. -dated May 2 2018.
  43. +Version: Based on commit 001384147050b9cd9daadb4d3115cc0f13f5b319
  44. +dated May 5 2019.
  45. Licence: GPLv2 or later.
  46. diff --git a/carl9170fw/carlfw/include/wl.h b/carl9170fw/carlfw/include/wl.h
  47. index 8499ca2..5566be4 100644
  48. --- a/carl9170fw/carlfw/include/wl.h
  49. +++ b/carl9170fw/carlfw/include/wl.h
  50. @@ -237,7 +237,7 @@ static inline __inline void unhide_super(struct dma_desc *desc)
  51. desc->totalLen += sizeof(struct carl9170_tx_superdesc);
  52. }
  53. -static inline __inline __hot void read_tsf(uint32_t *tsf)
  54. +static inline __inline __hot void read_tsf(uint32_t tsf[static 2])
  55. {
  56. /*
  57. * "According to the [hardware] documentation:
  58. diff --git a/carl9170fw/carlfw/src/hostif.c b/carl9170fw/carlfw/src/hostif.c
  59. index 73e89c7..06726db 100644
  60. --- a/carl9170fw/carlfw/src/hostif.c
  61. +++ b/carl9170fw/carlfw/src/hostif.c
  62. @@ -213,10 +213,14 @@ void handle_cmd(struct carl9170_rsp *resp)
  63. fw.reboot = 1;
  64. break;
  65. - case CARL9170_CMD_READ_TSF:
  66. + case CARL9170_CMD_READ_TSF: {
  67. + uint32_t tmptsf[2];
  68. +
  69. + read_tsf(tmptsf);
  70. resp->hdr.len = 8;
  71. - read_tsf((uint32_t *)resp->tsf.tsf);
  72. + memcpy(resp->tsf.tsf, tmptsf, sizeof(tmptsf));
  73. break;
  74. + }
  75. case CARL9170_CMD_RX_FILTER:
  76. resp->hdr.len = 0;
  77. diff --git a/carl9170fw/carlfw/src/printf.c b/carl9170fw/carlfw/src/printf.c
  78. old mode 100755
  79. new mode 100644
  80. diff --git a/carl9170fw/carlfw/src/wlantx.c b/carl9170fw/carlfw/src/wlantx.c
  81. index 474c040..a8d0952 100644
  82. --- a/carl9170fw/carlfw/src/wlantx.c
  83. +++ b/carl9170fw/carlfw/src/wlantx.c
  84. @@ -260,7 +260,7 @@ static void __wlan_tx(struct dma_desc *desc)
  85. if (unlikely(super->s.fill_in_tsf)) {
  86. struct ieee80211_mgmt *mgmt = (void *) &super->f.data.i3e;
  87. - uint32_t *tsf = (uint32_t *) &mgmt->u.probe_resp.timestamp;
  88. + uint32_t tmptsf[2];
  89. /*
  90. * Truth be told: this is a hack.
  91. @@ -272,7 +272,8 @@ static void __wlan_tx(struct dma_desc *desc)
  92. * (even, if it's got an accurate atomic clock source).
  93. */
  94. - read_tsf(tsf);
  95. + read_tsf(tmptsf);
  96. + memcpy(&mgmt->u.probe_resp.timestamp, tmptsf, sizeof(tmptsf));
  97. }
  98. wlan_tx_ampdu(super);
  99. diff --git a/carl9170fw/config/CMakeLists.txt b/carl9170fw/config/CMakeLists.txt
  100. index 0a96a82..23e7218 100644
  101. --- a/carl9170fw/config/CMakeLists.txt
  102. +++ b/carl9170fw/config/CMakeLists.txt
  103. @@ -11,13 +11,13 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  104. file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../include/generated")
  105. -BISON_TARGET(zconf zconf.y zconf.tab.c COMPILE_FLAGS "-l -b zconf -p zconf -t")
  106. -FLEX_TARGET(zconfscan zconf.l zconf.lex.c COMPILE_FLAGS "-Pzconf -L")
  107. +BISON_TARGET(zconf zconf.y zconf.tab.c COMPILE_FLAGS "-l -b zconf -p yy -t")
  108. +FLEX_TARGET(zconfscan zconf.l zconf.lex.c COMPILE_FLAGS "-Pyy -L")
  109. SET(zconf_deps ${FLEX_zconfscan_OUTPUTS})
  110. SET_SOURCE_FILES_PROPERTIES(${BISON_zconf_OUTPUTS}
  111. PROPERTIES OBJECT_DEPENDS "${zconf_deps}")
  112. -set(conf_src conf.c ${BISON_zconf_OUTPUTS})
  113. +set(conf_src conf.c symbol.c confdata.c expr.c preprocess.c ${BISON_zconf_OUTPUTS} ${FLEX_zconfscan_OUTPUTS})
  114. add_executable(conf ${conf_src})
  115. diff --git a/carl9170fw/config/conf.c b/carl9170fw/config/conf.c
  116. index 6be6143..2949b7d 100644
  117. --- a/carl9170fw/config/conf.c
  118. +++ b/carl9170fw/config/conf.c
  119. @@ -1,9 +1,8 @@
  120. +// SPDX-License-Identifier: GPL-2.0
  121. /*
  122. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  123. - * Released under the terms of the GNU GPL v2.0.
  124. */
  125. -#include <locale.h>
  126. #include <ctype.h>
  127. #include <limits.h>
  128. #include <stdio.h>
  129. @@ -20,10 +19,10 @@
  130. static void conf(struct menu *menu);
  131. static void check_conf(struct menu *menu);
  132. -static void xfgets(char *str, int size, FILE *in);
  133. enum input_mode {
  134. oldaskconfig,
  135. + syncconfig,
  136. oldconfig,
  137. allnoconfig,
  138. allyesconfig,
  139. @@ -33,12 +32,13 @@ enum input_mode {
  140. defconfig,
  141. savedefconfig,
  142. listnewconfig,
  143. - oldnoconfig,
  144. -} input_mode = oldaskconfig;
  145. + olddefconfig,
  146. +};
  147. +static enum input_mode input_mode = oldaskconfig;
  148. static int indent = 1;
  149. static int tty_stdio;
  150. -static int valid_stdin = 1;
  151. +static int sync_kconfig;
  152. static int conf_cnt;
  153. static char line[PATH_MAX];
  154. static struct menu *rootEntry;
  155. @@ -70,14 +70,14 @@ static void strip(char *str)
  156. *p-- = 0;
  157. }
  158. -static void check_stdin(void)
  159. +/* Helper function to facilitate fgets() by Jean Sacren. */
  160. +static void xfgets(char *str, int size, FILE *in)
  161. {
  162. - if (!valid_stdin) {
  163. - printf(_("aborted!\n\n"));
  164. - printf(_("Console input/output is redirected. "));
  165. - printf(_("Run 'make config' to update configuration.\n\n"));
  166. - exit(1);
  167. - }
  168. + if (!fgets(str, size, in))
  169. + fprintf(stderr, "\nError in reading or end of file.\n");
  170. +
  171. + if (!tty_stdio)
  172. + printf("%s", str);
  173. }
  174. static int conf_askvalue(struct symbol *sym, const char *def)
  175. @@ -85,7 +85,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)
  176. enum symbol_type type = sym_get_type(sym);
  177. if (!sym_has_value(sym))
  178. - printf(_("(NEW) "));
  179. + printf("(NEW) ");
  180. line[0] = '\n';
  181. line[1] = 0;
  182. @@ -99,17 +99,15 @@ static int conf_askvalue(struct symbol *sym, const char *def)
  183. switch (input_mode) {
  184. case oldconfig:
  185. + case syncconfig:
  186. if (sym_has_value(sym)) {
  187. printf("%s\n", def);
  188. return 0;
  189. }
  190. - check_stdin();
  191. /* fall through */
  192. case oldaskconfig:
  193. fflush(stdout);
  194. xfgets(line, sizeof(line), stdin);
  195. - if (!tty_stdio)
  196. - printf("\n");
  197. return 1;
  198. default:
  199. break;
  200. @@ -134,7 +132,7 @@ static int conf_string(struct menu *menu)
  201. const char *def;
  202. while (1) {
  203. - printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
  204. + printf("%*s%s ", indent - 1, "", menu->prompt->text);
  205. printf("(%s) ", sym->name);
  206. def = sym_get_string_value(sym);
  207. if (sym_get_string_value(sym))
  208. @@ -167,7 +165,7 @@ static int conf_sym(struct menu *menu)
  209. tristate oldval, newval;
  210. while (1) {
  211. - printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
  212. + printf("%*s%s ", indent - 1, "", menu->prompt->text);
  213. if (sym->name)
  214. printf("(%s) ", sym->name);
  215. putchar('[');
  216. @@ -189,9 +187,7 @@ static int conf_sym(struct menu *menu)
  217. printf("/m");
  218. if (oldval != yes && sym_tristate_within_range(sym, yes))
  219. printf("/y");
  220. - if (menu_has_help(menu))
  221. - printf("/?");
  222. - printf("] ");
  223. + printf("/?] ");
  224. if (!conf_askvalue(sym, sym_get_string_value(sym)))
  225. return 0;
  226. strip(line);
  227. @@ -254,7 +250,7 @@ static int conf_choice(struct menu *menu)
  228. case no:
  229. return 1;
  230. case mod:
  231. - printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
  232. + printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
  233. return 0;
  234. case yes:
  235. break;
  236. @@ -264,7 +260,7 @@ static int conf_choice(struct menu *menu)
  237. while (1) {
  238. int cnt, def;
  239. - printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
  240. + printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
  241. def_sym = sym_get_choice_value(sym);
  242. cnt = def = 0;
  243. line[0] = 0;
  244. @@ -272,7 +268,7 @@ static int conf_choice(struct menu *menu)
  245. if (!menu_is_visible(child))
  246. continue;
  247. if (!child->sym) {
  248. - printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
  249. + printf("%*c %s\n", indent, '*', menu_get_prompt(child));
  250. continue;
  251. }
  252. cnt++;
  253. @@ -281,30 +277,27 @@ static int conf_choice(struct menu *menu)
  254. printf("%*c", indent, '>');
  255. } else
  256. printf("%*c", indent, ' ');
  257. - printf(" %d. %s", cnt, _(menu_get_prompt(child)));
  258. + printf(" %d. %s", cnt, menu_get_prompt(child));
  259. if (child->sym->name)
  260. printf(" (%s)", child->sym->name);
  261. if (!sym_has_value(child->sym))
  262. - printf(_(" (NEW)"));
  263. + printf(" (NEW)");
  264. printf("\n");
  265. }
  266. - printf(_("%*schoice"), indent - 1, "");
  267. + printf("%*schoice", indent - 1, "");
  268. if (cnt == 1) {
  269. printf("[1]: 1\n");
  270. goto conf_childs;
  271. }
  272. - printf("[1-%d", cnt);
  273. - if (menu_has_help(menu))
  274. - printf("?");
  275. - printf("]: ");
  276. + printf("[1-%d?]: ", cnt);
  277. switch (input_mode) {
  278. case oldconfig:
  279. + case syncconfig:
  280. if (!is_new) {
  281. cnt = def;
  282. printf("%d\n", cnt);
  283. break;
  284. }
  285. - check_stdin();
  286. /* fall through */
  287. case oldaskconfig:
  288. fflush(stdout);
  289. @@ -364,9 +357,11 @@ static void conf(struct menu *menu)
  290. switch (prop->type) {
  291. case P_MENU:
  292. - if ((input_mode == listnewconfig ||
  293. - input_mode == oldnoconfig) &&
  294. - rootEntry != menu) {
  295. + /*
  296. + * Except in oldaskconfig mode, we show only menus that
  297. + * contain new symbols.
  298. + */
  299. + if (input_mode != oldaskconfig && rootEntry != menu) {
  300. check_conf(menu);
  301. return;
  302. }
  303. @@ -376,7 +371,7 @@ static void conf(struct menu *menu)
  304. if (prompt)
  305. printf("%*c\n%*c %s\n%*c\n",
  306. indent, '*',
  307. - indent, '*', _(prompt),
  308. + indent, '*', prompt,
  309. indent, '*');
  310. default:
  311. ;
  312. @@ -426,12 +421,22 @@ static void check_conf(struct menu *menu)
  313. if (sym_is_changable(sym) ||
  314. (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
  315. if (input_mode == listnewconfig) {
  316. - if (sym->name && !sym_is_choice_value(sym)) {
  317. - printf("%s%s\n", CONFIG_, sym->name);
  318. + if (sym->name) {
  319. + const char *str;
  320. +
  321. + if (sym->type == S_STRING) {
  322. + str = sym_get_string_value(sym);
  323. + str = sym_escape_string_value(str);
  324. + printf("%s%s=%s\n", CONFIG_, sym->name, str);
  325. + free((void *)str);
  326. + } else {
  327. + str = sym_get_string_value(sym);
  328. + printf("%s%s=%s\n", CONFIG_, sym->name, str);
  329. + }
  330. }
  331. - } else if (input_mode != oldnoconfig) {
  332. + } else {
  333. if (!conf_cnt++)
  334. - printf(_("*\n* Restart config...\n*\n"));
  335. + printf("*\n* Restart config...\n*\n");
  336. rootEntry = menu_get_parent_menu(menu);
  337. conf(rootEntry);
  338. }
  339. @@ -443,8 +448,9 @@ static void check_conf(struct menu *menu)
  340. }
  341. static struct option long_opts[] = {
  342. - {"askconfig", no_argument, NULL, oldaskconfig},
  343. - {"config", no_argument, NULL, oldconfig},
  344. + {"oldaskconfig", no_argument, NULL, oldaskconfig},
  345. + {"oldconfig", no_argument, NULL, oldconfig},
  346. + {"syncconfig", no_argument, NULL, syncconfig},
  347. {"defconfig", optional_argument, NULL, defconfig},
  348. {"savedefconfig", required_argument, NULL, savedefconfig},
  349. {"allnoconfig", no_argument, NULL, allnoconfig},
  350. @@ -453,7 +459,7 @@ static struct option long_opts[] = {
  351. {"alldefconfig", no_argument, NULL, alldefconfig},
  352. {"randconfig", no_argument, NULL, randconfig},
  353. {"listnewconfig", no_argument, NULL, listnewconfig},
  354. - {"noconfig", no_argument, NULL, oldnoconfig},
  355. + {"olddefconfig", no_argument, NULL, olddefconfig},
  356. {NULL, 0, NULL, 0}
  357. };
  358. @@ -463,10 +469,11 @@ static void conf_usage(const char *progname)
  359. printf("Usage: %s [-s] [option] <kconfig-file>\n", progname);
  360. printf("[option] is _one_ of the following:\n");
  361. printf(" --listnewconfig List new options\n");
  362. - printf(" --askconfig Start a new configuration using a line-oriented program\n");
  363. - printf(" --config Update a configuration using a provided .config as base\n");
  364. - printf(" --silentconfig Same as config, but quietly, additionally update deps\n");
  365. - printf(" --noconfig Same as silentconfig but set new symbols to no\n");
  366. + printf(" --oldaskconfig Start a new configuration using a line-oriented program\n");
  367. + printf(" --oldconfig Update a configuration using a provided .config as base\n");
  368. + printf(" --syncconfig Similar to oldconfig but generates configuration in\n"
  369. + " include/{generated/,config/}\n");
  370. + printf(" --olddefconfig Same as oldconfig but sets new symbols to their default value\n");
  371. printf(" --defconfig <file> New config with default defined in <file>\n");
  372. printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n");
  373. printf(" --allnoconfig New config where all options are answered with no\n");
  374. @@ -482,12 +489,9 @@ int main(int ac, char **av)
  375. int opt;
  376. const char *name, *defconfig_file = NULL /* gcc uninit */;
  377. struct stat tmpstat;
  378. + int no_conf_write = 0;
  379. - setlocale(LC_ALL, "");
  380. - bindtextdomain(PACKAGE, LOCALEDIR);
  381. - textdomain(PACKAGE);
  382. -
  383. - tty_stdio = isatty(0) && isatty(1) && isatty(2);
  384. + tty_stdio = isatty(0) && isatty(1);
  385. while ((opt = getopt_long(ac, av, "s", long_opts, NULL)) != -1) {
  386. if (opt == 's') {
  387. @@ -496,6 +500,14 @@ int main(int ac, char **av)
  388. }
  389. input_mode = (enum input_mode)opt;
  390. switch (opt) {
  391. + case syncconfig:
  392. + /*
  393. + * syncconfig is invoked during the build stage.
  394. + * Suppress distracting "configuration written to ..."
  395. + */
  396. + conf_set_message_callback(NULL);
  397. + sync_kconfig = 1;
  398. + break;
  399. case defconfig:
  400. case savedefconfig:
  401. defconfig_file = optarg;
  402. @@ -532,7 +544,7 @@ int main(int ac, char **av)
  403. case allmodconfig:
  404. case alldefconfig:
  405. case listnewconfig:
  406. - case oldnoconfig:
  407. + case olddefconfig:
  408. break;
  409. case '?':
  410. conf_usage(progname);
  411. @@ -541,30 +553,45 @@ int main(int ac, char **av)
  412. }
  413. }
  414. if (ac == optind) {
  415. - printf(_("%s: Kconfig file missing\n"), av[0]);
  416. + fprintf(stderr, "%s: Kconfig file missing\n", av[0]);
  417. conf_usage(progname);
  418. exit(1);
  419. }
  420. name = av[optind];
  421. conf_parse(name);
  422. //zconfdump(stdout);
  423. + if (sync_kconfig) {
  424. + name = conf_get_configname();
  425. + if (stat(name, &tmpstat)) {
  426. + fprintf(stderr, "***\n"
  427. + "*** Configuration file \"%s\" not found!\n"
  428. + "***\n"
  429. + "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
  430. + "*** \"make menuconfig\" or \"make xconfig\").\n"
  431. + "***\n", name);
  432. + exit(1);
  433. + }
  434. + }
  435. switch (input_mode) {
  436. case defconfig:
  437. if (!defconfig_file)
  438. defconfig_file = conf_get_default_confname();
  439. if (conf_read(defconfig_file)) {
  440. - printf(_("***\n"
  441. - "*** Can't find default configuration \"%s\"!\n"
  442. - "***\n"), defconfig_file);
  443. + fprintf(stderr,
  444. + "***\n"
  445. + "*** Can't find default configuration \"%s\"!\n"
  446. + "***\n",
  447. + defconfig_file);
  448. exit(1);
  449. }
  450. break;
  451. case savedefconfig:
  452. + case syncconfig:
  453. case oldaskconfig:
  454. case oldconfig:
  455. case listnewconfig:
  456. - case oldnoconfig:
  457. + case olddefconfig:
  458. conf_read(NULL);
  459. break;
  460. case allnoconfig:
  461. @@ -578,7 +605,7 @@ int main(int ac, char **av)
  462. if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) {
  463. if (conf_read_simple(name, S_DEF_USER)) {
  464. fprintf(stderr,
  465. - _("*** Can't read seed configuration \"%s\"!\n"),
  466. + "*** Can't read seed configuration \"%s\"!\n",
  467. name);
  468. exit(1);
  469. }
  470. @@ -595,7 +622,7 @@ int main(int ac, char **av)
  471. if (conf_read_simple(name, S_DEF_USER) &&
  472. conf_read_simple("all.config", S_DEF_USER)) {
  473. fprintf(stderr,
  474. - _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"),
  475. + "*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n",
  476. name);
  477. exit(1);
  478. }
  479. @@ -604,7 +631,17 @@ int main(int ac, char **av)
  480. break;
  481. }
  482. - valid_stdin = tty_stdio;
  483. + if (sync_kconfig) {
  484. + name = getenv("KCONFIG_NOSILENTUPDATE");
  485. + if (name && *name) {
  486. + if (conf_get_changed()) {
  487. + fprintf(stderr,
  488. + "\n*** The configuration requires explicit update.\n\n");
  489. + return 1;
  490. + }
  491. + no_conf_write = 1;
  492. + }
  493. + }
  494. switch (input_mode) {
  495. case allnoconfig:
  496. @@ -635,44 +672,51 @@ int main(int ac, char **av)
  497. /* fall through */
  498. case oldconfig:
  499. case listnewconfig:
  500. - case oldnoconfig:
  501. + case syncconfig:
  502. /* Update until a loop caused no more changes */
  503. do {
  504. conf_cnt = 0;
  505. check_conf(&rootmenu);
  506. - } while (conf_cnt &&
  507. - (input_mode != listnewconfig &&
  508. - input_mode != oldnoconfig));
  509. + } while (conf_cnt);
  510. + break;
  511. + case olddefconfig:
  512. + default:
  513. break;
  514. }
  515. if (input_mode == savedefconfig) {
  516. if (conf_write_defconfig(defconfig_file)) {
  517. - fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
  518. + fprintf(stderr, "n*** Error while saving defconfig to: %s\n\n",
  519. defconfig_file);
  520. return 1;
  521. }
  522. } else if (input_mode != listnewconfig) {
  523. - /*
  524. - * build so we shall update autoconf.
  525. - */
  526. - if (conf_write(NULL)) {
  527. - fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
  528. + if (!no_conf_write && conf_write(NULL)) {
  529. + fprintf(stderr, "\n*** Error during writing of the configuration.\n\n");
  530. exit(1);
  531. }
  532. - if (conf_write_autoconf()) {
  533. - fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
  534. +
  535. + /*
  536. + * Create auto.conf if it does not exist.
  537. + * This prevents GNU Make 4.1 or older from emitting
  538. + * "include/generated/auto.conf: No such file or directory"
  539. + * in the top-level Makefile
  540. + *
  541. + * syncconfig always creates or updates auto.conf because it is
  542. + * used during the build.
  543. + */
  544. +
  545. + /*
  546. + * In our cmake case, we always want to update the autogenerated
  547. + * files.
  548. + */
  549. + sync_kconfig = 1;
  550. +
  551. + if (conf_write_autoconf(sync_kconfig) && sync_kconfig) {
  552. + fprintf(stderr,
  553. + "\n*** Error during sync of the configuration.\n\n");
  554. return 1;
  555. }
  556. }
  557. return 0;
  558. }
  559. -
  560. -/*
  561. - * Helper function to facilitate fgets() by Jean Sacren.
  562. - */
  563. -void xfgets(char *str, int size, FILE *in)
  564. -{
  565. - if (fgets(str, size, in) == NULL)
  566. - fprintf(stderr, "\nError in reading or end of file.\n");
  567. -}
  568. diff --git a/carl9170fw/config/confdata.c b/carl9170fw/config/confdata.c
  569. index e606f06..d67695d 100644
  570. --- a/carl9170fw/config/confdata.c
  571. +++ b/carl9170fw/config/confdata.c
  572. @@ -1,12 +1,13 @@
  573. +// SPDX-License-Identifier: GPL-2.0
  574. /*
  575. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  576. - * Released under the terms of the GNU GPL v2.0.
  577. */
  578. #include <sys/stat.h>
  579. #include <ctype.h>
  580. #include <errno.h>
  581. #include <fcntl.h>
  582. +#include <limits.h>
  583. #include <stdarg.h>
  584. #include <stdio.h>
  585. #include <stdlib.h>
  586. @@ -16,6 +17,105 @@
  587. #include "lkc.h"
  588. +/* return true if 'path' exists, false otherwise */
  589. +static bool is_present(const char *path)
  590. +{
  591. + struct stat st;
  592. +
  593. + return !stat(path, &st);
  594. +}
  595. +
  596. +/* return true if 'path' exists and it is a directory, false otherwise */
  597. +static bool is_dir(const char *path)
  598. +{
  599. + struct stat st;
  600. +
  601. + if (stat(path, &st))
  602. + return 0;
  603. +
  604. + return S_ISDIR(st.st_mode);
  605. +}
  606. +
  607. +/*
  608. + * Create the parent directory of the given path.
  609. + *
  610. + * For example, if 'include/config/auto.conf' is given, create 'include/config'.
  611. + */
  612. +static int make_parent_dir(const char *path)
  613. +{
  614. + char tmp[PATH_MAX + 1];
  615. + char *p;
  616. +
  617. + strncpy(tmp, path, sizeof(tmp));
  618. + tmp[sizeof(tmp) - 1] = 0;
  619. +
  620. + /* Remove the base name. Just return if nothing is left */
  621. + p = strrchr(tmp, '/');
  622. + if (!p)
  623. + return 0;
  624. + *(p + 1) = 0;
  625. +
  626. + /* Just in case it is an absolute path */
  627. + p = tmp;
  628. + while (*p == '/')
  629. + p++;
  630. +
  631. + while ((p = strchr(p, '/'))) {
  632. + *p = 0;
  633. +
  634. + /* skip if the directory exists */
  635. + if (!is_dir(tmp) && mkdir(tmp, 0755))
  636. + return -1;
  637. +
  638. + *p = '/';
  639. + while (*p == '/')
  640. + p++;
  641. + }
  642. +
  643. + return 0;
  644. +}
  645. +
  646. +static char depfile_path[PATH_MAX];
  647. +static size_t depfile_prefix_len;
  648. +
  649. +/* touch depfile for symbol 'name' */
  650. +static int conf_touch_dep(const char *name)
  651. +{
  652. + int fd, ret;
  653. + const char *s;
  654. + char *d, c;
  655. +
  656. + /* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */
  657. + if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path))
  658. + return -1;
  659. +
  660. + d = depfile_path + depfile_prefix_len;
  661. + s = name;
  662. +
  663. + while ((c = *s++))
  664. + *d++ = (c == '_') ? '/' : tolower(c);
  665. + strcpy(d, ".h");
  666. +
  667. + /* Assume directory path already exists. */
  668. + fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  669. + if (fd == -1) {
  670. + if (errno != ENOENT)
  671. + return -1;
  672. +
  673. + ret = make_parent_dir(depfile_path);
  674. + if (ret)
  675. + return ret;
  676. +
  677. + /* Try it again. */
  678. + fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  679. + if (fd == -1)
  680. + return -1;
  681. + }
  682. + close(fd);
  683. +
  684. + return 0;
  685. +}
  686. +
  687. struct conf_printer {
  688. void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
  689. void (*print_comment)(FILE *, const char *, void *);
  690. @@ -28,7 +128,7 @@ static void conf_message(const char *fmt, ...)
  691. __attribute__ ((format (printf, 1, 2)));
  692. static const char *conf_filename;
  693. -static int conf_lineno, conf_warnings, conf_unsaved;
  694. +static int conf_lineno, conf_warnings;
  695. const char conf_defname[] = "include/generated/defconfig";
  696. @@ -43,16 +143,16 @@ static void conf_warning(const char *fmt, ...)
  697. conf_warnings++;
  698. }
  699. -static void conf_default_message_callback(const char *fmt, va_list ap)
  700. +static void conf_default_message_callback(const char *s)
  701. {
  702. printf("#\n# ");
  703. - vprintf(fmt, ap);
  704. + printf("%s", s);
  705. printf("\n#\n");
  706. }
  707. -static void (*conf_message_callback) (const char *fmt, va_list ap) =
  708. +static void (*conf_message_callback)(const char *s) =
  709. conf_default_message_callback;
  710. -void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))
  711. +void conf_set_message_callback(void (*fn)(const char *s))
  712. {
  713. conf_message_callback = fn;
  714. }
  715. @@ -60,10 +160,15 @@ void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))
  716. static void conf_message(const char *fmt, ...)
  717. {
  718. va_list ap;
  719. + char buf[4096];
  720. +
  721. + if (!conf_message_callback)
  722. + return;
  723. va_start(ap, fmt);
  724. - if (conf_message_callback)
  725. - conf_message_callback(fmt, ap);
  726. +
  727. + vsnprintf(buf, sizeof(buf), fmt, ap);
  728. + conf_message_callback(buf);
  729. va_end(ap);
  730. }
  731. @@ -81,43 +186,16 @@ const char *conf_get_autoconfig_name(void)
  732. return name ? name : "include/generated/auto.conf";
  733. }
  734. -static char *conf_expand_value(const char *in)
  735. -{
  736. - struct symbol *sym;
  737. - const char *src;
  738. - static char res_value[SYMBOL_MAXLENGTH];
  739. - char *dst, name[SYMBOL_MAXLENGTH];
  740. -
  741. - res_value[0] = 0;
  742. - dst = name;
  743. - while ((src = strchr(in, '$'))) {
  744. - strncat(res_value, in, src - in);
  745. - src++;
  746. - dst = name;
  747. - while (isalnum(*src) || *src == '_')
  748. - *dst++ = *src++;
  749. - *dst = 0;
  750. - sym = sym_lookup(name, 0);
  751. - sym_calc_value(sym);
  752. - strcat(res_value, sym_get_string_value(sym));
  753. - in = src;
  754. - }
  755. - strcat(res_value, in);
  756. -
  757. - return res_value;
  758. -}
  759. -
  760. char *conf_get_default_confname(void)
  761. {
  762. - struct stat buf;
  763. static char fullname[PATH_MAX+1];
  764. char *env, *name;
  765. - name = conf_expand_value(conf_defname);
  766. + name = expand_string(conf_defname);
  767. env = getenv(SRCTREE);
  768. if (env) {
  769. sprintf(fullname, "%s/%s", env, name);
  770. - if (!stat(fullname, &buf))
  771. + if (is_present(fullname))
  772. return fullname;
  773. }
  774. return name;
  775. @@ -150,14 +228,6 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
  776. conf_warning("symbol value '%s' invalid for %s",
  777. p, sym->name);
  778. return 1;
  779. - case S_OTHER:
  780. - if (*p != '"') {
  781. - for (p2 = p; *p2 && !isspace(*p2); p2++)
  782. - ;
  783. - sym->type = S_STRING;
  784. - goto done;
  785. - }
  786. - /* fall through */
  787. case S_STRING:
  788. if (*p++ != '"')
  789. break;
  790. @@ -176,9 +246,8 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
  791. /* fall through */
  792. case S_INT:
  793. case S_HEX:
  794. - done:
  795. if (sym_string_valid(sym, p)) {
  796. - sym->def[def].val = strdup(p);
  797. + sym->def[def].val = xstrdup(p);
  798. sym->flags |= def_flags;
  799. } else {
  800. if (def != S_DEF_AUTO)
  801. @@ -201,7 +270,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
  802. if (new_size > *n) {
  803. new_size += LINE_GROWTH - 1;
  804. new_size *= 2;
  805. - nline = realloc(*lineptr, new_size);
  806. + nline = xrealloc(*lineptr, new_size);
  807. if (!nline)
  808. return -1;
  809. @@ -274,10 +343,11 @@ int conf_read_simple(const char *name, int def)
  810. if (expr_calc_value(prop->visible.expr) == no ||
  811. prop->expr->type != E_SYMBOL)
  812. continue;
  813. - name = conf_expand_value(prop->expr->left.sym->name);
  814. + sym_calc_value(prop->expr->left.sym);
  815. + name = sym_get_string_value(prop->expr->left.sym);
  816. in = zconf_fopen(name);
  817. if (in) {
  818. - conf_message(_("using defaults found in %s"),
  819. + conf_message("using defaults found in %s",
  820. name);
  821. goto load;
  822. }
  823. @@ -290,7 +360,6 @@ load:
  824. conf_filename = name;
  825. conf_lineno = 0;
  826. conf_warnings = 0;
  827. - conf_unsaved = 0;
  828. def_flags = SYMBOL_DEF << def;
  829. for_all_symbols(i, sym) {
  830. @@ -327,7 +396,7 @@ load:
  831. sym = sym_find(line + 2 + strlen(CONFIG_));
  832. if (!sym) {
  833. sym_add_change_count(1);
  834. - goto setsym;
  835. + continue;
  836. }
  837. } else {
  838. sym = sym_lookup(line + 2 + strlen(CONFIG_), 0);
  839. @@ -357,17 +426,22 @@ load:
  840. if (*p2 == '\r')
  841. *p2 = 0;
  842. }
  843. - if (def == S_DEF_USER) {
  844. - sym = sym_find(line + strlen(CONFIG_));
  845. - if (!sym) {
  846. +
  847. + sym = sym_find(line + strlen(CONFIG_));
  848. + if (!sym) {
  849. + if (def == S_DEF_AUTO)
  850. + /*
  851. + * Reading from include/config/auto.conf
  852. + * If CONFIG_FOO previously existed in
  853. + * auto.conf but it is missing now,
  854. + * include/config/foo.h must be touched.
  855. + */
  856. + conf_touch_dep(line + strlen(CONFIG_));
  857. + else
  858. sym_add_change_count(1);
  859. - goto setsym;
  860. - }
  861. - } else {
  862. - sym = sym_lookup(line + strlen(CONFIG_), 0);
  863. - if (sym->type == S_UNKNOWN)
  864. - sym->type = S_OTHER;
  865. + continue;
  866. }
  867. +
  868. if (sym->flags & def_flags) {
  869. conf_warning("override: reassigning to symbol %s", sym->name);
  870. }
  871. @@ -380,7 +454,7 @@ load:
  872. continue;
  873. }
  874. -setsym:
  875. +
  876. if (sym && sym_is_choice_value(sym)) {
  877. struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
  878. switch (sym->def[def].tri) {
  879. @@ -409,6 +483,7 @@ setsym:
  880. int conf_read(const char *name)
  881. {
  882. struct symbol *sym;
  883. + int conf_unsaved = 0;
  884. int i;
  885. sym_set_change_count(0);
  886. @@ -422,7 +497,7 @@ int conf_read(const char *name)
  887. for_all_symbols(i, sym) {
  888. sym_calc_value(sym);
  889. - if (sym_is_choice(sym) || (sym->flags & SYMBOL_AUTO))
  890. + if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE))
  891. continue;
  892. if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) {
  893. /* check that calculated value agrees with saved value */
  894. @@ -678,7 +753,6 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym,
  895. const char *str;
  896. switch (sym->type) {
  897. - case S_OTHER:
  898. case S_UNKNOWN:
  899. break;
  900. case S_STRING:
  901. @@ -791,15 +865,14 @@ int conf_write(const char *name)
  902. struct menu *menu;
  903. const char *basename;
  904. const char *str;
  905. - char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
  906. + char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8];
  907. char *env;
  908. dirname[0] = 0;
  909. if (name && name[0]) {
  910. - struct stat st;
  911. char *slash;
  912. - if (!stat(name, &st) && S_ISDIR(st.st_mode)) {
  913. + if (is_dir(name)) {
  914. strcpy(dirname, name);
  915. strcat(dirname, "/");
  916. basename = conf_get_configname();
  917. @@ -877,33 +950,61 @@ next:
  918. return 1;
  919. }
  920. - conf_message(_("configuration written to %s"), newname);
  921. + conf_message("configuration written to %s", newname);
  922. sym_set_change_count(0);
  923. return 0;
  924. }
  925. -static int conf_split_config(void)
  926. +/* write a dependency file as used by kbuild to track dependencies */
  927. +static int conf_write_dep(const char *name)
  928. +{
  929. + struct file *file;
  930. + FILE *out;
  931. +
  932. + if (!name)
  933. + name = ".kconfig.d";
  934. + out = fopen("..config.tmp", "w");
  935. + if (!out)
  936. + return 1;
  937. + fprintf(out, "deps_config := \\\n");
  938. + for (file = file_list; file; file = file->next) {
  939. + if (file->next)
  940. + fprintf(out, "\t%s \\\n", file->name);
  941. + else
  942. + fprintf(out, "\t%s\n", file->name);
  943. + }
  944. + fprintf(out, "\n%s: \\\n"
  945. + "\t$(deps_config)\n\n", conf_get_autoconfig_name());
  946. +
  947. + env_write_dep(out, conf_get_autoconfig_name());
  948. +
  949. + fprintf(out, "\n$(deps_config): ;\n");
  950. + fclose(out);
  951. +
  952. + if (make_parent_dir(name))
  953. + return 1;
  954. + rename("..config.tmp", name);
  955. + return 0;
  956. +}
  957. +
  958. +static int conf_touch_deps(void)
  959. {
  960. const char *name;
  961. - char path[PATH_MAX+1];
  962. - char *s, *d, c;
  963. struct symbol *sym;
  964. - struct stat sb;
  965. - int res, i, fd;
  966. + int res, i;
  967. +
  968. + strcpy(depfile_path, "include/generated/");
  969. + depfile_prefix_len = strlen(depfile_path);
  970. name = conf_get_autoconfig_name();
  971. conf_read_simple(name, S_DEF_AUTO);
  972. sym_calc_value(modules_sym);
  973. - if (chdir("include/generated"))
  974. - return 1;
  975. -
  976. - res = 0;
  977. for_all_symbols(i, sym) {
  978. sym_calc_value(sym);
  979. - if ((sym->flags & SYMBOL_AUTO) || !sym->name)
  980. + if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name)
  981. continue;
  982. if (sym->flags & SYMBOL_WRITE) {
  983. if (sym->flags & SYMBOL_DEF_AUTO) {
  984. @@ -952,63 +1053,30 @@ static int conf_split_config(void)
  985. * different from 'no').
  986. */
  987. - /* Replace all '_' and append ".h" */
  988. - s = sym->name;
  989. - d = path;
  990. - while ((c = *s++)) {
  991. - c = tolower(c);
  992. - *d++ = (c == '_') ? '/' : c;
  993. - }
  994. - strcpy(d, ".h");
  995. -
  996. - /* Assume directory path already exists. */
  997. - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  998. - if (fd == -1) {
  999. - if (errno != ENOENT) {
  1000. - res = 1;
  1001. - break;
  1002. - }
  1003. - /*
  1004. - * Create directory components,
  1005. - * unless they exist already.
  1006. - */
  1007. - d = path;
  1008. - while ((d = strchr(d, '/'))) {
  1009. - *d = 0;
  1010. - if (stat(path, &sb) && mkdir(path, 0755)) {
  1011. - res = 1;
  1012. - goto out;
  1013. - }
  1014. - *d++ = '/';
  1015. - }
  1016. - /* Try it again. */
  1017. - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  1018. - if (fd == -1) {
  1019. - res = 1;
  1020. - break;
  1021. - }
  1022. - }
  1023. - close(fd);
  1024. + res = conf_touch_dep(sym->name);
  1025. + if (res)
  1026. + return res;
  1027. }
  1028. -out:
  1029. - if (chdir("../.."))
  1030. - return 1;
  1031. - return res;
  1032. + return 0;
  1033. }
  1034. -int conf_write_autoconf(void)
  1035. +int conf_write_autoconf(int overwrite)
  1036. {
  1037. struct symbol *sym;
  1038. const char *name;
  1039. + const char *autoconf_name = conf_get_autoconfig_name();
  1040. FILE *out, *tristate, *out_h, *out_c;
  1041. int i;
  1042. + if (!overwrite && is_present(autoconf_name))
  1043. + return 0;
  1044. +
  1045. sym_clear_all_valid();
  1046. - file_write_dep("include/generated/auto.conf.cmd");
  1047. + conf_write_dep("include/generated/auto.conf.cmd");
  1048. - if (conf_split_config())
  1049. + if (conf_touch_deps())
  1050. return 1;
  1051. out = fopen(".tmpconfig", "w");
  1052. @@ -1065,24 +1133,35 @@ int conf_write_autoconf(void)
  1053. name = getenv("KCONFIG_AUTOHEADER");
  1054. if (!name)
  1055. name = "include/generated/autoconf.h";
  1056. + if (make_parent_dir(name))
  1057. + return 1;
  1058. if (rename(".tmpconfig.h", name))
  1059. return 1;
  1060. +
  1061. name = getenv("KCONFIG_TRISTATE");
  1062. if (!name)
  1063. name = "include/generated/tristate.conf";
  1064. + if (make_parent_dir(name))
  1065. + return 1;
  1066. if (rename(".tmpconfig_tristate", name))
  1067. return 1;
  1068. +
  1069. + if (make_parent_dir(autoconf_name))
  1070. + return 1;
  1071. +
  1072. name = getenv("KCONFIG_CMAKE");
  1073. if (!name)
  1074. name = "config.cmake";
  1075. + if (make_parent_dir(name))
  1076. + return 1;
  1077. if (rename(".tmpconfig.cmake", name))
  1078. return 1;
  1079. - name = conf_get_autoconfig_name();
  1080. +
  1081. /*
  1082. * This must be the last step, kbuild has a dependency on auto.conf
  1083. * and this marks the successful completion of the previous steps.
  1084. */
  1085. - if (rename(".tmpconfig", name))
  1086. + if (rename(".tmpconfig", autoconf_name))
  1087. return 1;
  1088. return 0;
  1089. @@ -1186,7 +1265,7 @@ void set_all_choice_values(struct symbol *csym)
  1090. bool conf_set_all_new_symbols(enum conf_def_mode mode)
  1091. {
  1092. struct symbol *sym, *csym;
  1093. - int i, cnt, pby, pty, ptm; /* pby: probability of boolean = y
  1094. + int i, cnt, pby, pty, ptm; /* pby: probability of bool = y
  1095. * pty: probability of tristate = y
  1096. * ptm: probability of tristate = m
  1097. */
  1098. diff --git a/carl9170fw/config/expr.c b/carl9170fw/config/expr.c
  1099. index 8cee597..77ffff3 100644
  1100. --- a/carl9170fw/config/expr.c
  1101. +++ b/carl9170fw/config/expr.c
  1102. @@ -1,8 +1,10 @@
  1103. +// SPDX-License-Identifier: GPL-2.0
  1104. /*
  1105. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  1106. - * Released under the terms of the GNU GPL v2.0.
  1107. */
  1108. +#include <ctype.h>
  1109. +#include <errno.h>
  1110. #include <stdio.h>
  1111. #include <stdlib.h>
  1112. #include <string.h>
  1113. @@ -94,7 +96,7 @@ struct expr *expr_copy(const struct expr *org)
  1114. e->right.expr = expr_copy(org->right.expr);
  1115. break;
  1116. default:
  1117. - printf("can't copy type %d\n", e->type);
  1118. + fprintf(stderr, "can't copy type %d\n", e->type);
  1119. free(e);
  1120. e = NULL;
  1121. break;
  1122. @@ -113,7 +115,7 @@ void expr_free(struct expr *e)
  1123. break;
  1124. case E_NOT:
  1125. expr_free(e->left.expr);
  1126. - return;
  1127. + break;
  1128. case E_EQUAL:
  1129. case E_GEQ:
  1130. case E_GTH:
  1131. @@ -127,7 +129,7 @@ void expr_free(struct expr *e)
  1132. expr_free(e->right.expr);
  1133. break;
  1134. default:
  1135. - printf("how to free type %d?\n", e->type);
  1136. + fprintf(stderr, "how to free type %d?\n", e->type);
  1137. break;
  1138. }
  1139. free(e);
  1140. @@ -138,8 +140,18 @@ static int trans_count;
  1141. #define e1 (*ep1)
  1142. #define e2 (*ep2)
  1143. +/*
  1144. + * expr_eliminate_eq() helper.
  1145. + *
  1146. + * Walks the two expression trees given in 'ep1' and 'ep2'. Any node that does
  1147. + * not have type 'type' (E_OR/E_AND) is considered a leaf, and is compared
  1148. + * against all other leaves. Two equal leaves are both replaced with either 'y'
  1149. + * or 'n' as appropriate for 'type', to be eliminated later.
  1150. + */
  1151. static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct expr **ep2)
  1152. {
  1153. + /* Recurse down to leaves */
  1154. +
  1155. if (e1->type == type) {
  1156. __expr_eliminate_eq(type, &e1->left.expr, &e2);
  1157. __expr_eliminate_eq(type, &e1->right.expr, &e2);
  1158. @@ -150,12 +162,18 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e
  1159. __expr_eliminate_eq(type, &e1, &e2->right.expr);
  1160. return;
  1161. }
  1162. +
  1163. + /* e1 and e2 are leaves. Compare them. */
  1164. +
  1165. if (e1->type == E_SYMBOL && e2->type == E_SYMBOL &&
  1166. e1->left.sym == e2->left.sym &&
  1167. (e1->left.sym == &symbol_yes || e1->left.sym == &symbol_no))
  1168. return;
  1169. if (!expr_eq(e1, e2))
  1170. return;
  1171. +
  1172. + /* e1 and e2 are equal leaves. Prepare them for elimination. */
  1173. +
  1174. trans_count++;
  1175. expr_free(e1); expr_free(e2);
  1176. switch (type) {
  1177. @@ -172,6 +190,35 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e
  1178. }
  1179. }
  1180. +/*
  1181. + * Rewrites the expressions 'ep1' and 'ep2' to remove operands common to both.
  1182. + * Example reductions:
  1183. + *
  1184. + * ep1: A && B -> ep1: y
  1185. + * ep2: A && B && C -> ep2: C
  1186. + *
  1187. + * ep1: A || B -> ep1: n
  1188. + * ep2: A || B || C -> ep2: C
  1189. + *
  1190. + * ep1: A && (B && FOO) -> ep1: FOO
  1191. + * ep2: (BAR && B) && A -> ep2: BAR
  1192. + *
  1193. + * ep1: A && (B || C) -> ep1: y
  1194. + * ep2: (C || B) && A -> ep2: y
  1195. + *
  1196. + * Comparisons are done between all operands at the same "level" of && or ||.
  1197. + * For example, in the expression 'e1 && (e2 || e3) && (e4 || e5)', the
  1198. + * following operands will be compared:
  1199. + *
  1200. + * - 'e1', 'e2 || e3', and 'e4 || e5', against each other
  1201. + * - e2 against e3
  1202. + * - e4 against e5
  1203. + *
  1204. + * Parentheses are irrelevant within a single level. 'e1 && (e2 && e3)' and
  1205. + * '(e1 && e2) && e3' are both a single level.
  1206. + *
  1207. + * See __expr_eliminate_eq() as well.
  1208. + */
  1209. void expr_eliminate_eq(struct expr **ep1, struct expr **ep2)
  1210. {
  1211. if (!e1 || !e2)
  1212. @@ -197,6 +244,12 @@ void expr_eliminate_eq(struct expr **ep1, struct expr **ep2)
  1213. #undef e1
  1214. #undef e2
  1215. +/*
  1216. + * Returns true if 'e1' and 'e2' are equal, after minor simplification. Two
  1217. + * &&/|| expressions are considered equal if every operand in one expression
  1218. + * equals some operand in the other (operands do not need to appear in the same
  1219. + * order), recursively.
  1220. + */
  1221. static int expr_eq(struct expr *e1, struct expr *e2)
  1222. {
  1223. int res, old_count;
  1224. @@ -243,6 +296,17 @@ static int expr_eq(struct expr *e1, struct expr *e2)
  1225. return 0;
  1226. }
  1227. +/*
  1228. + * Recursively performs the following simplifications in-place (as well as the
  1229. + * corresponding simplifications with swapped operands):
  1230. + *
  1231. + * expr && n -> n
  1232. + * expr && y -> expr
  1233. + * expr || n -> expr
  1234. + * expr || y -> y
  1235. + *
  1236. + * Returns the optimized expression.
  1237. + */
  1238. static struct expr *expr_eliminate_yn(struct expr *e)
  1239. {
  1240. struct expr *tmp;
  1241. @@ -516,12 +580,21 @@ static struct expr *expr_join_and(struct expr *e1, struct expr *e2)
  1242. return NULL;
  1243. }
  1244. +/*
  1245. + * expr_eliminate_dups() helper.
  1246. + *
  1247. + * Walks the two expression trees given in 'ep1' and 'ep2'. Any node that does
  1248. + * not have type 'type' (E_OR/E_AND) is considered a leaf, and is compared
  1249. + * against all other leaves to look for simplifications.
  1250. + */
  1251. static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct expr **ep2)
  1252. {
  1253. #define e1 (*ep1)
  1254. #define e2 (*ep2)
  1255. struct expr *tmp;
  1256. + /* Recurse down to leaves */
  1257. +
  1258. if (e1->type == type) {
  1259. expr_eliminate_dups1(type, &e1->left.expr, &e2);
  1260. expr_eliminate_dups1(type, &e1->right.expr, &e2);
  1261. @@ -532,6 +605,9 @@ static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct
  1262. expr_eliminate_dups1(type, &e1, &e2->right.expr);
  1263. return;
  1264. }
  1265. +
  1266. + /* e1 and e2 are leaves. Compare and process them. */
  1267. +
  1268. if (e1 == e2)
  1269. return;
  1270. @@ -568,6 +644,17 @@ static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct
  1271. #undef e2
  1272. }
  1273. +/*
  1274. + * Rewrites 'e' in-place to remove ("join") duplicate and other redundant
  1275. + * operands.
  1276. + *
  1277. + * Example simplifications:
  1278. + *
  1279. + * A || B || A -> A || B
  1280. + * A && B && A=y -> A=y && B
  1281. + *
  1282. + * Returns the deduplicated expression.
  1283. + */
  1284. struct expr *expr_eliminate_dups(struct expr *e)
  1285. {
  1286. int oldcount;
  1287. @@ -584,6 +671,7 @@ struct expr *expr_eliminate_dups(struct expr *e)
  1288. ;
  1289. }
  1290. if (!trans_count)
  1291. + /* No simplifications done in this pass. We're done */
  1292. break;
  1293. e = expr_eliminate_yn(e);
  1294. }
  1295. @@ -591,6 +679,12 @@ struct expr *expr_eliminate_dups(struct expr *e)
  1296. return e;
  1297. }
  1298. +/*
  1299. + * Performs various simplifications involving logical operators and
  1300. + * comparisons.
  1301. + *
  1302. + * Allocates and returns a new expression.
  1303. + */
  1304. struct expr *expr_transform(struct expr *e)
  1305. {
  1306. struct expr *tmp;
  1307. @@ -805,6 +899,20 @@ bool expr_depends_symbol(struct expr *dep, struct symbol *sym)
  1308. return false;
  1309. }
  1310. +/*
  1311. + * Inserts explicit comparisons of type 'type' to symbol 'sym' into the
  1312. + * expression 'e'.
  1313. + *
  1314. + * Examples transformations for type == E_UNEQUAL, sym == &symbol_no:
  1315. + *
  1316. + * A -> A!=n
  1317. + * !A -> A=n
  1318. + * A && B -> !(A=n || B=n)
  1319. + * A || B -> !(A=n && B=n)
  1320. + * A && (B || C) -> !(A=n || (B=n && C=n))
  1321. + *
  1322. + * Allocates and returns a new expression.
  1323. + */
  1324. struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym)
  1325. {
  1326. struct expr *e1, *e2;
  1327. @@ -874,7 +982,6 @@ enum string_value_kind {
  1328. k_string,
  1329. k_signed,
  1330. k_unsigned,
  1331. - k_invalid
  1332. };
  1333. union string_value {
  1334. @@ -905,13 +1012,10 @@ static enum string_value_kind expr_parse_string(const char *str,
  1335. val->u = strtoull(str, &tail, 16);
  1336. kind = k_unsigned;
  1337. break;
  1338. - case S_STRING:
  1339. - case S_UNKNOWN:
  1340. + default:
  1341. val->s = strtoll(str, &tail, 0);
  1342. kind = k_signed;
  1343. break;
  1344. - default:
  1345. - return k_invalid;
  1346. }
  1347. return !errno && !*tail && tail > str && isxdigit(tail[-1])
  1348. ? kind : k_string;
  1349. @@ -967,13 +1071,7 @@ tristate expr_calc_value(struct expr *e)
  1350. if (k1 == k_string || k2 == k_string)
  1351. res = strcmp(str1, str2);
  1352. - else if (k1 == k_invalid || k2 == k_invalid) {
  1353. - if (e->type != E_EQUAL && e->type != E_UNEQUAL) {
  1354. - printf("Cannot compare \"%s\" and \"%s\"\n", str1, str2);
  1355. - return no;
  1356. - }
  1357. - res = strcmp(str1, str2);
  1358. - } else if (k1 == k_unsigned || k2 == k_unsigned)
  1359. + else if (k1 == k_unsigned || k2 == k_unsigned)
  1360. res = (lval.u > rval.u) - (lval.u < rval.u);
  1361. else /* if (k1 == k_signed && k2 == k_signed) */
  1362. res = (lval.s > rval.s) - (lval.s < rval.s);
  1363. @@ -1031,49 +1129,9 @@ static int expr_compare_type(enum expr_type t1, enum expr_type t2)
  1364. return 0;
  1365. }
  1366. -static inline struct expr *
  1367. -expr_get_leftmost_symbol(const struct expr *e)
  1368. -{
  1369. -
  1370. - if (e == NULL)
  1371. - return NULL;
  1372. -
  1373. - while (e->type != E_SYMBOL)
  1374. - e = e->left.expr;
  1375. -
  1376. - return expr_copy(e);
  1377. -}
  1378. -
  1379. -/*
  1380. - * Given expression `e1' and `e2', returns the leaf of the longest
  1381. - * sub-expression of `e1' not containing 'e2.
  1382. - */
  1383. -struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2)
  1384. -{
  1385. - struct expr *ret;
  1386. -
  1387. - switch (e1->type) {
  1388. - case E_OR:
  1389. - return expr_alloc_and(
  1390. - expr_simplify_unmet_dep(e1->left.expr, e2),
  1391. - expr_simplify_unmet_dep(e1->right.expr, e2));
  1392. - case E_AND: {
  1393. - struct expr *e;
  1394. - e = expr_alloc_and(expr_copy(e1), expr_copy(e2));
  1395. - e = expr_eliminate_dups(e);
  1396. - ret = (!expr_eq(e, e1)) ? e1 : NULL;
  1397. - expr_free(e);
  1398. - break;
  1399. - }
  1400. - default:
  1401. - ret = e1;
  1402. - break;
  1403. - }
  1404. -
  1405. - return expr_get_leftmost_symbol(ret);
  1406. -}
  1407. -
  1408. -void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken)
  1409. +void expr_print(struct expr *e,
  1410. + void (*fn)(void *, struct symbol *, const char *),
  1411. + void *data, int prevtoken)
  1412. {
  1413. if (!e) {
  1414. fn(data, NULL, "y");
  1415. @@ -1207,3 +1265,33 @@ void expr_gstr_print(struct expr *e, struct gstr *gs)
  1416. {
  1417. expr_print(e, expr_print_gstr_helper, gs, E_NONE);
  1418. }
  1419. +
  1420. +/*
  1421. + * Transform the top level "||" tokens into newlines and prepend each
  1422. + * line with a minus. This makes expressions much easier to read.
  1423. + * Suitable for reverse dependency expressions.
  1424. + */
  1425. +static void expr_print_revdep(struct expr *e,
  1426. + void (*fn)(void *, struct symbol *, const char *),
  1427. + void *data, tristate pr_type, const char **title)
  1428. +{
  1429. + if (e->type == E_OR) {
  1430. + expr_print_revdep(e->left.expr, fn, data, pr_type, title);
  1431. + expr_print_revdep(e->right.expr, fn, data, pr_type, title);
  1432. + } else if (expr_calc_value(e) == pr_type) {
  1433. + if (*title) {
  1434. + fn(data, NULL, *title);
  1435. + *title = NULL;
  1436. + }
  1437. +
  1438. + fn(data, NULL, " - ");
  1439. + expr_print(e, fn, data, E_NONE);
  1440. + fn(data, NULL, "\n");
  1441. + }
  1442. +}
  1443. +
  1444. +void expr_gstr_print_revdep(struct expr *e, struct gstr *gs,
  1445. + tristate pr_type, const char *title)
  1446. +{
  1447. + expr_print_revdep(e, expr_print_gstr_helper, gs, pr_type, &title);
  1448. +}
  1449. diff --git a/carl9170fw/config/expr.h b/carl9170fw/config/expr.h
  1450. index a73f762..999edb6 100644
  1451. --- a/carl9170fw/config/expr.h
  1452. +++ b/carl9170fw/config/expr.h
  1453. @@ -1,6 +1,6 @@
  1454. +/* SPDX-License-Identifier: GPL-2.0 */
  1455. /*
  1456. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  1457. - * Released under the terms of the GNU GPL v2.0.
  1458. */
  1459. #ifndef EXPR_H
  1460. @@ -62,7 +62,7 @@ struct symbol_value {
  1461. };
  1462. enum symbol_type {
  1463. - S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER
  1464. + S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING
  1465. };
  1466. /* enum values are used as index to symbol.def[] */
  1467. @@ -74,21 +74,64 @@ enum {
  1468. S_DEF_COUNT
  1469. };
  1470. +/*
  1471. + * Represents a configuration symbol.
  1472. + *
  1473. + * Choices are represented as a special kind of symbol and have the
  1474. + * SYMBOL_CHOICE bit set in 'flags'.
  1475. + */
  1476. struct symbol {
  1477. + /* The next symbol in the same bucket in the symbol hash table */
  1478. struct symbol *next;
  1479. +
  1480. + /* The name of the symbol, e.g. "FOO" for 'config FOO' */
  1481. char *name;
  1482. +
  1483. + /* S_BOOLEAN, S_TRISTATE, ... */
  1484. enum symbol_type type;
  1485. +
  1486. + /*
  1487. + * The calculated value of the symbol. The SYMBOL_VALID bit is set in
  1488. + * 'flags' when this is up to date. Note that this value might differ
  1489. + * from the user value set in e.g. a .config file, due to visibility.
  1490. + */
  1491. struct symbol_value curr;
  1492. +
  1493. + /*
  1494. + * Values for the symbol provided from outside. def[S_DEF_USER] holds
  1495. + * the .config value.
  1496. + */
  1497. struct symbol_value def[S_DEF_COUNT];
  1498. +
  1499. + /*
  1500. + * An upper bound on the tristate value the user can set for the symbol
  1501. + * if it is a boolean or tristate. Calculated from prompt dependencies,
  1502. + * which also inherit dependencies from enclosing menus, choices, and
  1503. + * ifs. If 'n', the user value will be ignored.
  1504. + *
  1505. + * Symbols lacking prompts always have visibility 'n'.
  1506. + */
  1507. tristate visible;
  1508. +
  1509. + /* SYMBOL_* flags */
  1510. int flags;
  1511. +
  1512. + /* List of properties. See prop_type. */
  1513. struct property *prop;
  1514. +
  1515. + /* Dependencies from enclosing menus, choices, and ifs */
  1516. struct expr_value dir_dep;
  1517. +
  1518. + /* Reverse dependencies through being selected by other symbols */
  1519. struct expr_value rev_dep;
  1520. +
  1521. + /*
  1522. + * "Weak" reverse dependencies through being implied by other symbols
  1523. + */
  1524. struct expr_value implied;
  1525. };
  1526. -#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER)
  1527. +#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next)
  1528. #define SYMBOL_CONST 0x0001 /* symbol is const */
  1529. #define SYMBOL_CHECK 0x0008 /* used during dependency checking */
  1530. @@ -98,7 +141,7 @@ struct symbol {
  1531. #define SYMBOL_OPTIONAL 0x0100 /* choice is optional - values can be 'n' */
  1532. #define SYMBOL_WRITE 0x0200 /* write symbol to file (KCONFIG_CONFIG) */
  1533. #define SYMBOL_CHANGED 0x0400 /* ? */
  1534. -#define SYMBOL_AUTO 0x1000 /* value from environment variable */
  1535. +#define SYMBOL_NO_WRITE 0x1000 /* Symbol for internal use only; it will not be written */
  1536. #define SYMBOL_CHECKED 0x2000 /* used during dependency checking */
  1537. #define SYMBOL_WARNED 0x8000 /* warning has been issued */
  1538. @@ -128,18 +171,20 @@ struct symbol {
  1539. * config BAZ
  1540. * int "BAZ Value"
  1541. * range 1..255
  1542. + *
  1543. + * Please, also check zconf.y:print_symbol() when modifying the
  1544. + * list of property types!
  1545. */
  1546. enum prop_type {
  1547. P_UNKNOWN,
  1548. P_PROMPT, /* prompt "foo prompt" or "BAZ Value" */
  1549. P_COMMENT, /* text associated with a comment */
  1550. - P_MENU, /* prompt associated with a menuconfig option */
  1551. + P_MENU, /* prompt associated with a menu or menuconfig symbol */
  1552. P_DEFAULT, /* default y */
  1553. P_CHOICE, /* choice value */
  1554. P_SELECT, /* select BAR */
  1555. P_IMPLY, /* imply BAR */
  1556. P_RANGE, /* range 7..100 (for a symbol) */
  1557. - P_ENV, /* value from environment variable */
  1558. P_SYMBOL, /* where a symbol is defined */
  1559. };
  1560. @@ -166,22 +211,67 @@ struct property {
  1561. for (st = sym->prop; st; st = st->next) \
  1562. if (st->text)
  1563. +/*
  1564. + * Represents a node in the menu tree, as seen in e.g. menuconfig (though used
  1565. + * for all front ends). Each symbol, menu, etc. defined in the Kconfig files
  1566. + * gets a node. A symbol defined in multiple locations gets one node at each
  1567. + * location.
  1568. + */
  1569. struct menu {
  1570. + /* The next menu node at the same level */
  1571. struct menu *next;
  1572. +
  1573. + /* The parent menu node, corresponding to e.g. a menu or choice */
  1574. struct menu *parent;
  1575. +
  1576. + /* The first child menu node, for e.g. menus and choices */
  1577. struct menu *list;
  1578. +
  1579. + /*
  1580. + * The symbol associated with the menu node. Choices are implemented as
  1581. + * a special kind of symbol. NULL for menus, comments, and ifs.
  1582. + */
  1583. struct symbol *sym;
  1584. +
  1585. + /*
  1586. + * The prompt associated with the node. This holds the prompt for a
  1587. + * symbol as well as the text for a menu or comment, along with the
  1588. + * type (P_PROMPT, P_MENU, etc.)
  1589. + */
  1590. struct property *prompt;
  1591. +
  1592. + /*
  1593. + * 'visible if' dependencies. If more than one is given, they will be
  1594. + * ANDed together.
  1595. + */
  1596. struct expr *visibility;
  1597. +
  1598. + /*
  1599. + * Ordinary dependencies from e.g. 'depends on' and 'if', ANDed
  1600. + * together
  1601. + */
  1602. struct expr *dep;
  1603. +
  1604. + /* MENU_* flags */
  1605. unsigned int flags;
  1606. +
  1607. + /* Any help text associated with the node */
  1608. char *help;
  1609. +
  1610. + /* The location where the menu node appears in the Kconfig files */
  1611. struct file *file;
  1612. int lineno;
  1613. +
  1614. + /* For use by front ends that need to store auxiliary data */
  1615. void *data;
  1616. };
  1617. +/*
  1618. + * Set on a menu node when the corresponding symbol changes state in some way.
  1619. + * Can be checked by front ends.
  1620. + */
  1621. #define MENU_CHANGED 0x0001
  1622. +
  1623. #define MENU_ROOT 0x0002
  1624. struct jump_key {
  1625. @@ -217,11 +307,12 @@ struct expr *expr_transform(struct expr *e);
  1626. int expr_contains_symbol(struct expr *dep, struct symbol *sym);
  1627. bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
  1628. struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
  1629. -struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2);
  1630. void expr_fprint(struct expr *e, FILE *out);
  1631. struct gstr; /* forward */
  1632. void expr_gstr_print(struct expr *e, struct gstr *gs);
  1633. +void expr_gstr_print_revdep(struct expr *e, struct gstr *gs,
  1634. + tristate pr_type, const char *title);
  1635. static inline int expr_is_yes(struct expr *e)
  1636. {
  1637. diff --git a/carl9170fw/config/kconf_id.c b/carl9170fw/config/kconf_id.c
  1638. deleted file mode 100644
  1639. index 5abbc72..0000000
  1640. --- a/carl9170fw/config/kconf_id.c
  1641. +++ /dev/null
  1642. @@ -1,54 +0,0 @@
  1643. -
  1644. -static struct kconf_id kconf_id_array[] = {
  1645. - { "mainmenu", T_MAINMENU, TF_COMMAND },
  1646. - { "menu", T_MENU, TF_COMMAND },
  1647. - { "endmenu", T_ENDMENU, TF_COMMAND },
  1648. - { "source", T_SOURCE, TF_COMMAND },
  1649. - { "choice", T_CHOICE, TF_COMMAND },
  1650. - { "endchoice", T_ENDCHOICE, TF_COMMAND },
  1651. - { "comment", T_COMMENT, TF_COMMAND },
  1652. - { "config", T_CONFIG, TF_COMMAND },
  1653. - { "menuconfig", T_MENUCONFIG, TF_COMMAND },
  1654. - { "help", T_HELP, TF_COMMAND },
  1655. - { "---help---", T_HELP, TF_COMMAND },
  1656. - { "if", T_IF, TF_COMMAND|TF_PARAM },
  1657. - { "endif", T_ENDIF, TF_COMMAND },
  1658. - { "depends", T_DEPENDS, TF_COMMAND },
  1659. - { "optional", T_OPTIONAL, TF_COMMAND },
  1660. - { "default", T_DEFAULT, TF_COMMAND, S_UNKNOWN },
  1661. - { "prompt", T_PROMPT, TF_COMMAND },
  1662. - { "tristate", T_TYPE, TF_COMMAND, S_TRISTATE },
  1663. - { "def_tristate", T_DEFAULT, TF_COMMAND, S_TRISTATE },
  1664. - { "bool", T_TYPE, TF_COMMAND, S_BOOLEAN },
  1665. - { "boolean", T_TYPE, TF_COMMAND, S_BOOLEAN },
  1666. - { "def_bool", T_DEFAULT, TF_COMMAND, S_BOOLEAN },
  1667. - { "int", T_TYPE, TF_COMMAND, S_INT },
  1668. - { "hex", T_TYPE, TF_COMMAND, S_HEX },
  1669. - { "string", T_TYPE, TF_COMMAND, S_STRING },
  1670. - { "select", T_SELECT, TF_COMMAND },
  1671. - { "imply", T_IMPLY, TF_COMMAND },
  1672. - { "range", T_RANGE, TF_COMMAND },
  1673. - { "visible", T_VISIBLE, TF_COMMAND },
  1674. - { "option", T_OPTION, TF_COMMAND },
  1675. - { "on", T_ON, TF_PARAM },
  1676. - { "modules", T_OPT_MODULES, TF_OPTION },
  1677. - { "defconfig_list", T_OPT_DEFCONFIG_LIST, TF_OPTION },
  1678. - { "env", T_OPT_ENV, TF_OPTION },
  1679. - { "allnoconfig_y", T_OPT_ALLNOCONFIG_Y, TF_OPTION },
  1680. -};
  1681. -
  1682. -#define KCONF_ID_ARRAY_SIZE (sizeof(kconf_id_array)/sizeof(struct kconf_id))
  1683. -
  1684. -static const struct kconf_id *kconf_id_lookup(register const char *str, register unsigned int len)
  1685. -{
  1686. - int i;
  1687. -
  1688. - for (i = 0; i < KCONF_ID_ARRAY_SIZE; i++) {
  1689. - struct kconf_id *id = kconf_id_array+i;
  1690. - int l = strlen(id->name);
  1691. -
  1692. - if (len == l && !memcmp(str, id->name, len))
  1693. - return id;
  1694. - }
  1695. - return NULL;
  1696. -}
  1697. diff --git a/carl9170fw/config/lkc.h b/carl9170fw/config/lkc.h
  1698. index cdcbe43..531ff7c 100644
  1699. --- a/carl9170fw/config/lkc.h
  1700. +++ b/carl9170fw/config/lkc.h
  1701. @@ -1,6 +1,6 @@
  1702. +/* SPDX-License-Identifier: GPL-2.0 */
  1703. /*
  1704. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  1705. - * Released under the terms of the GNU GPL v2.0.
  1706. */
  1707. #ifndef LKC_H
  1708. @@ -8,15 +8,6 @@
  1709. #include "expr.h"
  1710. -#ifndef KBUILD_NO_NLS
  1711. -# include <libintl.h>
  1712. -#else
  1713. -static inline const char *gettext(const char *txt) { return txt; }
  1714. -static inline void textdomain(const char *domainname) {}
  1715. -static inline void bindtextdomain(const char *name, const char *dir) {}
  1716. -static inline char *bind_textdomain_codeset(const char *dn, char *c) { return c; }
  1717. -#endif
  1718. -
  1719. #ifdef __cplusplus
  1720. extern "C" {
  1721. #endif
  1722. @@ -29,11 +20,6 @@ extern "C" {
  1723. #define PACKAGE "linux"
  1724. #endif
  1725. -#define LOCALEDIR "/usr/share/locale"
  1726. -
  1727. -#define _(text) gettext(text)
  1728. -#define N_(text) (text)
  1729. -
  1730. #ifndef CONFIG_
  1731. #define CONFIG_ "CONFIG_"
  1732. #endif
  1733. @@ -44,10 +30,6 @@ static inline const char *CONFIG_prefix(void)
  1734. #undef CONFIG_
  1735. #define CONFIG_ CONFIG_prefix()
  1736. -#define TF_COMMAND 0x0001
  1737. -#define TF_PARAM 0x0002
  1738. -#define TF_OPTION 0x0004
  1739. -
  1740. enum conf_def_mode {
  1741. def_default,
  1742. def_yes,
  1743. @@ -56,18 +38,7 @@ enum conf_def_mode {
  1744. def_random
  1745. };
  1746. -#define T_OPT_MODULES 1
  1747. -#define T_OPT_DEFCONFIG_LIST 2
  1748. -#define T_OPT_ENV 3
  1749. -#define T_OPT_ALLNOCONFIG_Y 4
  1750. -
  1751. -struct kconf_id {
  1752. - const char *name;
  1753. - int token;
  1754. - unsigned int flags;
  1755. - enum symbol_type stype;
  1756. -};
  1757. -
  1758. +extern int yylineno;
  1759. void zconfdump(FILE *out);
  1760. void zconf_starthelp(void);
  1761. FILE *zconf_fopen(const char *name);
  1762. @@ -100,21 +71,27 @@ void menu_warn(struct menu *menu, const char *fmt, ...);
  1763. struct menu *menu_add_menu(void);
  1764. void menu_end_menu(void);
  1765. void menu_add_entry(struct symbol *sym);
  1766. -void menu_end_entry(void);
  1767. void menu_add_dep(struct expr *dep);
  1768. void menu_add_visibility(struct expr *dep);
  1769. struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
  1770. void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
  1771. void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
  1772. -void menu_add_option(int token, char *arg);
  1773. +void menu_add_option_modules(void);
  1774. +void menu_add_option_defconfig_list(void);
  1775. +void menu_add_option_allnoconfig_y(void);
  1776. void menu_finalize(struct menu *parent);
  1777. void menu_set_type(int type);
  1778. /* util.c */
  1779. struct file *file_lookup(const char *name);
  1780. -int file_write_dep(const char *name);
  1781. void *xmalloc(size_t size);
  1782. void *xcalloc(size_t nmemb, size_t size);
  1783. +void *xrealloc(void *p, size_t size);
  1784. +char *xstrdup(const char *s);
  1785. +char *xstrndup(const char *s, size_t n);
  1786. +
  1787. +/* zconf.l */
  1788. +int yylex(void);
  1789. struct gstr {
  1790. size_t len;
  1791. @@ -132,16 +109,13 @@ void str_printf(struct gstr *gs, const char *fmt, ...);
  1792. const char *str_get(struct gstr *gs);
  1793. /* symbol.c */
  1794. -extern struct expr *sym_env_list;
  1795. -
  1796. -void sym_init(void);
  1797. void sym_clear_all_valid(void);
  1798. struct symbol *sym_choice_default(struct symbol *sym);
  1799. +struct property *sym_get_range_prop(struct symbol *sym);
  1800. const char *sym_get_string_default(struct symbol *sym);
  1801. struct symbol *sym_check_deps(struct symbol *sym);
  1802. struct property *prop_alloc(enum prop_type type, struct symbol *sym);
  1803. struct symbol *prop_get_symbol(struct property *prop);
  1804. -struct property *sym_get_env_prop(struct symbol *sym);
  1805. static inline tristate sym_get_tristate_value(struct symbol *sym)
  1806. {
  1807. diff --git a/carl9170fw/config/lkc_proto.h b/carl9170fw/config/lkc_proto.h
  1808. index 5d86e2d..86c2675 100644
  1809. --- a/carl9170fw/config/lkc_proto.h
  1810. +++ b/carl9170fw/config/lkc_proto.h
  1811. @@ -7,10 +7,10 @@ int conf_read(const char *name);
  1812. int conf_read_simple(const char *name, int);
  1813. int conf_write_defconfig(const char *name);
  1814. int conf_write(const char *name);
  1815. -int conf_write_autoconf(void);
  1816. +int conf_write_autoconf(int overwrite);
  1817. bool conf_get_changed(void);
  1818. void conf_set_changed_callback(void (*fn)(void));
  1819. -void conf_set_message_callback(void (*fn)(const char *fmt, va_list ap));
  1820. +void conf_set_message_callback(void (*fn)(const char *s));
  1821. /* menu.c */
  1822. extern struct menu rootmenu;
  1823. @@ -31,7 +31,6 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE];
  1824. struct symbol * sym_lookup(const char *name, int flags);
  1825. struct symbol * sym_find(const char *name);
  1826. -const char * sym_expand_string_value(const char *in);
  1827. const char * sym_escape_string_value(const char *in);
  1828. struct symbol ** sym_re_search(const char *pattern);
  1829. const char * sym_type_name(enum symbol_type type);
  1830. @@ -49,5 +48,19 @@ const char * sym_get_string_value(struct symbol *sym);
  1831. const char * prop_get_type_name(enum prop_type type);
  1832. +/* preprocess.c */
  1833. +enum variable_flavor {
  1834. + VAR_SIMPLE,
  1835. + VAR_RECURSIVE,
  1836. + VAR_APPEND,
  1837. +};
  1838. +void env_write_dep(FILE *f, const char *auto_conf_name);
  1839. +void variable_add(const char *name, const char *value,
  1840. + enum variable_flavor flavor);
  1841. +void variable_all_del(void);
  1842. +char *expand_string(const char *in);
  1843. +char *expand_dollar(const char **str);
  1844. +char *expand_one_token(const char **str);
  1845. +
  1846. /* expr.c */
  1847. void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken);
  1848. diff --git a/carl9170fw/config/menu.c b/carl9170fw/config/menu.c
  1849. index e935793..d9d1646 100644
  1850. --- a/carl9170fw/config/menu.c
  1851. +++ b/carl9170fw/config/menu.c
  1852. @@ -1,6 +1,6 @@
  1853. +// SPDX-License-Identifier: GPL-2.0
  1854. /*
  1855. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  1856. - * Released under the terms of the GNU GPL v2.0.
  1857. */
  1858. #include <ctype.h>
  1859. @@ -62,13 +62,8 @@ void menu_add_entry(struct symbol *sym)
  1860. menu_add_symbol(P_SYMBOL, sym, NULL);
  1861. }
  1862. -void menu_end_entry(void)
  1863. -{
  1864. -}
  1865. -
  1866. struct menu *menu_add_menu(void)
  1867. {
  1868. - menu_end_entry();
  1869. last_entry_ptr = &current_entry->list;
  1870. return current_menu = current_entry;
  1871. }
  1872. @@ -79,19 +74,23 @@ void menu_end_menu(void)
  1873. current_menu = current_menu->parent;
  1874. }
  1875. -static struct expr *menu_check_dep(struct expr *e)
  1876. +/*
  1877. + * Rewrites 'm' to 'm' && MODULES, so that it evaluates to 'n' when running
  1878. + * without modules
  1879. + */
  1880. +static struct expr *rewrite_m(struct expr *e)
  1881. {
  1882. if (!e)
  1883. return e;
  1884. switch (e->type) {
  1885. case E_NOT:
  1886. - e->left.expr = menu_check_dep(e->left.expr);
  1887. + e->left.expr = rewrite_m(e->left.expr);
  1888. break;
  1889. case E_OR:
  1890. case E_AND:
  1891. - e->left.expr = menu_check_dep(e->left.expr);
  1892. - e->right.expr = menu_check_dep(e->right.expr);
  1893. + e->left.expr = rewrite_m(e->left.expr);
  1894. + e->right.expr = rewrite_m(e->right.expr);
  1895. break;
  1896. case E_SYMBOL:
  1897. /* change 'm' into 'm' && MODULES */
  1898. @@ -106,7 +105,7 @@ static struct expr *menu_check_dep(struct expr *e)
  1899. void menu_add_dep(struct expr *dep)
  1900. {
  1901. - current_entry->dep = expr_alloc_and(current_entry->dep, menu_check_dep(dep));
  1902. + current_entry->dep = expr_alloc_and(current_entry->dep, dep);
  1903. }
  1904. void menu_set_type(int type)
  1905. @@ -131,7 +130,7 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, struct
  1906. prop->menu = current_entry;
  1907. prop->expr = expr;
  1908. - prop->visible.expr = menu_check_dep(dep);
  1909. + prop->visible.expr = dep;
  1910. if (prompt) {
  1911. if (isspace(*prompt)) {
  1912. @@ -196,31 +195,26 @@ void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
  1913. menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
  1914. }
  1915. -void menu_add_option(int token, char *arg)
  1916. +void menu_add_option_modules(void)
  1917. {
  1918. - switch (token) {
  1919. - case T_OPT_MODULES:
  1920. - if (modules_sym)
  1921. - zconf_error("symbol '%s' redefines option 'modules'"
  1922. - " already defined by symbol '%s'",
  1923. - current_entry->sym->name,
  1924. - modules_sym->name
  1925. - );
  1926. - modules_sym = current_entry->sym;
  1927. - break;
  1928. - case T_OPT_DEFCONFIG_LIST:
  1929. - if (!sym_defconfig_list)
  1930. - sym_defconfig_list = current_entry->sym;
  1931. - else if (sym_defconfig_list != current_entry->sym)
  1932. - zconf_error("trying to redefine defconfig symbol");
  1933. - break;
  1934. - case T_OPT_ENV:
  1935. - prop_add_env(arg);
  1936. - break;
  1937. - case T_OPT_ALLNOCONFIG_Y:
  1938. - current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y;
  1939. - break;
  1940. - }
  1941. + if (modules_sym)
  1942. + zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'",
  1943. + current_entry->sym->name, modules_sym->name);
  1944. + modules_sym = current_entry->sym;
  1945. +}
  1946. +
  1947. +void menu_add_option_defconfig_list(void)
  1948. +{
  1949. + if (!sym_defconfig_list)
  1950. + sym_defconfig_list = current_entry->sym;
  1951. + else if (sym_defconfig_list != current_entry->sym)
  1952. + zconf_error("trying to redefine defconfig symbol");
  1953. + sym_defconfig_list->flags |= SYMBOL_NO_WRITE;
  1954. +}
  1955. +
  1956. +void menu_add_option_allnoconfig_y(void)
  1957. +{
  1958. + current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y;
  1959. }
  1960. static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
  1961. @@ -252,6 +246,16 @@ static void sym_check_prop(struct symbol *sym)
  1962. "'%s': number is invalid",
  1963. sym->name);
  1964. }
  1965. + if (sym_is_choice(sym)) {
  1966. + struct property *choice_prop =
  1967. + sym_get_choice_prop(sym2);
  1968. +
  1969. + if (!choice_prop ||
  1970. + prop_get_symbol(choice_prop) != sym)
  1971. + prop_warn(prop,
  1972. + "choice default symbol '%s' is not contained in the choice",
  1973. + sym2->name);
  1974. + }
  1975. break;
  1976. case P_SELECT:
  1977. case P_IMPLY:
  1978. @@ -260,13 +264,13 @@ static void sym_check_prop(struct symbol *sym)
  1979. if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE)
  1980. prop_warn(prop,
  1981. "config symbol '%s' uses %s, but is "
  1982. - "not boolean or tristate", sym->name, use);
  1983. + "not bool or tristate", sym->name, use);
  1984. else if (sym2->type != S_UNKNOWN &&
  1985. sym2->type != S_BOOLEAN &&
  1986. sym2->type != S_TRISTATE)
  1987. prop_warn(prop,
  1988. "'%s' has wrong type. '%s' only "
  1989. - "accept arguments of boolean and "
  1990. + "accept arguments of bool and "
  1991. "tristate type", sym2->name, use);
  1992. break;
  1993. case P_RANGE:
  1994. @@ -292,6 +296,11 @@ void menu_finalize(struct menu *parent)
  1995. sym = parent->sym;
  1996. if (parent->list) {
  1997. + /*
  1998. + * This menu node has children. We (recursively) process them
  1999. + * and propagate parent dependencies before moving on.
  2000. + */
  2001. +
  2002. if (sym && sym_is_choice(sym)) {
  2003. if (sym->type == S_UNKNOWN) {
  2004. /* find the first choice value to find out choice type */
  2005. @@ -309,30 +318,83 @@ void menu_finalize(struct menu *parent)
  2006. if (menu->sym && menu->sym->type == S_UNKNOWN)
  2007. menu_set_type(sym->type);
  2008. }
  2009. +
  2010. + /*
  2011. + * Use the choice itself as the parent dependency of
  2012. + * the contained items. This turns the mode of the
  2013. + * choice into an upper bound on the visibility of the
  2014. + * choice value symbols.
  2015. + */
  2016. parentdep = expr_alloc_symbol(sym);
  2017. } else if (parent->prompt)
  2018. + /* Menu node for 'menu' */
  2019. parentdep = parent->prompt->visible.expr;
  2020. else
  2021. + /* Menu node for 'if' */
  2022. parentdep = parent->dep;
  2023. + /* For each child menu node... */
  2024. for (menu = parent->list; menu; menu = menu->next) {
  2025. - basedep = expr_transform(menu->dep);
  2026. + /*
  2027. + * Propagate parent dependencies to the child menu
  2028. + * node, also rewriting and simplifying expressions
  2029. + */
  2030. + basedep = rewrite_m(menu->dep);
  2031. + basedep = expr_transform(basedep);
  2032. basedep = expr_alloc_and(expr_copy(parentdep), basedep);
  2033. basedep = expr_eliminate_dups(basedep);
  2034. menu->dep = basedep;
  2035. +
  2036. if (menu->sym)
  2037. + /*
  2038. + * Note: For symbols, all prompts are included
  2039. + * too in the symbol's own property list
  2040. + */
  2041. prop = menu->sym->prop;
  2042. else
  2043. + /*
  2044. + * For non-symbol menu nodes, we just need to
  2045. + * handle the prompt
  2046. + */
  2047. prop = menu->prompt;
  2048. +
  2049. + /* For each property... */
  2050. for (; prop; prop = prop->next) {
  2051. if (prop->menu != menu)
  2052. + /*
  2053. + * Two possibilities:
  2054. + *
  2055. + * 1. The property lacks dependencies
  2056. + * and so isn't location-specific,
  2057. + * e.g. an 'option'
  2058. + *
  2059. + * 2. The property belongs to a symbol
  2060. + * defined in multiple locations and
  2061. + * is from some other location. It
  2062. + * will be handled there in that
  2063. + * case.
  2064. + *
  2065. + * Skip the property.
  2066. + */
  2067. continue;
  2068. - dep = expr_transform(prop->visible.expr);
  2069. +
  2070. + /*
  2071. + * Propagate parent dependencies to the
  2072. + * property's condition, rewriting and
  2073. + * simplifying expressions at the same time
  2074. + */
  2075. + dep = rewrite_m(prop->visible.expr);
  2076. + dep = expr_transform(dep);
  2077. dep = expr_alloc_and(expr_copy(basedep), dep);
  2078. dep = expr_eliminate_dups(dep);
  2079. if (menu->sym && menu->sym->type != S_TRISTATE)
  2080. dep = expr_trans_bool(dep);
  2081. prop->visible.expr = dep;
  2082. +
  2083. + /*
  2084. + * Handle selects and implies, which modify the
  2085. + * dependencies of the selected/implied symbol
  2086. + */
  2087. if (prop->type == P_SELECT) {
  2088. struct symbol *es = prop_get_symbol(prop);
  2089. es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr,
  2090. @@ -344,34 +406,81 @@ void menu_finalize(struct menu *parent)
  2091. }
  2092. }
  2093. }
  2094. +
  2095. + if (sym && sym_is_choice(sym))
  2096. + expr_free(parentdep);
  2097. +
  2098. + /*
  2099. + * Recursively process children in the same fashion before
  2100. + * moving on
  2101. + */
  2102. for (menu = parent->list; menu; menu = menu->next)
  2103. menu_finalize(menu);
  2104. } else if (sym) {
  2105. + /*
  2106. + * Automatic submenu creation. If sym is a symbol and A, B, C,
  2107. + * ... are consecutive items (symbols, menus, ifs, etc.) that
  2108. + * all depend on sym, then the following menu structure is
  2109. + * created:
  2110. + *
  2111. + * sym
  2112. + * +-A
  2113. + * +-B
  2114. + * +-C
  2115. + * ...
  2116. + *
  2117. + * This also works recursively, giving the following structure
  2118. + * if A is a symbol and B depends on A:
  2119. + *
  2120. + * sym
  2121. + * +-A
  2122. + * | +-B
  2123. + * +-C
  2124. + * ...
  2125. + */
  2126. +
  2127. basedep = parent->prompt ? parent->prompt->visible.expr : NULL;
  2128. basedep = expr_trans_compare(basedep, E_UNEQUAL, &symbol_no);
  2129. basedep = expr_eliminate_dups(expr_transform(basedep));
  2130. +
  2131. + /* Examine consecutive elements after sym */
  2132. last_menu = NULL;
  2133. for (menu = parent->next; menu; menu = menu->next) {
  2134. dep = menu->prompt ? menu->prompt->visible.expr : menu->dep;
  2135. if (!expr_contains_symbol(dep, sym))
  2136. + /* No dependency, quit */
  2137. break;
  2138. if (expr_depends_symbol(dep, sym))
  2139. + /* Absolute dependency, put in submenu */
  2140. goto next;
  2141. +
  2142. + /*
  2143. + * Also consider it a dependency on sym if our
  2144. + * dependencies contain sym and are a "superset" of
  2145. + * sym's dependencies, e.g. '(sym || Q) && R' when sym
  2146. + * depends on R.
  2147. + *
  2148. + * Note that 'R' might be from an enclosing menu or if,
  2149. + * making this a more common case than it might seem.
  2150. + */
  2151. dep = expr_trans_compare(dep, E_UNEQUAL, &symbol_no);
  2152. dep = expr_eliminate_dups(expr_transform(dep));
  2153. dep2 = expr_copy(basedep);
  2154. expr_eliminate_eq(&dep, &dep2);
  2155. expr_free(dep);
  2156. if (!expr_is_yes(dep2)) {
  2157. + /* Not superset, quit */
  2158. expr_free(dep2);
  2159. break;
  2160. }
  2161. + /* Superset, put in submenu */
  2162. expr_free(dep2);
  2163. next:
  2164. menu_finalize(menu);
  2165. menu->parent = parent;
  2166. last_menu = menu;
  2167. }
  2168. + expr_free(basedep);
  2169. if (last_menu) {
  2170. parent->list = parent->next;
  2171. parent->next = last_menu->next;
  2172. @@ -420,6 +529,35 @@ void menu_finalize(struct menu *parent)
  2173. *ep = expr_alloc_one(E_LIST, NULL);
  2174. (*ep)->right.sym = menu->sym;
  2175. }
  2176. +
  2177. + /*
  2178. + * This code serves two purposes:
  2179. + *
  2180. + * (1) Flattening 'if' blocks, which do not specify a submenu
  2181. + * and only add dependencies.
  2182. + *
  2183. + * (Automatic submenu creation might still create a submenu
  2184. + * from an 'if' before this code runs.)
  2185. + *
  2186. + * (2) "Undoing" any automatic submenus created earlier below
  2187. + * promptless symbols.
  2188. + *
  2189. + * Before:
  2190. + *
  2191. + * A
  2192. + * if ... (or promptless symbol)
  2193. + * +-B
  2194. + * +-C
  2195. + * D
  2196. + *
  2197. + * After:
  2198. + *
  2199. + * A
  2200. + * if ... (or promptless symbol)
  2201. + * B
  2202. + * C
  2203. + * D
  2204. + */
  2205. if (menu->list && (!menu->prompt || !menu->prompt->text)) {
  2206. for (last_menu = menu->list; ; last_menu = last_menu->next) {
  2207. last_menu->parent = parent;
  2208. @@ -444,6 +582,15 @@ void menu_finalize(struct menu *parent)
  2209. sym->flags |= SYMBOL_WARNED;
  2210. }
  2211. + /*
  2212. + * For non-optional choices, add a reverse dependency (corresponding to
  2213. + * a select) of '<visibility> && m'. This prevents the user from
  2214. + * setting the choice mode to 'n' when the choice is visible.
  2215. + *
  2216. + * This would also work for non-choice symbols, but only non-optional
  2217. + * choices clear SYMBOL_OPTIONAL as of writing. Choices are implemented
  2218. + * as a type of symbol.
  2219. + */
  2220. if (sym && !sym_is_optional(sym) && parent->prompt) {
  2221. sym->rev_dep.expr = expr_alloc_or(sym->rev_dep.expr,
  2222. expr_alloc_and(parent->prompt->visible.expr,
  2223. @@ -558,7 +705,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
  2224. struct menu *submenu[8], *menu, *location = NULL;
  2225. struct jump_key *jump = NULL;
  2226. - str_printf(r, _("Prompt: %s\n"), _(prop->text));
  2227. + str_printf(r, "Prompt: %s\n", prop->text);
  2228. menu = prop->menu->parent;
  2229. for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) {
  2230. bool accessible = menu_is_visible(menu);
  2231. @@ -591,16 +738,16 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
  2232. }
  2233. if (i > 0) {
  2234. - str_printf(r, _(" Location:\n"));
  2235. + str_printf(r, " Location:\n");
  2236. for (j = 4; --i >= 0; j += 2) {
  2237. menu = submenu[i];
  2238. if (jump && menu == location)
  2239. jump->offset = strlen(r->s);
  2240. str_printf(r, "%*c-> %s", j, ' ',
  2241. - _(menu_get_prompt(menu)));
  2242. + menu_get_prompt(menu));
  2243. if (menu->sym) {
  2244. str_printf(r, " (%s [=%s])", menu->sym->name ?
  2245. - menu->sym->name : _("<choice>"),
  2246. + menu->sym->name : "<choice>",
  2247. sym_get_string_value(menu->sym));
  2248. }
  2249. str_append(r, "\n");
  2250. @@ -664,27 +811,27 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym,
  2251. prop = get_symbol_prop(sym);
  2252. if (prop) {
  2253. - str_printf(r, _(" Defined at %s:%d\n"), prop->menu->file->name,
  2254. + str_printf(r, " Defined at %s:%d\n", prop->menu->file->name,
  2255. prop->menu->lineno);
  2256. if (!expr_is_yes(prop->visible.expr)) {
  2257. - str_append(r, _(" Depends on: "));
  2258. + str_append(r, " Depends on: ");
  2259. expr_gstr_print(prop->visible.expr, r);
  2260. str_append(r, "\n");
  2261. }
  2262. }
  2263. - get_symbol_props_str(r, sym, P_SELECT, _(" Selects: "));
  2264. + get_symbol_props_str(r, sym, P_SELECT, " Selects: ");
  2265. if (sym->rev_dep.expr) {
  2266. - str_append(r, _(" Selected by: "));
  2267. - expr_gstr_print(sym->rev_dep.expr, r);
  2268. - str_append(r, "\n");
  2269. + expr_gstr_print_revdep(sym->rev_dep.expr, r, yes, " Selected by [y]:\n");
  2270. + expr_gstr_print_revdep(sym->rev_dep.expr, r, mod, " Selected by [m]:\n");
  2271. + expr_gstr_print_revdep(sym->rev_dep.expr, r, no, " Selected by [n]:\n");
  2272. }
  2273. - get_symbol_props_str(r, sym, P_IMPLY, _(" Implies: "));
  2274. + get_symbol_props_str(r, sym, P_IMPLY, " Implies: ");
  2275. if (sym->implied.expr) {
  2276. - str_append(r, _(" Implied by: "));
  2277. - expr_gstr_print(sym->implied.expr, r);
  2278. - str_append(r, "\n");
  2279. + expr_gstr_print_revdep(sym->implied.expr, r, yes, " Implied by [y]:\n");
  2280. + expr_gstr_print_revdep(sym->implied.expr, r, mod, " Implied by [m]:\n");
  2281. + expr_gstr_print_revdep(sym->implied.expr, r, no, " Implied by [n]:\n");
  2282. }
  2283. str_append(r, "\n\n");
  2284. @@ -699,7 +846,7 @@ struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head)
  2285. for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
  2286. get_symbol_str(&res, sym, head);
  2287. if (!i)
  2288. - str_append(&res, _("No matches found.\n"));
  2289. + str_append(&res, "No matches found.\n");
  2290. return res;
  2291. }
  2292. @@ -714,7 +861,7 @@ void menu_get_ext_help(struct menu *menu, struct gstr *help)
  2293. str_printf(help, "%s%s:\n\n", CONFIG_, sym->name);
  2294. help_text = menu_get_help(menu);
  2295. }
  2296. - str_printf(help, "%s\n", _(help_text));
  2297. + str_printf(help, "%s\n", help_text);
  2298. if (sym)
  2299. get_symbol_str(help, sym, NULL);
  2300. }
  2301. diff --git a/carl9170fw/config/preprocess.c b/carl9170fw/config/preprocess.c
  2302. new file mode 100644
  2303. index 0000000..592dfbf
  2304. --- /dev/null
  2305. +++ b/carl9170fw/config/preprocess.c
  2306. @@ -0,0 +1,573 @@
  2307. +// SPDX-License-Identifier: GPL-2.0
  2308. +//
  2309. +// Copyright (C) 2018 Masahiro Yamada <yamada.masahiro@socionext.com>
  2310. +
  2311. +#include <ctype.h>
  2312. +#include <stdarg.h>
  2313. +#include <stdbool.h>
  2314. +#include <stdio.h>
  2315. +#include <stdlib.h>
  2316. +#include <string.h>
  2317. +
  2318. +#include "list.h"
  2319. +#include "lkc.h"
  2320. +
  2321. +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  2322. +
  2323. +static char *expand_string_with_args(const char *in, int argc, char *argv[]);
  2324. +
  2325. +static void __attribute__((noreturn)) pperror(const char *format, ...)
  2326. +{
  2327. + va_list ap;
  2328. +
  2329. + fprintf(stderr, "%s:%d: ", current_file->name, yylineno);
  2330. + va_start(ap, format);
  2331. + vfprintf(stderr, format, ap);
  2332. + va_end(ap);
  2333. + fprintf(stderr, "\n");
  2334. +
  2335. + exit(1);
  2336. +}
  2337. +
  2338. +/*
  2339. + * Environment variables
  2340. + */
  2341. +static LIST_HEAD(env_list);
  2342. +
  2343. +struct env {
  2344. + char *name;
  2345. + char *value;
  2346. + struct list_head node;
  2347. +};
  2348. +
  2349. +static void env_add(const char *name, const char *value)
  2350. +{
  2351. + struct env *e;
  2352. +
  2353. + e = xmalloc(sizeof(*e));
  2354. + e->name = xstrdup(name);
  2355. + e->value = xstrdup(value);
  2356. +
  2357. + list_add_tail(&e->node, &env_list);
  2358. +}
  2359. +
  2360. +static void env_del(struct env *e)
  2361. +{
  2362. + list_del(&e->node);
  2363. + free(e->name);
  2364. + free(e->value);
  2365. + free(e);
  2366. +}
  2367. +
  2368. +/* The returned pointer must be freed when done */
  2369. +static char *env_expand(const char *name)
  2370. +{
  2371. + struct env *e;
  2372. + const char *value;
  2373. +
  2374. + if (!*name)
  2375. + return NULL;
  2376. +
  2377. + list_for_each_entry(e, &env_list, node) {
  2378. + if (!strcmp(name, e->name))
  2379. + return xstrdup(e->value);
  2380. + }
  2381. +
  2382. + value = getenv(name);
  2383. + if (!value)
  2384. + return NULL;
  2385. +
  2386. + /*
  2387. + * We need to remember all referenced environment variables.
  2388. + * They will be written out to include/config/auto.conf.cmd
  2389. + */
  2390. + env_add(name, value);
  2391. +
  2392. + return xstrdup(value);
  2393. +}
  2394. +
  2395. +void env_write_dep(FILE *f, const char *autoconfig_name)
  2396. +{
  2397. + struct env *e, *tmp;
  2398. +
  2399. + list_for_each_entry_safe(e, tmp, &env_list, node) {
  2400. + fprintf(f, "ifneq \"$(%s)\" \"%s\"\n", e->name, e->value);
  2401. + fprintf(f, "%s: FORCE\n", autoconfig_name);
  2402. + fprintf(f, "endif\n");
  2403. + env_del(e);
  2404. + }
  2405. +}
  2406. +
  2407. +/*
  2408. + * Built-in functions
  2409. + */
  2410. +struct function {
  2411. + const char *name;
  2412. + unsigned int min_args;
  2413. + unsigned int max_args;
  2414. + char *(*func)(int argc, char *argv[]);
  2415. +};
  2416. +
  2417. +static char *do_error_if(int argc, char *argv[])
  2418. +{
  2419. + if (!strcmp(argv[0], "y"))
  2420. + pperror("%s", argv[1]);
  2421. +
  2422. + return NULL;
  2423. +}
  2424. +
  2425. +static char *do_filename(int argc, char *argv[])
  2426. +{
  2427. + return xstrdup(current_file->name);
  2428. +}
  2429. +
  2430. +static char *do_info(int argc, char *argv[])
  2431. +{
  2432. + printf("%s\n", argv[0]);
  2433. +
  2434. + return xstrdup("");
  2435. +}
  2436. +
  2437. +static char *do_lineno(int argc, char *argv[])
  2438. +{
  2439. + char buf[16];
  2440. +
  2441. + sprintf(buf, "%d", yylineno);
  2442. +
  2443. + return xstrdup(buf);
  2444. +}
  2445. +
  2446. +static char *do_shell(int argc, char *argv[])
  2447. +{
  2448. + FILE *p;
  2449. + char buf[256];
  2450. + char *cmd;
  2451. + size_t nread;
  2452. + int i;
  2453. +
  2454. + cmd = argv[0];
  2455. +
  2456. + p = popen(cmd, "r");
  2457. + if (!p) {
  2458. + perror(cmd);
  2459. + exit(1);
  2460. + }
  2461. +
  2462. + nread = fread(buf, 1, sizeof(buf), p);
  2463. + if (nread == sizeof(buf))
  2464. + nread--;
  2465. +
  2466. + /* remove trailing new lines */
  2467. + while (nread > 0 && buf[nread - 1] == '\n')
  2468. + nread--;
  2469. +
  2470. + buf[nread] = 0;
  2471. +
  2472. + /* replace a new line with a space */
  2473. + for (i = 0; i < nread; i++) {
  2474. + if (buf[i] == '\n')
  2475. + buf[i] = ' ';
  2476. + }
  2477. +
  2478. + if (pclose(p) == -1) {
  2479. + perror(cmd);
  2480. + exit(1);
  2481. + }
  2482. +
  2483. + return xstrdup(buf);
  2484. +}
  2485. +
  2486. +static char *do_warning_if(int argc, char *argv[])
  2487. +{
  2488. + if (!strcmp(argv[0], "y"))
  2489. + fprintf(stderr, "%s:%d: %s\n",
  2490. + current_file->name, yylineno, argv[1]);
  2491. +
  2492. + return xstrdup("");
  2493. +}
  2494. +
  2495. +static const struct function function_table[] = {
  2496. + /* Name MIN MAX Function */
  2497. + { "error-if", 2, 2, do_error_if },
  2498. + { "filename", 0, 0, do_filename },
  2499. + { "info", 1, 1, do_info },
  2500. + { "lineno", 0, 0, do_lineno },
  2501. + { "shell", 1, 1, do_shell },
  2502. + { "warning-if", 2, 2, do_warning_if },
  2503. +};
  2504. +
  2505. +#define FUNCTION_MAX_ARGS 16
  2506. +
  2507. +static char *function_expand(const char *name, int argc, char *argv[])
  2508. +{
  2509. + const struct function *f;
  2510. + int i;
  2511. +
  2512. + for (i = 0; i < ARRAY_SIZE(function_table); i++) {
  2513. + f = &function_table[i];
  2514. + if (strcmp(f->name, name))
  2515. + continue;
  2516. +
  2517. + if (argc < f->min_args)
  2518. + pperror("too few function arguments passed to '%s'",
  2519. + name);
  2520. +
  2521. + if (argc > f->max_args)
  2522. + pperror("too many function arguments passed to '%s'",
  2523. + name);
  2524. +
  2525. + return f->func(argc, argv);
  2526. + }
  2527. +
  2528. + return NULL;
  2529. +}
  2530. +
  2531. +/*
  2532. + * Variables (and user-defined functions)
  2533. + */
  2534. +static LIST_HEAD(variable_list);
  2535. +
  2536. +struct variable {
  2537. + char *name;
  2538. + char *value;
  2539. + enum variable_flavor flavor;
  2540. + int exp_count;
  2541. + struct list_head node;
  2542. +};
  2543. +
  2544. +static struct variable *variable_lookup(const char *name)
  2545. +{
  2546. + struct variable *v;
  2547. +
  2548. + list_for_each_entry(v, &variable_list, node) {
  2549. + if (!strcmp(name, v->name))
  2550. + return v;
  2551. + }
  2552. +
  2553. + return NULL;
  2554. +}
  2555. +
  2556. +static char *variable_expand(const char *name, int argc, char *argv[])
  2557. +{
  2558. + struct variable *v;
  2559. + char *res;
  2560. +
  2561. + v = variable_lookup(name);
  2562. + if (!v)
  2563. + return NULL;
  2564. +
  2565. + if (argc == 0 && v->exp_count)
  2566. + pperror("Recursive variable '%s' references itself (eventually)",
  2567. + name);
  2568. +
  2569. + if (v->exp_count > 1000)
  2570. + pperror("Too deep recursive expansion");
  2571. +
  2572. + v->exp_count++;
  2573. +
  2574. + if (v->flavor == VAR_RECURSIVE)
  2575. + res = expand_string_with_args(v->value, argc, argv);
  2576. + else
  2577. + res = xstrdup(v->value);
  2578. +
  2579. + v->exp_count--;
  2580. +
  2581. + return res;
  2582. +}
  2583. +
  2584. +void variable_add(const char *name, const char *value,
  2585. + enum variable_flavor flavor)
  2586. +{
  2587. + struct variable *v;
  2588. + char *new_value;
  2589. + bool append = false;
  2590. +
  2591. + v = variable_lookup(name);
  2592. + if (v) {
  2593. + /* For defined variables, += inherits the existing flavor */
  2594. + if (flavor == VAR_APPEND) {
  2595. + flavor = v->flavor;
  2596. + append = true;
  2597. + } else {
  2598. + free(v->value);
  2599. + }
  2600. + } else {
  2601. + /* For undefined variables, += assumes the recursive flavor */
  2602. + if (flavor == VAR_APPEND)
  2603. + flavor = VAR_RECURSIVE;
  2604. +
  2605. + v = xmalloc(sizeof(*v));
  2606. + v->name = xstrdup(name);
  2607. + v->exp_count = 0;
  2608. + list_add_tail(&v->node, &variable_list);
  2609. + }
  2610. +
  2611. + v->flavor = flavor;
  2612. +
  2613. + if (flavor == VAR_SIMPLE)
  2614. + new_value = expand_string(value);
  2615. + else
  2616. + new_value = xstrdup(value);
  2617. +
  2618. + if (append) {
  2619. + v->value = xrealloc(v->value,
  2620. + strlen(v->value) + strlen(new_value) + 2);
  2621. + strcat(v->value, " ");
  2622. + strcat(v->value, new_value);
  2623. + free(new_value);
  2624. + } else {
  2625. + v->value = new_value;
  2626. + }
  2627. +}
  2628. +
  2629. +static void variable_del(struct variable *v)
  2630. +{
  2631. + list_del(&v->node);
  2632. + free(v->name);
  2633. + free(v->value);
  2634. + free(v);
  2635. +}
  2636. +
  2637. +void variable_all_del(void)
  2638. +{
  2639. + struct variable *v, *tmp;
  2640. +
  2641. + list_for_each_entry_safe(v, tmp, &variable_list, node)
  2642. + variable_del(v);
  2643. +}
  2644. +
  2645. +/*
  2646. + * Evaluate a clause with arguments. argc/argv are arguments from the upper
  2647. + * function call.
  2648. + *
  2649. + * Returned string must be freed when done
  2650. + */
  2651. +static char *eval_clause(const char *str, size_t len, int argc, char *argv[])
  2652. +{
  2653. + char *tmp, *name, *res, *endptr, *prev, *p;
  2654. + int new_argc = 0;
  2655. + char *new_argv[FUNCTION_MAX_ARGS];
  2656. + int nest = 0;
  2657. + int i;
  2658. + unsigned long n;
  2659. +
  2660. + tmp = xstrndup(str, len);
  2661. +
  2662. + /*
  2663. + * If variable name is '1', '2', etc. It is generally an argument
  2664. + * from a user-function call (i.e. local-scope variable). If not
  2665. + * available, then look-up global-scope variables.
  2666. + */
  2667. + n = strtoul(tmp, &endptr, 10);
  2668. + if (!*endptr && n > 0 && n <= argc) {
  2669. + res = xstrdup(argv[n - 1]);
  2670. + goto free_tmp;
  2671. + }
  2672. +
  2673. + prev = p = tmp;
  2674. +
  2675. + /*
  2676. + * Split into tokens
  2677. + * The function name and arguments are separated by a comma.
  2678. + * For example, if the function call is like this:
  2679. + * $(foo,$(x),$(y))
  2680. + *
  2681. + * The input string for this helper should be:
  2682. + * foo,$(x),$(y)
  2683. + *
  2684. + * and split into:
  2685. + * new_argv[0] = 'foo'
  2686. + * new_argv[1] = '$(x)'
  2687. + * new_argv[2] = '$(y)'
  2688. + */
  2689. + while (*p) {
  2690. + if (nest == 0 && *p == ',') {
  2691. + *p = 0;
  2692. + if (new_argc >= FUNCTION_MAX_ARGS)
  2693. + pperror("too many function arguments");
  2694. + new_argv[new_argc++] = prev;
  2695. + prev = p + 1;
  2696. + } else if (*p == '(') {
  2697. + nest++;
  2698. + } else if (*p == ')') {
  2699. + nest--;
  2700. + }
  2701. +
  2702. + p++;
  2703. + }
  2704. + new_argv[new_argc++] = prev;
  2705. +
  2706. + /*
  2707. + * Shift arguments
  2708. + * new_argv[0] represents a function name or a variable name. Put it
  2709. + * into 'name', then shift the rest of the arguments. This simplifies
  2710. + * 'const' handling.
  2711. + */
  2712. + name = expand_string_with_args(new_argv[0], argc, argv);
  2713. + new_argc--;
  2714. + for (i = 0; i < new_argc; i++)
  2715. + new_argv[i] = expand_string_with_args(new_argv[i + 1],
  2716. + argc, argv);
  2717. +
  2718. + /* Search for variables */
  2719. + res = variable_expand(name, new_argc, new_argv);
  2720. + if (res)
  2721. + goto free;
  2722. +
  2723. + /* Look for built-in functions */
  2724. + res = function_expand(name, new_argc, new_argv);
  2725. + if (res)
  2726. + goto free;
  2727. +
  2728. + /* Last, try environment variable */
  2729. + if (new_argc == 0) {
  2730. + res = env_expand(name);
  2731. + if (res)
  2732. + goto free;
  2733. + }
  2734. +
  2735. + res = xstrdup("");
  2736. +free:
  2737. + for (i = 0; i < new_argc; i++)
  2738. + free(new_argv[i]);
  2739. + free(name);
  2740. +free_tmp:
  2741. + free(tmp);
  2742. +
  2743. + return res;
  2744. +}
  2745. +
  2746. +/*
  2747. + * Expand a string that follows '$'
  2748. + *
  2749. + * For example, if the input string is
  2750. + * ($(FOO)$($(BAR)))$(BAZ)
  2751. + * this helper evaluates
  2752. + * $($(FOO)$($(BAR)))
  2753. + * and returns a new string containing the expansion (note that the string is
  2754. + * recursively expanded), also advancing 'str' to point to the next character
  2755. + * after the corresponding closing parenthesis, in this case, *str will be
  2756. + * $(BAR)
  2757. + */
  2758. +static char *expand_dollar_with_args(const char **str, int argc, char *argv[])
  2759. +{
  2760. + const char *p = *str;
  2761. + const char *q;
  2762. + int nest = 0;
  2763. +
  2764. + /*
  2765. + * In Kconfig, variable/function references always start with "$(".
  2766. + * Neither single-letter variables as in $A nor curly braces as in ${CC}
  2767. + * are supported. '$' not followed by '(' loses its special meaning.
  2768. + */
  2769. + if (*p != '(') {
  2770. + *str = p;
  2771. + return xstrdup("$");
  2772. + }
  2773. +
  2774. + p++;
  2775. + q = p;
  2776. + while (*q) {
  2777. + if (*q == '(') {
  2778. + nest++;
  2779. + } else if (*q == ')') {
  2780. + if (nest-- == 0)
  2781. + break;
  2782. + }
  2783. + q++;
  2784. + }
  2785. +
  2786. + if (!*q)
  2787. + pperror("unterminated reference to '%s': missing ')'", p);
  2788. +
  2789. + /* Advance 'str' to after the expanded initial portion of the string */
  2790. + *str = q + 1;
  2791. +
  2792. + return eval_clause(p, q - p, argc, argv);
  2793. +}
  2794. +
  2795. +char *expand_dollar(const char **str)
  2796. +{
  2797. + return expand_dollar_with_args(str, 0, NULL);
  2798. +}
  2799. +
  2800. +static char *__expand_string(const char **str, bool (*is_end)(char c),
  2801. + int argc, char *argv[])
  2802. +{
  2803. + const char *in, *p;
  2804. + char *expansion, *out;
  2805. + size_t in_len, out_len;
  2806. +
  2807. + out = xmalloc(1);
  2808. + *out = 0;
  2809. + out_len = 1;
  2810. +
  2811. + p = in = *str;
  2812. +
  2813. + while (1) {
  2814. + if (*p == '$') {
  2815. + in_len = p - in;
  2816. + p++;
  2817. + expansion = expand_dollar_with_args(&p, argc, argv);
  2818. + out_len += in_len + strlen(expansion);
  2819. + out = xrealloc(out, out_len);
  2820. + strncat(out, in, in_len);
  2821. + strcat(out, expansion);
  2822. + free(expansion);
  2823. + in = p;
  2824. + continue;
  2825. + }
  2826. +
  2827. + if (is_end(*p))
  2828. + break;
  2829. +
  2830. + p++;
  2831. + }
  2832. +
  2833. + in_len = p - in;
  2834. + out_len += in_len;
  2835. + out = xrealloc(out, out_len);
  2836. + strncat(out, in, in_len);
  2837. +
  2838. + /* Advance 'str' to the end character */
  2839. + *str = p;
  2840. +
  2841. + return out;
  2842. +}
  2843. +
  2844. +static bool is_end_of_str(char c)
  2845. +{
  2846. + return !c;
  2847. +}
  2848. +
  2849. +/*
  2850. + * Expand variables and functions in the given string. Undefined variables
  2851. + * expand to an empty string.
  2852. + * The returned string must be freed when done.
  2853. + */
  2854. +static char *expand_string_with_args(const char *in, int argc, char *argv[])
  2855. +{
  2856. + return __expand_string(&in, is_end_of_str, argc, argv);
  2857. +}
  2858. +
  2859. +char *expand_string(const char *in)
  2860. +{
  2861. + return expand_string_with_args(in, 0, NULL);
  2862. +}
  2863. +
  2864. +static bool is_end_of_token(char c)
  2865. +{
  2866. + return !(isalnum(c) || c == '_' || c == '-');
  2867. +}
  2868. +
  2869. +/*
  2870. + * Expand variables in a token. The parsing stops when a token separater
  2871. + * (in most cases, it is a whitespace) is encountered. 'str' is updated to
  2872. + * point to the next character.
  2873. + *
  2874. + * The returned string must be freed when done.
  2875. + */
  2876. +char *expand_one_token(const char **str)
  2877. +{
  2878. + return __expand_string(str, is_end_of_token, 0, NULL);
  2879. +}
  2880. diff --git a/carl9170fw/config/symbol.c b/carl9170fw/config/symbol.c
  2881. index 3c8bd9b..1f9266d 100644
  2882. --- a/carl9170fw/config/symbol.c
  2883. +++ b/carl9170fw/config/symbol.c
  2884. @@ -1,6 +1,6 @@
  2885. +// SPDX-License-Identifier: GPL-2.0
  2886. /*
  2887. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  2888. - * Released under the terms of the GNU GPL v2.0.
  2889. */
  2890. #include <ctype.h>
  2891. @@ -33,33 +33,6 @@ struct symbol *sym_defconfig_list;
  2892. struct symbol *modules_sym;
  2893. tristate modules_val;
  2894. -struct expr *sym_env_list;
  2895. -
  2896. -static void sym_add_default(struct symbol *sym, const char *def)
  2897. -{
  2898. - struct property *prop = prop_alloc(P_DEFAULT, sym);
  2899. -
  2900. - prop->expr = expr_alloc_symbol(sym_lookup(def, SYMBOL_CONST));
  2901. -}
  2902. -
  2903. -void sym_init(void)
  2904. -{
  2905. - struct symbol *sym;
  2906. - struct utsname uts;
  2907. - static bool inited = false;
  2908. -
  2909. - if (inited)
  2910. - return;
  2911. - inited = true;
  2912. -
  2913. - uname(&uts);
  2914. -
  2915. - sym = sym_lookup("UNAME_RELEASE", 0);
  2916. - sym->type = S_STRING;
  2917. - sym->flags |= SYMBOL_AUTO;
  2918. - sym_add_default(sym, uts.release);
  2919. -}
  2920. -
  2921. enum symbol_type sym_get_type(struct symbol *sym)
  2922. {
  2923. enum symbol_type type = sym->type;
  2924. @@ -77,7 +50,7 @@ const char *sym_type_name(enum symbol_type type)
  2925. {
  2926. switch (type) {
  2927. case S_BOOLEAN:
  2928. - return "boolean";
  2929. + return "bool";
  2930. case S_TRISTATE:
  2931. return "tristate";
  2932. case S_INT:
  2933. @@ -88,8 +61,6 @@ const char *sym_type_name(enum symbol_type type)
  2934. return "string";
  2935. case S_UNKNOWN:
  2936. return "unknown";
  2937. - case S_OTHER:
  2938. - break;
  2939. }
  2940. return "???";
  2941. }
  2942. @@ -103,15 +74,6 @@ struct property *sym_get_choice_prop(struct symbol *sym)
  2943. return NULL;
  2944. }
  2945. -struct property *sym_get_env_prop(struct symbol *sym)
  2946. -{
  2947. - struct property *prop;
  2948. -
  2949. - for_all_properties(sym, prop, P_ENV)
  2950. - return prop;
  2951. - return NULL;
  2952. -}
  2953. -
  2954. static struct property *sym_get_default_prop(struct symbol *sym)
  2955. {
  2956. struct property *prop;
  2957. @@ -124,7 +86,7 @@ static struct property *sym_get_default_prop(struct symbol *sym)
  2958. return NULL;
  2959. }
  2960. -static struct property *sym_get_range_prop(struct symbol *sym)
  2961. +struct property *sym_get_range_prop(struct symbol *sym)
  2962. {
  2963. struct property *prop;
  2964. @@ -183,7 +145,7 @@ static void sym_validate_range(struct symbol *sym)
  2965. sprintf(str, "%lld", val2);
  2966. else
  2967. sprintf(str, "0x%llx", val2);
  2968. - sym->curr.val = strdup(str);
  2969. + sym->curr.val = xstrdup(str);
  2970. }
  2971. static void sym_set_changed(struct symbol *sym)
  2972. @@ -243,7 +205,7 @@ static void sym_calc_visibility(struct symbol *sym)
  2973. tri = yes;
  2974. if (sym->dir_dep.expr)
  2975. tri = expr_calc_value(sym->dir_dep.expr);
  2976. - if (tri == mod)
  2977. + if (tri == mod && sym_get_type(sym) == S_BOOLEAN)
  2978. tri = yes;
  2979. if (sym->dir_dep.tri != tri) {
  2980. sym->dir_dep.tri = tri;
  2981. @@ -333,6 +295,27 @@ static struct symbol *sym_calc_choice(struct symbol *sym)
  2982. return def_sym;
  2983. }
  2984. +static void sym_warn_unmet_dep(struct symbol *sym)
  2985. +{
  2986. + struct gstr gs = str_new();
  2987. +
  2988. + str_printf(&gs,
  2989. + "\nWARNING: unmet direct dependencies detected for %s\n",
  2990. + sym->name);
  2991. + str_printf(&gs,
  2992. + " Depends on [%c]: ",
  2993. + sym->dir_dep.tri == mod ? 'm' : 'n');
  2994. + expr_gstr_print(sym->dir_dep.expr, &gs);
  2995. + str_printf(&gs, "\n");
  2996. +
  2997. + expr_gstr_print_revdep(sym->rev_dep.expr, &gs, yes,
  2998. + " Selected by [y]:\n");
  2999. + expr_gstr_print_revdep(sym->rev_dep.expr, &gs, mod,
  3000. + " Selected by [m]:\n");
  3001. +
  3002. + fputs(str_get(&gs), stderr);
  3003. +}
  3004. +
  3005. void sym_calc_value(struct symbol *sym)
  3006. {
  3007. struct symbol_value newval, oldval;
  3008. @@ -371,11 +354,13 @@ void sym_calc_value(struct symbol *sym)
  3009. sym->curr.tri = no;
  3010. return;
  3011. }
  3012. - if (!sym_is_choice_value(sym))
  3013. - sym->flags &= ~SYMBOL_WRITE;
  3014. + sym->flags &= ~SYMBOL_WRITE;
  3015. sym_calc_visibility(sym);
  3016. + if (sym->visible != no)
  3017. + sym->flags |= SYMBOL_WRITE;
  3018. +
  3019. /* set default if recursively called */
  3020. sym->curr = newval;
  3021. @@ -390,7 +375,6 @@ void sym_calc_value(struct symbol *sym)
  3022. /* if the symbol is visible use the user value
  3023. * if available, otherwise try the default value
  3024. */
  3025. - sym->flags |= SYMBOL_WRITE;
  3026. if (sym_has_value(sym)) {
  3027. newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri,
  3028. sym->visible);
  3029. @@ -402,9 +386,10 @@ void sym_calc_value(struct symbol *sym)
  3030. if (!sym_is_choice(sym)) {
  3031. prop = sym_get_default_prop(sym);
  3032. if (prop) {
  3033. - sym->flags |= SYMBOL_WRITE;
  3034. newval.tri = EXPR_AND(expr_calc_value(prop->expr),
  3035. prop->visible.tri);
  3036. + if (newval.tri != no)
  3037. + sym->flags |= SYMBOL_WRITE;
  3038. }
  3039. if (sym->implied.tri != no) {
  3040. sym->flags |= SYMBOL_WRITE;
  3041. @@ -412,18 +397,8 @@ void sym_calc_value(struct symbol *sym)
  3042. }
  3043. }
  3044. calc_newval:
  3045. - if (sym->dir_dep.tri == no && sym->rev_dep.tri != no) {
  3046. - struct expr *e;
  3047. - e = expr_simplify_unmet_dep(sym->rev_dep.expr,
  3048. - sym->dir_dep.expr);
  3049. - fprintf(stderr, "warning: (");
  3050. - expr_fprint(e, stderr);
  3051. - fprintf(stderr, ") selects %s which has unmet direct dependencies (",
  3052. - sym->name);
  3053. - expr_fprint(sym->dir_dep.expr, stderr);
  3054. - fprintf(stderr, ")\n");
  3055. - expr_free(e);
  3056. - }
  3057. + if (sym->dir_dep.tri < sym->rev_dep.tri)
  3058. + sym_warn_unmet_dep(sym);
  3059. newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
  3060. }
  3061. if (newval.tri == mod &&
  3062. @@ -433,12 +408,9 @@ void sym_calc_value(struct symbol *sym)
  3063. case S_STRING:
  3064. case S_HEX:
  3065. case S_INT:
  3066. - if (sym->visible != no) {
  3067. - sym->flags |= SYMBOL_WRITE;
  3068. - if (sym_has_value(sym)) {
  3069. - newval.val = sym->def[S_DEF_USER].val;
  3070. - break;
  3071. - }
  3072. + if (sym->visible != no && sym_has_value(sym)) {
  3073. + newval.val = sym->def[S_DEF_USER].val;
  3074. + break;
  3075. }
  3076. prop = sym_get_default_prop(sym);
  3077. if (prop) {
  3078. @@ -480,7 +452,7 @@ void sym_calc_value(struct symbol *sym)
  3079. }
  3080. }
  3081. - if (sym->flags & SYMBOL_AUTO)
  3082. + if (sym->flags & SYMBOL_NO_WRITE)
  3083. sym->flags &= ~SYMBOL_WRITE;
  3084. if (sym->flags & SYMBOL_NEED_SET_CHOICE_VALUES)
  3085. @@ -783,7 +755,6 @@ const char *sym_get_string_default(struct symbol *sym)
  3086. return str;
  3087. case S_STRING:
  3088. return str;
  3089. - case S_OTHER:
  3090. case S_UNKNOWN:
  3091. break;
  3092. }
  3093. @@ -851,7 +822,7 @@ struct symbol *sym_lookup(const char *name, int flags)
  3094. : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE))))
  3095. return symbol;
  3096. }
  3097. - new_name = strdup(name);
  3098. + new_name = xstrdup(name);
  3099. } else {
  3100. new_name = NULL;
  3101. hash = 0;
  3102. @@ -896,55 +867,6 @@ struct symbol *sym_find(const char *name)
  3103. return symbol;
  3104. }
  3105. -/*
  3106. - * Expand symbol's names embedded in the string given in argument. Symbols'
  3107. - * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to
  3108. - * the empty string.
  3109. - */
  3110. -const char *sym_expand_string_value(const char *in)
  3111. -{
  3112. - const char *src;
  3113. - char *res;
  3114. - size_t reslen;
  3115. -
  3116. - reslen = strlen(in) + 1;
  3117. - res = xmalloc(reslen);
  3118. - res[0] = '\0';
  3119. -
  3120. - while ((src = strchr(in, '$'))) {
  3121. - char *p, name[SYMBOL_MAXLENGTH];
  3122. - const char *symval = "";
  3123. - struct symbol *sym;
  3124. - size_t newlen;
  3125. -
  3126. - strncat(res, in, src - in);
  3127. - src++;
  3128. -
  3129. - p = name;
  3130. - while (isalnum(*src) || *src == '_')
  3131. - *p++ = *src++;
  3132. - *p = '\0';
  3133. -
  3134. - sym = sym_find(name);
  3135. - if (sym != NULL) {
  3136. - sym_calc_value(sym);
  3137. - symval = sym_get_string_value(sym);
  3138. - }
  3139. -
  3140. - newlen = strlen(res) + strlen(symval) + strlen(src) + 1;
  3141. - if (newlen > reslen) {
  3142. - reslen = newlen;
  3143. - res = realloc(res, reslen);
  3144. - }
  3145. -
  3146. - strcat(res, symval);
  3147. - in = src;
  3148. - }
  3149. - strcat(res, in);
  3150. -
  3151. - return res;
  3152. -}
  3153. -
  3154. const char *sym_escape_string_value(const char *in)
  3155. {
  3156. const char *p;
  3157. @@ -1086,7 +1008,7 @@ static struct dep_stack {
  3158. struct dep_stack *prev, *next;
  3159. struct symbol *sym;
  3160. struct property *prop;
  3161. - struct expr *expr;
  3162. + struct expr **expr;
  3163. } *check_top;
  3164. static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym)
  3165. @@ -1150,37 +1072,52 @@ static void sym_check_print_recursive(struct symbol *last_sym)
  3166. if (stack->sym == last_sym)
  3167. fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
  3168. prop->file->name, prop->lineno);
  3169. - fprintf(stderr, "For a resolution refer to Documentation/kbuild/kconfig-language.txt\n");
  3170. - fprintf(stderr, "subsection \"Kconfig recursive dependency limitations\"\n");
  3171. - if (stack->expr) {
  3172. - fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
  3173. - prop->file->name, prop->lineno,
  3174. +
  3175. + if (sym_is_choice(sym)) {
  3176. + fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
  3177. + menu->file->name, menu->lineno,
  3178. sym->name ? sym->name : "<choice>",
  3179. - prop_get_type_name(prop->type),
  3180. next_sym->name ? next_sym->name : "<choice>");
  3181. - } else if (stack->prop) {
  3182. + } else if (sym_is_choice_value(sym)) {
  3183. + fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
  3184. + menu->file->name, menu->lineno,
  3185. + sym->name ? sym->name : "<choice>",
  3186. + next_sym->name ? next_sym->name : "<choice>");
  3187. + } else if (stack->expr == &sym->dir_dep.expr) {
  3188. fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
  3189. prop->file->name, prop->lineno,
  3190. sym->name ? sym->name : "<choice>",
  3191. next_sym->name ? next_sym->name : "<choice>");
  3192. - } else if (sym_is_choice(sym)) {
  3193. - fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
  3194. - menu->file->name, menu->lineno,
  3195. + } else if (stack->expr == &sym->rev_dep.expr) {
  3196. + fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
  3197. + prop->file->name, prop->lineno,
  3198. sym->name ? sym->name : "<choice>",
  3199. next_sym->name ? next_sym->name : "<choice>");
  3200. - } else if (sym_is_choice_value(sym)) {
  3201. - fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
  3202. - menu->file->name, menu->lineno,
  3203. + } else if (stack->expr == &sym->implied.expr) {
  3204. + fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n",
  3205. + prop->file->name, prop->lineno,
  3206. + sym->name ? sym->name : "<choice>",
  3207. + next_sym->name ? next_sym->name : "<choice>");
  3208. + } else if (stack->expr) {
  3209. + fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
  3210. + prop->file->name, prop->lineno,
  3211. sym->name ? sym->name : "<choice>",
  3212. + prop_get_type_name(prop->type),
  3213. next_sym->name ? next_sym->name : "<choice>");
  3214. } else {
  3215. - fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
  3216. + fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
  3217. prop->file->name, prop->lineno,
  3218. sym->name ? sym->name : "<choice>",
  3219. + prop_get_type_name(prop->type),
  3220. next_sym->name ? next_sym->name : "<choice>");
  3221. }
  3222. }
  3223. + fprintf(stderr,
  3224. + "For a resolution refer to Documentation/kbuild/kconfig-language.txt\n"
  3225. + "subsection \"Kconfig recursive dependency limitations\"\n"
  3226. + "\n");
  3227. +
  3228. if (check_top == &cv_stack)
  3229. dep_stack_remove();
  3230. }
  3231. @@ -1215,7 +1152,7 @@ static struct symbol *sym_check_expr_deps(struct expr *e)
  3232. default:
  3233. break;
  3234. }
  3235. - printf("Oops! How to check %d?\n", e->type);
  3236. + fprintf(stderr, "Oops! How to check %d?\n", e->type);
  3237. return NULL;
  3238. }
  3239. @@ -1228,12 +1165,26 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
  3240. dep_stack_insert(&stack, sym);
  3241. + stack.expr = &sym->dir_dep.expr;
  3242. + sym2 = sym_check_expr_deps(sym->dir_dep.expr);
  3243. + if (sym2)
  3244. + goto out;
  3245. +
  3246. + stack.expr = &sym->rev_dep.expr;
  3247. sym2 = sym_check_expr_deps(sym->rev_dep.expr);
  3248. if (sym2)
  3249. goto out;
  3250. + stack.expr = &sym->implied.expr;
  3251. + sym2 = sym_check_expr_deps(sym->implied.expr);
  3252. + if (sym2)
  3253. + goto out;
  3254. +
  3255. + stack.expr = NULL;
  3256. +
  3257. for (prop = sym->prop; prop; prop = prop->next) {
  3258. - if (prop->type == P_CHOICE || prop->type == P_SELECT)
  3259. + if (prop->type == P_CHOICE || prop->type == P_SELECT ||
  3260. + prop->type == P_IMPLY)
  3261. continue;
  3262. stack.prop = prop;
  3263. sym2 = sym_check_expr_deps(prop->visible.expr);
  3264. @@ -1241,7 +1192,7 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
  3265. break;
  3266. if (prop->type != P_DEFAULT || sym_is_choice(sym))
  3267. continue;
  3268. - stack.expr = prop->expr;
  3269. + stack.expr = &prop->expr;
  3270. sym2 = sym_check_expr_deps(prop->expr);
  3271. if (sym2)
  3272. break;
  3273. @@ -1319,9 +1270,6 @@ struct symbol *sym_check_deps(struct symbol *sym)
  3274. sym->flags &= ~SYMBOL_CHECK;
  3275. }
  3276. - if (sym2 && sym2 == sym)
  3277. - sym2 = NULL;
  3278. -
  3279. return sym2;
  3280. }
  3281. @@ -1360,8 +1308,6 @@ const char *prop_get_type_name(enum prop_type type)
  3282. switch (type) {
  3283. case P_PROMPT:
  3284. return "prompt";
  3285. - case P_ENV:
  3286. - return "env";
  3287. case P_COMMENT:
  3288. return "comment";
  3289. case P_MENU:
  3290. @@ -1383,32 +1329,3 @@ const char *prop_get_type_name(enum prop_type type)
  3291. }
  3292. return "unknown";
  3293. }
  3294. -
  3295. -static void prop_add_env(const char *env)
  3296. -{
  3297. - struct symbol *sym, *sym2;
  3298. - struct property *prop;
  3299. - char *p;
  3300. -
  3301. - sym = current_entry->sym;
  3302. - sym->flags |= SYMBOL_AUTO;
  3303. - for_all_properties(sym, prop, P_ENV) {
  3304. - sym2 = prop_get_symbol(prop);
  3305. - if (strcmp(sym2->name, env))
  3306. - menu_warn(current_entry, "redefining environment symbol from %s",
  3307. - sym2->name);
  3308. - return;
  3309. - }
  3310. -
  3311. - prop = prop_alloc(P_ENV, sym);
  3312. - prop->expr = expr_alloc_symbol(sym_lookup(env, SYMBOL_CONST));
  3313. -
  3314. - sym_env_list = expr_alloc_one(E_LIST, sym_env_list);
  3315. - sym_env_list->right.sym = sym;
  3316. -
  3317. - p = getenv(env);
  3318. - if (p)
  3319. - sym_add_default(sym, p);
  3320. - else
  3321. - menu_warn(current_entry, "environment variable %s undefined", env);
  3322. -}
  3323. diff --git a/carl9170fw/config/util.c b/carl9170fw/config/util.c
  3324. index 0e76042..2958539 100644
  3325. --- a/carl9170fw/config/util.c
  3326. +++ b/carl9170fw/config/util.c
  3327. @@ -1,8 +1,7 @@
  3328. +// SPDX-License-Identifier: GPL-2.0
  3329. /*
  3330. * Copyright (C) 2002-2005 Roman Zippel <zippel@linux-m68k.org>
  3331. * Copyright (C) 2002-2005 Sam Ravnborg <sam@ravnborg.org>
  3332. - *
  3333. - * Released under the terms of the GNU GPL v2.0.
  3334. */
  3335. #include <stdarg.h>
  3336. @@ -14,69 +13,21 @@
  3337. struct file *file_lookup(const char *name)
  3338. {
  3339. struct file *file;
  3340. - const char *file_name = sym_expand_string_value(name);
  3341. for (file = file_list; file; file = file->next) {
  3342. if (!strcmp(name, file->name)) {
  3343. - free((void *)file_name);
  3344. return file;
  3345. }
  3346. }
  3347. file = xmalloc(sizeof(*file));
  3348. memset(file, 0, sizeof(*file));
  3349. - file->name = file_name;
  3350. + file->name = xstrdup(name);
  3351. file->next = file_list;
  3352. file_list = file;
  3353. return file;
  3354. }
  3355. -/* write a dependency file as used by kbuild to track dependencies */
  3356. -int file_write_dep(const char *name)
  3357. -{
  3358. - struct symbol *sym, *env_sym;
  3359. - struct expr *e;
  3360. - struct file *file;
  3361. - FILE *out;
  3362. -
  3363. - if (!name)
  3364. - name = ".kconfig.d";
  3365. - out = fopen("..config.tmp", "w");
  3366. - if (!out)
  3367. - return 1;
  3368. - fprintf(out, "deps_config := \\\n");
  3369. - for (file = file_list; file; file = file->next) {
  3370. - if (file->next)
  3371. - fprintf(out, "\t%s \\\n", file->name);
  3372. - else
  3373. - fprintf(out, "\t%s\n", file->name);
  3374. - }
  3375. - fprintf(out, "\n%s: \\\n"
  3376. - "\t$(deps_config)\n\n", conf_get_autoconfig_name());
  3377. -
  3378. - expr_list_for_each_sym(sym_env_list, e, sym) {
  3379. - struct property *prop;
  3380. - const char *value;
  3381. -
  3382. - prop = sym_get_env_prop(sym);
  3383. - env_sym = prop_get_symbol(prop);
  3384. - if (!env_sym)
  3385. - continue;
  3386. - value = getenv(env_sym->name);
  3387. - if (!value)
  3388. - value = "";
  3389. - fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value);
  3390. - fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name());
  3391. - fprintf(out, "endif\n");
  3392. - }
  3393. -
  3394. - fprintf(out, "\n$(deps_config): ;\n");
  3395. - fclose(out);
  3396. - rename("..config.tmp", name);
  3397. - return 0;
  3398. -}
  3399. -
  3400. -
  3401. /* Allocate initial growable string */
  3402. struct gstr str_new(void)
  3403. {
  3404. @@ -104,7 +55,7 @@ void str_append(struct gstr *gs, const char *s)
  3405. if (s) {
  3406. l = strlen(gs->s) + strlen(s) + 1;
  3407. if (l > gs->len) {
  3408. - gs->s = realloc(gs->s, l);
  3409. + gs->s = xrealloc(gs->s, l);
  3410. gs->len = l;
  3411. }
  3412. strcat(gs->s, s);
  3413. @@ -145,3 +96,34 @@ void *xcalloc(size_t nmemb, size_t size)
  3414. fprintf(stderr, "Out of memory.\n");
  3415. exit(1);
  3416. }
  3417. +
  3418. +void *xrealloc(void *p, size_t size)
  3419. +{
  3420. + p = realloc(p, size);
  3421. + if (p)
  3422. + return p;
  3423. + fprintf(stderr, "Out of memory.\n");
  3424. + exit(1);
  3425. +}
  3426. +
  3427. +char *xstrdup(const char *s)
  3428. +{
  3429. + char *p;
  3430. +
  3431. + p = strdup(s);
  3432. + if (p)
  3433. + return p;
  3434. + fprintf(stderr, "Out of memory.\n");
  3435. + exit(1);
  3436. +}
  3437. +
  3438. +char *xstrndup(const char *s, size_t n)
  3439. +{
  3440. + char *p;
  3441. +
  3442. + p = strndup(s, n);
  3443. + if (p)
  3444. + return p;
  3445. + fprintf(stderr, "Out of memory.\n");
  3446. + exit(1);
  3447. +}
  3448. diff --git a/carl9170fw/config/zconf.l b/carl9170fw/config/zconf.l
  3449. index 9720530..c52cce8 100644
  3450. --- a/carl9170fw/config/zconf.l
  3451. +++ b/carl9170fw/config/zconf.l
  3452. @@ -1,13 +1,13 @@
  3453. -%option nostdinit noyywrap never-interactive full ecs
  3454. -%option 8bit nodefault perf-report perf-report
  3455. -%option noinput
  3456. -%x COMMAND HELP STRING PARAM
  3457. -%{
  3458. +/* SPDX-License-Identifier: GPL-2.0 */
  3459. /*
  3460. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  3461. - * Released under the terms of the GNU GPL v2.0.
  3462. */
  3463. +%option nostdinit noyywrap never-interactive full ecs
  3464. +%option 8bit nodefault yylineno
  3465. +%x ASSIGN_VAL HELP STRING
  3466. +%{
  3467. +#include <assert.h>
  3468. #include <limits.h>
  3469. #include <stdio.h>
  3470. #include <stdlib.h>
  3471. @@ -15,6 +15,9 @@
  3472. #include <unistd.h>
  3473. #include "lkc.h"
  3474. +#include "zconf.tab.h"
  3475. +
  3476. +#define YY_DECL static int yylex1(void)
  3477. #define START_STRSIZE 16
  3478. @@ -23,6 +26,8 @@ static struct {
  3479. int lineno;
  3480. } current_pos;
  3481. +static int prev_prev_token = T_EOL;
  3482. +static int prev_token = T_EOL;
  3483. static char *text;
  3484. static int text_size, text_asize;
  3485. @@ -35,6 +40,8 @@ struct buffer *current_buf;
  3486. static int last_ts, first_ts;
  3487. +static char *expand_token(const char *in, size_t n);
  3488. +static void append_expanded_string(const char *in);
  3489. static void zconf_endhelp(void);
  3490. static void zconf_endfile(void);
  3491. @@ -52,7 +59,7 @@ static void append_string(const char *str, int size)
  3492. if (new_size > text_asize) {
  3493. new_size += START_STRSIZE - 1;
  3494. new_size &= -START_STRSIZE;
  3495. - text = realloc(text, new_size);
  3496. + text = xrealloc(text, new_size);
  3497. text_asize = new_size;
  3498. }
  3499. memcpy(text + text_size, str, size);
  3500. @@ -71,7 +78,7 @@ static void warn_ignored_character(char chr)
  3501. {
  3502. fprintf(stderr,
  3503. "%s:%d:warning: ignoring unsupported character '%c'\n",
  3504. - zconf_curname(), zconf_lineno(), chr);
  3505. + current_file->name, yylineno, chr);
  3506. }
  3507. %}
  3508. @@ -81,116 +88,113 @@ n [A-Za-z0-9_-]
  3509. int str = 0;
  3510. int ts, i;
  3511. -[ \t]*#.*\n |
  3512. -[ \t]*\n {
  3513. - current_file->lineno++;
  3514. - return T_EOL;
  3515. -}
  3516. -[ \t]*#.*
  3517. -
  3518. -
  3519. -[ \t]+ {
  3520. - BEGIN(COMMAND);
  3521. -}
  3522. -
  3523. -. {
  3524. - unput(yytext[0]);
  3525. - BEGIN(COMMAND);
  3526. -}
  3527. -
  3528. -
  3529. -<COMMAND>{
  3530. - {n}+ {
  3531. - const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
  3532. - BEGIN(PARAM);
  3533. - current_pos.file = current_file;
  3534. - current_pos.lineno = current_file->lineno;
  3535. - if (id && id->flags & TF_COMMAND) {
  3536. - zconflval.id = id;
  3537. - return id->token;
  3538. - }
  3539. - alloc_string(yytext, yyleng);
  3540. - zconflval.string = text;
  3541. - return T_WORD;
  3542. - }
  3543. - . warn_ignored_character(*yytext);
  3544. - \n {
  3545. - BEGIN(INITIAL);
  3546. - current_file->lineno++;
  3547. - return T_EOL;
  3548. - }
  3549. -}
  3550. +#.* /* ignore comment */
  3551. +[ \t]* /* whitespaces */
  3552. +\\\n /* escaped new line */
  3553. +\n return T_EOL;
  3554. +"allnoconfig_y" return T_ALLNOCONFIG_Y;
  3555. +"bool" return T_BOOL;
  3556. +"choice" return T_CHOICE;
  3557. +"comment" return T_COMMENT;
  3558. +"config" return T_CONFIG;
  3559. +"def_bool" return T_DEF_BOOL;
  3560. +"def_tristate" return T_DEF_TRISTATE;
  3561. +"default" return T_DEFAULT;
  3562. +"defconfig_list" return T_DEFCONFIG_LIST;
  3563. +"depends" return T_DEPENDS;
  3564. +"endchoice" return T_ENDCHOICE;
  3565. +"endif" return T_ENDIF;
  3566. +"endmenu" return T_ENDMENU;
  3567. +"help"|"---help---" return T_HELP;
  3568. +"hex" return T_HEX;
  3569. +"if" return T_IF;
  3570. +"imply" return T_IMPLY;
  3571. +"int" return T_INT;
  3572. +"mainmenu" return T_MAINMENU;
  3573. +"menu" return T_MENU;
  3574. +"menuconfig" return T_MENUCONFIG;
  3575. +"modules" return T_MODULES;
  3576. +"on" return T_ON;
  3577. +"option" return T_OPTION;
  3578. +"optional" return T_OPTIONAL;
  3579. +"prompt" return T_PROMPT;
  3580. +"range" return T_RANGE;
  3581. +"select" return T_SELECT;
  3582. +"source" return T_SOURCE;
  3583. +"string" return T_STRING;
  3584. +"tristate" return T_TRISTATE;
  3585. +"visible" return T_VISIBLE;
  3586. +"||" return T_OR;
  3587. +"&&" return T_AND;
  3588. +"=" return T_EQUAL;
  3589. +"!=" return T_UNEQUAL;
  3590. +"<" return T_LESS;
  3591. +"<=" return T_LESS_EQUAL;
  3592. +">" return T_GREATER;
  3593. +">=" return T_GREATER_EQUAL;
  3594. +"!" return T_NOT;
  3595. +"(" return T_OPEN_PAREN;
  3596. +")" return T_CLOSE_PAREN;
  3597. +":=" return T_COLON_EQUAL;
  3598. +"+=" return T_PLUS_EQUAL;
  3599. +\"|\' {
  3600. + str = yytext[0];
  3601. + new_string();
  3602. + BEGIN(STRING);
  3603. + }
  3604. +{n}+ {
  3605. + alloc_string(yytext, yyleng);
  3606. + yylval.string = text;
  3607. + return T_WORD;
  3608. + }
  3609. +({n}|$)+ {
  3610. + /* this token includes at least one '$' */
  3611. + yylval.string = expand_token(yytext, yyleng);
  3612. + if (strlen(yylval.string))
  3613. + return T_WORD;
  3614. + free(yylval.string);
  3615. + }
  3616. +. warn_ignored_character(*yytext);
  3617. -<PARAM>{
  3618. - "&&" return T_AND;
  3619. - "||" return T_OR;
  3620. - "(" return T_OPEN_PAREN;
  3621. - ")" return T_CLOSE_PAREN;
  3622. - "!" return T_NOT;
  3623. - "=" return T_EQUAL;
  3624. - "!=" return T_UNEQUAL;
  3625. - "<=" return T_LESS_EQUAL;
  3626. - ">=" return T_GREATER_EQUAL;
  3627. - "<" return T_LESS;
  3628. - ">" return T_GREATER;
  3629. - \"|\' {
  3630. - str = yytext[0];
  3631. - new_string();
  3632. - BEGIN(STRING);
  3633. - }
  3634. - \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
  3635. - ({n}|[/.])+ {
  3636. - const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
  3637. - if (id && id->flags & TF_PARAM) {
  3638. - zconflval.id = id;
  3639. - return id->token;
  3640. - }
  3641. +<ASSIGN_VAL>{
  3642. + [^[:blank:]\n]+.* {
  3643. alloc_string(yytext, yyleng);
  3644. - zconflval.string = text;
  3645. - return T_WORD;
  3646. - }
  3647. - #.* /* comment */
  3648. - \\\n current_file->lineno++;
  3649. - [[:blank:]]+
  3650. - . warn_ignored_character(*yytext);
  3651. - <<EOF>> {
  3652. - BEGIN(INITIAL);
  3653. + yylval.string = text;
  3654. + return T_ASSIGN_VAL;
  3655. }
  3656. + \n { BEGIN(INITIAL); return T_EOL; }
  3657. + .
  3658. }
  3659. <STRING>{
  3660. - [^'"\\\n]+/\n {
  3661. - append_string(yytext, yyleng);
  3662. - zconflval.string = text;
  3663. - return T_WORD_QUOTE;
  3664. - }
  3665. - [^'"\\\n]+ {
  3666. + "$".* append_expanded_string(yytext);
  3667. + [^$'"\\\n]+ {
  3668. append_string(yytext, yyleng);
  3669. }
  3670. - \\.?/\n {
  3671. - append_string(yytext + 1, yyleng - 1);
  3672. - zconflval.string = text;
  3673. - return T_WORD_QUOTE;
  3674. - }
  3675. \\.? {
  3676. append_string(yytext + 1, yyleng - 1);
  3677. }
  3678. \'|\" {
  3679. if (str == yytext[0]) {
  3680. - BEGIN(PARAM);
  3681. - zconflval.string = text;
  3682. + BEGIN(INITIAL);
  3683. + yylval.string = text;
  3684. return T_WORD_QUOTE;
  3685. } else
  3686. append_string(yytext, 1);
  3687. }
  3688. \n {
  3689. - printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
  3690. - current_file->lineno++;
  3691. + fprintf(stderr,
  3692. + "%s:%d:warning: multi-line strings not supported\n",
  3693. + zconf_curname(), zconf_lineno());
  3694. + unput('\n');
  3695. BEGIN(INITIAL);
  3696. - return T_EOL;
  3697. + yylval.string = text;
  3698. + return T_WORD_QUOTE;
  3699. }
  3700. <<EOF>> {
  3701. BEGIN(INITIAL);
  3702. + yylval.string = text;
  3703. + return T_WORD_QUOTE;
  3704. }
  3705. }
  3706. @@ -218,12 +222,10 @@ n [A-Za-z0-9_-]
  3707. }
  3708. }
  3709. [ \t]*\n/[^ \t\n] {
  3710. - current_file->lineno++;
  3711. zconf_endhelp();
  3712. return T_HELPTEXT;
  3713. }
  3714. [ \t]*\n {
  3715. - current_file->lineno++;
  3716. append_string("\n", 1);
  3717. }
  3718. [^ \t\n].* {
  3719. @@ -243,6 +245,12 @@ n [A-Za-z0-9_-]
  3720. }
  3721. <<EOF>> {
  3722. + BEGIN(INITIAL);
  3723. +
  3724. + if (prev_token != T_EOL && prev_token != T_HELPTEXT)
  3725. + fprintf(stderr, "%s:%d:warning: no new line at end of file\n",
  3726. + current_file->name, yylineno);
  3727. +
  3728. if (current_file) {
  3729. zconf_endfile();
  3730. return T_EOL;
  3731. @@ -252,6 +260,93 @@ n [A-Za-z0-9_-]
  3732. }
  3733. %%
  3734. +
  3735. +/* second stage lexer */
  3736. +int yylex(void)
  3737. +{
  3738. + int token;
  3739. +
  3740. +repeat:
  3741. + token = yylex1();
  3742. +
  3743. + if (prev_token == T_EOL || prev_token == T_HELPTEXT) {
  3744. + if (token == T_EOL) {
  3745. + /* Do not pass unneeded T_EOL to the parser. */
  3746. + goto repeat;
  3747. + } else {
  3748. + /*
  3749. + * For the parser, update file/lineno at the first token
  3750. + * of each statement. Generally, \n is a statement
  3751. + * terminator in Kconfig, but it is not always true
  3752. + * because \n could be escaped by a backslash.
  3753. + */
  3754. + current_pos.file = current_file;
  3755. + current_pos.lineno = yylineno;
  3756. + }
  3757. + }
  3758. +
  3759. + if (prev_prev_token == T_EOL && prev_token == T_WORD &&
  3760. + (token == T_EQUAL || token == T_COLON_EQUAL || token == T_PLUS_EQUAL))
  3761. + BEGIN(ASSIGN_VAL);
  3762. +
  3763. + prev_prev_token = prev_token;
  3764. + prev_token = token;
  3765. +
  3766. + return token;
  3767. +}
  3768. +
  3769. +static char *expand_token(const char *in, size_t n)
  3770. +{
  3771. + char *out;
  3772. + int c;
  3773. + char c2;
  3774. + const char *rest, *end;
  3775. +
  3776. + new_string();
  3777. + append_string(in, n);
  3778. +
  3779. + /* get the whole line because we do not know the end of token. */
  3780. + while ((c = input()) != EOF) {
  3781. + if (c == '\n') {
  3782. + unput(c);
  3783. + break;
  3784. + }
  3785. + c2 = c;
  3786. + append_string(&c2, 1);
  3787. + }
  3788. +
  3789. + rest = text;
  3790. + out = expand_one_token(&rest);
  3791. +
  3792. + /* push back unused characters to the input stream */
  3793. + end = rest + strlen(rest);
  3794. + while (end > rest)
  3795. + unput(*--end);
  3796. +
  3797. + free(text);
  3798. +
  3799. + return out;
  3800. +}
  3801. +
  3802. +static void append_expanded_string(const char *str)
  3803. +{
  3804. + const char *end;
  3805. + char *res;
  3806. +
  3807. + str++;
  3808. +
  3809. + res = expand_dollar(&str);
  3810. +
  3811. + /* push back unused characters to the input stream */
  3812. + end = str + strlen(str);
  3813. + while (end > str)
  3814. + unput(*--end);
  3815. +
  3816. + append_string(res, strlen(res));
  3817. +
  3818. + free(res);
  3819. +}
  3820. +
  3821. void zconf_starthelp(void)
  3822. {
  3823. new_string();
  3824. @@ -261,7 +356,7 @@ void zconf_starthelp(void)
  3825. static void zconf_endhelp(void)
  3826. {
  3827. - zconflval.string = text;
  3828. + yylval.string = text;
  3829. BEGIN(INITIAL);
  3830. }
  3831. @@ -294,7 +389,7 @@ void zconf_initscan(const char *name)
  3832. {
  3833. yyin = zconf_fopen(name);
  3834. if (!yyin) {
  3835. - printf("can't find file %s\n", name);
  3836. + fprintf(stderr, "can't find file %s\n", name);
  3837. exit(1);
  3838. }
  3839. @@ -302,7 +397,7 @@ void zconf_initscan(const char *name)
  3840. memset(current_buf, 0, sizeof(*current_buf));
  3841. current_file = file_lookup(name);
  3842. - current_file->lineno = 1;
  3843. + yylineno = 1;
  3844. }
  3845. void zconf_nextfile(const char *name)
  3846. @@ -315,35 +410,34 @@ void zconf_nextfile(const char *name)
  3847. current_buf->state = YY_CURRENT_BUFFER;
  3848. yyin = zconf_fopen(file->name);
  3849. if (!yyin) {
  3850. - printf("%s:%d: can't open file \"%s\"\n",
  3851. - zconf_curname(), zconf_lineno(), file->name);
  3852. + fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
  3853. + zconf_curname(), zconf_lineno(), file->name);
  3854. exit(1);
  3855. }
  3856. yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
  3857. buf->parent = current_buf;
  3858. current_buf = buf;
  3859. - for (iter = current_file->parent; iter; iter = iter->parent ) {
  3860. - if (!strcmp(current_file->name,iter->name) ) {
  3861. - printf("%s:%d: recursive inclusion detected. "
  3862. - "Inclusion path:\n current file : '%s'\n",
  3863. - zconf_curname(), zconf_lineno(),
  3864. - zconf_curname());
  3865. - iter = current_file->parent;
  3866. - while (iter && \
  3867. - strcmp(iter->name,current_file->name)) {
  3868. - printf(" included from: '%s:%d'\n",
  3869. - iter->name, iter->lineno-1);
  3870. + current_file->lineno = yylineno;
  3871. + file->parent = current_file;
  3872. +
  3873. + for (iter = current_file; iter; iter = iter->parent) {
  3874. + if (!strcmp(iter->name, file->name)) {
  3875. + fprintf(stderr,
  3876. + "Recursive inclusion detected.\n"
  3877. + "Inclusion path:\n"
  3878. + " current file : %s\n", file->name);
  3879. + iter = file;
  3880. + do {
  3881. iter = iter->parent;
  3882. - }
  3883. - if (iter)
  3884. - printf(" included from: '%s:%d'\n",
  3885. - iter->name, iter->lineno+1);
  3886. + fprintf(stderr, " included from: %s:%d\n",
  3887. + iter->name, iter->lineno - 1);
  3888. + } while (strcmp(iter->name, file->name));
  3889. exit(1);
  3890. }
  3891. }
  3892. - file->lineno = 1;
  3893. - file->parent = current_file;
  3894. +
  3895. + yylineno = 1;
  3896. current_file = file;
  3897. }
  3898. @@ -352,6 +446,8 @@ static void zconf_endfile(void)
  3899. struct buffer *parent;
  3900. current_file = current_file->parent;
  3901. + if (current_file)
  3902. + yylineno = current_file->lineno;
  3903. parent = current_buf->parent;
  3904. if (parent) {
  3905. diff --git a/carl9170fw/config/zconf.y b/carl9170fw/config/zconf.y
  3906. index 79c4f04..60936c7 100644
  3907. --- a/carl9170fw/config/zconf.y
  3908. +++ b/carl9170fw/config/zconf.y
  3909. @@ -1,8 +1,8 @@
  3910. -%{
  3911. +/* SPDX-License-Identifier: GPL-2.0 */
  3912. /*
  3913. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  3914. - * Released under the terms of the GNU GPL v2.0.
  3915. */
  3916. +%{
  3917. #include <ctype.h>
  3918. #include <stdarg.h>
  3919. @@ -20,63 +20,69 @@
  3920. int cdebug = PRINTD;
  3921. -extern int zconflex(void);
  3922. +static void yyerror(const char *err);
  3923. static void zconfprint(const char *err, ...);
  3924. static void zconf_error(const char *err, ...);
  3925. -static void zconferror(const char *err);
  3926. -static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken);
  3927. +static bool zconf_endtoken(const char *tokenname,
  3928. + const char *expected_tokenname);
  3929. struct symbol *symbol_hash[SYMBOL_HASHSIZE];
  3930. static struct menu *current_menu, *current_entry;
  3931. %}
  3932. -%expect 32
  3933. %union
  3934. {
  3935. char *string;
  3936. - struct file *file;
  3937. struct symbol *symbol;
  3938. struct expr *expr;
  3939. struct menu *menu;
  3940. - const struct kconf_id *id;
  3941. + enum symbol_type type;
  3942. + enum variable_flavor flavor;
  3943. }
  3944. -%token <id>T_MAINMENU
  3945. -%token <id>T_MENU
  3946. -%token <id>T_ENDMENU
  3947. -%token <id>T_SOURCE
  3948. -%token <id>T_CHOICE
  3949. -%token <id>T_ENDCHOICE
  3950. -%token <id>T_COMMENT
  3951. -%token <id>T_CONFIG
  3952. -%token <id>T_MENUCONFIG
  3953. -%token <id>T_HELP
  3954. %token <string> T_HELPTEXT
  3955. -%token <id>T_IF
  3956. -%token <id>T_ENDIF
  3957. -%token <id>T_DEPENDS
  3958. -%token <id>T_OPTIONAL
  3959. -%token <id>T_PROMPT
  3960. -%token <id>T_TYPE
  3961. -%token <id>T_DEFAULT
  3962. -%token <id>T_SELECT
  3963. -%token <id>T_IMPLY
  3964. -%token <id>T_RANGE
  3965. -%token <id>T_VISIBLE
  3966. -%token <id>T_OPTION
  3967. -%token <id>T_ON
  3968. %token <string> T_WORD
  3969. %token <string> T_WORD_QUOTE
  3970. -%token T_UNEQUAL
  3971. -%token T_LESS
  3972. -%token T_LESS_EQUAL
  3973. -%token T_GREATER
  3974. -%token T_GREATER_EQUAL
  3975. +%token T_ALLNOCONFIG_Y
  3976. +%token T_BOOL
  3977. +%token T_CHOICE
  3978. %token T_CLOSE_PAREN
  3979. +%token T_COLON_EQUAL
  3980. +%token T_COMMENT
  3981. +%token T_CONFIG
  3982. +%token T_DEFAULT
  3983. +%token T_DEFCONFIG_LIST
  3984. +%token T_DEF_BOOL
  3985. +%token T_DEF_TRISTATE
  3986. +%token T_DEPENDS
  3987. +%token T_ENDCHOICE
  3988. +%token T_ENDIF
  3989. +%token T_ENDMENU
  3990. +%token T_HELP
  3991. +%token T_HEX
  3992. +%token T_IF
  3993. +%token T_IMPLY
  3994. +%token T_INT
  3995. +%token T_MAINMENU
  3996. +%token T_MENU
  3997. +%token T_MENUCONFIG
  3998. +%token T_MODULES
  3999. +%token T_ON
  4000. %token T_OPEN_PAREN
  4001. +%token T_OPTION
  4002. +%token T_OPTIONAL
  4003. +%token T_PLUS_EQUAL
  4004. +%token T_PROMPT
  4005. +%token T_RANGE
  4006. +%token T_SELECT
  4007. +%token T_SOURCE
  4008. +%token T_STRING
  4009. +%token T_TRISTATE
  4010. +%token T_VISIBLE
  4011. %token T_EOL
  4012. +%token <string> T_ASSIGN_VAL
  4013. %left T_OR
  4014. %left T_AND
  4015. @@ -85,13 +91,15 @@ static struct menu *current_menu, *current_entry;
  4016. %nonassoc T_NOT
  4017. %type <string> prompt
  4018. +%type <symbol> nonconst_symbol
  4019. %type <symbol> symbol
  4020. +%type <type> type logic_type default
  4021. %type <expr> expr
  4022. %type <expr> if_expr
  4023. -%type <id> end
  4024. -%type <id> option_name
  4025. +%type <string> end
  4026. %type <menu> if_entry menu_entry choice_entry
  4027. -%type <string> symbol_option_arg word_opt
  4028. +%type <string> word_opt assign_val
  4029. +%type <flavor> assign_op
  4030. %destructor {
  4031. fprintf(stderr, "%s:%d: missing end statement for this entry\n",
  4032. @@ -100,71 +108,53 @@ static struct menu *current_menu, *current_entry;
  4033. menu_end_menu();
  4034. } if_entry menu_entry choice_entry
  4035. -%{
  4036. -/* Include zconf_id.c here so it can see the token constants. */
  4037. -#include "kconf_id.c"
  4038. -%}
  4039. -
  4040. %%
  4041. -input: nl start | start;
  4042. +input: mainmenu_stmt stmt_list | stmt_list;
  4043. -start: mainmenu_stmt stmt_list | stmt_list;
  4044. +/* mainmenu entry */
  4045. +
  4046. +mainmenu_stmt: T_MAINMENU prompt T_EOL
  4047. +{
  4048. + menu_add_prompt(P_MENU, $2, NULL);
  4049. +};
  4050. stmt_list:
  4051. /* empty */
  4052. | stmt_list common_stmt
  4053. | stmt_list choice_stmt
  4054. | stmt_list menu_stmt
  4055. - | stmt_list end { zconf_error("unexpected end statement"); }
  4056. | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
  4057. - | stmt_list option_name error T_EOL
  4058. -{
  4059. - zconf_error("unexpected option \"%s\"", $2->name);
  4060. -}
  4061. | stmt_list error T_EOL { zconf_error("invalid statement"); }
  4062. ;
  4063. -option_name:
  4064. - T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
  4065. -;
  4066. -
  4067. common_stmt:
  4068. - T_EOL
  4069. - | if_stmt
  4070. + if_stmt
  4071. | comment_stmt
  4072. | config_stmt
  4073. | menuconfig_stmt
  4074. | source_stmt
  4075. + | assignment_stmt
  4076. ;
  4077. -option_error:
  4078. - T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
  4079. - | error T_EOL { zconf_error("invalid option"); }
  4080. -;
  4081. -
  4082. -
  4083. /* config/menuconfig entry */
  4084. -config_entry_start: T_CONFIG T_WORD T_EOL
  4085. +config_entry_start: T_CONFIG nonconst_symbol T_EOL
  4086. {
  4087. - struct symbol *sym = sym_lookup($2, 0);
  4088. - sym->flags |= SYMBOL_OPTIONAL;
  4089. - menu_add_entry(sym);
  4090. - printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
  4091. + $2->flags |= SYMBOL_OPTIONAL;
  4092. + menu_add_entry($2);
  4093. + printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name);
  4094. };
  4095. config_stmt: config_entry_start config_option_list
  4096. {
  4097. - menu_end_entry();
  4098. printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
  4099. };
  4100. -menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
  4101. +menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
  4102. {
  4103. - struct symbol *sym = sym_lookup($2, 0);
  4104. - sym->flags |= SYMBOL_OPTIONAL;
  4105. - menu_add_entry(sym);
  4106. - printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
  4107. + $2->flags |= SYMBOL_OPTIONAL;
  4108. + menu_add_entry($2);
  4109. + printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name);
  4110. };
  4111. menuconfig_stmt: menuconfig_entry_start config_option_list
  4112. @@ -173,26 +163,22 @@ menuconfig_stmt: menuconfig_entry_start config_option_list
  4113. current_entry->prompt->type = P_MENU;
  4114. else
  4115. zconfprint("warning: menuconfig statement without prompt");
  4116. - menu_end_entry();
  4117. printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
  4118. };
  4119. config_option_list:
  4120. /* empty */
  4121. | config_option_list config_option
  4122. - | config_option_list symbol_option
  4123. | config_option_list depends
  4124. | config_option_list help
  4125. - | config_option_list option_error
  4126. - | config_option_list T_EOL
  4127. ;
  4128. -config_option: T_TYPE prompt_stmt_opt T_EOL
  4129. +config_option: type prompt_stmt_opt T_EOL
  4130. {
  4131. - menu_set_type($1->stype);
  4132. + menu_set_type($1);
  4133. printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
  4134. zconf_curname(), zconf_lineno(),
  4135. - $1->stype);
  4136. + $1);
  4137. };
  4138. config_option: T_PROMPT prompt if_expr T_EOL
  4139. @@ -201,25 +187,25 @@ config_option: T_PROMPT prompt if_expr T_EOL
  4140. printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
  4141. };
  4142. -config_option: T_DEFAULT expr if_expr T_EOL
  4143. +config_option: default expr if_expr T_EOL
  4144. {
  4145. menu_add_expr(P_DEFAULT, $2, $3);
  4146. - if ($1->stype != S_UNKNOWN)
  4147. - menu_set_type($1->stype);
  4148. + if ($1 != S_UNKNOWN)
  4149. + menu_set_type($1);
  4150. printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
  4151. zconf_curname(), zconf_lineno(),
  4152. - $1->stype);
  4153. + $1);
  4154. };
  4155. -config_option: T_SELECT T_WORD if_expr T_EOL
  4156. +config_option: T_SELECT nonconst_symbol if_expr T_EOL
  4157. {
  4158. - menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
  4159. + menu_add_symbol(P_SELECT, $2, $3);
  4160. printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
  4161. };
  4162. -config_option: T_IMPLY T_WORD if_expr T_EOL
  4163. +config_option: T_IMPLY nonconst_symbol if_expr T_EOL
  4164. {
  4165. - menu_add_symbol(P_IMPLY, sym_lookup($2, 0), $3);
  4166. + menu_add_symbol(P_IMPLY, $2, $3);
  4167. printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
  4168. };
  4169. @@ -229,34 +215,30 @@ config_option: T_RANGE symbol symbol if_expr T_EOL
  4170. printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
  4171. };
  4172. -symbol_option: T_OPTION symbol_option_list T_EOL
  4173. -;
  4174. +config_option: T_OPTION T_MODULES T_EOL
  4175. +{
  4176. + menu_add_option_modules();
  4177. +};
  4178. -symbol_option_list:
  4179. - /* empty */
  4180. - | symbol_option_list T_WORD symbol_option_arg
  4181. +config_option: T_OPTION T_DEFCONFIG_LIST T_EOL
  4182. {
  4183. - const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
  4184. - if (id && id->flags & TF_OPTION)
  4185. - menu_add_option(id->token, $3);
  4186. - else
  4187. - zconfprint("warning: ignoring unknown option %s", $2);
  4188. - free($2);
  4189. + menu_add_option_defconfig_list();
  4190. };
  4191. -symbol_option_arg:
  4192. - /* empty */ { $$ = NULL; }
  4193. - | T_EQUAL prompt { $$ = $2; }
  4194. -;
  4195. +config_option: T_OPTION T_ALLNOCONFIG_Y T_EOL
  4196. +{
  4197. + menu_add_option_allnoconfig_y();
  4198. +};
  4199. /* choice entry */
  4200. choice: T_CHOICE word_opt T_EOL
  4201. {
  4202. struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
  4203. - sym->flags |= SYMBOL_AUTO;
  4204. + sym->flags |= SYMBOL_NO_WRITE;
  4205. menu_add_entry(sym);
  4206. menu_add_expr(P_CHOICE, NULL, NULL);
  4207. + free($2);
  4208. printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
  4209. };
  4210. @@ -267,7 +249,7 @@ choice_entry: choice choice_option_list
  4211. choice_end: end
  4212. {
  4213. - if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
  4214. + if (zconf_endtoken($1, "choice")) {
  4215. menu_end_menu();
  4216. printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
  4217. }
  4218. @@ -281,8 +263,6 @@ choice_option_list:
  4219. | choice_option_list choice_option
  4220. | choice_option_list depends
  4221. | choice_option_list help
  4222. - | choice_option_list T_EOL
  4223. - | choice_option_list option_error
  4224. ;
  4225. choice_option: T_PROMPT prompt if_expr T_EOL
  4226. @@ -291,15 +271,11 @@ choice_option: T_PROMPT prompt if_expr T_EOL
  4227. printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
  4228. };
  4229. -choice_option: T_TYPE prompt_stmt_opt T_EOL
  4230. +choice_option: logic_type prompt_stmt_opt T_EOL
  4231. {
  4232. - if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
  4233. - menu_set_type($1->stype);
  4234. - printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
  4235. - zconf_curname(), zconf_lineno(),
  4236. - $1->stype);
  4237. - } else
  4238. - YYERROR;
  4239. + menu_set_type($1);
  4240. + printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
  4241. + zconf_curname(), zconf_lineno(), $1);
  4242. };
  4243. choice_option: T_OPTIONAL T_EOL
  4244. @@ -308,16 +284,28 @@ choice_option: T_OPTIONAL T_EOL
  4245. printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
  4246. };
  4247. -choice_option: T_DEFAULT T_WORD if_expr T_EOL
  4248. +choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
  4249. {
  4250. - if ($1->stype == S_UNKNOWN) {
  4251. - menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
  4252. - printd(DEBUG_PARSE, "%s:%d:default\n",
  4253. - zconf_curname(), zconf_lineno());
  4254. - } else
  4255. - YYERROR;
  4256. + menu_add_symbol(P_DEFAULT, $2, $3);
  4257. + printd(DEBUG_PARSE, "%s:%d:default\n",
  4258. + zconf_curname(), zconf_lineno());
  4259. };
  4260. +type:
  4261. + logic_type
  4262. + | T_INT { $$ = S_INT; }
  4263. + | T_HEX { $$ = S_HEX; }
  4264. + | T_STRING { $$ = S_STRING; }
  4265. +
  4266. +logic_type:
  4267. + T_BOOL { $$ = S_BOOLEAN; }
  4268. + | T_TRISTATE { $$ = S_TRISTATE; }
  4269. +
  4270. +default:
  4271. + T_DEFAULT { $$ = S_UNKNOWN; }
  4272. + | T_DEF_BOOL { $$ = S_BOOLEAN; }
  4273. + | T_DEF_TRISTATE { $$ = S_TRISTATE; }
  4274. +
  4275. choice_block:
  4276. /* empty */
  4277. | choice_block common_stmt
  4278. @@ -325,7 +313,7 @@ choice_block:
  4279. /* if entry */
  4280. -if_entry: T_IF expr nl
  4281. +if_entry: T_IF expr T_EOL
  4282. {
  4283. printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
  4284. menu_add_entry(NULL);
  4285. @@ -335,29 +323,15 @@ if_entry: T_IF expr nl
  4286. if_end: end
  4287. {
  4288. - if (zconf_endtoken($1, T_IF, T_ENDIF)) {
  4289. + if (zconf_endtoken($1, "if")) {
  4290. menu_end_menu();
  4291. printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
  4292. }
  4293. };
  4294. -if_stmt: if_entry if_block if_end
  4295. +if_stmt: if_entry stmt_list if_end
  4296. ;
  4297. -if_block:
  4298. - /* empty */
  4299. - | if_block common_stmt
  4300. - | if_block menu_stmt
  4301. - | if_block choice_stmt
  4302. -;
  4303. -
  4304. -/* mainmenu entry */
  4305. -
  4306. -mainmenu_stmt: T_MAINMENU prompt nl
  4307. -{
  4308. - menu_add_prompt(P_MENU, $2, NULL);
  4309. -};
  4310. -
  4311. /* menu entry */
  4312. menu: T_MENU prompt T_EOL
  4313. @@ -367,33 +341,33 @@ menu: T_MENU prompt T_EOL
  4314. printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
  4315. };
  4316. -menu_entry: menu visibility_list depends_list
  4317. +menu_entry: menu menu_option_list
  4318. {
  4319. $$ = menu_add_menu();
  4320. };
  4321. menu_end: end
  4322. {
  4323. - if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
  4324. + if (zconf_endtoken($1, "menu")) {
  4325. menu_end_menu();
  4326. printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
  4327. }
  4328. };
  4329. -menu_stmt: menu_entry menu_block menu_end
  4330. +menu_stmt: menu_entry stmt_list menu_end
  4331. ;
  4332. -menu_block:
  4333. +menu_option_list:
  4334. /* empty */
  4335. - | menu_block common_stmt
  4336. - | menu_block menu_stmt
  4337. - | menu_block choice_stmt
  4338. + | menu_option_list visible
  4339. + | menu_option_list depends
  4340. ;
  4341. source_stmt: T_SOURCE prompt T_EOL
  4342. {
  4343. printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
  4344. zconf_nextfile($2);
  4345. + free($2);
  4346. };
  4347. /* comment entry */
  4348. @@ -405,10 +379,13 @@ comment: T_COMMENT prompt T_EOL
  4349. printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
  4350. };
  4351. -comment_stmt: comment depends_list
  4352. -{
  4353. - menu_end_entry();
  4354. -};
  4355. +comment_stmt: comment comment_option_list
  4356. +;
  4357. +
  4358. +comment_option_list:
  4359. + /* empty */
  4360. + | comment_option_list depends
  4361. +;
  4362. /* help option */
  4363. @@ -420,18 +397,22 @@ help_start: T_HELP T_EOL
  4364. help: help_start T_HELPTEXT
  4365. {
  4366. + if (current_entry->help) {
  4367. + free(current_entry->help);
  4368. + zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
  4369. + current_entry->sym->name ?: "<choice>");
  4370. + }
  4371. +
  4372. + /* Is the help text empty or all whitespace? */
  4373. + if ($2[strspn($2, " \f\n\r\t\v")] == '\0')
  4374. + zconfprint("warning: '%s' defined with blank help text",
  4375. + current_entry->sym->name ?: "<choice>");
  4376. +
  4377. current_entry->help = $2;
  4378. };
  4379. /* depends option */
  4380. -depends_list:
  4381. - /* empty */
  4382. - | depends_list depends
  4383. - | depends_list T_EOL
  4384. - | depends_list option_error
  4385. -;
  4386. -
  4387. depends: T_DEPENDS T_ON expr T_EOL
  4388. {
  4389. menu_add_dep($3);
  4390. @@ -439,14 +420,7 @@ depends: T_DEPENDS T_ON expr T_EOL
  4391. };
  4392. /* visibility option */
  4393. -
  4394. -visibility_list:
  4395. - /* empty */
  4396. - | visibility_list visible
  4397. - | visibility_list T_EOL
  4398. -;
  4399. -
  4400. -visible: T_VISIBLE if_expr
  4401. +visible: T_VISIBLE if_expr T_EOL
  4402. {
  4403. menu_add_visibility($2);
  4404. };
  4405. @@ -464,14 +438,9 @@ prompt: T_WORD
  4406. | T_WORD_QUOTE
  4407. ;
  4408. -end: T_ENDMENU T_EOL { $$ = $1; }
  4409. - | T_ENDCHOICE T_EOL { $$ = $1; }
  4410. - | T_ENDIF T_EOL { $$ = $1; }
  4411. -;
  4412. -
  4413. -nl:
  4414. - T_EOL
  4415. - | nl T_EOL
  4416. +end: T_ENDMENU T_EOL { $$ = "menu"; }
  4417. + | T_ENDCHOICE T_EOL { $$ = "choice"; }
  4418. + | T_ENDIF T_EOL { $$ = "if"; }
  4419. ;
  4420. if_expr: /* empty */ { $$ = NULL; }
  4421. @@ -491,13 +460,31 @@ expr: symbol { $$ = expr_alloc_symbol($1); }
  4422. | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
  4423. ;
  4424. -symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
  4425. +/* For symbol definitions, selects, etc., where quotes are not accepted */
  4426. +nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
  4427. +
  4428. +symbol: nonconst_symbol
  4429. | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
  4430. ;
  4431. word_opt: /* empty */ { $$ = NULL; }
  4432. | T_WORD
  4433. +/* assignment statement */
  4434. +
  4435. +assignment_stmt: T_WORD assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
  4436. +
  4437. +assign_op:
  4438. + T_EQUAL { $$ = VAR_RECURSIVE; }
  4439. + | T_COLON_EQUAL { $$ = VAR_SIMPLE; }
  4440. + | T_PLUS_EQUAL { $$ = VAR_APPEND; }
  4441. +;
  4442. +
  4443. +assign_val:
  4444. + /* empty */ { $$ = xstrdup(""); };
  4445. + | T_ASSIGN_VAL
  4446. +;
  4447. +
  4448. %%
  4449. void conf_parse(const char *name)
  4450. @@ -507,61 +494,51 @@ void conf_parse(const char *name)
  4451. zconf_initscan(name);
  4452. - sym_init();
  4453. _menu_init();
  4454. - rootmenu.prompt = menu_add_prompt(P_MENU, "CARL9170 Firmware Configuration", NULL);
  4455. if (getenv("ZCONF_DEBUG"))
  4456. - zconfdebug = 1;
  4457. - zconfparse();
  4458. - if (zconfnerrs)
  4459. + yydebug = 1;
  4460. + yyparse();
  4461. +
  4462. + /* Variables are expanded in the parse phase. We can free them here. */
  4463. + variable_all_del();
  4464. +
  4465. + if (yynerrs)
  4466. exit(1);
  4467. if (!modules_sym)
  4468. modules_sym = sym_find( "n" );
  4469. - rootmenu.prompt->text = _(rootmenu.prompt->text);
  4470. - rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
  4471. + if (!menu_has_prompt(&rootmenu)) {
  4472. + current_entry = &rootmenu;
  4473. + menu_add_prompt(P_MENU, "Main menu", NULL);
  4474. + }
  4475. menu_finalize(&rootmenu);
  4476. for_all_symbols(i, sym) {
  4477. if (sym_check_deps(sym))
  4478. - zconfnerrs++;
  4479. + yynerrs++;
  4480. }
  4481. - if (zconfnerrs)
  4482. + if (yynerrs)
  4483. exit(1);
  4484. sym_set_change_count(1);
  4485. }
  4486. -static const char *zconf_tokenname(int token)
  4487. -{
  4488. - switch (token) {
  4489. - case T_MENU: return "menu";
  4490. - case T_ENDMENU: return "endmenu";
  4491. - case T_CHOICE: return "choice";
  4492. - case T_ENDCHOICE: return "endchoice";
  4493. - case T_IF: return "if";
  4494. - case T_ENDIF: return "endif";
  4495. - case T_DEPENDS: return "depends";
  4496. - case T_VISIBLE: return "visible";
  4497. - }
  4498. - return "<token>";
  4499. -}
  4500. -
  4501. -static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
  4502. +static bool zconf_endtoken(const char *tokenname,
  4503. + const char *expected_tokenname)
  4504. {
  4505. - if (id->token != endtoken) {
  4506. + if (strcmp(tokenname, expected_tokenname)) {
  4507. zconf_error("unexpected '%s' within %s block",
  4508. - id->name, zconf_tokenname(starttoken));
  4509. - zconfnerrs++;
  4510. + tokenname, expected_tokenname);
  4511. + yynerrs++;
  4512. return false;
  4513. }
  4514. if (current_menu->file != current_file) {
  4515. zconf_error("'%s' in different file than '%s'",
  4516. - id->name, zconf_tokenname(starttoken));
  4517. + tokenname, expected_tokenname);
  4518. fprintf(stderr, "%s:%d: location of the '%s'\n",
  4519. current_menu->file->name, current_menu->lineno,
  4520. - zconf_tokenname(starttoken));
  4521. - zconfnerrs++;
  4522. + expected_tokenname);
  4523. + yynerrs++;
  4524. return false;
  4525. }
  4526. return true;
  4527. @@ -582,7 +559,7 @@ static void zconf_error(const char *err, ...)
  4528. {
  4529. va_list ap;
  4530. - zconfnerrs++;
  4531. + yynerrs++;
  4532. fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
  4533. va_start(ap, err);
  4534. vfprintf(stderr, err, ap);
  4535. @@ -590,7 +567,7 @@ static void zconf_error(const char *err, ...)
  4536. fprintf(stderr, "\n");
  4537. }
  4538. -static void zconferror(const char *err)
  4539. +static void yyerror(const char *err)
  4540. {
  4541. fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
  4542. }
  4543. @@ -623,7 +600,7 @@ static void print_symbol(FILE *out, struct menu *menu)
  4544. fprintf(out, "\nconfig %s\n", sym->name);
  4545. switch (sym->type) {
  4546. case S_BOOLEAN:
  4547. - fputs(" boolean\n", out);
  4548. + fputs(" bool\n", out);
  4549. break;
  4550. case S_TRISTATE:
  4551. fputs(" tristate\n", out);
  4552. @@ -686,6 +663,10 @@ static void print_symbol(FILE *out, struct menu *menu)
  4553. print_quoted_string(out, prop->text);
  4554. fputc('\n', out);
  4555. break;
  4556. + case P_SYMBOL:
  4557. + fputs( " symbol ", out);
  4558. + fprintf(out, "%s\n", prop->sym->name);
  4559. + break;
  4560. default:
  4561. fprintf(out, " unknown prop %d!\n", prop->type);
  4562. break;
  4563. @@ -746,9 +727,5 @@ void zconfdump(FILE *out)
  4564. }
  4565. }
  4566. -#include "zconf.lex.c"
  4567. #include "util.c"
  4568. -#include "confdata.c"
  4569. -#include "expr.c"
  4570. -#include "symbol.c"
  4571. #include "menu.c"
  4572. diff --git a/carl9170fw/include/linux/ieee80211.h b/carl9170fw/include/linux/ieee80211.h
  4573. index 31c59ea..46ce6cf 100644
  4574. --- a/carl9170fw/include/linux/ieee80211.h
  4575. +++ b/carl9170fw/include/linux/ieee80211.h
  4576. @@ -897,33 +897,33 @@ struct ieee80211_mgmt {
  4577. __le16 status_code;
  4578. /* possibly followed by Challenge text */
  4579. u8 variable[0];
  4580. - } __packed auth;
  4581. + } __packed __aligned(4) auth;
  4582. struct {
  4583. __le16 reason_code;
  4584. - } __packed deauth;
  4585. + } __packed __aligned(4) deauth;
  4586. struct {
  4587. __le16 capab_info;
  4588. __le16 listen_interval;
  4589. /* followed by SSID and Supported rates */
  4590. u8 variable[0];
  4591. - } __packed assoc_req;
  4592. + } __packed __aligned(4) assoc_req;
  4593. struct {
  4594. __le16 capab_info;
  4595. __le16 status_code;
  4596. __le16 aid;
  4597. /* followed by Supported rates */
  4598. u8 variable[0];
  4599. - } __packed assoc_resp, reassoc_resp;
  4600. + } __packed __aligned(4) assoc_resp, reassoc_resp;
  4601. struct {
  4602. __le16 capab_info;
  4603. __le16 listen_interval;
  4604. u8 current_ap[6];
  4605. /* followed by SSID and Supported rates */
  4606. u8 variable[0];
  4607. - } __packed reassoc_req;
  4608. + } __packed __aligned(4) reassoc_req;
  4609. struct {
  4610. __le16 reason_code;
  4611. - } __packed disassoc;
  4612. + } __packed __aligned(4) disassoc;
  4613. struct {
  4614. __le64 timestamp;
  4615. __le16 beacon_int;
  4616. @@ -931,11 +931,11 @@ struct ieee80211_mgmt {
  4617. /* followed by some of SSID, Supported rates,
  4618. * FH Params, DS Params, CF Params, IBSS Params, TIM */
  4619. u8 variable[0];
  4620. - } __packed beacon;
  4621. + } __packed __aligned(4) beacon;
  4622. struct {
  4623. /* only variable items: SSID, Supported rates */
  4624. u8 variable[0];
  4625. - } __packed probe_req;
  4626. + } __packed __aligned(4) probe_req;
  4627. struct {
  4628. __le64 timestamp;
  4629. __le16 beacon_int;
  4630. @@ -943,7 +943,7 @@ struct ieee80211_mgmt {
  4631. /* followed by some of SSID, Supported rates,
  4632. * FH Params, DS Params, CF Params, IBSS Params */
  4633. u8 variable[0];
  4634. - } __packed probe_resp;
  4635. + } __packed __aligned(4) probe_resp;
  4636. struct {
  4637. u8 category;
  4638. union {
  4639. @@ -1041,8 +1041,8 @@ struct ieee80211_mgmt {
  4640. u8 variable[0];
  4641. } __packed ftm;
  4642. } u;
  4643. - } __packed action;
  4644. - } u;
  4645. + } __packed __aligned(4) action;
  4646. + } u __aligned(2);
  4647. } __packed __aligned(2);
  4648. /* Supported rates membership selectors */
  4649. @@ -1245,7 +1245,7 @@ struct ieee80211_bar {
  4650. __u8 ta[6];
  4651. __le16 control;
  4652. __le16 start_seq_num;
  4653. -} __packed __aligned(4);
  4654. +} __packed __aligned(2);
  4655. /* 802.11 BA(R) control masks */
  4656. #define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
  4657. diff --git a/carl9170fw/include/shared/wlan.h b/carl9170fw/include/shared/wlan.h
  4658. index 9c6b7ff..117f005 100644
  4659. --- a/carl9170fw/include/shared/wlan.h
  4660. +++ b/carl9170fw/include/shared/wlan.h
  4661. @@ -273,7 +273,7 @@ struct ar9170_tx_frame {
  4662. struct ieee80211_hdr i3e;
  4663. u8 payload[0];
  4664. } data;
  4665. -} __packed;
  4666. +} __packed __aligned(4);
  4667. struct carl9170_tx_superframe {
  4668. struct carl9170_tx_superdesc s;
  4669. diff --git a/carl9170fw/toolchain/Makefile b/carl9170fw/toolchain/Makefile
  4670. index 11db906..43e546d 100644
  4671. --- a/carl9170fw/toolchain/Makefile
  4672. +++ b/carl9170fw/toolchain/Makefile
  4673. @@ -1,16 +1,16 @@
  4674. -BINUTILS_VER=2.31.1
  4675. +BINUTILS_VER=2.32
  4676. BINUTILS_TAR=binutils-$(BINUTILS_VER).tar.xz
  4677. BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/$(BINUTILS_TAR)"
  4678. -NEWLIB_VER=3.0.0
  4679. +NEWLIB_VER=3.1.0
  4680. NEWLIB_TAR=newlib-$(NEWLIB_VER).tar.gz
  4681. NEWLIB_URL="ftp://sourceware.org/pub/newlib/$(NEWLIB_TAR)"
  4682. -GCC_VER=8.2.0
  4683. +GCC_VER=9.1.0
  4684. GCC_TAR=gcc-$(GCC_VER).tar.xz
  4685. GCC_URL="https://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VER)/$(GCC_TAR)"
  4686. -MPFR_VER=4.0.1
  4687. +MPFR_VER=4.0.2
  4688. MPFR_TAR=mpfr-$(MPFR_VER).tar.xz
  4689. MPFR_URL="https://ftp.gnu.org/gnu/mpfr/$(MPFR_TAR)"
  4690. diff --git a/carl9170fw/toolchain/SHA256SUMS b/carl9170fw/toolchain/SHA256SUMS
  4691. index 1b65040..3a53959 100644
  4692. --- a/carl9170fw/toolchain/SHA256SUMS
  4693. +++ b/carl9170fw/toolchain/SHA256SUMS
  4694. @@ -1,16 +1,6 @@
  4695. -1cf7adf8ff4b5aa49041c8734bbcf1ad18cc4c94d0029aae0f4e48841088479a src/gcc-7.2.0.tar.xz
  4696. -5b76a9b97c9464209772ed25ce55181a7bb144a66e5669aaec945aa64da3189b src/newlib-2.5.0.tar.gz
  4697. -0b871e271c4c620444f8264f72143b4d224aa305306d85dd77ab8dce785b1e85 src/binutils-2.29.tar.xz
  4698. 87b565e89a9a684fe4ebeeddb8399dce2599f9c9049854ca8c0dfbdea0e21912 src/gmp-6.1.2.tar.xz
  4699. -617decc6ea09889fb08ede330917a00b16809b8db88c29c31bfbb49cbf88ecc3 src/mpc-1.0.3.tar.gz
  4700. -7a62ac1a04408614fccdc506e4844b10cf0ad2c2b1677097f8f35d3a1344a950 src/mpfr-3.1.6.tar.xz
  4701. 6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e src/mpc-1.1.0.tar.gz
  4702. -fbe2cd1418b321f5c899ce4f0f0f4e73f5ecc7d02145b0e1fd096f5c3afb8a1d src/mpfr-4.0.0.tar.xz
  4703. -c8566335ee74e5fcaeb8595b4ebd0400c4b043d6acb3263ecb1314f8f5501332 src/newlib-3.0.0.tar.gz
  4704. -832ca6ae04636adbb430e865a1451adf6979ab44ca1c8374f61fba65645ce15c src/gcc-7.3.0.tar.xz
  4705. -e7010a46969f9d3e53b650a518663f98a5dde3c3ae21b7d71e5e6803bc36b577 src/binutils-2.29.1.tar.xz
  4706. -67874a60826303ee2fb6affc6dc0ddd3e749e9bfcb4c8655e3953d0458a6e16e src/mpfr-4.0.1.tar.xz
  4707. -6e46b8aeae2f727a36f0bd9505e405768a72218f1796f0d09757d45209871ae6 src/binutils-2.30.tar.xz
  4708. -1d1866f992626e61349a1ccd0b8d5253816222cdc13390dcfaa74b093aa2b153 src/gcc-8.1.0.tar.xz
  4709. -5d20086ecf5752cc7d9134246e9588fa201740d540f7eb84d795b1f7a93bca86 src/binutils-2.31.1.tar.xz
  4710. -196c3c04ba2613f893283977e6011b2345d1cd1af9abeac58e916b1aab3e0080 src/gcc-8.2.0.tar.xz
  4711. \ No newline at end of file
  4712. +fb4fa1cc21e9060719208300a61420e4089d6de6ef59cf533b57fe74801d102a src/newlib-3.1.0.tar.gz
  4713. +1d3be708604eae0e42d578ba93b390c2a145f17743a744d8f3f8c2ad5855a38a src/mpfr-4.0.2.tar.xz
  4714. +0ab6c55dd86a92ed561972ba15b9b70a8b9f75557f896446c82e8b36e473ee04 src/binutils-2.32.tar.xz
  4715. +79a66834e96a6050d8fe78db2c3b32fb285b230b855d0a66288235bc04b327a0 src/gcc-9.1.0.tar.xz
  4716. --
  4717. 2.26.0