From c539d64d22a0fdef1bd044a6e28e02a6bcfd0adf Mon Sep 17 00:00:00 2001 From: Jacob Moody Date: Sat, 9 Jul 2022 03:43:33 +0000 Subject: [PATCH 01/14] man: turn on troff -mnihongo if JP font is used This specifically fixes % man -P ktrans We dont have font widths for kanji in our troff font files, so we can use aux/mnihongo to render the character using libdraw, and grab the bitmap from there. It's not pretty, but aux/mnihongo exists so lets at least use it. This also updates /sys/man/1/ktrans to specify the Jp font to comply with aux/mnihongo. --- rc/bin/man | 13 ++++++++----- sys/man/1/ktrans | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/rc/bin/man b/rc/bin/man index f002c2121..086163f1a 100755 --- a/rc/bin/man +++ b/rc/bin/man @@ -11,6 +11,7 @@ d=0 fn roff { preproc=() + Jpflag=() postproc=cat x=`{doctype $2} if (~ $1 t) { @@ -19,6 +20,8 @@ fn roff { if(~ $x *pic*) preproc=($preproc pic) Nflag=-Tutf + if(grep -s '^.ft Jp|\f\[Jp\]' $2) + Jpflag='-mnihongo' } if not { Nflag='-N' @@ -34,17 +37,17 @@ fn roff { {echo -n $FONTS; cat $2 Date: Sat, 9 Jul 2022 14:13:07 +0000 Subject: [PATCH 02/14] imx8: turn backlight off when blanking --- sys/src/9/imx8/lcd.c | 6 ++++++ sys/src/9/imx8/screen.c | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sys/src/9/imx8/lcd.c b/sys/src/9/imx8/lcd.c index 78549f036..3b39a6c74 100644 --- a/sys/src/9/imx8/lcd.c +++ b/sys/src/9/imx8/lcd.c @@ -812,6 +812,12 @@ backlighton(void) gpioout(GPIO_PIN(1, 10), 1); } +void +blankscreen(int blank) +{ + gpioout(GPIO_PIN(1, 10), blank == 0); +} + void lcdinit(void) { diff --git a/sys/src/9/imx8/screen.c b/sys/src/9/imx8/screen.c index 5be30fa79..151b5b0af 100644 --- a/sys/src/9/imx8/screen.c +++ b/sys/src/9/imx8/screen.c @@ -178,11 +178,6 @@ setcolor(ulong p, ulong r, ulong g, ulong b) return 0; } -void -blankscreen(int) -{ -} - static void myscreenputs(char *s, int n) { From 2b89cdee025d9b3faccd62bc3515d7ed749ae26f Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 9 Jul 2022 15:15:55 +0000 Subject: [PATCH 03/14] imx8: set virtual timer offset to zero for all cores we want CNTVCT_EL0 to be the same on all cores, so we set the offset the same so it effectively becomes the system counter. --- sys/src/9/imx8/clock.c | 3 +++ sys/src/9/imx8/l.s | 4 ++++ sys/src/9/imx8/sysreg.h | 1 + 3 files changed, 8 insertions(+) diff --git a/sys/src/9/imx8/clock.c b/sys/src/9/imx8/clock.c index 0338856aa..a6b9ab034 100644 --- a/sys/src/9/imx8/clock.c +++ b/sys/src/9/imx8/clock.c @@ -41,6 +41,9 @@ clockinit(void) freq = sysrd(CNTFRQ_EL0); print("timer frequency %lld Hz\n", freq); } + m->cpuhz = freq; + m->cpumhz = (freq + Mhz/2 - 1) / Mhz; + m->cyclefreq = freq; intrenable(IRQcntpns, localclockintr, nil, BUSUNKNOWN, "clock"); } diff --git a/sys/src/9/imx8/l.s b/sys/src/9/imx8/l.s index d51555d58..f08218c66 100644 --- a/sys/src/9/imx8/l.s +++ b/sys/src/9/imx8/l.s @@ -96,6 +96,10 @@ el2: MSR R0, MDCR_EL2 ISB $SY + /* set virtual timer offset to zero */ + MOV $0, R0 + MSR R0, CNTVOFF_EL2 + /* HCR = RW, HCD, SWIO, BSU, FB */ MOVWU $(1<<31 | 1<<29 | 1<<2 | 0<<10 | 0<<9), R0 MSR R0, HCR_EL2 diff --git a/sys/src/9/imx8/sysreg.h b/sys/src/9/imx8/sysreg.h index 46dd1c3cd..b9bbc7142 100644 --- a/sys/src/9/imx8/sysreg.h +++ b/sys/src/9/imx8/sysreg.h @@ -38,6 +38,7 @@ #define CNTP_TVAL_EL0 SYSREG(3,3,14,2,0) #define CNTP_CTL_EL0 SYSREG(3,3,14,2,1) #define CNTP_CVAL_EL0 SYSREG(3,3,14,2,2) +#define CNTVOFF_EL2 SYSREG(3,4,14,0,3) #define TPIDR_EL0 SYSREG(3,3,13,0,2) #define TPIDR_EL1 SYSREG(3,0,13,0,4) From 90f47fadf8808d84d9bde8316f3945e60650093d Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 9 Jul 2022 16:06:42 +0000 Subject: [PATCH 04/14] imx8: detect cpu lcycles() frequency --- sys/src/9/imx8/clock.c | 21 +++++++++++++++++++-- sys/src/9/imx8/main.c | 8 ++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/sys/src/9/imx8/clock.c b/sys/src/9/imx8/clock.c index a6b9ab034..19bbc9625 100644 --- a/sys/src/9/imx8/clock.c +++ b/sys/src/9/imx8/clock.c @@ -29,6 +29,9 @@ localclockintr(Ureg *ureg, void *) void clockinit(void) { + uvlong tstart, tend; + ulong t0, t1; + syswr(PMCR_EL0, 1<<6 | 7); syswr(PMCNTENSET, 1<<31); syswr(PMUSERENR_EL0, 1<<2); @@ -41,8 +44,22 @@ clockinit(void) freq = sysrd(CNTFRQ_EL0); print("timer frequency %lld Hz\n", freq); } - m->cpuhz = freq; - m->cpumhz = (freq + Mhz/2 - 1) / Mhz; + tstart = sysrd(CNTPCT_EL0); + do{ + t0 = lcycles(); + }while(sysrd(CNTPCT_EL0) == tstart); + tend = tstart + (freq/100); + do{ + t1 = lcycles(); + }while(sysrd(CNTPCT_EL0) < tend); + t1 -= t0; + m->cpuhz = 100 * t1; + m->cpumhz = (m->cpuhz + Mhz/2 - 1) / Mhz; + + /* + * we are using virtual counter register CNTVCT_EL0 + * instead of the performance counter in userspace. + */ m->cyclefreq = freq; intrenable(IRQcntpns, localclockintr, nil, BUSUNKNOWN, "clock"); diff --git a/sys/src/9/imx8/main.c b/sys/src/9/imx8/main.c index b0494f682..1b7ee9969 100644 --- a/sys/src/9/imx8/main.c +++ b/sys/src/9/imx8/main.c @@ -134,6 +134,12 @@ mpinit(void) spllo(); } +void +cpuidprint(void) +{ + iprint("cpu%d: %dMHz ARM Cortex A53\n", m->machno, m->cpumhz); +} + void main(void) { @@ -143,6 +149,7 @@ main(void) fpuinit(); intrinit(); clockinit(); + cpuidprint(); synccycles(); timersinit(); flushtlb(); @@ -162,6 +169,7 @@ main(void) fpuinit(); intrinit(); clockinit(); + cpuidprint(); timersinit(); pageinit(); procinit0(); From 414cefcb0b40082d73942ea619de59b371bd685d Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 9 Jul 2022 21:12:20 +0000 Subject: [PATCH 05/14] imx8: fix fracpll code, enable 1.4Ghz turbo for arm --- sys/src/9/imx8/ccm.c | 40 ++++++++++++++++------------------------ sys/src/9/imx8/clock.c | 4 ++++ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/sys/src/9/imx8/ccm.c b/sys/src/9/imx8/ccm.c index 153644c6c..036d1e3e9 100644 --- a/sys/src/9/imx8/ccm.c +++ b/sys/src/9/imx8/ccm.c @@ -146,7 +146,7 @@ enum { }; static int input_clk_freq[] = { - [ARM_PLL_CLK] 1600*Mhz, + [ARM_PLL_CLK] 1400*Mhz, [GPU_PLL_CLK] 1600*Mhz, [VPU_PLL_CLK] 800*Mhz, [DRAM_PLL1_CLK] 800*Mhz, @@ -977,25 +977,21 @@ enablefracpll(u32int *reg, int ref_sel, int ref_freq, int freq) error = freq; for(divq = 2; divq <= 64; divq += 2){ - for(divr = 1; divr <= 64; divr++){ + for(divr = 2; divr <= 64; divr++){ ref = ref_freq/divr; - if(ref < 10*Mhz || ref > 300*Mhz) + + v = (vlong)freq*divq; + v <<= 24; + v /= ref * 8; + + divfi = v >> 24; + divff = v & 0xFFFFFF; + if(divfi < 1 || divfi > 128) continue; - ref *= 8; - divfi = ((vlong)freq*divq) / ref; - if(divfi < 1 || divfi > 32) - continue; - - v = ((vlong)freq*divq) - (vlong)ref*divfi; - divff = (v<<24) / ref; - if(divff < 1 || divff > (1<<24)) - continue; - - v = (vlong)ref*(vlong)divff; - pllout = (ref*divfi + (v>>24))/divq; - if(pllout < 30*Mhz || pllout > 2000*Mhz) - continue; + v *= (vlong)ref * 8; + v /= (vlong)divq << 24; + pllout = v; if(pllout > freq) continue; @@ -1003,16 +999,15 @@ enablefracpll(u32int *reg, int ref_sel, int ref_freq, int freq) if(freq - pllout > error) continue; -// iprint("%p enablefracpll: freq=%d (actual %d)\n", PADDR(reg), freq, pllout); - cfg0 = 1<<21 | ref_sel<<16 | 1<<15 | (divr-1)<<5 | (divq/2)-1; - cfg1 = divff<<7 | divfi-1; + cfg1 = divff<<7 | (divfi-1); error = freq - pllout; if(error == 0) goto Found; } } + panic("enablefracpll: %#p freq %d: out of range", PADDR(reg), freq); Found: /* skip if nothing has changed */ @@ -1022,19 +1017,16 @@ Found: reg[0] |= 1<<14; /* bypass */ -// iprint("%p cfg1=%.8ux\n", PADDR(reg), cfg1); reg[1] = cfg1; -// iprint("%p cfg0=%.8ux\n", PADDR(reg), cfg0); reg[0] = cfg0 | (1<<14) | (1<<12); /* unbypass */ reg[0] &= ~(1<<14); -// iprint("%p wait for lock...", PADDR(reg)); while((reg[0] & (1<<31)) == 0) ; -// iprint("locked!\n"); + reg[0] &= ~(1<<12); } diff --git a/sys/src/9/imx8/clock.c b/sys/src/9/imx8/clock.c index 19bbc9625..5148176e7 100644 --- a/sys/src/9/imx8/clock.c +++ b/sys/src/9/imx8/clock.c @@ -43,6 +43,10 @@ clockinit(void) if(m->machno == 0){ freq = sysrd(CNTFRQ_EL0); print("timer frequency %lld Hz\n", freq); + + /* TURBO! */ + setclkrate("ccm_arm_a53_clk_root", "osc_25m_ref_clk", 25*Mhz); + setclkrate("ccm_arm_a53_clk_root", "arm_pll_clk", 1400*Mhz); } tstart = sysrd(CNTPCT_EL0); do{ From 32183b1abf7a670e11c59595fda4cd64dad1008b Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 10 Jul 2022 11:35:58 +0000 Subject: [PATCH 06/14] imx8: implement /dev/reboot support --- sys/src/9/imx8/main.c | 58 +++++++++++++++++++++++++++++++++---- sys/src/9/imx8/mem.h | 5 +++- sys/src/9/imx8/mkfile | 7 +++++ sys/src/9/imx8/mmu.c | 18 ++++++++++++ sys/src/9/imx8/rebootcode.s | 48 ++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 sys/src/9/imx8/rebootcode.s diff --git a/sys/src/9/imx8/main.c b/sys/src/9/imx8/main.c index 1b7ee9969..d83dca421 100644 --- a/sys/src/9/imx8/main.c +++ b/sys/src/9/imx8/main.c @@ -10,6 +10,8 @@ #include "sysreg.h" #include "ureg.h" +#include "rebootcode.i" + Conf conf; /* @@ -124,7 +126,7 @@ mpinit(void) MACHP(i)->machno = i; cachedwbinvse(MACHP(i), MACHSIZE); - u.r0 = 0x84000003; + u.r0 = 0x84000003; /* CPU_ON */ u.r1 = (sysrd(MPIDR_EL1) & ~0xFF) | i; u.r2 = PADDR(_start); u.r3 = i; @@ -188,12 +190,13 @@ main(void) void exit(int) { - Ureg u = { .r0 = 0x84000009 }; + Ureg u = { .r0 = 0x84000002 }; /* CPU_OFF */ cpushutdown(); splfhi(); - /* system reset */ + if(m->machno == 0) + u.r0 = 0x84000009; /* SYSTEM RESET */ smccall(&u); } @@ -214,9 +217,54 @@ writeconf(void) { } -void -reboot(void *, void *, ulong) +static void +rebootjump(void *entry, void *code, ulong size) { + void (*f)(void*, void*, ulong); + + intrcpushutdown(); + + /* redo identity map */ + mmuidmap((uintptr*)L1); + + /* setup reboot trampoline function */ + f = (void*)REBOOTADDR; + memmove(f, rebootcode, sizeof(rebootcode)); + + cachedwbinvse(f, sizeof(rebootcode)); + cacheiinvse(f, sizeof(rebootcode)); + + (*f)(entry, code, size); + + for(;;); +} + +void +reboot(void*, void *code, ulong size) +{ + writeconf(); + while(m->machno != 0){ + procwired(up, 0); + sched(); + } + + cpushutdown(); + delay(2000); + + splfhi(); + + /* turn off buffered serial console */ + serialoq = nil; + + /* shutdown devices */ + chandevshutdown(); + + /* stop the clock */ + clockshutdown(); + intrsoff(); + + /* off we go - never to return */ + rebootjump((void*)(KTZERO-KZERO), code, size); } void diff --git a/sys/src/9/imx8/mem.h b/sys/src/9/imx8/mem.h index 0c92e9ae2..5f0f15649 100644 --- a/sys/src/9/imx8/mem.h +++ b/sys/src/9/imx8/mem.h @@ -44,7 +44,7 @@ #define UCRAMSIZE (8*MiB) #define VDRAM (0xFFFFFFFFC0000000ULL) /* 0x40000000 - 0x80000000 */ -#define KTZERO (VDRAM + 0x100000) /* kernel text start */ +#define KTZERO (VDRAM + 0x100000) /* 0x40100000 - kernel text start */ #define ARMLOCAL (0xFFFFFFFFB1000000ULL) /* 0x31000000 */ #define VIRTIO (0xFFFFFFFFB0000000ULL) /* 0x30000000 */ @@ -64,6 +64,9 @@ #define MACHADDR(n) (KTZERO-((n)+1)*MACHSIZE) +#define CONFADDR (VDRAM + 0x10000) /* 0x40010000 */ +#define REBOOTADDR (0x40020000) /* 0x40020000 */ + #define UZERO 0ULL /* user segment */ #define UTZERO (UZERO+0x10000) /* user text start */ #define USTKTOP ((EVAMASK>>1)-0xFFFF) /* user segment end +1 */ diff --git a/sys/src/9/imx8/mkfile b/sys/src/9/imx8/mkfile index 10d50f06b..97d6a471a 100644 --- a/sys/src/9/imx8/mkfile +++ b/sys/src/9/imx8/mkfile @@ -87,8 +87,15 @@ install:V: /$objtype/$p$CONF <../port/portmkfile <|../port/mkbootrules $CONF +main.$O: rebootcode.i + +pciimx.$O: ../port/pci.h + initcode.out: init9.$O initcode.$O /$objtype/lib/libc.a $LD -l -R1 -s -o $target $prereq +rebootcode.out: rebootcode.$O cache.v8.$O + $LD -l -H6 -R1 -T0x40020000 -s -o $target $prereq + $CONF.clean: rm -rf $p$CONF $p$CONF.u errstr.h $CONF.c boot$CONF.c diff --git a/sys/src/9/imx8/mmu.c b/sys/src/9/imx8/mmu.c index c61ca7f01..031514018 100644 --- a/sys/src/9/imx8/mmu.c +++ b/sys/src/9/imx8/mmu.c @@ -60,6 +60,24 @@ mmu0clear(uintptr *l1) l1[PTL1X(pa, 3)] = 0; } +void +mmuidmap(uintptr *l1) +{ + uintptr va, pa, pe; + + pe = -VDRAM; + for(pa = VDRAM - KZERO, va = VDRAM; pa < pe; pa += PGLSZ(1), va += PGLSZ(1)) + l1[PTL1X(pa, 1)] = l1[PTL1X(va, 1)]; + if(PTLEVELS > 2) + for(pa = VDRAM - KZERO, va = VDRAM; pa < pe; pa += PGLSZ(2), va += PGLSZ(2)) + l1[PTL1X(pa, 2)] = l1[PTL1X(va, 2)]; + if(PTLEVELS > 3) + for(pa = VDRAM - KZERO, va = VDRAM; pa < pe; pa += PGLSZ(3), va += PGLSZ(3)) + l1[PTL1X(pa, 3)] = l1[PTL1X(va, 3)]; + setttbr(PADDR(&l1[L1TABLEX(0, PTLEVELS-1)])); + flushtlb(); +} + void mmu1init(void) { diff --git a/sys/src/9/imx8/rebootcode.s b/sys/src/9/imx8/rebootcode.s new file mode 100644 index 000000000..4406350f2 --- /dev/null +++ b/sys/src/9/imx8/rebootcode.s @@ -0,0 +1,48 @@ +#include "mem.h" +#include "sysreg.h" + +#undef SYSREG +#define SYSREG(op0,op1,Cn,Cm,op2) SPR(((op0)<<19|(op1)<<16|(Cn)<<12|(Cm)<<8|(op2)<<5)) + +TEXT _start(SB), 1, $-4 + MOV $setSB(SB), R28 + + MOV R0, R27 + + MOV code+8(FP), R1 + MOVWU size+16(FP), R2 + BIC $3, R2 + ADD R1, R2, R3 + +_copy: + MOVW (R1)4!, R4 + MOVW R4, (R0)4! + CMP R1, R3 + BNE _copy + + BL cachedwbinv(SB) + BL l2cacheuwbinv(SB) + + ISB $SY + MRS SCTLR_EL1, R0 + BIC $(1<<0 | 1<<2 | 1<<12), R0 + ISB $SY + MSR R0, SCTLR_EL1 + ISB $SY + + DSB $NSHST + TLBI R0, 0,8,7,0 /* VMALLE1 */ + DSB $NSH + ISB $SY + + BL cachedwbinv(SB) + BL cacheiinv(SB) + + MOVWU $0, R0 + MOVWU $0, R1 + MOVWU $0, R2 + MOVWU $0, R3 + + MOV R27, LR + + RETURN From fdd3e1808fc2ec0f6a2d2c5dd8cec914a0b20476 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 10 Jul 2022 11:42:03 +0000 Subject: [PATCH 07/14] imx8: cleanup mem.h --- sys/src/9/imx8/mem.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sys/src/9/imx8/mem.h b/sys/src/9/imx8/mem.h index 5f0f15649..2831aa0f0 100644 --- a/sys/src/9/imx8/mem.h +++ b/sys/src/9/imx8/mem.h @@ -46,7 +46,6 @@ #define VDRAM (0xFFFFFFFFC0000000ULL) /* 0x40000000 - 0x80000000 */ #define KTZERO (VDRAM + 0x100000) /* 0x40100000 - kernel text start */ -#define ARMLOCAL (0xFFFFFFFFB1000000ULL) /* 0x31000000 */ #define VIRTIO (0xFFFFFFFFB0000000ULL) /* 0x30000000 */ #define KZERO (0xFFFFFFFF80000000ULL) /* 0x00000000 - kernel address space */ @@ -65,7 +64,7 @@ #define MACHADDR(n) (KTZERO-((n)+1)*MACHSIZE) #define CONFADDR (VDRAM + 0x10000) /* 0x40010000 */ -#define REBOOTADDR (0x40020000) /* 0x40020000 */ +#define REBOOTADDR (VDRAM-KZERO + 0x20000) /* 0x40020000 */ #define UZERO 0ULL /* user segment */ #define UTZERO (UZERO+0x10000) /* user text start */ From fe14f67c92704dc608eff7453150448d4ad7c0d5 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 10 Jul 2022 12:02:00 +0000 Subject: [PATCH 08/14] imx8: get mac address from OTP rom --- sys/src/9/imx8/etherimx.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/sys/src/9/imx8/etherimx.c b/sys/src/9/imx8/etherimx.c index 9b816920f..4ed331f8d 100644 --- a/sys/src/9/imx8/etherimx.c +++ b/sys/src/9/imx8/etherimx.c @@ -655,18 +655,22 @@ ctl(Ether*, void*, long len) static int reset(Ether *edev) { - Ctlr *ctlr = edev->ctlr; - u32int paddr1, paddr2; + enum { + OCOTP_HW_OCOTP_MAC_ADDR0 = 0x640/4, + OCOTP_HW_OCOTP_MAC_ADDR1 = 0x650/4, + }; + static u32int *ocotp = (u32int*)(VIRTIO + 0x350000); + u32int a0, a1; - /* steal mac address from uboot */ - paddr1 = rr(ctlr, ENET_PALR); - paddr2 = rr(ctlr, ENET_PAUR); - edev->ea[0] = paddr1>>24; - edev->ea[1] = paddr1>>16; - edev->ea[2] = paddr1>>8; - edev->ea[3] = paddr1>>0; - edev->ea[4] = paddr2>>24; - edev->ea[5] = paddr2>>16; + a0 = ocotp[OCOTP_HW_OCOTP_MAC_ADDR0]; + a1 = ocotp[OCOTP_HW_OCOTP_MAC_ADDR1]; + + edev->ea[0] = a1>>8; + edev->ea[1] = a1>>0; + edev->ea[2] = a0>>24; + edev->ea[3] = a0>>16; + edev->ea[4] = a0>>8; + edev->ea[5] = a0>>0; shutdown(edev); From 739e15c17839ae1bf03f9a27ed170f3bcb280430 Mon Sep 17 00:00:00 2001 From: rodri Date: Sun, 10 Jul 2022 12:54:09 +0000 Subject: [PATCH 09/14] ktrans(1): documented $jisho and made some improvements. (thanks to Kenji Okamoto, cinap, BurnZez, romi and Aaron for your work on ktrans!) --- sys/man/1/ktrans | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/sys/man/1/ktrans b/sys/man/1/ktrans index 6e3ba6af1..824ffb67d 100644 --- a/sys/man/1/ktrans +++ b/sys/man/1/ktrans @@ -19,7 +19,7 @@ return to default English mode (no transliteration). .B ctl-n Japanese hiragana: interpret lower-case letters as a Hepburn representation of hiragana. In this mode, typing ctl-\\ looks up the -last `word' in a hiragana-kanji dictionary and replaces it. +last `word' in a kana-kanji dictionary and replaces it. Subsequent ctl-\\ characters cycle through the possibilities. A word is the longest immediately preceding unbroken string of hiragana characters. @@ -28,15 +28,14 @@ characters. Japanese katakana. .TP .B ctl-l -If you want to put the hiragana not converted, you can type. +If you want to put the hiragana without modification. .TP .B ctl-x -Read kana-kanji conversion dictionary once more, and renews it. This -will be convenient when you updated kana-kanji conversion dictionary -on such acme editor.In default, the kana-kanji conversion dictionary -is read once at beginning and to make a hashed table, which will be -arranged so that the last selected candidate will be the first -candidate for later search. +Reload the in-memory kana-kanji conversion dictionary (kanji jisho). +This is so you can update the kanji jisho on-the-fly. By default, the +kanji jisho is read once at the beginning, to make a hash table, which +will be arranged so that the last selected candidate will be the first +candidate for later searches. .TP .B ctl-r Russian: interpret letters as Cyrillic; the transliteration is mostly @@ -62,7 +61,10 @@ Greek. .B ctl-s Korean. .PP -To use it you have to run it before a rio session. You can put it on your $home/lib/profile like: +To use +.I ktrans +you have to run it before a rio session. You can put it on your +$home/lib/profile like: .EX ... ktrans @@ -74,6 +76,13 @@ or run it with a sub-rio on a window like: % @{ktrans; rio} .EE .PP +The default location of the kanji jisho is +.LR /lib/kanji.jisho . +You can change that by means of the +.L $jisho +environment variable, so you can keep a customized version of the +dictionary that fits your personal needs. +.PP .SH SOURCE .B /sys/src/cmd/ktrans .SH SEE ALSO From 34dab15f408e8c272af406010b2bc6e5f7b1c473 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 10 Jul 2022 13:03:55 +0000 Subject: [PATCH 10/14] imx8: reset lcdif and sn65sdi86 bridge before init --- sys/src/9/imx8/lcd.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sys/src/9/imx8/lcd.c b/sys/src/9/imx8/lcd.c index 3b39a6c74..e69f6ff96 100644 --- a/sys/src/9/imx8/lcd.c +++ b/sys/src/9/imx8/lcd.c @@ -440,6 +440,14 @@ dsiparams(struct dsi_cfg *cfg, int lanes, int hs_clk, int ref_clk, int tx_esc_cl cfg->wakeup_ps = 1000000000000LL; } +static void +lcdifreset(void) +{ + wr(lcdif, LCDIF_CTRL_SET, CTRL_SFTRST); + delay(1); + wr(lcdif, LCDIF_CTRL_SET, CTRL_CLKGATE); +} + static void lcdifinit(struct video_mode *mode) { @@ -501,6 +509,11 @@ bridgeinit(I2Cdev *dev, struct video_mode *mode, struct dsi_cfg *cfg) { int n; + // soft reset + i2cwritebyte(dev, 0x09, 1); + while(i2creadbyte(dev, 0x09) & 1) + ; + // clock derived from dsi clock switch(cfg->hs_clk/2000000){ case 384: @@ -838,8 +851,10 @@ lcdinit(void) gpioout(GPIO_PIN(3, 20), 1); bridge = i2cdev(i2cbus("i2c4"), 0x2C); - if(bridge == nil) - return; + if(bridge == nil){ + err = "could not find bridge"; + goto out; + } bridge->subaddr = 1; /* power on mipi dsi */ @@ -858,6 +873,8 @@ lcdinit(void) setclkgate("disp.axi_clk", 1); setclkgate("sim_display.mainclk", 1); + lcdifreset(); + setclkrate("mipi.core", "system_pll1_div3", 266*Mhz); setclkrate("mipi.CLKREF", "system_pll2_clk", 25*Mhz); setclkrate("mipi.RxClkEsc", "system_pll1_clk", 80*Mhz); From cd64b7129c81102c811b3df9a32ceb4004420f54 Mon Sep 17 00:00:00 2001 From: Jacob Moody Date: Sun, 10 Jul 2022 13:13:03 +0000 Subject: [PATCH 11/14] auth/box: -s, -. flags -. decides where we chdir to before execing, we can't sit where we are because our directory may not exist. If not specified we go to '/'. -s is used to source a rc script instead of execing cmd. This is primarily to enable: '#!/bin/auth/box -s' Shebang line size is a bit tight(32), so we have this shorthand to use rc along with setting up the required namespace components. --- sys/man/8/auth | 6 +++- sys/src/cmd/auth/box.c | 79 +++++++++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/sys/man/8/auth b/sys/man/8/auth index e31730a30..9c80885b9 100644 --- a/sys/man/8/auth +++ b/sys/man/8/auth @@ -296,7 +296,11 @@ removes access to all kernel drivers from the child namespace; the .B -e flag specifies a string of driver -characters to keep. +characters to keep. The +.B -s +flag gives a base set of namespace +components, ones expected by rc, then passes +the first argument as a script file to rc. .PP .I As executes diff --git a/sys/src/cmd/auth/box.c b/sys/src/cmd/auth/box.c index 4f01e43de..60d842b90 100644 --- a/sys/src/cmd/auth/box.c +++ b/sys/src/cmd/auth/box.c @@ -10,11 +10,11 @@ binderr(char *new, char *old, int flag) char dash[4] = { '-' }; if(debug){ - if(flag & MCREATE){ + if(flag & MCREATE) dash[2] = 'c'; - flag &= ~MCREATE; - } + switch(flag){ + case MCREATE|MREPL: case MREPL: dash[0] = ' '; if(dash[2] == 'c') @@ -133,26 +133,40 @@ skelfs(void) sysfatal("/mnt/d mount setup: %r"); } +static char *parts[256]; +static int mflags[nelem(parts)]; +static int nparts; +static char *rc[] = { "/bin/rc", nil , nil}; + +static void +push(char *path, int flag) +{ + if(nparts == nelem(parts)) + sysfatal("component overflow"); + parts[nparts] = path; + mflags[nparts++] = flag; +} + void usage(void) { - fprint(2, "usage %s: [ -d ] [ -r file ] [ -c dir ] [ -e devs ] cmd args...\n", argv0); + fprint(2, "usage %s: [ -d ] [ -r file ] [ -c dir ] [ -e devs ] [ -. path ] cmd args...\n", argv0); exits("usage"); } void main(int argc, char **argv) { - char *b; - Dir *d; char devs[1024]; int dfd; - char *parts[256]; - int mflags[256]; - int nparts; + char *path; + char *a; + int sflag; nparts = 0; + path = "/"; memset(devs, 0, sizeof devs); + sflag = 0; ARGBEGIN{ case 'D': debug++; @@ -160,35 +174,48 @@ main(int argc, char **argv) debug++; break; case 'r': - parts[nparts] = EARGF(usage()); - mflags[nparts++] = MREPL; + a = EARGF(usage()); + push(a, MREPL); break; case 'c': - parts[nparts] = EARGF(usage()); - mflags[nparts++] = MCREATE|MREPL; + a = EARGF(usage()); + push(a, MREPL|MCREATE); break; case 'e': snprint(devs, sizeof devs, "%s%s", devs, EARGF(usage())); break; + case '.': + path = EARGF(usage()); + break; + case 's': + sflag = 1; + break; default: usage(); break; }ARGEND + if(argc == 0) usage(); - b = argv[0]; - d = dirstat(b); - if(d == nil){ - b = smprint("/bin/%s", b); - d = dirstat(b); - if(d == nil) - sysfatal("could not stat %s %r", argv[0]); + if(sflag){ + snprint(devs, sizeof devs, "%s%s", devs, "|d"); + push("/srv", MREPL|MCREATE); + push("/env", MREPL|MCREATE); + push("/rc", MREPL); + push("/bin", MREPL); + push(argv[0], MREPL); + rc[1] = argv[0]; + argv = rc; + } else { + if(access(argv[0], AEXIST) == -1){ + if((argv[0] = smprint("/bin/%s", argv[0])) == nil) + sysfatal("smprint: %r"); + if(access(argv[0], AEXIST) == -1) + sysfatal("could not stat %s %r", argv[0]); + } + push(argv[0], MREPL); } - free(d); - parts[nparts] = b; - mflags[nparts++] = MREPL; - argv[0] = b; rfork(RFNAMEG|RFFDG); skelfs(); @@ -210,5 +237,9 @@ main(int argc, char **argv) sysfatal("could not write chdev: %r"); } close(dfd); + + if(chdir(path) < 0) + sysfatal("can not cd to %s", path); exec(argv[0], argv); + sysfatal("exec: %r"); } From 65bd53b9b89b0a84d0f16db4adc3f53fa6ab3a3a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 10 Jul 2022 16:40:36 +0000 Subject: [PATCH 12/14] imx8: load a plan9.ini at CONFADDR 0x40010000 --- sys/src/9/imx8/main.c | 127 ++++++++++++++++++++++++++++++----- sys/src/9/imx8/mem.h | 4 ++ sys/src/boot/reform/boot.txt | 6 +- 3 files changed, 118 insertions(+), 19 deletions(-) diff --git a/sys/src/9/imx8/main.c b/sys/src/9/imx8/main.c index d83dca421..6196e3aa8 100644 --- a/sys/src/9/imx8/main.c +++ b/sys/src/9/imx8/main.c @@ -14,6 +14,114 @@ Conf conf; +#define MAXCONF 64 +static char *confname[MAXCONF]; +static char *confval[MAXCONF]; +static int nconf; + +void +bootargsinit(void) +{ + int i, j, n; + char *cp, *line[MAXCONF], *p, *q; + + /* + * parse configuration args from dos file plan9.ini + */ + cp = BOOTARGS; /* where b.com leaves its config */ + cp[BOOTARGSLEN-1] = 0; + + /* + * Strip out '\r', change '\t' -> ' '. + */ + p = cp; + for(q = cp; *q; q++){ + if(*q == -1) + break; + if(*q == '\r') + continue; + if(*q == '\t') + *q = ' '; + *p++ = *q; + } + *p = 0; + + n = getfields(cp, line, MAXCONF, 1, "\n"); + for(i = 0; i < n; i++){ + if(*line[i] == '#') + continue; + cp = strchr(line[i], '='); + if(cp == nil) + continue; + *cp++ = '\0'; + for(j = 0; j < nconf; j++){ + if(cistrcmp(confname[j], line[i]) == 0) + break; + } + confname[j] = line[i]; + confval[j] = cp; + if(j == nconf) + nconf++; + } +} + +char* +getconf(char *name) +{ + int i; + + for(i = 0; i < nconf; i++) + if(cistrcmp(confname[i], name) == 0) + return confval[i]; + return nil; +} + +void +setconfenv(void) +{ + int i; + + for(i = 0; i < nconf; i++){ + if(confname[i][0] != '*') + ksetenv(confname[i], confval[i], 0); + ksetenv(confname[i], confval[i], 1); + } +} + +void +writeconf(void) +{ + char *p, *q; + int n; + + p = getconfenv(); + if(waserror()) { + free(p); + nexterror(); + } + + /* convert to name=value\n format */ + for(q=p; *q; q++) { + q += strlen(q); + *q = '='; + q += strlen(q); + *q = '\n'; + } + n = q - p + 1; + if(n >= BOOTARGSLEN) + error("kernel configuration too large"); + memmove(BOOTARGS, p, n); + memset(BOOTARGS+n, 0, BOOTARGSLEN-n); + poperror(); + free(p); +} + +int +isaconfig(char *, int, ISAConf *) +{ + return 0; +} + /* * starting place for first process */ @@ -31,6 +139,7 @@ init0(void) else ksetenv("service", "terminal", 0); ksetenv("console", "0", 0); + setconfenv(); poperror(); } kproc("alarm", alarmkproc, 0); @@ -161,6 +270,7 @@ main(void) return; } quotefmtinstall(); + bootargsinit(); meminit(); confinit(); xinit(); @@ -200,23 +310,6 @@ exit(int) smccall(&u); } -int -isaconfig(char *, int, ISAConf *) -{ - return 0; -} - -char* -getconf(char *) -{ - return nil; -} - -void -writeconf(void) -{ -} - static void rebootjump(void *entry, void *code, ulong size) { diff --git a/sys/src/9/imx8/mem.h b/sys/src/9/imx8/mem.h index 2831aa0f0..117722bc1 100644 --- a/sys/src/9/imx8/mem.h +++ b/sys/src/9/imx8/mem.h @@ -64,6 +64,10 @@ #define MACHADDR(n) (KTZERO-((n)+1)*MACHSIZE) #define CONFADDR (VDRAM + 0x10000) /* 0x40010000 */ + +#define BOOTARGS ((char*)CONFADDR) +#define BOOTARGSLEN 0x10000 + #define REBOOTADDR (VDRAM-KZERO + 0x20000) /* 0x40020000 */ #define UZERO 0ULL /* user segment */ diff --git a/sys/src/boot/reform/boot.txt b/sys/src/boot/reform/boot.txt index 738fd305d..1fdc0f533 100644 --- a/sys/src/boot/reform/boot.txt +++ b/sys/src/boot/reform/boot.txt @@ -1,2 +1,4 @@ -load ${devtype} ${devnum}:${bootpart} ${kernel_addr_r} ${prefix}9reform.u -bootm ${kernel_addr_r} +mw.b 0x40010000 0x0 0x10000 +load ${devtype} ${devnum}:${bootpart} 0x40010000 ${prefix}plan9.ini +load ${devtype} ${devnum}:${bootpart} 0x40100000 ${prefix}9reform.u +bootm 0x40100000 From 845f8d12e4e417aaafaa6e62a80bf03856e7d906 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 10 Jul 2022 16:50:07 +0000 Subject: [PATCH 13/14] /sys/lib/dist/mkfile: create a default plan9.ini for reform image --- sys/lib/dist/mkfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/lib/dist/mkfile b/sys/lib/dist/mkfile index ac9118ab3..703602846 100644 --- a/sys/lib/dist/mkfile +++ b/sys/lib/dist/mkfile @@ -92,7 +92,8 @@ cd:V: /tmp/9front.386.iso.gz @{ objtype=arm64 kernel=/n/src9/$objtype/9reform.u - fatfiles=(/n/src9/sys/src/boot/reform/boot.scr $kernel) + echo 'bootargs=local!/dev/sdM0/fs' > /env/plan9.ini + fatfiles=(/n/src9/sys/src/boot/reform/boot.scr /env/plan9.ini $kernel) mb=1885 # storage vendors idea of 2GB mk $target.$pid.disk mv $target.$pid.disk $target && dd -trunc 0 -bs 1024 -oseek 33 -if /n/src9/sys/src/boot/reform/flash.bin -of $target From 76f8d642eeb77fd9fbfcf98189bcdbffb229d3d1 Mon Sep 17 00:00:00 2001 From: rodri Date: Mon, 11 Jul 2022 20:24:24 +0000 Subject: [PATCH 14/14] ktrans(1): added a history section (thanks moody!) --- sys/man/1/ktrans | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/man/1/ktrans b/sys/man/1/ktrans index 824ffb67d..49417240d 100644 --- a/sys/man/1/ktrans +++ b/sys/man/1/ktrans @@ -115,3 +115,7 @@ method. There is no way to generate the control characters literally. At the beggining of a new line, you have to begin with ctl-l for successful kana-kanji conversion. +.SH HISTORY +Ktrans was originally written by Kenji Okamoto in August of 2000 for +the 2nd edition of Plan 9. It was imported in to 9front in July of +2022, with patches by several contributors.