find the greatest weight that can be added to $B$ before $B$ starts to descend. 
A light rope $AB$ passes over a rough circular cylinder, which is fixed with its axis horizontal. Bodies of
weights $M$ and $m$ are attached at $A$ and $B$ respectively so that the ends of the rope hang in a vertical plane
perpendicular to the axis of the cylinder. If $A$ is about to descend, find the greatest weight that can be added to $B$ before $B$ starts to descend.

Here what I tried  but some parts not sure. (Here $T$=tension, $s$ =arc length,$\varphi$= the angle that the tangent to the curve ,R=reaction from the cylinder)

First I consider when  $A$ is about to descend, and  derive two equation
$$\frac{dT}{ds}=\mu R \space\space \text{and} \space\space R\frac{ds}{d\varphi}=T$$ by solving I got $\ln(T)=\mu \varphi+c$ where c is arbitary constant.
Since at $\varphi=\pi/2$ , $T=M$ so
$$ \ln\big{(}\frac{T}{M} \big{)}=\mu\varphi-\frac{\mu \pi }{2}$$
At $\varphi=-\pi/2$ ,$T=m$ therefore
$$\ln \big( \frac{m}{M}\big{)}=-\mu \pi $$
Similarly for the second case I got $\ln \big( \frac{m+w}{M}\big{)}=\mu \pi $ so
finally $w=\frac{M^2-m^2}{m}$
Can anyone verify my answer? Is there anything wrong here?
 A: This looks correct. The equations for equilibrium can be derived by looking at a small piece of rope of length $ds$ somewhere along the circle centered at some angle $\phi$ with $\phi=0$ at the attachment point of mass $m$. Suppose $M>m$ and $M$ is hanging on the left side. Friction forces then should be pointing counterclockwise. Denote $T_2$ the force exerted at the right side of the segment and $T_2$ the force on the left side of the segment. Then we can write
$$T_1=-T(s-ds/2)\hat{t}(s-ds/2)=-T(s)\hat{t}(s)+\frac{ds}{2}\left(T(s)\hat{n}(s)\left\|\frac{d\hat{t}}{ds}\right\|+\frac{dT}{ds}\hat{t}(s)\right)$$
$$T_2=T(s+ds/2)\hat{t}(s+ds/2)=T(s)\hat{t}(s)+\frac{ds}{2}\left(T(s)\hat{n}(s)\left\|\frac{d\hat{t}}{ds}\right\|+\frac{dT}{ds}\hat{t}(s)\right)$$
where we have defined per considerations of differential geometry the unit tangent vector along the circle $\hat{t}$ and the normal vector $\kappa(s)\hat{n}(s)=d\hat t/ds$, where $\kappa$ is the curvature, $\kappa(s)=\|d\hat t/ds\|$. Since the normal force is defined to be $N=R(s)\hat n(s)ds$ and the limiting friction force $f=\mu R(s)\hat t (s)ds$, setting the sum of forces equal to zero we deduce the equations
$$R(s)=\kappa(s)T(s)$$
$$ \frac{dT(s)}{ds}=\mu R(s)$$
For a circle with radius $R_0$, $\phi=s/R_0~,~\kappa=1/R_0$ and therefore by substituting the first equation into the second and solving we obtain that
$$T(s)=T(s=0)e^{\mu\phi}$$
and by the initial and final conditions we obtain
$$M=me^{\mu\pi}$$
This fixes a relation between the two masses. To reverse the situation we need $w<M-m$ such that $m+w>M$, but then the relation between the new masses is fixed by the same relation with the appropriate swapping:
$$m+w=Me^{\mu\pi}$$
which yields that the mass to be added is, independently of how big the friction coefficient is
$$w=\frac{M^2-m^2}{m}$$
