From owner-freebsd-embedded@FreeBSD.ORG Sun Nov 24 21:13:07 2013 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 494B94F3 for ; Sun, 24 Nov 2013 21:13:07 +0000 (UTC) Received: from olymp.kibab.com (olymp6.kibab.com [IPv6:2a01:4f8:160:84c1::2]) by mx1.freebsd.org (Postfix) with ESMTP id 11C6C25F4 for ; Sun, 24 Nov 2013 21:13:07 +0000 (UTC) X-DKIM: OpenDKIM Filter v2.5.2 olymp.kibab.com 5C2F43F447 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=kibab.com; s=default; t=1385327585; bh=yGyu4EoN6KpjHK186uHdP45GuuSKsEwMFcueNZaHtgM=; h=Date:From:To:Subject; b=g4AO1JC56kicLoZ+35CVMQnunnPsn0v6dDnh+FobQ4JetXbcystW6lndhK8w8Nn5Y lZQLctIOM7rKUkup+LJM6Mjk9PKti4VoHgVCZmjsdogu/L5GCz2JThVDleh4F25Kkk l6LniT+hWcdv34Mi/VNGsAcsQA/2so8q8LvABsDU= Message-ID: <52926BE0.8050003@kibab.com> Date: Sun, 24 Nov 2013 22:13:04 +0100 From: Ilya Bakulin MIME-Version: 1.0 To: "freebsd-embedded@freebsd.org" Subject: NanoBSD update scripts are broken when using disk labels Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Nov 2013 21:13:07 -0000 Hi list, I'm trying to build a NanoBSD image for the small Soekris net5501 board. Everything went well, including flashing on the CF card and then booting from the first partition. However after generating an update image I couln't flash it, update scripts don't work. After looking in the /root/updatep2 script I realized that it cannot work when NANO_LABEL parameter is set when building the NanoBSD image. I use NANO_LABEL="FBSDFLT", so after booting the system it has the following configuration: # uname -a FreeBSD fbsd-gs 11.0-CURRENT FreeBSD 11.0-CURRENT #0 af4d383(fbsd-gs)-dirty: Sun Nov 24 19:03:58 CET 2013 root@olymp.kibab.com:/stor0/jails/buildhost.kibab.com/usr/home/kibab/repos/freebsd-git/gs0/obj/i386.i386/stor0/jails/buildhost.kibab.com/usr/home/kibab/repos/freebsd-git/freebsd/sys/GS0 i386 ("dirty" is because I haven't committed GS0 kernel configuration file, the repository is clean) # cat /etc/nanobsd.conf NANO_DRIVE=ufs/FBSDFLT # glabel status Name Status Components ufs/FBSDFLTs3 N/A ada0s3 ufs/FBSDFLTs4 N/A ada0s4 ufs/FBSDFLTs1a N/A ada0s1a ufs/FBSDFLTs2a N/A ada0s2a # ls -1 /dev/ufs FBSDFLTs1a FBSDFLTs2a FBSDFLTs3 FBSDFLTs4 ... and here is the actual problem. The system doesn't create a separate entry for FBSDFLTs1 and FBSDFLTs2. The update scripts expect such entries to exist: # cat /root/updatep2 [... BSD license ...] . /etc/nanobsd.conf if mount | grep ${NANO_DRIVE}s2 > /dev/null ; then echo "You are running partition 2 already" echo "you probably want to use 'updatep1' instead" exit 1 fi # Blow away old system. dd if=/dev/zero of=/dev/${NANO_DRIVE}s2 bs=1m count=1 > /dev/null 2>&1 # Copy in new system dd of=/dev/${NANO_DRIVE}s2 obs=64k ---------------------------- So, it tries to `dd` to /dev/ufs/FBSDFLTs1 which doesn't exist. I haven't found a good way to resolve ufs/FBSDFLTs1a to ada0s1 (actually ada0s1 is the parent of ufs/FBSDFLTs1a). Maybe someone has a good solution for this? -- Ilya From owner-freebsd-embedded@FreeBSD.ORG Mon Nov 25 05:01:58 2013 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D956EDBA for ; Mon, 25 Nov 2013 05:01:58 +0000 (UTC) Received: from mail-vc0-x236.google.com (mail-vc0-x236.google.com [IPv6:2607:f8b0:400c:c03::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9DA792A7A for ; Mon, 25 Nov 2013 05:01:58 +0000 (UTC) Received: by mail-vc0-f182.google.com with SMTP id lc6so2349782vcb.41 for ; Sun, 24 Nov 2013 21:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=KnO2nKEHMhUUR187D+PnSp1WHY1+0COMTZZvINUOohk=; b=eIP2L2AXOGmNArXJ8GRy1JjtUylLmtlw9UR/fWB4gwSTu0zBffPn4FqOykWMYmxr9H 5NnHyPgITebOcEoxZxqCZyDI0h2bzl9M8Gll+v5/vP+LH1YD8lcRCDjQAZGfGZr9GOEB sI8Wq7o086kuLQfKhZNDyPAR4HYmfZ1AzinQDll6dSIRq7e8RsP2zysQTq4/uo5wmLvV oSGJEbW8RbeJmmPGATce7A18NYO1EDfrCcl5xS7Ytsmwyd4zNjnlnd7gYZD2lvI1qArk wR14vJwfhuzSNt5fdyJ3ftZexidOe2AfXtyLNG0BZROtQNSb8E1+IZfGBdoVKLUXZaZE 98dg== X-Received: by 10.58.210.66 with SMTP id ms2mr24962365vec.10.1385355716968; Sun, 24 Nov 2013 21:01:56 -0800 (PST) MIME-Version: 1.0 Sender: cochard@gmail.com Received: by 10.58.123.5 with HTTP; Sun, 24 Nov 2013 21:01:35 -0800 (PST) In-Reply-To: <52926BE0.8050003@kibab.com> References: <52926BE0.8050003@kibab.com> From: =?ISO-8859-1?Q?Olivier_Cochard=2DLabb=E9?= Date: Mon, 25 Nov 2013 06:01:35 +0100 X-Google-Sender-Auth: VpNoLTblw-TiK-03i2M0vuEde-I Message-ID: Subject: Re: NanoBSD update scripts are broken when using disk labels To: Ilya Bakulin Content-Type: text/plain; charset=ISO-8859-1 Cc: "freebsd-embedded@freebsd.org" X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Nov 2013 05:01:58 -0000 On Sun, Nov 24, 2013 at 10:13 PM, Ilya Bakulin wrote: > Hi list, > I'm trying to build a NanoBSD image for the small Soekris net5501 board. > Everything went well, including flashing on the CF card and then booting > from the first partition. > However after generating an update image I couln't flash it, update > scripts don't work. > Hi, you can try my version of nanobsd update script that merge updatep1 and updatep2 in one script: http://sourceforge.net/p/bsdrp/code/HEAD/tree/trunk/BSDRP/Files/usr/local/sbin/upgrade Regards, Olivier From owner-freebsd-embedded@FreeBSD.ORG Mon Nov 25 11:06:47 2013 Return-Path: Delivered-To: freebsd-embedded@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 244DE553 for ; Mon, 25 Nov 2013 11:06:47 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 133C12F40 for ; Mon, 25 Nov 2013 11:06:47 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id rAPB6kib089815 for ; Mon, 25 Nov 2013 11:06:46 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id rAPB6kHo089813 for freebsd-embedded@FreeBSD.org; Mon, 25 Nov 2013 11:06:46 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 25 Nov 2013 11:06:46 GMT Message-Id: <201311251106.rAPB6kHo089813@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-embedded@FreeBSD.org Subject: Current problem reports assigned to freebsd-embedded@FreeBSD.org X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Nov 2013 11:06:47 -0000 Note: to view an individual PR, use: http://www.freebsd.org/cgi/query-pr.cgi?pr=(number). The following is a listing of current problems submitted by FreeBSD users. These represent problem reports covering all versions including experimental development code and obsolete releases. S Tracker Resp. Description -------------------------------------------------------------------------------- o misc/52256 embedded [picobsd] picobsd build script does not read in user/s o kern/42728 embedded [picobsd] many problems in src/usr.sbin/ppp/* after c 2 problems total. From owner-freebsd-embedded@FreeBSD.ORG Mon Nov 25 22:17:27 2013 Return-Path: Delivered-To: freebsd-embedded@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CA8E6F3C; Mon, 25 Nov 2013 22:17:27 +0000 (UTC) Received: from venus.codepro.be (venus.codepro.be [IPv6:2a01:4f8:162:1127::2]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8DC9E2DE7; Mon, 25 Nov 2013 22:17:27 +0000 (UTC) Received: from vega.codepro.be (unknown [172.16.1.3]) by venus.codepro.be (Postfix) with ESMTP id 4CCBEFF53; Mon, 25 Nov 2013 23:17:26 +0100 (CET) Received: by vega.codepro.be (Postfix, from userid 1001) id 48CCBE29D; Mon, 25 Nov 2013 23:17:26 +0100 (CET) Date: Mon, 25 Nov 2013 23:17:26 +0100 From: Kristof Provost To: Ian Lepore Subject: Re: Incorrect struct onfi_params definition Message-ID: <20131125221726.GV58987@vega.codepro.be> References: <1383782353.31172.183.camel@revolution.hippie.lan> <1384381960-98851-1-git-send-email-kristof@sigsegv.be> <1384537153.31172.398.camel@revolution.hippie.lan> <20131115191315.GF58987@vega.codepro.be> <1384544870.31172.420.camel@revolution.hippie.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1384544870.31172.420.camel@revolution.hippie.lan> X-PGP-Fingerprint: E114 D9EA 909E D469 8F57 17A5 7D15 91C6 9EFA F286 User-Agent: Mutt/1.5.22 (2013-10-16) Cc: Grzegorz Bernacki , freebsd-embedded@FreeBSD.org X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Nov 2013 22:17:27 -0000 On 2013-11-15 12:47:50 (-0700), Ian Lepore wrote: > Is it only the parameter-read that has this problem, or do regular reads > and writes fail to get status too? Maybe there's something in the > marvell nand flash interface that leads to this; I did my work on an > Atmel SoC (but I do have a Dreamplug here that has nand flash on it, > it's sort of a Guruplug in a Dreamplug case; not many were shipped). > It's only the parameter-read. Regular reads do not time out. I've managed to format the flash with nandfs and can now read/write it normally. Regards, Kristof From owner-freebsd-embedded@FreeBSD.ORG Thu Nov 28 08:49:19 2013 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 22EE9CEC for ; Thu, 28 Nov 2013 08:49:19 +0000 (UTC) Received: from vps.van-laarhoven.org (www.hibma.org [IPv6:2a02:2308::216:3eff:feec:b1b5]) by mx1.freebsd.org (Postfix) with ESMTP id 9496A1E3C for ; Thu, 28 Nov 2013 08:49:18 +0000 (UTC) Received: from [192.168.178.39] (thuis.van-laarhoven.org [80.100.41.4]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by vps.van-laarhoven.org (Postfix) with ESMTPSA id 0DDCF5F27AD; Thu, 28 Nov 2013 09:45:16 +0100 (CET) Content-Type: multipart/mixed; boundary="Apple-Mail=_DB20417F-0D8E-4E7B-98E8-34239F8201FE" Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1822\)) Subject: Re: NanoBSD update scripts are broken when using disk labels From: Nick Hibma In-Reply-To: <52926BE0.8050003@kibab.com> Date: Thu, 28 Nov 2013 09:49:08 +0100 Message-Id: <4615AB4C-9DA5-4475-BFB6-68964B4CFC0A@van-laarhoven.org> References: <52926BE0.8050003@kibab.com> To: Ilya Bakulin X-Mailer: Apple Mail (2.1822) Cc: "freebsd-embedded@freebsd.org" X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Nov 2013 08:49:19 -0000 --Apple-Mail=_DB20417F-0D8E-4E7B-98E8-34239F8201FE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On 24 Nov 2013, at 22:13, Ilya Bakulin wrote: > After looking in the /root/updatep2 script I realized that it cannot > work when NANO_LABEL parameter > is set when building the NanoBSD image. The problem is that you need the device, not the UFS label to update the = active partition. Attached the fixed updatep1 and updatep2 scripts. I=92ve= fixed exactly this problem yesterday to make booting from a USB thumb = drive, and embedded CF card using the same image work. If you could test them, I=92d be more than happy to commit them. Thanks in advance. Nick --Apple-Mail=_DB20417F-0D8E-4E7B-98E8-34239F8201FE Content-Disposition: attachment; filename=updatep1 Content-Type: application/octet-stream; x-unix-mode=0644; name="updatep1" Content-Transfer-Encoding: 7bit #!/bin/sh # # Copyright (c) 2004-2005 Poul-Henning Kamp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: head/tools/tools/nanobsd/Files/root/updatep1 205584 2010-03-24 11:21:33Z phk $ # # Script to update partition 1 on a NanoBSD system. # # usage: # ssh somewhere cat image.s1 | sh updatep1 # set -e . /etc/nanobsd.conf if mount | grep ${NANO_DRIVE}s1 > /dev/null ; then echo "You are running partition 1 already" echo "you probably want to use 'updatep2' instead" exit 1 fi dev=$NANO_DRIVE test -n "$NANO_LABEL" \ && dev=$(glabel status -s | grep "$NANO_DRIVE""s1a" | awk '{gsub("s1a",""); print $3}') # Blow away old system. dd if=/dev/zero of=/dev/${dev}s1 bs=1m count=1 > /dev/null 2>&1 # Copy in new system dd of=/dev/${dev}s1 obs=64k # Check that it worked fsck_ffs -n /dev/${NANO_DRIVE}s1a gpart set -a active -i 1 ${dev} --Apple-Mail=_DB20417F-0D8E-4E7B-98E8-34239F8201FE Content-Disposition: attachment; filename=updatep2 Content-Type: application/octet-stream; x-unix-mode=0644; name="updatep2" Content-Transfer-Encoding: 7bit #!/bin/sh # # Copyright (c) 2004-2005 Poul-Henning Kamp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: head/tools/tools/nanobsd/Files/root/updatep2 205584 2010-03-24 11:21:33Z phk $ # # Script to update partition 2 on a NanoBSD system. # # usage: # ssh somewhere cat image.s1 | sh updatep2 # set -e . /etc/nanobsd.conf if mount | grep ${NANO_DRIVE}s2 > /dev/null ; then echo "You are running partition 2 already" echo "you probably want to use 'updatep1' instead" exit 1 fi dev=$NANO_DRIVE test -n "$NANO_LABEL" \ && dev=$(glabel status -s | grep "$NANO_DRIVE""s1a" | awk '{gsub("s1a",""); print $3}') # Blow away old system. dd if=/dev/zero of=/dev/${dev}s2 bs=1m count=1 > /dev/null 2>&1 # Copy in new system dd of=/dev/${dev}s2 obs=64k # Check that it worked fsck_ffs -n /dev/${NANO_DRIVE}s2a # Update the /etc/fstab trap "umount /mnt" 1 2 15 EXIT mount /dev/${NANO_DRIVE}s2a /mnt sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/conf/base/etc/fstab sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/etc/fstab umount /mnt trap 1 2 15 EXIT gpart set -a active -i 2 ${dev} --Apple-Mail=_DB20417F-0D8E-4E7B-98E8-34239F8201FE Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_DB20417F-0D8E-4E7B-98E8-34239F8201FE-- From owner-freebsd-embedded@FreeBSD.ORG Thu Nov 28 10:00:54 2013 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9F3BE53A for ; Thu, 28 Nov 2013 10:00:54 +0000 (UTC) Received: from vps.van-laarhoven.org (www.hibma.org [IPv6:2a02:2308::216:3eff:feec:b1b5]) by mx1.freebsd.org (Postfix) with ESMTP id 4C8A31268 for ; Thu, 28 Nov 2013 10:00:54 +0000 (UTC) Received: from [192.168.178.39] (thuis.van-laarhoven.org [80.100.41.4]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by vps.van-laarhoven.org (Postfix) with ESMTPSA id E83E15F20D7; Thu, 28 Nov 2013 10:56:59 +0100 (CET) Content-Type: multipart/mixed; boundary="Apple-Mail=_E662584A-B864-41AE-A2CB-42CB72BF2E6F" Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1822\)) Subject: Re: NanoBSD update scripts are broken when using disk labels From: Nick Hibma In-Reply-To: <4615AB4C-9DA5-4475-BFB6-68964B4CFC0A@van-laarhoven.org> Date: Thu, 28 Nov 2013 11:00:52 +0100 Message-Id: <330D2CBB-9A54-487D-B780-1936E8F58B74@van-laarhoven.org> References: <52926BE0.8050003@kibab.com> <4615AB4C-9DA5-4475-BFB6-68964B4CFC0A@van-laarhoven.org> To: Ilya Bakulin X-Mailer: Apple Mail (2.1822) Cc: "freebsd-embedded@freebsd.org" X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Nov 2013 10:00:54 -0000 --Apple-Mail=_E662584A-B864-41AE-A2CB-42CB72BF2E6F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On 28 Nov 2013, at 09:49, Nick Hibma wrote: > On 24 Nov 2013, at 22:13, Ilya Bakulin wrote: >=20 >> After looking in the /root/updatep2 script I realized that it cannot >> work when NANO_LABEL parameter >> is set when building the NanoBSD image. >=20 > The problem is that you need the device, not the UFS label to update = the active partition. Attached the fixed updatep1 and updatep2 scripts. = I=92ve fixed exactly this problem yesterday to make booting from a USB = thumb drive, and embedded CF card using the same image work. >=20 > If you could test them, I=92d be more than happy to commit them. The dev=3D line was incorrect in the scripts I provided. Try the = attached files instead. Nick Hibma nick@van-laarhoven.org --Apple-Mail=_E662584A-B864-41AE-A2CB-42CB72BF2E6F Content-Disposition: attachment; filename=updatep1 Content-Type: application/octet-stream; x-unix-mode=0644; name="updatep1" Content-Transfer-Encoding: 7bit #!/bin/sh # # Copyright (c) 2004-2005 Poul-Henning Kamp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: head/tools/tools/nanobsd/Files/root/updatep1 205584 2010-03-24 11:21:33Z phk $ # # Script to update partition 1 on a NanoBSD system. # # usage: # ssh somewhere cat image.s1 | sh updatep1 # set -e . /etc/nanobsd.conf if mount | grep ${NANO_DRIVE}s1 > /dev/null ; then echo "You are running partition 1 already" echo "you probably want to use 'updatep2' instead" exit 1 fi dev=$NANO_DRIVE test -n "$NANO_LABEL" \ && dev=$(glabel status -s | grep $NANO_DRIVE | awk '{gsub("s[0-9]a?$",""); print $3; exit 0}') # Blow away old system. dd if=/dev/zero of=/dev/${dev}s1 bs=1m count=1 > /dev/null 2>&1 # Copy in new system dd of=/dev/${dev}s1 obs=64k # Check that it worked fsck_ffs -n /dev/${NANO_DRIVE}s1a gpart set -a active -i 1 ${dev} --Apple-Mail=_E662584A-B864-41AE-A2CB-42CB72BF2E6F Content-Disposition: attachment; filename=updatep2 Content-Type: application/octet-stream; x-unix-mode=0644; name="updatep2" Content-Transfer-Encoding: 7bit #!/bin/sh # # Copyright (c) 2004-2005 Poul-Henning Kamp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: head/tools/tools/nanobsd/Files/root/updatep2 205584 2010-03-24 11:21:33Z phk $ # # Script to update partition 2 on a NanoBSD system. # # usage: # ssh somewhere cat image.s1 | sh updatep2 # set -e . /etc/nanobsd.conf if mount | grep ${NANO_DRIVE}s2 > /dev/null ; then echo "You are running partition 2 already" echo "you probably want to use 'updatep1' instead" exit 1 fi dev=$NANO_DRIVE test -n "$NANO_LABEL" \ && dev=$(glabel status -s | grep $NANO_DRIVE | awk '{gsub("s[0-9]a?$",""); print $3; exit 0}') # Blow away old system. dd if=/dev/zero of=/dev/${dev}s2 bs=1m count=1 > /dev/null 2>&1 # Copy in new system dd of=/dev/${dev}s2 obs=64k # Check that it worked fsck_ffs -n /dev/${NANO_DRIVE}s2a # Update the /etc/fstab trap "umount /mnt" 1 2 15 EXIT mount /dev/${NANO_DRIVE}s2a /mnt sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/conf/base/etc/fstab sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/etc/fstab umount /mnt trap 1 2 15 EXIT gpart set -a active -i 2 ${dev} --Apple-Mail=_E662584A-B864-41AE-A2CB-42CB72BF2E6F-- From owner-freebsd-embedded@FreeBSD.ORG Fri Nov 29 19:28:33 2013 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1090AFAE for ; Fri, 29 Nov 2013 19:28:33 +0000 (UTC) Received: from mail-qe0-x231.google.com (mail-qe0-x231.google.com [IPv6:2607:f8b0:400d:c02::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BFED01ADE for ; Fri, 29 Nov 2013 19:28:32 +0000 (UTC) Received: by mail-qe0-f49.google.com with SMTP id w7so10754716qeb.36 for ; Fri, 29 Nov 2013 11:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version; bh=TWNKgkAF7T0VEMGmpeVWgV/FybELo63tEfMRLvBwJnc=; b=Xay4Fu2SpTbb9mP1EWpC3Jk8881nxrHxaE1GS5KNViCNXXTXRpGcf/8OYQ8WM1e4/9 xc6/LIndnwDUnvvzrnS9gb9uqBX0u1Jx6OYnVTaRLN8cSTazh/DTlwDAksFqkHqPMvFR 9KF1BvU+qDlrEZN5KRQVgC+tBZorUge/5+zRQq6P8/53Byxey6jcfG9ZMUNuG86whFKv pqSTuo/5fBVwX4NBo7ZRg8yTI9HScSv9bkALtS1p36mm8i7tEBJDlwuQBVAMIiKFNWoR RL2l9gkF6rzRTxTMW1VGBES3h8G4Eob4CGNqcYJseWVh6nDTK44bjZbfRBMECh7rPshj nUEw== X-Received: by 10.49.38.37 with SMTP id d5mr15627811qek.17.1385753311931; Fri, 29 Nov 2013 11:28:31 -0800 (PST) Received: from [192.168.1.7] ([187.120.137.162]) by mx.google.com with ESMTPSA id nq5sm25666731qeb.8.2013.11.29.11.28.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 11:28:31 -0800 (PST) From: Luiz Otavio O Souza Content-Type: multipart/mixed; boundary="Apple-Mail=_13A74922-970E-4308-9EC5-22D6556CBCE5" Subject: [patch] LM75 kernel driver Message-Id: <69CF7423-FD5B-44B3-8B90-E76BA96BB31A@gmail.com> Date: Fri, 29 Nov 2013 17:28:20 -0200 To: freebsd-embedded@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1822\)) X-Mailer: Apple Mail (2.1822) X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Nov 2013 19:28:33 -0000 --Apple-Mail=_13A74922-970E-4308-9EC5-22D6556CBCE5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Hi, I=92ve written a kernel driver for lm75 (i2c temperature sensor). It=92s a very simple, convenient and cheap way to verify an i2c bus. This driver provides full control of the lm75 registers (configuration = bits, over temperature and hysteresis settings) and so provides basic = read and write test abilities. The high resolution version (lm75b - 11 bits) isn=92t supported ATM, but = i have plans to do so. On my RPi i=92ve added this to sys/boot/fdt/dts/rpi.dts: bsc0 { lm750 { compatible =3D "lm75"; i2c-address =3D <0x96>; }; lm751 { compatible =3D "lm75"; i2c-address =3D <0x9e>; }; }; And =91device lm75=92 to RPI-B kernel file (after apply the attached = patch). Here is the result: iichb0: mem 0x20205000-0x2020501f irq 61 = on simplebus0 iicbus1: on iichb0 iic1: on iicbus1 lm751: at addr 0x96 on iicbus1 lm752: at addr 0x9e on iicbus1 # sysctl dev.lm75.1 dev.lm75.1.%desc: LM75 temperature sensor dev.lm75.1.%driver: lm75 dev.lm75.1.%location: addr=3D0x96 dev.lm75.1.%pnpinfo: name=3Dlm750 compat=3Dlm75 dev.lm75.1.%parent: iicbus1 dev.lm75.1.temperature: 30.0C dev.lm75.1.thyst: 75.0C dev.lm75.1.tos: 80.0C dev.lm75.1.conf.faults: 1 dev.lm75.1.conf.mode: comparator dev.lm75.1.conf.polarity: active-low dev.lm75.1.conf.shutdown: 0 # sysctl dev.lm75.2 dev.lm75.2.%desc: LM75 temperature sensor dev.lm75.2.%driver: lm75 dev.lm75.2.%location: addr=3D0x9e dev.lm75.2.%pnpinfo: name=3Dlm751 compat=3Dlm75 dev.lm75.2.%parent: iicbus1 dev.lm75.2.temperature: 29.5C dev.lm75.2.thyst: 60.0C dev.lm75.2.tos: 80.0C dev.lm75.2.conf.faults: 2 dev.lm75.2.conf.mode: interrupt dev.lm75.2.conf.polarity: active-low dev.lm75.2.conf.shutdown: 0 I hope this may be useful for someone else. Luiz --Apple-Mail=_13A74922-970E-4308-9EC5-22D6556CBCE5 Content-Disposition: attachment; filename=lm75.diff Content-Type: application/octet-stream; name="lm75.diff" Content-Transfer-Encoding: 7bit Index: sys/conf/files =================================================================== --- sys/conf/files (revision 258680) +++ sys/conf/files (working copy) @@ -1472,6 +1472,7 @@ dev/iicbus/iicsmb.c optional iicsmb \ dependency "iicbus_if.h" dev/iicbus/iicoc.c optional iicoc +dev/iicbus/lm75.c optional lm75 dev/iicbus/pcf8563.c optional pcf8563 dev/iicbus/s35390a.c optional s35390a dev/iir/iir.c optional iir --- /dev/null 2013-11-29 15:00:00.000000000 -0200 +++ sys/dev/iicbus/lm75.c 2013-11-29 14:58:31.174941027 -0200 @@ -0,0 +1,510 @@ +/*- + * Copyright (c) 2010 Andreas Tobler. + * Copyright (c) 2013 Luiz Otavio O Souza . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +/* LM75 registers */ +#define LM75_TEMP 0x0 +#define LM75_CONF 0x1 +#define LM75_CONF_FSHIFT 3 +#define LM75_CONF_FAULT 0x18 +#define LM75_CONF_POL 0x04 +#define LM75_CONF_MODE 0x02 +#define LM75_CONF_SHUTD 0x01 +#define LM75_CONF_MASK 0x1f +#define LM75_THYST 0x2 +#define LM75_TOS 0x3 + +/* LM75 constants */ +#define LM75_MIN_TEMP -55 +#define LM75_MAX_TEMP 125 +#define LM75_LSB 0x80 +#define LM75_MSB 0x8000 +#define LM75_NEG_BIT LM75_MSB +#define TZ_ZEROC 2732 + +/* Regular bus attachment functions */ +static int lm75_probe(device_t); +static int lm75_attach(device_t); + +struct lm75_softc { + device_t sc_dev; + struct intr_config_hook enum_hook; + uint32_t sc_addr; + uint32_t sc_conf; +}; + +int lm75_faults[4] = { 1, 2, 4, 6 }; + +/* Utility functions */ +static int lm75_conf_read(struct lm75_softc *); +static int lm75_conf_write(struct lm75_softc *); +static int lm75_temp_read(struct lm75_softc *, uint8_t, int *); +static int lm75_temp_write(struct lm75_softc *, uint8_t, int); +static void lm75_start(void *); +static int lm75_read(device_t, uint32_t, uint8_t, uint8_t *, size_t); +static int lm75_write(device_t, uint32_t, uint8_t *, size_t); +static int lm75_str_mode(char *); +static int lm75_str_pol(char *); +static int lm75_temp_sysctl(SYSCTL_HANDLER_ARGS); +static int lm75_faults_sysctl(SYSCTL_HANDLER_ARGS); +static int lm75_mode_sysctl(SYSCTL_HANDLER_ARGS); +static int lm75_pol_sysctl(SYSCTL_HANDLER_ARGS); +static int lm75_shutdown_sysctl(SYSCTL_HANDLER_ARGS); + +static device_method_t lm75_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, lm75_probe), + DEVMETHOD(device_attach, lm75_attach), + + DEVMETHOD_END +}; + +static driver_t lm75_driver = { + "lm75", + lm75_methods, + sizeof(struct lm75_softc) +}; + +static devclass_t lm75_devclass; + +DRIVER_MODULE(lm75, iicbus, lm75_driver, lm75_devclass, 0, 0); + +static int +lm75_read(device_t dev, uint32_t addr, uint8_t reg, uint8_t *data, size_t len) +{ + int try; + + struct iic_msg msg[2] = { + { addr, IIC_M_WR | IIC_M_NOSTOP, 1, ® }, + { addr, IIC_M_RD, len, data }, + }; + + try = 0; + for (;;) { + if (iicbus_transfer(dev, msg, 2) != 0) + goto retry; + + return (0); + retry: + if (++try > 5) { + device_printf(dev, "iicbus read failed\n"); + return (-1); + } + pause("lm75_read", hz); + } +} + +static int +lm75_write(device_t dev, uint32_t addr, uint8_t *data, size_t len) +{ + int try; + + struct iic_msg msg[1] = { + { addr, IIC_M_WR, len, data }, + }; + + try = 0; + for (;;) { + if (iicbus_transfer(dev, msg, 1) != 0) + goto retry; + + return (0); + retry: + if (++try > 5) { + device_printf(dev, "iicbus write failed\n"); + return (-1); + } + pause("lm75_write", hz); + } +} + +static int +lm75_probe(device_t dev) +{ + + if (!ofw_bus_is_compatible(dev, "lm75")) + return (ENXIO); + + device_set_desc(dev, "LM75 temperature sensor"); + + return (BUS_PROBE_GENERIC); +} + +static int +lm75_attach(device_t dev) +{ + struct lm75_softc *sc; + + sc = device_get_softc(dev); + sc->sc_dev = dev; + sc->sc_addr = iicbus_get_addr(dev); + + sc->enum_hook.ich_func = lm75_start; + sc->enum_hook.ich_arg = dev; + + /* + * We have to wait until interrupts are enabled. I2C read and write + * only works if the interrupts are available. + */ + if (config_intrhook_establish(&sc->enum_hook) != 0) + return (ENOMEM); + + return (0); +} + +static void +lm75_start(void *xdev) +{ + device_t dev; + struct lm75_softc *sc; + struct sysctl_ctx_list *ctx; + struct sysctl_oid *conf_node, *tree_node; + struct sysctl_oid_list *conf_tree, *tree; + + dev = (device_t)xdev; + sc = device_get_softc(dev); + ctx = device_get_sysctl_ctx(dev); + tree_node = device_get_sysctl_tree(dev); + tree = SYSCTL_CHILDREN(tree_node); + + config_intrhook_disestablish(&sc->enum_hook); + + /* Read the configuration register. */ + if (lm75_conf_read(sc) != 0) { + device_printf(dev, "cannot read the configuration register.\n"); + return; + } + + SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temperature", + CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, LM75_TEMP, + lm75_temp_sysctl, "IK", "Current temperature"); + SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "thyst", + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, LM75_THYST, + lm75_temp_sysctl, "IK", "Hysteresis temperature"); + SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "tos", + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, LM75_TOS, + lm75_temp_sysctl, "IK", "Overtemperature"); + + conf_node = SYSCTL_ADD_NODE(ctx, tree, OID_AUTO, "conf", + CTLFLAG_RD, NULL, "LM75 configuration"); + conf_tree = SYSCTL_CHILDREN(conf_node); + + SYSCTL_ADD_PROC(ctx, conf_tree, OID_AUTO, "faults", + CTLFLAG_RW | CTLTYPE_UINT, dev, 0, + lm75_faults_sysctl, "IU", "LM75 fault queue"); + SYSCTL_ADD_PROC(ctx, conf_tree, OID_AUTO, "mode", + CTLFLAG_RW | CTLTYPE_STRING, dev, 0, + lm75_mode_sysctl, "A", "LM75 mode"); + SYSCTL_ADD_PROC(ctx, conf_tree, OID_AUTO, "polarity", + CTLFLAG_RW | CTLTYPE_STRING, dev, 0, + lm75_pol_sysctl, "A", "LM75 OS polarity"); + SYSCTL_ADD_PROC(ctx, conf_tree, OID_AUTO, "shutdown", + CTLFLAG_RW | CTLTYPE_UINT, dev, 0, + lm75_shutdown_sysctl, "IU", "LM75 shutdown"); +} + +static int +lm75_conf_read(struct lm75_softc *sc) +{ + uint8_t buf8; + + if (lm75_read(sc->sc_dev, sc->sc_addr, LM75_CONF, &buf8, 1) < 0) + return (-1); + + sc->sc_conf = (uint32_t)buf8; + + return (0); +} + +static int +lm75_conf_write(struct lm75_softc *sc) +{ + uint8_t buf8[2]; + + buf8[0] = LM75_CONF; + buf8[1] = (uint8_t)sc->sc_conf & LM75_CONF_MASK; + + if (lm75_write(sc->sc_dev, sc->sc_addr, buf8, 2) < 0) + return (-1); + + return (0); +} + +static int +lm75_temp_read(struct lm75_softc *sc, uint8_t reg, int *temp) +{ + uint8_t buf8[2]; + uint16_t buf; + + if (lm75_read(sc->sc_dev, sc->sc_addr, reg, buf8, 2) < 0) + return (-1); + + buf = (buf8[0] << 8) | (buf8[1] & 0xff); + + /* + * LM75 has 9 bit ADC with resolution of 0.5 C per bit. Temperature is + * stored with two's complement. + */ + if (buf & LM75_NEG_BIT) + buf = ~buf + 1; + *temp = ((int16_t)buf >> 8) * 10; + if (buf & LM75_LSB) + *temp += 5; + if (buf & LM75_NEG_BIT) + *temp = -(*temp); + *temp += TZ_ZEROC; + + return (0); +} + +static int +lm75_temp_write(struct lm75_softc *sc, uint8_t reg, int temp) +{ + uint8_t buf8[3]; + uint16_t buf; + + if (temp > LM75_MAX_TEMP) + temp = LM75_MAX_TEMP; + if (temp < LM75_MIN_TEMP) + temp = LM75_MIN_TEMP; + + buf = (uint16_t)temp; + buf <<= 8; + + buf8[0] = reg; + buf8[1] = buf >> 8; + buf8[2] = buf & 0xff; + + if (lm75_write(sc->sc_dev, sc->sc_addr, buf8, 3) < 0) + return (-1); + + return (0); +} + +static int +lm75_str_mode(char *buf) +{ + int len, rtrn; + + rtrn = -1; + len = strlen(buf); + if (len > 2 && strncasecmp("interrupt", buf, len) == 0) + rtrn = 1; + else if (len > 2 && strncasecmp("comparator", buf, len) == 0) + rtrn = 0; + + return (rtrn); +} +static int +lm75_str_pol(char *buf) +{ + int len, rtrn; + + rtrn = -1; + len = strlen(buf); + if (len > 1 && strncasecmp("high", buf, len) == 0) + rtrn = 1; + else if (len > 1 && strncasecmp("low", buf, len) == 0) + rtrn = 0; + else if (len > 8 && strncasecmp("active-high", buf, len) == 0) + rtrn = 1; + else if (len > 8 && strncasecmp("active-low", buf, len) == 0) + rtrn = 0; + + return (rtrn); +} + +static int +lm75_temp_sysctl(SYSCTL_HANDLER_ARGS) +{ + device_t dev; + int error, temp; + struct lm75_softc *sc; + uint8_t reg; + + dev = arg1; + reg = arg2; + sc = device_get_softc(dev); + + if (lm75_temp_read(sc, reg, &temp) != 0) + return (EIO); + + error = sysctl_handle_int(oidp, &temp, 0, req); + if (error != 0 || req->newptr == NULL) + return (error); + + if (lm75_temp_write(sc, reg, temp) != 0) + return (EIO); + + return (error); +} + +static int +lm75_faults_sysctl(SYSCTL_HANDLER_ARGS) +{ + device_t dev; + int error, faults, i, newf, tmp; + struct lm75_softc *sc; + + dev = arg1; + sc = device_get_softc(dev); + tmp = (sc->sc_conf & LM75_CONF_FAULT) >> LM75_CONF_FSHIFT; + if (tmp > nitems(lm75_faults)) + tmp = nitems(lm75_faults); + faults = lm75_faults[tmp]; + + error = sysctl_handle_int(oidp, &faults, 0, req); + if (error != 0 || req->newptr == NULL) + return (error); + + if (faults != lm75_faults[tmp]) { + newf = 0; + for (i = 0; i < nitems(lm75_faults); i++) + if (faults >= lm75_faults[i]) + newf = i; + sc->sc_conf &= ~LM75_CONF_FAULT; + sc->sc_conf |= newf << LM75_CONF_FSHIFT; + if (lm75_conf_write(sc) != 0) + return (EIO); + } + + return (error); +} + +static int +lm75_mode_sysctl(SYSCTL_HANDLER_ARGS) +{ + char buf[16]; + device_t dev; + int error, mode, newm; + struct lm75_softc *sc; + + dev = arg1; + sc = device_get_softc(dev); + if (sc->sc_conf & LM75_CONF_MODE) { + mode = 1; + strlcpy(buf, "interrupt", sizeof(buf)); + } else { + mode = 0; + strlcpy(buf, "comparator", sizeof(buf)); + } + + error = sysctl_handle_string(oidp, buf, sizeof(buf), req); + if (error != 0 || req->newptr == NULL) + return (error); + + newm = lm75_str_mode(buf); + if (newm != -1 && mode != newm) { + sc->sc_conf &= ~LM75_CONF_MODE; + if (newm == 1) + sc->sc_conf |= LM75_CONF_MODE; + if (lm75_conf_write(sc) != 0) + return (EIO); + } + + return (error); +} + +static int +lm75_pol_sysctl(SYSCTL_HANDLER_ARGS) +{ + char buf[16]; + device_t dev; + int error, newp, pol; + struct lm75_softc *sc; + + dev = arg1; + sc = device_get_softc(dev); + if (sc->sc_conf & LM75_CONF_POL) { + pol = 1; + strlcpy(buf, "active-high", sizeof(buf)); + } else { + pol = 0; + strlcpy(buf, "active-low", sizeof(buf)); + } + + error = sysctl_handle_string(oidp, buf, sizeof(buf), req); + if (error != 0 || req->newptr == NULL) + return (error); + + newp = lm75_str_pol(buf); + if (newp != -1 && pol != newp) { + sc->sc_conf &= ~LM75_CONF_POL; + if (newp == 1) + sc->sc_conf |= LM75_CONF_POL; + if (lm75_conf_write(sc) != 0) + return (EIO); + } + + return (error); +} + +static int +lm75_shutdown_sysctl(SYSCTL_HANDLER_ARGS) +{ + device_t dev; + int error, shutdown, tmp; + struct lm75_softc *sc; + + dev = arg1; + sc = device_get_softc(dev); + tmp = shutdown = (sc->sc_conf & LM75_CONF_SHUTD) ? 1 : 0; + + error = sysctl_handle_int(oidp, &shutdown, 0, req); + if (error != 0 || req->newptr == NULL) + return (error); + + if (shutdown != tmp) { + sc->sc_conf &= ~LM75_CONF_SHUTD; + if (shutdown) + sc->sc_conf |= LM75_CONF_SHUTD; + if (lm75_conf_write(sc) != 0) + return (EIO); + } + + return (error); +} --Apple-Mail=_13A74922-970E-4308-9EC5-22D6556CBCE5-- From owner-freebsd-embedded@FreeBSD.ORG Fri Nov 29 22:38:28 2013 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 87984D60 for ; Fri, 29 Nov 2013 22:38:28 +0000 (UTC) Received: from mail-qa0-x230.google.com (mail-qa0-x230.google.com [IPv6:2607:f8b0:400d:c00::230]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 45BED135B for ; Fri, 29 Nov 2013 22:38:28 +0000 (UTC) Received: by mail-qa0-f48.google.com with SMTP id w5so2326131qac.7 for ; Fri, 29 Nov 2013 14:38:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=hxw8J2N0NEgkhDpw2+l1+InKB4HCeE/Dw4/SHGr0rWo=; b=fY4RUJ3MeHv3KcW6U8uwouD6IlmzLSJQISGbnYnGubQ6d2rw8tj6j2E9hui3KyqOtI AMidwNmWxi8UUNmSVEp33k1DR+QaXQcDsv6pk9CaqhAn5xO1U9Wyo1IEA5qVB+FvIPQY urPPV7kB1B/s9QgzEphSlzUZivqTvkzocX8axKGKL2NCVDopmer7w2s6iNTK70hXICBa jXhEDzthgFO+3Ap09nYx3V2dU3Nd2Tb0x7MdGZB2rSiZjvlIPb1rZCB3H9BQLFoixLn8 8vzt58tL1D+nWXTG1e5G9vSWDuVPI7I9rq2a633DxshvBCY4VnwQ/DWEaU5YEXlj+XkN CDMQ== MIME-Version: 1.0 X-Received: by 10.49.35.144 with SMTP id h16mr90922504qej.35.1385764707150; Fri, 29 Nov 2013 14:38:27 -0800 (PST) Sender: adrian.chadd@gmail.com Received: by 10.224.53.200 with HTTP; Fri, 29 Nov 2013 14:38:27 -0800 (PST) In-Reply-To: <69CF7423-FD5B-44B3-8B90-E76BA96BB31A@gmail.com> References: <69CF7423-FD5B-44B3-8B90-E76BA96BB31A@gmail.com> Date: Fri, 29 Nov 2013 14:38:27 -0800 X-Google-Sender-Auth: 7yeUtTAuo8572sLyJLhwWCD34go Message-ID: Subject: Re: [patch] LM75 kernel driver From: Adrian Chadd To: Luiz Otavio O Souza Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: "freebsd-embedded@freebsd.org" X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Nov 2013 22:38:28 -0000 Hi! Have you run this on the very latest -HEAD? -adrian On 29 November 2013 11:28, Luiz Otavio O Souza wrote: > Hi, > > I=92ve written a kernel driver for lm75 (i2c temperature sensor). > > It=92s a very simple, convenient and cheap way to verify an i2c bus. > > This driver provides full control of the lm75 registers (configuration bi= ts, over temperature and hysteresis settings) and so provides basic read an= d write test abilities. > > The high resolution version (lm75b - 11 bits) isn=92t supported ATM, but = i have plans to do so. > > On my RPi i=92ve added this to sys/boot/fdt/dts/rpi.dts: > > bsc0 { > > lm750 { > compatible =3D "lm75"; > i2c-address =3D <0x96>; > }; > > lm751 { > compatible =3D "lm75"; > i2c-address =3D <0x9e>; > }; > }; > > And =91device lm75=92 to RPI-B kernel file (after apply the attached patc= h). > > Here is the result: > > iichb0: mem 0x20205000-0x2020501f irq 61 on= simplebus0 > iicbus1: on iichb0 > iic1: on iicbus1 > lm751: at addr 0x96 on iicbus1 > lm752: at addr 0x9e on iicbus1 > > # sysctl dev.lm75.1 > dev.lm75.1.%desc: LM75 temperature sensor > dev.lm75.1.%driver: lm75 > dev.lm75.1.%location: addr=3D0x96 > dev.lm75.1.%pnpinfo: name=3Dlm750 compat=3Dlm75 > dev.lm75.1.%parent: iicbus1 > dev.lm75.1.temperature: 30.0C > dev.lm75.1.thyst: 75.0C > dev.lm75.1.tos: 80.0C > dev.lm75.1.conf.faults: 1 > dev.lm75.1.conf.mode: comparator > dev.lm75.1.conf.polarity: active-low > dev.lm75.1.conf.shutdown: 0 > > # sysctl dev.lm75.2 > dev.lm75.2.%desc: LM75 temperature sensor > dev.lm75.2.%driver: lm75 > dev.lm75.2.%location: addr=3D0x9e > dev.lm75.2.%pnpinfo: name=3Dlm751 compat=3Dlm75 > dev.lm75.2.%parent: iicbus1 > dev.lm75.2.temperature: 29.5C > dev.lm75.2.thyst: 60.0C > dev.lm75.2.tos: 80.0C > dev.lm75.2.conf.faults: 2 > dev.lm75.2.conf.mode: interrupt > dev.lm75.2.conf.polarity: active-low > dev.lm75.2.conf.shutdown: 0 > > > I hope this may be useful for someone else. > > Luiz > > > > _______________________________________________ > freebsd-embedded@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-embedded > To unsubscribe, send any mail to "freebsd-embedded-unsubscribe@freebsd.or= g"